Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -28,6 +28,9 @@ def parse_args(): · 27 unmodified lines | |||
| 28 | parser.add_option("-t","--threshold", | 28 | parser.add_option("-t","--threshold", |
| 29 | action="store", dest="threshold", default=0.650, | 29 | action="store", dest="threshold", default=0.650, |
| 30 | help="onset peak picking threshold [default=0.650]") | 30 | help="onset peak picking threshold [default=0.650]") |
| 31 | parser.add_option("-C","--dcthreshold", | ||
| 32 | action="store", dest="dcthreshold", default=-1., | ||
| 33 | help="onset peak picking DC component [default=-1.]") | ||
| 31 | parser.add_option("-s","--silence", | 34 | parser.add_option("-s","--silence", |
| 32 | action="store", dest="silence", default=-70, | 35 | action="store", dest="silence", default=-70, |
| 33 | help="silence threshold [default=-70]") | 36 | help="silence threshold [default=-70]") |
| @@ -58,6 +61,12 @@ def parse_args(): · 24 unmodified lines | |||
| 58 | parser.add_option("-p","--plot", | 61 | parser.add_option("-p","--plot", |
| 59 | action="store_true", dest="plot", default=False, | 62 | action="store_true", dest="plot", default=False, |
| 60 | help="draw plot") | 63 | help="draw plot") |
| 64 | parser.add_option("-f","--function", | ||
| 65 | action="store_true", dest="func", default=False, | ||
| 66 | help="print detection function") | ||
| 67 | parser.add_option("-n","--no-onsets", | ||
| 68 | action="store_true", dest="nplot", default=False, | ||
| 69 | help="plot only detection functions") | ||
| 61 | parser.add_option("-O","--outplot", | 70 | parser.add_option("-O","--outplot", |
| 62 | action="store", dest="outplot", default=None, | 71 | action="store", dest="outplot", default=None, |
| 63 | help="save plot to output.{ps,png}") | 72 | help="save plot to output.{ps,png}") |
| @@ -84,66 +93,44 @@ params = taskparams() · 20 unmodified lines | |||
| 84 | params.hopsize = int(options.hopsize) | 93 | params.hopsize = int(options.hopsize) |
| 85 | params.bufsize = int(options.bufsize) | 94 | params.bufsize = int(options.bufsize) |
| 86 | params.threshold = float(options.threshold) | 95 | params.threshold = float(options.threshold) |
| 96 | params.dcthreshold = float(options.dcthreshold) | ||
| 87 | params.zerothres = float(options.zerothres) | 97 | params.zerothres = float(options.zerothres) |
| 88 | params.silence = float(options.silence) | 98 | params.silence = float(options.silence) |
| 89 | params.mintol = float(options.mintol) | 99 | params.mintol = float(options.mintol) |
| 100 | params.verbose = options.verbose | ||
| 90 | # default take back system delay | 101 | # default take back system delay |
| 91 | if options.delay: delay = float(options.delay) | 102 | if options.delay: params.delay = int(float(options.delay)/params.step) |
| 92 | else: delay = 3./params.step | ||
| 93 | 103 | ||
| 104 | dotask = taskonset | ||
| 105 | if options.beat: | ||
| 106 | dotask = taskbeat | ||
| 107 | elif options.silencecut: | ||
| 108 | dotask = tasksilence | ||
| 109 | elif options.plot or options.func: | ||
| 110 | params.storefunc=True | ||
| 111 | else: | ||
| 112 | params.storefunc=False | ||
| 94 | 113 | ||
| 95 | lonsets, lofunc = [], [] | 114 | lonsets, lofunc = [], [] |
| 115 | wplot,oplots = [],[] | ||
| 96 | modes = options.mode.split(',') | 116 | modes = options.mode.split(',') |
| 97 | for i in range(len(modes)): | 117 | for i in range(len(modes)): |
| 98 | |||
| 99 | params.onsetmode = modes[i] | 118 | params.onsetmode = modes[i] |
| 100 | dotask = taskonset | ||
| 101 | if options.beat: | ||
| 102 | dotask = taskbeat | ||
| 103 | elif options.silencecut: | ||
| 104 | dotask = tasksilence | ||
| 105 | elif options.plot: | ||
| 106 | params.storefunc=True | ||
| 107 | else: | ||
| 108 | params.storefunc=False | ||
| 109 | filetask = dotask(filename,params=params) | 119 | filetask = dotask(filename,params=params) |
| 110 | onsets = filetask.compute_all() | 120 | onsets = filetask.compute_all() |
| 111 | if not options.silencecut: | ||
| 112 | ofunc = filetask.ofunc | ||
| 113 | #onsets, ofunc = getonsets(filename,threshold,silence, | ||
| 114 | # mode=mode[i],localmin=options.localmin, | ||
| 115 | # derivate=options.derivate, | ||
| 116 | # bufsize=bufsize,hopsize=hopsize,storefunc=True) | ||
| 117 | |||
| 118 | # take back system delay | ||
| 119 | if delay != 0: | ||
| 120 | for each in range(len(onsets)): | ||
| 121 | onsets[each] = onsets[each][0] - delay*params.step | ||
| 122 | 121 | ||
| 123 | # prune doubled | 122 | #lonsets.append(onsets) |
| 124 | params.mintol *= params.step | ||
| 125 | if params.mintol > 0: | ||
| 126 | last = -2*params.mintol | ||
| 127 | newonsets = [] | ||
| 128 | for new in onsets: | ||
| 129 | if (new - last > params.mintol): | ||
| 130 | newonsets.append(new) | ||
| 131 | last = new | ||
| 132 | onsets = newonsets | ||
| 133 | |||
| 134 | lonsets.append(onsets) | ||
| 135 | if not options.silencecut: | 123 | if not options.silencecut: |
| 124 | ofunc = filetask.ofunc | ||
| 136 | lofunc.append(ofunc) | 125 | lofunc.append(ofunc) |
| 137 | 126 | ||
| 138 | # print times in second | 127 | if options.plot: filetask.plot(onsets, ofunc, wplot, oplots, nplot=options.nplot) |
| 139 | if options.verbose: | 128 | |
| 140 | #print modes[i] | 129 | if options.func: |
| 141 | for i in range(len(onsets)): | 130 | for i in ofunc: |
| 142 | print onsets[i]*params.step | 131 | print i |
| 143 | 132 | ||
| 144 | if options.plot: | 133 | if options.plot: filetask.plotplot(wplot, oplots, outplot=options.outplot) |
| 145 | filetask.plot(onsets, ofunc) | ||
| 146 | filetask.plotplot(outplot=options.outplot) | ||
| 147 | 134 | ||
| 148 | if options.cut: | 135 | if options.cut: |
| 149 | a = taskcut(filename,onsets,params=params) | 136 | a = taskcut(filename,onsets,params=params) |