aubio 0.4.9
Loading...
Searching...
No Matches
pitch/test-pitch.c
#include <aubio.h>
int main (void)
{
// 1. allocate some memory
uint_t n = 0; // frame counter
uint_t win_s = 1024; // window size
uint_t hop_s = win_s / 4; // hop size
uint_t samplerate = 44100; // samplerate
// create some vectors
fvec_t *input = new_fvec (hop_s); // input buffer
fvec_t *out = new_fvec (1); // output candidates
// create pitch object
aubio_pitch_t *o = new_aubio_pitch ("default", win_s, hop_s, samplerate);
// 2. do something with it
while (n < 100) {
// get `hop_s` new samples into `input`
// ...
// exectute pitch
aubio_pitch_do (o, input, out);
// do something with output candidates
// ...
n++;
};
// 3. clean up memory
del_fvec (out);
del_fvec (input);
if (new_aubio_pitch(0, win_s, hop_s, samplerate)) return 1;
if (new_aubio_pitch("unknown", win_s, hop_s, samplerate)) return 1;
if (new_aubio_pitch("default", win_s, 0, samplerate)) return 1;
if (new_aubio_pitch("default", 0, hop_s, samplerate)) return 1;
if (new_aubio_pitch("default", hop_s, win_s, samplerate)) return 1;
if (new_aubio_pitch("default", win_s, hop_s, 0)) return 1;
o = new_aubio_pitch("default", win_s, hop_s, samplerate);
if (aubio_pitch_set_unit(o, "freq")) return 1;
if (aubio_pitch_set_unit(o, "hertz")) return 1;
if (aubio_pitch_set_unit(o, "Hertz")) return 1;
if (aubio_pitch_set_unit(o, "Hz")) return 1;
if (aubio_pitch_set_unit(o, "f0")) return 1;
if (aubio_pitch_set_unit(o, "midi")) return 1;
if (aubio_pitch_set_unit(o, "cent")) return 1;
if (aubio_pitch_set_unit(o, "bin")) return 1;
if (!aubio_pitch_set_unit(o, "unknown")) return 1;
if (aubio_pitch_set_tolerance(o, 0.3)) return 1;
if (aubio_pitch_set_silence(o, 0)) return 1;
if (aubio_pitch_set_silence(o, -200)) return 1;
if (!aubio_pitch_set_silence(o, -300)) return 1;
// fft based might fail with non power of 2
o = new_aubio_pitch("yinfft", win_s + 1, hop_s, samplerate);
if (o) del_aubio_pitch(o);
o = new_aubio_pitch("yinfast", win_s + 1, hop_s, samplerate);
if (o) del_aubio_pitch(o);
o = new_aubio_pitch("fcomb", win_s + 1, hop_s, samplerate);
if (o) del_aubio_pitch(o);
o = new_aubio_pitch("mcomb", win_s + 1, hop_s, samplerate);
if (o) del_aubio_pitch(o);
o = new_aubio_pitch("specacf", win_s + 1, hop_s, samplerate);
if (o) del_aubio_pitch(o);
return 0;
}
Global aubio include file.
fvec_t * new_fvec(uint_t length)
fvec_t buffer creation function
void del_fvec(fvec_t *s)
fvec_t buffer deletion function
void aubio_cleanup(void)
clean up cached memory at the end of program
uint_t aubio_pitch_set_unit(aubio_pitch_t *o, const char_t *mode)
set the output unit of the pitch detection object
void aubio_pitch_do(aubio_pitch_t *o, const fvec_t *in, fvec_t *out)
execute pitch detection on an input signal frame
void del_aubio_pitch(aubio_pitch_t *o)
deletion of the pitch detection object
aubio_pitch_t * new_aubio_pitch(const char_t *method, uint_t buf_size, uint_t hop_size, uint_t samplerate)
creation of the pitch detection object
uint_t aubio_pitch_set_tolerance(aubio_pitch_t *o, smpl_t tol)
change yin or yinfft tolerance threshold
struct _aubio_pitch_t aubio_pitch_t
pitch detection object
Definition pitch.h:106
uint_t aubio_pitch_set_silence(aubio_pitch_t *o, smpl_t silence)
set the silence threshold of the pitch detection object
Buffer for real data.
Definition fvec.h:67
unsigned int uint_t
unsigned integer
Definition types.h:60