elif nvalue == 'dual' :
setattr(parser.values, option.dest, 'dual')
else:
- print "unknown detection function selected\n", usage
+ print "unknown onset detection function selected"
sys.exit(1)
def check_pitch_mode(option, opt, value, parser):
nvalue = parser.rargs[0]
- if nvalue == 'mcomb' :
+ if nvalue == 'mcomb' :
setattr(parser.values, option.dest, aubio_pitch_mcomb)
- elif nvalue == 'yin' :
+ elif nvalue == 'yin' :
setattr(parser.values, option.dest, aubio_pitch_yin)
- elif nvalue == 'fcomb' :
+ elif nvalue == 'fcomb' :
setattr(parser.values, option.dest, aubio_pitch_fcomb)
- elif nvalue == 'schmitt' :
+ elif nvalue == 'schmitt':
setattr(parser.values, option.dest, aubio_pitch_schmitt)
else:
- print "unknown detection function selected\n", usage
+ print "error: unknown pitch detection function selected"
+ sys.exit(1)
+
+def check_pitchm_mode(option, opt, value, parser):
+ nvalue = parser.rargs[0]
+ if nvalue == 'freq' :
+ setattr(parser.values, option.dest, aubio_pitchm_freq)
+ elif nvalue == 'midi' :
+ setattr(parser.values, option.dest, aubio_pitchm_midi)
+ elif nvalue == 'cent' :
+ setattr(parser.values, option.dest, aubio_pitchm_cent)
+ elif nvalue == 'bin' :
+ setattr(parser.values, option.dest, aubio_pitchm_bin)
+ else:
+ print "error: unknown pitch detection output selected"
sys.exit(1)
filei = sndfile(filein)
framestep = hopsize/(filei.samplerate()+0.)
channels = filei.channels()
- newname = "%s%s%f%s%s" % (filein.split(".")[0].split("/")[-1],".",
+ newname = "%s%s%09.5f%s%s" % (filein.split(".")[0].split("/")[-1],".",
frameread*framestep,".",filein.split(".")[-1])
fileo = sndfile(newname,model=filei)
myvec = fvec(hopsize,channels)
fromcross += 1
zerocross += 1
del fileo
- fileo = sndfile("%s%s%f%s%s" %
+ fileo = sndfile("%s%s%09.5f%s%s" %
(filein.split(".")[0].split("/")[-1],".",
frameread*framestep,".",filein.split(".")[-1]),model=filei)
writesize = fileo.write(fromcross,mycopy)
if (aubio_silence_detection(myvec(),silence)!=1):
mylist.append(freq)
else:
- mylist.append(0)
+ mylist.append(-1.)
frameread += 1
return mylist
default=aubio_pitch_mcomb,
help="pitch detection mode [default=mcomb] \
mcomb|yin|fcomb|schmitt")
+ parser.add_option("-u","--units", action="callback",
+ callback=check_pitchm_mode, dest="omode",
+ default=aubio_pitchm_freq,
+ help="output pitch in units [default=Hz] \
+ freq|midi|cent|bin")
parser.add_option("-B","--bufsize",
- action="store", dest="bufsize", default=1024,
+ action="store", dest="bufsize", default=None,
help="buffer size [default=1024]")
parser.add_option("-H","--hopsize",
- action="store", dest="hopsize", default=512,
+ action="store", dest="hopsize", default=None,
help="overlap size [default=512]")
parser.add_option("-t","--threshold",
action="store", dest="threshold", default=0.1,
action="store_false", dest="verbose", default=False,
help="be quiet")
(options, args) = parser.parse_args()
+ if not options.bufsize:
+ if options.mode == aubio_pitch_yin: options.bufsize = 1024
+ if options.mode == aubio_pitch_schmitt: options.bufsize = 2048
+ if options.mode == aubio_pitch_mcomb: options.bufsize = 4096
+ if options.mode == aubio_pitch_fcomb: options.bufsize = 4096
+ if not options.hopsize:
+ options.hopsize = float(options.bufsize) / 2
if not options.filename:
- print "no file name given\n", usage
- sys.exit(1)
+ print "no file name given\n", usage
+ sys.exit(1)
return options, args
options, args = parse_args()
+#print options.bufsize, options.hopsize
+
filename = options.filename
samplerate = float(sndfile(filename).samplerate())
hopsize = int(options.hopsize)
if options.note:
exit("not implemented yet")
else:
- pitch = getpitch(filename, #threshold,silence,
+ pitch = getpitch(filename, #threshold,
mode=options.mode,
- bufsize=bufsize,hopsize=hopsize)
+ omode=options.omode,
+ bufsize=bufsize,hopsize=hopsize,
+ silence=silence)
## take back system delay
#if delay != 0:
#include "pitchschmitt.h"
#include "pitchdetection.h"
+smpl_t freqconvpass(smpl_t f);
+smpl_t freqconvpass(smpl_t f){
+ return f;
+}
+
typedef smpl_t (*aubio_pitchdetection_func_t)(aubio_pitchdetection_t *p,
fvec_t * ibuf);
+typedef smpl_t (*aubio_pitchdetection_conv_t)(smpl_t value);
void aubio_pitchdetection_slideblock(aubio_pitchdetection_t *p, fvec_t *ibuf);
struct _aubio_pitchdetection_t {
fvec_t * buf;
fvec_t * yin;
aubio_pitchdetection_func_t callback;
+ aubio_pitchdetection_conv_t freqconv;
};
aubio_pitchdetection_t * new_aubio_pitchdetection(uint_t bufsize,
aubio_pitchdetection_t *p = AUBIO_NEW(aubio_pitchdetection_t);
p->srate = samplerate;
p->type = type;
+ p->mode = mode;
p->bufsize = bufsize;
switch(p->type) {
case aubio_pitch_yin:
default:
break;
}
+ switch(p->mode) {
+ case aubio_pitchm_freq:
+ p->freqconv = freqconvpass;
+ break;
+ case aubio_pitchm_midi:
+ p->freqconv = aubio_freqtomidi;
+ break;
+ case aubio_pitchm_cent:
+ /** bug: not implemented */
+ p->freqconv = freqconvpass;
+ break;
+ case aubio_pitchm_bin:
+ /** bug: not implemented */
+ p->freqconv = freqconvpass;
+ break;
+ default:
+ break;
+ }
return p;
}
}
smpl_t aubio_pitchdetection(aubio_pitchdetection_t *p, fvec_t * ibuf) {
- return p->callback(p,ibuf);
+ return p->freqconv(p->callback(p,ibuf));
}
smpl_t aubio_pitchdetection_mcomb(aubio_pitchdetection_t *p, fvec_t *ibuf) {