Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -5,83 +5,86 @@ · 4 unmodified lines | ||
| 5 | 5 | """ |
| 6 | 6 | |
| 7 | 7 | import sys |
| 8 | +import warnings | |
| 8 | 9 | from aubio.cmd import AubioArgumentParser |
| 10 | +from aubio.slicing import slice_source_at_stamps | |
| 11 | + | |
| 9 | 12 | |
| 10 | 13 | def aubio_cut_parser(): |
| 11 | 14 | parser = AubioArgumentParser() |
| 12 | 15 | parser.add_input() |
| 13 | − parser.add_argument("-O","--onset-method", | |
| 16 | + parser.add_argument("-O", "--onset-method", | |
| 14 | 17 | action="store", dest="onset_method", default='default', |
| 15 | 18 | metavar = "<onset_method>", |
| 16 | 19 | help="onset detection method [default=default] \ |
| 17 | 20 | complexdomain|hfc|phase|specdiff|energy|kl|mkl") |
| 18 | 21 | # cutting methods |
| 19 | − parser.add_argument("-b","--beat", | |
| 22 | + parser.add_argument("-b", "--beat", | |
| 20 | 23 | action="store_true", dest="beat", default=False, |
| 21 | 24 | help="slice at beat locations") |
| 22 | 25 | """ |
| 23 | − parser.add_argument("-S","--silencecut", | |
| 26 | + parser.add_argument("-S", "--silencecut", | |
| 24 | 27 | action="store_true", dest="silencecut", default=False, |
| 25 | 28 | help="use silence locations") |
| 26 | − parser.add_argument("-s","--silence", | |
| 29 | + parser.add_argument("-s", "--silence", | |
| 27 | 30 | metavar = "<value>", |
| 28 | 31 | action="store", dest="silence", default=-70, |
| 29 | 32 | help="silence threshold [default=-70]") |
| 30 | 33 | """ |
| 31 | 34 | # algorithm parameters |
| 32 | 35 | parser.add_buf_hop_size() |
| 33 | − parser.add_argument("-t","--threshold", "--onset-threshold", | |
| 36 | + parser.add_argument("-t", "--threshold", "--onset-threshold", | |
| 34 | 37 | metavar = "<threshold>", type=float, |
| 35 | 38 | action="store", dest="threshold", default=0.3, |
| 36 | 39 | help="onset peak picking threshold [default=0.3]") |
| 37 | − parser.add_argument("-c","--cut", | |
| 40 | + parser.add_argument("-c", "--cut", | |
| 38 | 41 | action="store_true", dest="cut", default=False, |
| 39 | 42 | help="cut input sound file at detected labels") |
| 40 | 43 | parser.add_minioi() |
| 41 | 44 | |
| 42 | 45 | """ |
| 43 | − parser.add_argument("-D","--delay", | |
| 46 | + parser.add_argument("-D", "--delay", | |
| 44 | 47 | action = "store", dest = "delay", type = float, |
| 45 | 48 | metavar = "<seconds>", default=0, |
| 46 | 49 | help="number of seconds to take back [default=system]\ |
| 47 | 50 | default system delay is 3*hopsize/samplerate") |
| 48 | − parser.add_argument("-C","--dcthreshold", | |
| 51 | + parser.add_argument("-C", "--dcthreshold", | |
| 49 | 52 | metavar = "<value>", |
| 50 | 53 | action="store", dest="dcthreshold", default=1., |
| 51 | 54 | help="onset peak picking DC component [default=1.]") |
| 52 | − parser.add_argument("-L","--localmin", | |
| 55 | + parser.add_argument("-L", "--localmin", | |
| 53 | 56 | action="store_true", dest="localmin", default=False, |
| 54 | 57 | help="use local minima after peak detection") |
| 55 | − parser.add_argument("-d","--derivate", | |
| 58 | + parser.add_argument("-d", "--derivate", | |
| 56 | 59 | action="store_true", dest="derivate", default=False, |
| 57 | 60 | help="derivate onset detection function") |
| 58 | − parser.add_argument("-z","--zerocross", | |
| 61 | + parser.add_argument("-z", "--zerocross", | |
| 59 | 62 | metavar = "<value>", |
| 60 | 63 | action="store", dest="zerothres", default=0.008, |
| 61 | 64 | help="zero-crossing threshold for slicing [default=0.00008]") |
| 62 | 65 | # plotting functions |
| 63 | − parser.add_argument("-p","--plot", | |
| 66 | + parser.add_argument("-p", "--plot", | |
| 64 | 67 | action="store_true", dest="plot", default=False, |
| 65 | 68 | help="draw plot") |
| 66 | − parser.add_argument("-x","--xsize", | |
| 69 | + parser.add_argument("-x", "--xsize", | |
| 67 | 70 | metavar = "<size>", |
| 68 | 71 | action="store", dest="xsize", default=1., |
| 69 | 72 | type=float, help="define xsize for plot") |
| 70 | − parser.add_argument("-y","--ysize", | |
| 73 | + parser.add_argument("-y", "--ysize", | |
| 71 | 74 | metavar = "<size>", |
| 72 | 75 | action="store", dest="ysize", default=1., |
| 73 | 76 | type=float, help="define ysize for plot") |
| 74 | − parser.add_argument("-f","--function", | |
| 77 | + parser.add_argument("-f", "--function", | |
| 75 | 78 | action="store_true", dest="func", default=False, |
| 76 | 79 | help="print detection function") |
| 77 | − parser.add_argument("-n","--no-onsets", | |
| 80 | + parser.add_argument("-n", "--no-onsets", | |
| 78 | 81 | action="store_true", dest="nplot", default=False, |
| 79 | 82 | help="do not plot detected onsets") |
| 80 | − parser.add_argument("-O","--outplot", | |
| 83 | + parser.add_argument("-O", "--outplot", | |
| 81 | 84 | metavar = "<output_image>", |
| 82 | 85 | action="store", dest="outplot", default=None, |
| 83 | 86 | help="save plot to output.{ps,png}") |
| 84 | − parser.add_argument("-F","--spectrogram", | |
| 87 | + parser.add_argument("-F", "--spectrogram", | |
| 85 | 88 | action="store_true", dest="spectro", default=False, |
| 86 | 89 | help="add spectrogram to the plot") |
| 87 | 90 | """ |
| @@ -105,9 +108,11 @@ def _cut_analyze(options): · 17 unmodified lines | ||
| 105 | 108 | options.samplerate = samplerate |
| 106 | 109 | |
| 107 | 110 | if options.beat: |
| 108 | − o = tempo(options.onset_method, bufsize, hopsize, samplerate=samplerate) | |
| 111 | + o = tempo(options.onset_method, bufsize, hopsize, | |
| 112 | + samplerate=samplerate) | |
| 109 | 113 | else: |
| 110 | − o = onset(options.onset_method, bufsize, hopsize, samplerate=samplerate) | |
| 114 | + o = onset(options.onset_method, bufsize, hopsize, | |
| 115 | + samplerate=samplerate) | |
| 111 | 116 | if options.minioi: |
| 112 | 117 | if options.minioi.endswith('ms'): |
| 113 | 118 | o.set_minioi_ms(int(options.minioi[:-2])) |
| @@ -122,31 +127,36 @@ def _cut_analyze(options): · 8 unmodified lines | ||
| 122 | 127 | while True: |
| 123 | 128 | samples, read = s() |
| 124 | 129 | if o(samples): |
| 125 | − timestamps.append (o.get_last()) | |
| 126 | − if options.verbose: print ("%.4f" % o.get_last_s()) | |
| 130 | + timestamps.append(o.get_last()) | |
| 131 | + if options.verbose: | |
| 132 | + print("%.4f" % o.get_last_s()) | |
| 127 | 133 | total_frames += read |
| 128 | − if read < hopsize: break | |
| 134 | + if read < hopsize: | |
| 135 | + break | |
| 129 | 136 | del s |
| 130 | 137 | return timestamps, total_frames |
| 131 | 138 | |
| 139 | + | |
| 132 | 140 | def _cut_slice(options, timestamps): |
| 133 | 141 | # cutting pass |
| 134 | 142 | nstamps = len(timestamps) |
| 135 | 143 | if nstamps > 0: |
| 136 | 144 | # generate output files |
| 137 | − from aubio.slicing import slice_source_at_stamps | |
| 138 | 145 | timestamps_end = None |
| 139 | 146 | if options.cut_every_nslices: |
| 140 | 147 | timestamps = timestamps[::options.cut_every_nslices] |
| 141 | 148 | nstamps = len(timestamps) |
| 142 | 149 | if options.cut_until_nslices and options.cut_until_nsamples: |
| 143 | − print ("warning: using cut_until_nslices, but cut_until_nsamples is set") | |
| 150 | + msg = "using cut_until_nslices, but cut_until_nsamples is set" | |
| 151 | + warnings.warn(msg) | |
| 144 | 152 | if options.cut_until_nsamples: |
| 145 | − timestamps_end = [t + options.cut_until_nsamples for t in timestamps[1:]] | |
| 146 | − timestamps_end += [ 1e120 ] | |
| 153 | + lag = options.cut_until_nsamples | |
| 154 | + timestamps_end = [t + lag for t in timestamps[1:]] | |
| 155 | + timestamps_end += [1e120] | |
| 147 | 156 | if options.cut_until_nslices: |
| 148 | − timestamps_end = [t for t in timestamps[1 + options.cut_until_nslices:]] | |
| 149 | − timestamps_end += [ 1e120 ] * (options.cut_until_nslices + 1) | |
| 157 | + slice_lag = options.cut_until_nslices | |
| 158 | + timestamps_end = [t for t in timestamps[1 + slice_lag:]] | |
| 159 | + timestamps_end += [1e120] * (options.cut_until_nslices + 1) | |
| 150 | 160 | slice_source_at_stamps(options.source_uri, |
| 151 | 161 | timestamps, timestamps_end = timestamps_end, |
| 152 | 162 | output_dir = options.output_directory, |
| @@ -167,7 +177,7 @@ def main(): · 14 unmodified lines | ||
| 167 | 177 | timestamps, total_frames = _cut_analyze(options) |
| 168 | 178 | |
| 169 | 179 | # print some info |
| 170 | − duration = float (total_frames) / float(options.samplerate) | |
| 180 | + duration = float(total_frames) / float(options.samplerate) | |
| 171 | 181 | base_info = '%(source_uri)s' % {'source_uri': options.source_uri} |
| 172 | 182 | base_info += ' (total %(duration).2fs at %(samplerate)dHz)\n' % \ |
| 173 | 183 | {'duration': duration, 'samplerate': options.samplerate} |