/* block loop */
aubio_pvoc_do (pv,ibuf, fftgrain);
aubio_onsetdetection_do(o,fftgrain, onset);
- if (usedoubled) {
- aubio_onsetdetection_do(o2,fftgrain, onset2);
- onset->data[0][0] *= onset2->data[0][0];
- }
isonset = aubio_peakpicker_do(parms, onset);
aubio_pitchdetection_do (pitchdet, ibuf, pitch_obuf);
/* block loop */
aubio_pvoc_do (pv,ibuf, fftgrain);
aubio_onsetdetection_do (o,fftgrain, onset);
- if (usedoubled) {
- aubio_onsetdetection_do (o2,fftgrain, onset2);
- onset->data[0][0] *= onset2->data[0][0];
- }
isonset = aubio_peakpicker_do(parms, onset);
if (isonset) {
/* test for silence */
cvec_t *fftgrain;
fvec_t *woodblock;
aubio_onsetdetection_t *o;
-aubio_onsetdetection_t *o2;
fvec_t *onset;
fvec_t *onset2;
smpl_t isonset = 0;
/* pitch objects */
smpl_t pitch = 0.;
aubio_pitchdetection_t *pitchdet;
-aubio_pitchdetection_type type_pitch = aubio_pitch_yinfft; // aubio_pitch_mcomb
-aubio_pitchdetection_mode mode_pitch = aubio_pitchm_freq;
+char_t * pitch_unit = "default";
+char_t * pitch_mode = "default";
uint_t median = 6;
fvec_t *note_buffer = NULL;
*/
break;
case 'p':
- if (strcmp (optarg, "mcomb") == 0)
- type_pitch = aubio_pitch_mcomb;
- else if (strcmp (optarg, "yinfft") == 0)
- type_pitch = aubio_pitch_yin;
- else if (strcmp (optarg, "yin") == 0)
- type_pitch = aubio_pitch_yin;
- else if (strcmp (optarg, "schmitt") == 0)
- type_pitch = aubio_pitch_schmitt;
- else if (strcmp (optarg, "fcomb") == 0)
- type_pitch = aubio_pitch_fcomb;
- else {
- errmsg ("unknown pitch type.\n");
- abort ();
- }
+ pitch_mode = optarg;
break;
case 'a':
averaging = 1;
fftgrain = new_cvec (buffer_size, channels);
if (usepitch) {
- pitchdet = new_aubio_pitchdetection (buffer_size * 4,
- overlap_size, channels, samplerate, type_pitch, mode_pitch);
+ pitchdet = new_aubio_pitchdetection (pitch_mode, buffer_size * 4,
+ overlap_size, channels, samplerate);
aubio_pitchdetection_set_tolerance (pitchdet, 0.7);
pitch_obuf = new_fvec (1, channels);
}
del_fvec (pitch_obuf);
}
- if (usedoubled) {
- del_aubio_onsetdetection (o2);
- del_fvec (onset2);
- }
del_aubio_onsetdetection (o);
del_aubio_peakpicker (parms);
del_aubio_pvoc (pv);
/* pitch objects */
extern smpl_t pitch;
extern aubio_pitchdetection_t *pitchdet;
-extern aubio_pitchdetection_type mode;
extern uint_t median;
extern fvec_t *note_buffer;
char aubiopitch_version[] = "aubiopitch~ version 0.1";
-aubio_pitchdetection_type type_pitch = aubio_pitch_yinfft;
-aubio_pitchdetection_mode mode_pitch = aubio_pitchm_freq;
-
static t_class *aubiopitch_tilde_class;
void aubiopitch_tilde_setup (void);
x->bufsize = 2048;
x->hopsize = x->bufsize / 2;
- if (strcmp(s->s_name,"mcomb") == 0)
- type_pitch = aubio_pitch_mcomb;
- else if (strcmp(s->s_name,"yinfft") == 0)
- type_pitch = aubio_pitch_yin;
- else if (strcmp(s->s_name,"yin") == 0)
- type_pitch = aubio_pitch_yin;
- else if (strcmp(s->s_name,"schmitt") == 0)
- type_pitch = aubio_pitch_schmitt;
- else if (strcmp(s->s_name,"fcomb") == 0)
- type_pitch = aubio_pitch_fcomb;
- else {
- post("unknown pitch type, using default.\n");
- }
-
//FIXME: get the real samplerate
- x->o = new_aubio_pitchdetection(x->bufsize,
- x->hopsize, 1, 44100., type_pitch, mode_pitch);
+ x->o = new_aubio_pitchdetection(s->s_name, x->bufsize,
+ x->hopsize, 1, 44100.);
aubio_pitchdetection_set_tolerance (x->o, 0.7);
x->vec = (fvec_t *)new_fvec(x->hopsize,1);
x->pitchvec = (fvec_t *)new_fvec(1,1);
return isonset, dval
class pitchdetection:
- def __init__(self,mode=aubio_pitch_mcomb,bufsize=2048,hopsize=1024,
- channels=1,samplerate=44100.,omode=aubio_pitchm_freq,tolerance=0.1):
- self.pitchp = new_aubio_pitchdetection(bufsize,hopsize,channels,
- samplerate,mode,omode)
+ def __init__(self,mode="mcomb",bufsize=2048,hopsize=1024,
+ channels=1,samplerate=44100.,omode="freq",tolerance=0.1):
+ self.pitchp = new_aubio_pitchdetection(mode,bufsize,hopsize,channels,
+ samplerate)
self.mypitch = fvec(1, channels)
+ aubio_pitchdetection_set_unit(self.pitchp,omode)
aubio_pitchdetection_set_tolerance(self.pitchp,tolerance)
#self.filt = filter(srate,"adsgn")
def __del__(self):
-from aubio.aubioclass import aubio_pitchm_freq
class taskparams(object):
""" default parameters for task classes """
self.pitchmax=20000.
self.pitchdelay = -0.5
self.dcthreshold = -1.
- self.omode = aubio_pitchm_freq
+ self.omode = "freq"
self.verbose = False
tolerance = self.params.yinfftthresh
else:
tolerance = 0.
- self.pitchdet = pitchdetection(mode=get_pitch_mode(self.params.pitchmode),
+ self.pitchdet = pitchdetection(mode=self.params.pitchmode,
bufsize=self.params.bufsize,
hopsize=self.params.hopsize,
channels=self.channels,
print "unknown onset detection function selected: %s" % nvalue
sys.exit(1)
-def get_pitch_mode(nvalue):
- """ utility function to convert a string to aubio_pitchdetection_type """
- if nvalue == 'mcomb' :
- return aubio_pitch_mcomb
- elif nvalue == 'yin' :
- return aubio_pitch_yin
- elif nvalue == 'fcomb' :
- return aubio_pitch_fcomb
- elif nvalue == 'schmitt':
- return aubio_pitch_schmitt
- elif nvalue == 'yinfft':
- return aubio_pitch_yinfft
- else:
- import sys
- print "error: unknown pitch detection function selected"
- sys.exit(1)
-
def check_onset_mode(option, opt, value, parser):
""" wrapper function to convert a list of modes to
aubio_onsetdetection_type """
for nvalue in nvalues:
val.append(get_pitch_mode(nvalue))
setattr(parser.values, option.dest, val)
-
-def check_pitchm_mode(option, opt, value, parser):
- """ utility function to convert a string to aubio_pitchdetection_mode """
- 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:
- import sys
- print "error: unknown pitch detection output selected"
- sys.exit(1)
-
-
action="store", dest="filename",
help="input sound file")
parser.add_option("-m","--mode",
- action="store", dest="mode", default='mcomb',
+ action="store", dest="mode", default='yinfft',
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,
+ parser.add_option("-u","--units",
+ action="store", dest="omode", default="freq",
help="output pitch in units [default=Hz] \
freq|midi|cent|bin")
parser.add_option("-B","--bufsize",
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 options.mode == "yin": options.bufsize = 1024
+ if options.mode == "schmitt": options.bufsize = 2048
+ if options.mode == "mcomb": options.bufsize = 4096
+ if options.mode == "fcomb": options.bufsize = 4096
else: options.bufsize = 2048
if not options.hopsize:
options.hopsize = float(options.bufsize) / 2
if options.smoothing: params.pitchsmooth = int(options.smoothing)
if options.pitchmax: params.pitchmax = int(options.pitchmax)
if options.pitchmin: params.pitchmin = int(options.pitchmin)
-if options.omode: params.omode = int(options.omode)
#mintol = float(options.mintol)*step
# default take back system delay
if options.delay: params.pitchdelay = float(options.delay)
#include "pitch/pitchyinfft.h"
#include "pitch/pitchdetection.h"
+/** pitch detection algorithm */
+typedef enum {
+ aubio_pitch_yin, /**< YIN algorithm */
+ aubio_pitch_mcomb, /**< Multi-comb filter */
+ aubio_pitch_schmitt, /**< Schmitt trigger */
+ aubio_pitch_fcomb, /**< Fast comb filter */
+ aubio_pitch_yinfft, /**< Spectral YIN */
+ aubio_pitch_default = aubio_pitch_yinfft, /**< the one used when "default" is asked */
+} aubio_pitchdetection_type;
+
+/** pitch detection output mode */
+typedef enum {
+ aubio_pitchm_freq, /**< Frequency (Hz) */
+ aubio_pitchm_midi, /**< MIDI note (0.,127) */
+ aubio_pitchm_cent, /**< Cent */
+ aubio_pitchm_bin, /**< Frequency bin (0,bufsize) */
+ aubio_pitchm_default = aubio_pitchm_freq, /**< the one used when "default" is asked */
+} aubio_pitchdetection_mode;
+
typedef void (*aubio_pitchdetection_func_t)
(aubio_pitchdetection_t *p, fvec_t * ibuf, fvec_t *obuf);
typedef smpl_t (*aubio_pitchdetection_conv_t)
return f;
}
-aubio_pitchdetection_t * new_aubio_pitchdetection(uint_t bufsize,
- uint_t hopsize,
- uint_t channels,
- uint_t samplerate,
- aubio_pitchdetection_type type,
- aubio_pitchdetection_mode mode)
+aubio_pitchdetection_t *
+new_aubio_pitchdetection (char_t * pitch_mode,
+ uint_t bufsize, uint_t hopsize, uint_t channels, uint_t samplerate)
{
aubio_pitchdetection_t *p = AUBIO_NEW(aubio_pitchdetection_t);
+ aubio_pitchdetection_type pitch_type;
+ if (strcmp (pitch_mode, "mcomb") == 0)
+ pitch_type = aubio_pitch_mcomb;
+ else if (strcmp (pitch_mode, "yinfft") == 0)
+ pitch_type = aubio_pitch_yin;
+ else if (strcmp (pitch_mode, "yin") == 0)
+ pitch_type = aubio_pitch_yin;
+ else if (strcmp (pitch_mode, "schmitt") == 0)
+ pitch_type = aubio_pitch_schmitt;
+ else if (strcmp (pitch_mode, "fcomb") == 0)
+ pitch_type = aubio_pitch_fcomb;
+ else if (strcmp (pitch_mode, "default") == 0)
+ pitch_type = aubio_pitch_default;
+ else {
+ AUBIO_ERR ("unknown pitch detection method %s, using default.\n", pitch_mode);
+ pitch_type = aubio_pitch_default;
+ return NULL;
+ }
p->srate = samplerate;
- p->type = type;
- p->mode = mode;
+ p->type = pitch_type;
+ aubio_pitchdetection_set_unit (p, "default");
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 = freqconvmidi;
- break;
- case aubio_pitchm_cent:
- /* bug: not implemented */
- p->freqconv = freqconvmidi;
- break;
- case aubio_pitchm_bin:
- p->freqconv = freqconvbin;
- break;
- default:
- break;
- }
return p;
}
}
}
+uint_t aubio_pitchdetection_set_unit (aubio_pitchdetection_t *p, char_t * pitch_unit) {
+ aubio_pitchdetection_mode pitch_mode;
+ if (strcmp (pitch_unit, "freq") == 0)
+ pitch_mode = aubio_pitchm_freq;
+ else if (strcmp (pitch_unit, "midi") == 0)
+ pitch_mode = aubio_pitchm_midi;
+ else if (strcmp (pitch_unit, "cent") == 0)
+ pitch_mode = aubio_pitchm_cent;
+ else if (strcmp (pitch_unit, "bin") == 0)
+ pitch_mode = aubio_pitchm_bin;
+ else if (strcmp (pitch_unit, "default") == 0)
+ pitch_mode = aubio_pitchm_default;
+ else {
+ AUBIO_ERR ("unknown pitch detection unit %s, using default\n", pitch_unit);
+ pitch_mode = aubio_pitchm_default;
+ }
+ p->mode = pitch_mode;
+ switch(p->mode) {
+ case aubio_pitchm_freq:
+ p->freqconv = freqconvpass;
+ break;
+ case aubio_pitchm_midi:
+ p->freqconv = freqconvmidi;
+ break;
+ case aubio_pitchm_cent:
+ /* bug: not implemented */
+ p->freqconv = freqconvmidi;
+ break;
+ case aubio_pitchm_bin:
+ p->freqconv = freqconvbin;
+ break;
+ default:
+ break;
+ }
+ return 0;
+}
+
void aubio_pitchdetection_set_tolerance(aubio_pitchdetection_t *p, smpl_t tol) {
switch(p->type) {
case aubio_pitch_yin:
*/
-/** pitch detection algorithm */
-typedef enum {
- aubio_pitch_yin, /**< YIN algorithm */
- aubio_pitch_mcomb, /**< Multi-comb filter */
- aubio_pitch_schmitt, /**< Schmitt trigger */
- aubio_pitch_fcomb, /**< Fast comb filter */
- aubio_pitch_yinfft /**< Spectral YIN */
-} aubio_pitchdetection_type;
-
-/** pitch detection output mode */
-typedef enum {
- aubio_pitchm_freq, /**< Frequency (Hz) */
- aubio_pitchm_midi, /**< MIDI note (0.,127) */
- aubio_pitchm_cent, /**< Cent */
- aubio_pitchm_bin /**< Frequency bin (0,bufsize) */
-} aubio_pitchdetection_mode;
-
/** pitch detection object */
typedef struct _aubio_pitchdetection_t aubio_pitchdetection_t;
\param mode set pitch units for output
*/
-aubio_pitchdetection_t * new_aubio_pitchdetection(uint_t bufsize,
- uint_t hopsize,
- uint_t channels,
- uint_t samplerate,
- aubio_pitchdetection_type pitch_type,
- aubio_pitchdetection_mode pitch_mode);
+aubio_pitchdetection_t *new_aubio_pitchdetection (char_t * pitch_mode,
+ uint_t bufsize, uint_t hopsize, uint_t channels, uint_t samplerate);
+
+/** set the output unit of the pitch detection object */
+uint_t aubio_pitchdetection_set_unit (aubio_pitchdetection_t *p, char_t * pitch_unit);
#ifdef __cplusplus
}
void aubio_pvoc_rdo(aubio_pvoc_t *pv, cvec_t * fftgrain, fvec_t *out);
/* pitch detection */
-typedef enum {
- aubio_pitch_yin,
- aubio_pitch_mcomb,
- aubio_pitch_schmitt,
- aubio_pitch_fcomb,
- aubio_pitch_yinfft
-} aubio_pitchdetection_type;
-
-typedef enum {
- aubio_pitchm_freq,
- aubio_pitchm_midi,
- aubio_pitchm_cent,
- aubio_pitchm_bin
-} aubio_pitchdetection_mode;
-
+aubio_pitchdetection_t *new_aubio_pitchdetection (char *pitch_mode,
+ uint_t bufsize, uint_t hopsize, uint_t channels, uint_t samplerate);
void aubio_pitchdetection_do (aubio_pitchdetection_t * p, fvec_t * ibuf, fvec_t * obuf);
-
void aubio_pitchdetection_set_tolerance(aubio_pitchdetection_t *p, smpl_t thres);
-
+void aubio_pitchdetection_set_unit(aubio_pitchdetection_t *p, char * pitch_unit);
void del_aubio_pitchdetection(aubio_pitchdetection_t * p);
-aubio_pitchdetection_t * new_aubio_pitchdetection(uint_t bufsize,
- uint_t hopsize,
- uint_t channels,
- uint_t samplerate,
- aubio_pitchdetection_type type,
- aubio_pitchdetection_mode mode);
-
/* pitch mcomb */
aubio_pitchmcomb_t * new_aubio_pitchmcomb(uint_t bufsize, uint_t hopsize, uint_t channels);
#include <aubio.h>
-int main(){
- /* allocate some memory */
- uint_t win_s = 1024; /* window size */
- uint_t hop_s = win_s/4; /* hop size */
- uint_t samplerate = 44100; /* samplerate */
- uint_t channels = 1; /* number of channel */
- aubio_pitchdetection_mode mode = aubio_pitchm_freq;
- aubio_pitchdetection_type type = aubio_pitch_yinfft;
- fvec_t * in = new_fvec (hop_s, channels); /* input buffer */
- fvec_t * out = new_fvec (1, channels); /* input buffer */
- aubio_pitchdetection_t * o = new_aubio_pitchdetection(
- win_s, hop_s, channels, samplerate, type, mode
- );
- uint_t i = 0;
+int
+main ()
+{
+ /* allocate some memory */
+ uint_t win_s = 1024; /* window size */
+ uint_t hop_s = win_s / 4; /* hop size */
+ uint_t samplerate = 44100; /* samplerate */
+ uint_t channels = 1; /* number of channel */
+ fvec_t *in = new_fvec (hop_s, channels); /* input buffer */
+ fvec_t *out = new_fvec (1, channels); /* input buffer */
+ aubio_pitchdetection_t *o =
+ new_aubio_pitchdetection ("default", win_s, hop_s, channels, samplerate);
+ uint_t i = 0;
- while (i < 100) {
- aubio_pitchdetection_do (o,in, out);
- i++;
- };
+ while (i < 100) {
+ aubio_pitchdetection_do (o, in, out);
+ i++;
+ };
- del_aubio_pitchdetection(o);
- del_fvec(in);
- aubio_cleanup();
+ del_aubio_pitchdetection (o);
+ del_fvec (in);
+ aubio_cleanup ();
- return 0;
+ return 0;
}