[96fb8ad] | 1 | #!/usr/bin/python |
---|
| 2 | |
---|
[d4a0cc4] | 3 | """ this file was written by Paul Brossier |
---|
| 4 | it is released under the GNU/GPL license. |
---|
| 5 | """ |
---|
| 6 | |
---|
| 7 | import sys |
---|
[13c3fba] | 8 | from aubio.task import * |
---|
[d4a0cc4] | 9 | |
---|
| 10 | usage = "usage: %s [options] -i soundfile" % sys.argv[0] |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | def parse_args(): |
---|
| 14 | from optparse import OptionParser |
---|
| 15 | parser = OptionParser(usage=usage) |
---|
| 16 | parser.add_option("-i","--input", |
---|
| 17 | action="store", dest="filename", |
---|
| 18 | help="input sound file") |
---|
[d9101a5] | 19 | parser.add_option("-m","--mode", |
---|
| 20 | action="store", dest="mode", default='mcomb', |
---|
[97b8c3d] | 21 | help="pitch detection mode [default=mcomb] \ |
---|
[d4a0cc4] | 22 | mcomb|yin|fcomb|schmitt") |
---|
[aa17581] | 23 | parser.add_option("-u","--units", action="callback", |
---|
| 24 | callback=check_pitchm_mode, dest="omode", |
---|
| 25 | default=aubio_pitchm_freq, |
---|
| 26 | help="output pitch in units [default=Hz] \ |
---|
| 27 | freq|midi|cent|bin") |
---|
[d4a0cc4] | 28 | parser.add_option("-B","--bufsize", |
---|
[aa17581] | 29 | action="store", dest="bufsize", default=None, |
---|
[d4a0cc4] | 30 | help="buffer size [default=1024]") |
---|
| 31 | parser.add_option("-H","--hopsize", |
---|
[aa17581] | 32 | action="store", dest="hopsize", default=None, |
---|
[d4a0cc4] | 33 | help="overlap size [default=512]") |
---|
| 34 | parser.add_option("-t","--threshold", |
---|
| 35 | action="store", dest="threshold", default=0.1, |
---|
| 36 | help="pitch threshold (for yin) [default=0.1]") |
---|
| 37 | parser.add_option("-s","--silence", |
---|
| 38 | action="store", dest="silence", default=-70, |
---|
| 39 | help="silence threshold [default=-70]") |
---|
| 40 | parser.add_option("-D","--delay", |
---|
| 41 | action="store", dest="delay", |
---|
| 42 | help="number of seconds to take back [default=system]\ |
---|
| 43 | default system delay is 2*hopsize/samplerate") |
---|
| 44 | parser.add_option("-L","--localmin", |
---|
| 45 | action="store_true", dest="localmin", default=False, |
---|
| 46 | help="use local minima after peak detection") |
---|
| 47 | parser.add_option("-c","--cut", |
---|
| 48 | action="store_true", dest="cut", default=False, |
---|
| 49 | help="cut input sound file at detected labels \ |
---|
| 50 | best used with option -L") |
---|
| 51 | # to be implemented |
---|
| 52 | parser.add_option("-n","--note", |
---|
| 53 | action="store_true", dest="note", default=False, |
---|
| 54 | help="NOT IMPLEMENTED output notes") |
---|
| 55 | # plotting functions |
---|
| 56 | parser.add_option("-p","--plot", |
---|
| 57 | action="store_true", dest="plot", default=False, |
---|
| 58 | help="NOT IMPLEMENTED draw plot") |
---|
| 59 | parser.add_option("-O","--outplot", |
---|
| 60 | action="store", dest="outplot", default=None, |
---|
| 61 | help="NOT IMPLEMENTED save plot to output.{ps,png}") |
---|
| 62 | parser.add_option("-v","--verbose", |
---|
| 63 | action="store_true", dest="verbose", default=False, |
---|
| 64 | help="make lots of noise [default]") |
---|
| 65 | parser.add_option("-q","--quiet", |
---|
| 66 | action="store_false", dest="verbose", default=False, |
---|
| 67 | help="be quiet") |
---|
| 68 | (options, args) = parser.parse_args() |
---|
[aa17581] | 69 | if not options.bufsize: |
---|
| 70 | if options.mode == aubio_pitch_yin: options.bufsize = 1024 |
---|
| 71 | if options.mode == aubio_pitch_schmitt: options.bufsize = 2048 |
---|
| 72 | if options.mode == aubio_pitch_mcomb: options.bufsize = 4096 |
---|
| 73 | if options.mode == aubio_pitch_fcomb: options.bufsize = 4096 |
---|
[5e491b3b] | 74 | else: options.bufsize = 2048 |
---|
[aa17581] | 75 | if not options.hopsize: |
---|
| 76 | options.hopsize = float(options.bufsize) / 2 |
---|
[d4a0cc4] | 77 | if not options.filename: |
---|
[aa17581] | 78 | print "no file name given\n", usage |
---|
| 79 | sys.exit(1) |
---|
[d4a0cc4] | 80 | return options, args |
---|
| 81 | |
---|
| 82 | options, args = parse_args() |
---|
| 83 | |
---|
[aa17581] | 84 | #print options.bufsize, options.hopsize |
---|
| 85 | |
---|
[d4a0cc4] | 86 | filename = options.filename |
---|
[d9101a5] | 87 | params = taskparams() |
---|
[0fe9aab] | 88 | params.samplerate = float(sndfile(filename).samplerate()) |
---|
[d9101a5] | 89 | params.hopsize = int(options.hopsize) |
---|
| 90 | params.bufsize = int(options.bufsize) |
---|
[0fe9aab] | 91 | params.step = params.samplerate/float(params.hopsize) |
---|
[d9101a5] | 92 | params.threshold = float(options.threshold) |
---|
| 93 | params.silence = float(options.silence) |
---|
[0fe9aab] | 94 | params.verbose = options.verbose |
---|
[d4a0cc4] | 95 | #mintol = float(options.mintol)*step |
---|
| 96 | # default take back system delay |
---|
| 97 | if options.delay: delay = float(options.delay) |
---|
[d9101a5] | 98 | else: delay = 2./params.step |
---|
[d4a0cc4] | 99 | |
---|
| 100 | if options.note: |
---|
| 101 | exit("not implemented yet") |
---|
| 102 | |
---|
| 103 | |
---|
[0fe9aab] | 104 | wplot,oplots = [],[] |
---|
[d9101a5] | 105 | modes = options.mode.split(',') |
---|
| 106 | for i in range(len(modes)): |
---|
[0fe9aab] | 107 | pitch = [] |
---|
[d9101a5] | 108 | params.pitchmode = modes[i] |
---|
[0fe9aab] | 109 | filetask = taskpitch(filename,params=params) |
---|
| 110 | pitch = filetask.compute_all() |
---|
| 111 | #print filetask.eval(pitch[i]) |
---|
[9610f0a] | 112 | if options.plot: filetask.plot(pitch,wplot,oplots) |
---|
[d4a0cc4] | 113 | |
---|
[9610f0a] | 114 | if options.plot: |
---|
| 115 | filetask.plotplot(wplot,oplots,outplot=options.outplot) |
---|