Changeset af98cb8 for python/lib/aubio
- Timestamp:
- Mar 24, 2017, 2:23:41 AM (8 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, sampler
- Children:
- 86026a0
- Parents:
- b7208f8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/lib/aubio/cmd.py
rb7208f8 raf98cb8 162 162 # some utilities 163 163 164 def parse_options(args, valid_opts):165 options = {k :v for k,v in vars(args).items() if k in valid_opts}166 return options167 168 def remap_pvoc_options(options):169 # remap buf_size to win_s, hop_size to hop_s170 # FIXME: adjust python/ext/py-phasevoc.c to understand buf_size/hop_size171 options['win_s'] = options['buf_size']172 del options['buf_size']173 options['hop_s'] = options['hop_size']174 del options['hop_size']175 return options176 177 164 def samples2seconds(n_frames, samplerate): 178 165 return "%f\t" % (n_frames / float(samplerate)) … … 205 192 sys.stderr.write(optstr) 206 193 def flush(self, n_frames, samplerate): 194 # optionally called at the end of process 207 195 pass 196 197 def parse_options(self, args, valid_opts): 198 # get any valid options found in a dictionnary of arguments 199 options = {k :v for k,v in vars(args).items() if k in valid_opts} 200 self.options = options 201 202 def remap_pvoc_options(self, options): 203 # FIXME: we need to remap buf_size to win_s, hop_size to hop_s 204 # adjust python/ext/py-phasevoc.c to understand buf_size/hop_size 205 if 'buf_size' in options: 206 options['win_s'] = options['buf_size'] 207 del options['buf_size'] 208 if 'hop_size' in options: 209 options['hop_s'] = options['hop_size'] 210 del options['hop_size'] 211 self.options = options 208 212 209 213 class process_onset(default_process): 210 214 valid_opts = ['method', 'hop_size', 'buf_size', 'samplerate'] 211 215 def __init__(self, args): 212 self. options =parse_options(args, self.valid_opts)216 self.parse_options(args, self.valid_opts) 213 217 self.onset = aubio.onset(**self.options) 214 218 if args.threshold is not None: … … 234 238 valid_opts = ['method', 'hop_size', 'buf_size', 'samplerate'] 235 239 def __init__(self, args): 236 self. options =parse_options(args, self.valid_opts)240 self.parse_options(args, self.valid_opts) 237 241 self.pitch = aubio.pitch(**self.options) 238 242 if args.threshold is not None: … … 250 254 valid_opts = ['method', 'hop_size', 'buf_size', 'samplerate'] 251 255 def __init__(self, args): 252 self. options =parse_options(args, self.valid_opts)256 self.parse_options(args, self.valid_opts) 253 257 self.tempo = aubio.tempo(**self.options) 254 258 super(process_beat, self).__init__(args) … … 276 280 valid_opts = ['method', 'hop_size', 'buf_size', 'samplerate'] 277 281 def __init__(self, args): 278 self. options =parse_options(args, self.valid_opts)282 self.parse_options(args, self.valid_opts) 279 283 self.notes = aubio.notes(**self.options) 280 284 super(process_notes, self).__init__(args) … … 296 300 class process_mfcc(default_process): 297 301 def __init__(self, args): 298 valid_opts = ['hop_size', 'buf_size'] 299 options = parse_options(args, valid_opts) 300 self.options = remap_pvoc_options(options) 301 self.pv = aubio.pvoc(**options) 302 303 valid_opts = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate'] 304 options = parse_options(args, valid_opts) 305 self.mfcc = aubio.mfcc(**options) 306 self.options.update(options) 302 valid_opts1 = ['hop_size', 'buf_size'] 303 self.parse_options(args, valid_opts1) 304 self.remap_pvoc_options(self.options) 305 self.pv = aubio.pvoc(**self.options) 306 307 valid_opts2 = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate'] 308 self.parse_options(args, valid_opts2) 309 self.mfcc = aubio.mfcc(**self.options) 310 311 # remember all options 312 self.parse_options(args, list(set(valid_opts1 + valid_opts2))) 307 313 308 314 super(process_mfcc, self).__init__(args) … … 320 326 self.args = args 321 327 valid_opts = ['hop_size', 'buf_size'] 322 options =parse_options(args, valid_opts)323 options = remap_pvoc_options(options)324 self.pv = aubio.pvoc(** options)328 self.parse_options(args, valid_opts) 329 self.remap_pvoc_options(self.options) 330 self.pv = aubio.pvoc(**self.options) 325 331 326 332 valid_opts = ['buf_size', 'n_filters'] 327 options = {k :v for k,v in vars(args).items() if k in valid_opts} 328 # FIXME 329 options['win_s'] = options['buf_size'] 330 del options['buf_size'] 331 self.filterbank = aubio.filterbank(**options) 333 self.parse_options(args, valid_opts) 334 self.remap_pvoc_options(self.options) 335 self.filterbank = aubio.filterbank(**self.options) 332 336 self.filterbank.set_mel_coeffs_slaney(args.samplerate) 333 337 … … 362 366 with aubio.source(args.source_uri, hop_size=args.hop_size, 363 367 samplerate=args.samplerate) as a_source: 368 # always update args.samplerate to native samplerate, in case 369 # source was opened with args.samplerate=0 364 370 args.samplerate = a_source.samplerate 365 371 # create the processor for this subcommand
Note: See TracChangeset
for help on using the changeset viewer.