Changeset c03d191 for python/lib/aubio/cut.py
- Timestamp:
- Nov 17, 2018, 10:19:27 PM (6 years ago)
- Branches:
- feature/constantq
- Children:
- d1d4ad4
- Parents:
- 088760e (diff), a114fe0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/lib/aubio/cut.py
r088760e rc03d191 6 6 7 7 import sys 8 from aubio.cmd import AubioArgumentParser 8 from aubio.cmd import AubioArgumentParser, _cut_slice 9 9 10 10 def aubio_cut_parser(): 11 11 parser = AubioArgumentParser() 12 12 parser.add_input() 13 parser.add_argument("-O", "--onset-method",13 parser.add_argument("-O", "--onset-method", 14 14 action="store", dest="onset_method", default='default', 15 15 metavar = "<onset_method>", … … 17 17 complexdomain|hfc|phase|specdiff|energy|kl|mkl") 18 18 # cutting methods 19 parser.add_argument("-b", "--beat",19 parser.add_argument("-b", "--beat", 20 20 action="store_true", dest="beat", default=False, 21 21 help="slice at beat locations") 22 22 """ 23 parser.add_argument("-S", "--silencecut",23 parser.add_argument("-S", "--silencecut", 24 24 action="store_true", dest="silencecut", default=False, 25 25 help="use silence locations") 26 parser.add_argument("-s", "--silence",26 parser.add_argument("-s", "--silence", 27 27 metavar = "<value>", 28 28 action="store", dest="silence", default=-70, … … 31 31 # algorithm parameters 32 32 parser.add_buf_hop_size() 33 parser.add_argument("-t", "--threshold", "--onset-threshold",33 parser.add_argument("-t", "--threshold", "--onset-threshold", 34 34 metavar = "<threshold>", type=float, 35 35 action="store", dest="threshold", default=0.3, 36 36 help="onset peak picking threshold [default=0.3]") 37 parser.add_argument("-c", "--cut",37 parser.add_argument("-c", "--cut", 38 38 action="store_true", dest="cut", default=False, 39 39 help="cut input sound file at detected labels") … … 41 41 42 42 """ 43 parser.add_argument("-D", "--delay",43 parser.add_argument("-D", "--delay", 44 44 action = "store", dest = "delay", type = float, 45 45 metavar = "<seconds>", default=0, 46 46 help="number of seconds to take back [default=system]\ 47 47 default system delay is 3*hopsize/samplerate") 48 parser.add_argument("-C", "--dcthreshold",48 parser.add_argument("-C", "--dcthreshold", 49 49 metavar = "<value>", 50 50 action="store", dest="dcthreshold", default=1., 51 51 help="onset peak picking DC component [default=1.]") 52 parser.add_argument("-L", "--localmin",52 parser.add_argument("-L", "--localmin", 53 53 action="store_true", dest="localmin", default=False, 54 54 help="use local minima after peak detection") 55 parser.add_argument("-d", "--derivate",55 parser.add_argument("-d", "--derivate", 56 56 action="store_true", dest="derivate", default=False, 57 57 help="derivate onset detection function") 58 parser.add_argument("-z", "--zerocross",58 parser.add_argument("-z", "--zerocross", 59 59 metavar = "<value>", 60 60 action="store", dest="zerothres", default=0.008, 61 61 help="zero-crossing threshold for slicing [default=0.00008]") 62 62 # plotting functions 63 parser.add_argument("-p", "--plot",63 parser.add_argument("-p", "--plot", 64 64 action="store_true", dest="plot", default=False, 65 65 help="draw plot") 66 parser.add_argument("-x", "--xsize",66 parser.add_argument("-x", "--xsize", 67 67 metavar = "<size>", 68 68 action="store", dest="xsize", default=1., 69 69 type=float, help="define xsize for plot") 70 parser.add_argument("-y", "--ysize",70 parser.add_argument("-y", "--ysize", 71 71 metavar = "<size>", 72 72 action="store", dest="ysize", default=1., 73 73 type=float, help="define ysize for plot") 74 parser.add_argument("-f", "--function",74 parser.add_argument("-f", "--function", 75 75 action="store_true", dest="func", default=False, 76 76 help="print detection function") 77 parser.add_argument("-n", "--no-onsets",77 parser.add_argument("-n", "--no-onsets", 78 78 action="store_true", dest="nplot", default=False, 79 79 help="do not plot detected onsets") 80 parser.add_argument("-O", "--outplot",80 parser.add_argument("-O", "--outplot", 81 81 metavar = "<output_image>", 82 82 action="store", dest="outplot", default=None, 83 83 help="save plot to output.{ps,png}") 84 parser.add_argument("-F", "--spectrogram",84 parser.add_argument("-F", "--spectrogram", 85 85 action="store_true", dest="spectro", default=False, 86 86 help="add spectrogram to the plot") … … 106 106 107 107 if options.beat: 108 o = tempo(options.onset_method, bufsize, hopsize, samplerate=samplerate) 108 o = tempo(options.onset_method, bufsize, hopsize, 109 samplerate=samplerate) 109 110 else: 110 o = onset(options.onset_method, bufsize, hopsize, samplerate=samplerate) 111 o = onset(options.onset_method, bufsize, hopsize, 112 samplerate=samplerate) 111 113 if options.minioi: 112 114 if options.minioi.endswith('ms'): … … 123 125 samples, read = s() 124 126 if o(samples): 125 timestamps.append (o.get_last()) 126 if options.verbose: print ("%.4f" % o.get_last_s()) 127 timestamps.append(o.get_last()) 128 if options.verbose: 129 print("%.4f" % o.get_last_s()) 127 130 total_frames += read 128 if read < hopsize: break 131 if read < hopsize: 132 break 129 133 del s 130 134 return timestamps, total_frames 131 132 def _cut_slice(options, timestamps):133 # cutting pass134 nstamps = len(timestamps)135 if nstamps > 0:136 # generate output files137 from aubio.slicing import slice_source_at_stamps138 timestamps_end = None139 if options.cut_every_nslices:140 timestamps = timestamps[::options.cut_every_nslices]141 nstamps = len(timestamps)142 if options.cut_until_nslices and options.cut_until_nsamples:143 print ("warning: using cut_until_nslices, but cut_until_nsamples is set")144 if options.cut_until_nsamples:145 timestamps_end = [t + options.cut_until_nsamples for t in timestamps[1:]]146 timestamps_end += [ 1e120 ]147 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)150 slice_source_at_stamps(options.source_uri,151 timestamps, timestamps_end = timestamps_end,152 output_dir = options.output_directory,153 samplerate = options.samplerate,154 create_first = options.create_first)155 135 156 136 def main(): … … 168 148 169 149 # print some info 170 duration = float 150 duration = float(total_frames) / float(options.samplerate) 171 151 base_info = '%(source_uri)s' % {'source_uri': options.source_uri} 172 152 base_info += ' (total %(duration).2fs at %(samplerate)dHz)\n' % \
Note: See TracChangeset
for help on using the changeset viewer.