Showing the changes to python (2 of 3 files). Show all
Unified · Split
| @@ -124,21 +124,35 @@ def check_onset_mode(option, opt, value, parser): · 123 unmodified lines | |||
| 124 | elif nvalue == 'dual' : | 124 | elif nvalue == 'dual' : |
| 125 | setattr(parser.values, option.dest, 'dual') | 125 | setattr(parser.values, option.dest, 'dual') |
| 126 | else: | 126 | else: |
| 127 | print "unknown detection function selected\n", usage | 127 | print "unknown onset detection function selected" |
| 128 | sys.exit(1) | 128 | sys.exit(1) |
| 129 | 129 | ||
| 130 | def check_pitch_mode(option, opt, value, parser): | 130 | def check_pitch_mode(option, opt, value, parser): |
| 131 | nvalue = parser.rargs[0] | 131 | nvalue = parser.rargs[0] |
| 132 | if nvalue == 'mcomb' : | 132 | if nvalue == 'mcomb' : |
| 133 | setattr(parser.values, option.dest, aubio_pitch_mcomb) | 133 | setattr(parser.values, option.dest, aubio_pitch_mcomb) |
| 134 | elif nvalue == 'yin' : | 134 | elif nvalue == 'yin' : |
| 135 | setattr(parser.values, option.dest, aubio_pitch_yin) | 135 | setattr(parser.values, option.dest, aubio_pitch_yin) |
| 136 | elif nvalue == 'fcomb' : | 136 | elif nvalue == 'fcomb' : |
| 137 | setattr(parser.values, option.dest, aubio_pitch_fcomb) | 137 | setattr(parser.values, option.dest, aubio_pitch_fcomb) |
| 138 | elif nvalue == 'schmitt' : | 138 | elif nvalue == 'schmitt': |
| 139 | setattr(parser.values, option.dest, aubio_pitch_schmitt) | 139 | setattr(parser.values, option.dest, aubio_pitch_schmitt) |
| 140 | else: | 140 | else: |
| 141 | print "unknown detection function selected\n", usage | 141 | print "error: unknown pitch detection function selected" |
| 142 | sys.exit(1) | ||
| 143 | |||
| 144 | def check_pitchm_mode(option, opt, value, parser): | ||
| 145 | nvalue = parser.rargs[0] | ||
| 146 | if nvalue == 'freq' : | ||
| 147 | setattr(parser.values, option.dest, aubio_pitchm_freq) | ||
| 148 | elif nvalue == 'midi' : | ||
| 149 | setattr(parser.values, option.dest, aubio_pitchm_midi) | ||
| 150 | elif nvalue == 'cent' : | ||
| 151 | setattr(parser.values, option.dest, aubio_pitchm_cent) | ||
| 152 | elif nvalue == 'bin' : | ||
| 153 | setattr(parser.values, option.dest, aubio_pitchm_bin) | ||
| 154 | else: | ||
| 155 | print "error: unknown pitch detection output selected" | ||
| 142 | sys.exit(1) | 156 | sys.exit(1) |
| 143 | 157 | ||
| 144 | 158 | ||
| @@ -191,7 +205,7 @@ def cutfile(filein,slicetimes,zerothres=0.008,bufsize=1024,hopsize=512): · 46 unmodified lines | |||
| 191 | filei = sndfile(filein) | 205 | filei = sndfile(filein) |
| 192 | framestep = hopsize/(filei.samplerate()+0.) | 206 | framestep = hopsize/(filei.samplerate()+0.) |
| 193 | channels = filei.channels() | 207 | channels = filei.channels() |
| 194 | newname = "%s%s%f%s%s" % (filein.split(".")[0].split("/")[-1],".", | 208 | newname = "%s%s%09.5f%s%s" % (filein.split(".")[0].split("/")[-1],".", |
| 195 | frameread*framestep,".",filein.split(".")[-1]) | 209 | frameread*framestep,".",filein.split(".")[-1]) |
| 196 | fileo = sndfile(newname,model=filei) | 210 | fileo = sndfile(newname,model=filei) |
| 197 | myvec = fvec(hopsize,channels) | 211 | myvec = fvec(hopsize,channels) |
| @@ -213,7 +227,7 @@ def cutfile(filein,slicetimes,zerothres=0.008,bufsize=1024,hopsize=512): · 15 unmodified lines | |||
| 213 | fromcross += 1 | 227 | fromcross += 1 |
| 214 | zerocross += 1 | 228 | zerocross += 1 |
| 215 | del fileo | 229 | del fileo |
| 216 | fileo = sndfile("%s%s%f%s%s" % | 230 | fileo = sndfile("%s%s%09.5f%s%s" % |
| 217 | (filein.split(".")[0].split("/")[-1],".", | 231 | (filein.split(".")[0].split("/")[-1],".", |
| 218 | frameread*framestep,".",filein.split(".")[-1]),model=filei) | 232 | frameread*framestep,".",filein.split(".")[-1]),model=filei) |
| 219 | writesize = fileo.write(fromcross,mycopy) | 233 | writesize = fileo.write(fromcross,mycopy) |
| @@ -260,7 +274,7 @@ def getpitch(filein,mode=aubio_pitch_mcomb,bufsize=1024,hopsize=512,omode=aubio_ · 40 unmodified lines | |||
| 260 | if (aubio_silence_detection(myvec(),silence)!=1): | 274 | if (aubio_silence_detection(myvec(),silence)!=1): |
| 261 | mylist.append(freq) | 275 | mylist.append(freq) |
| 262 | else: | 276 | else: |
| 263 | mylist.append(0) | 277 | mylist.append(-1.) |
| 264 | frameread += 1 | 278 | frameread += 1 |
| 265 | return mylist | 279 | return mylist |
| 266 | 280 | ||
| @@ -22,11 +22,16 @@ def parse_args(): · 21 unmodified lines | |||
| 22 | default=aubio_pitch_mcomb, | 22 | default=aubio_pitch_mcomb, |
| 23 | help="pitch detection mode [default=mcomb] \ | 23 | help="pitch detection mode [default=mcomb] \ |
| 24 | mcomb|yin|fcomb|schmitt") | 24 | mcomb|yin|fcomb|schmitt") |
| 25 | parser.add_option("-u","--units", action="callback", | ||
| 26 | callback=check_pitchm_mode, dest="omode", | ||
| 27 | default=aubio_pitchm_freq, | ||
| 28 | help="output pitch in units [default=Hz] \ | ||
| 29 | freq|midi|cent|bin") | ||
| 25 | parser.add_option("-B","--bufsize", | 30 | parser.add_option("-B","--bufsize", |
| 26 | action="store", dest="bufsize", default=1024, | 31 | action="store", dest="bufsize", default=None, |
| 27 | help="buffer size [default=1024]") | 32 | help="buffer size [default=1024]") |
| 28 | parser.add_option("-H","--hopsize", | 33 | parser.add_option("-H","--hopsize", |
| 29 | action="store", dest="hopsize", default=512, | 34 | action="store", dest="hopsize", default=None, |
| 30 | help="overlap size [default=512]") | 35 | help="overlap size [default=512]") |
| 31 | parser.add_option("-t","--threshold", | 36 | parser.add_option("-t","--threshold", |
| 32 | action="store", dest="threshold", default=0.1, | 37 | action="store", dest="threshold", default=0.1, |
| @@ -63,13 +68,22 @@ def parse_args(): · 30 unmodified lines | |||
| 63 | action="store_false", dest="verbose", default=False, | 68 | action="store_false", dest="verbose", default=False, |
| 64 | help="be quiet") | 69 | help="be quiet") |
| 65 | (options, args) = parser.parse_args() | 70 | (options, args) = parser.parse_args() |
| 71 | if not options.bufsize: | ||
| 72 | if options.mode == aubio_pitch_yin: options.bufsize = 1024 | ||
| 73 | if options.mode == aubio_pitch_schmitt: options.bufsize = 2048 | ||
| 74 | if options.mode == aubio_pitch_mcomb: options.bufsize = 4096 | ||
| 75 | if options.mode == aubio_pitch_fcomb: options.bufsize = 4096 | ||
| 76 | if not options.hopsize: | ||
| 77 | options.hopsize = float(options.bufsize) / 2 | ||
| 66 | if not options.filename: | 78 | if not options.filename: |
| 67 | print "no file name given\n", usage | 79 | print "no file name given\n", usage |
| 68 | sys.exit(1) | 80 | sys.exit(1) |
| 69 | return options, args | 81 | return options, args |
| 70 | 82 | ||
| 71 | options, args = parse_args() | 83 | options, args = parse_args() |
| 72 | 84 | ||
| 85 | #print options.bufsize, options.hopsize | ||
| 86 | |||
| 73 | filename = options.filename | 87 | filename = options.filename |
| 74 | samplerate = float(sndfile(filename).samplerate()) | 88 | samplerate = float(sndfile(filename).samplerate()) |
| 75 | hopsize = int(options.hopsize) | 89 | hopsize = int(options.hopsize) |
| @@ -85,9 +99,11 @@ else: delay = 2./step · 9 unmodified lines | |||
| 85 | if options.note: | 99 | if options.note: |
| 86 | exit("not implemented yet") | 100 | exit("not implemented yet") |
| 87 | else: | 101 | else: |
| 88 | pitch = getpitch(filename, #threshold,silence, | 102 | pitch = getpitch(filename, #threshold, |
| 89 | mode=options.mode, | 103 | mode=options.mode, |
| 90 | bufsize=bufsize,hopsize=hopsize) | 104 | omode=options.omode, |
| 105 | bufsize=bufsize,hopsize=hopsize, | ||
| 106 | silence=silence) | ||
| 91 | 107 | ||
| 92 | ## take back system delay | 108 | ## take back system delay |
| 93 | #if delay != 0: | 109 | #if delay != 0: |