[4e9101e] | 1 | #include <aubio.h> |
---|
| 2 | |
---|
[158e031] | 3 | int main (void) |
---|
[fe163ad] | 4 | { |
---|
[c71aa44] | 5 | // 1. allocate some memory |
---|
| 6 | uint_t n = 0; // frame counter |
---|
| 7 | uint_t win_s = 1024; // window size |
---|
| 8 | uint_t hop_s = win_s / 4; // hop size |
---|
| 9 | uint_t samplerate = 44100; // samplerate |
---|
| 10 | // create some vectors |
---|
| 11 | fvec_t *input = new_fvec (hop_s); // input buffer |
---|
| 12 | fvec_t *out = new_fvec (1); // output candidates |
---|
| 13 | // create pitch object |
---|
| 14 | aubio_pitch_t *o = new_aubio_pitch ("default", win_s, hop_s, samplerate); |
---|
[4e9101e] | 15 | |
---|
[c71aa44] | 16 | // 2. do something with it |
---|
| 17 | while (n < 100) { |
---|
| 18 | // get `hop_s` new samples into `input` |
---|
| 19 | // ... |
---|
| 20 | // exectute pitch |
---|
| 21 | aubio_pitch_do (o, input, out); |
---|
| 22 | // do something with output candidates |
---|
| 23 | // ... |
---|
| 24 | n++; |
---|
[fe163ad] | 25 | }; |
---|
[4e9101e] | 26 | |
---|
[c71aa44] | 27 | // 3. clean up memory |
---|
[ca1abdd] | 28 | del_aubio_pitch (o); |
---|
[9d6001cb] | 29 | del_fvec (out); |
---|
[c71aa44] | 30 | del_fvec (input); |
---|
[fe163ad] | 31 | aubio_cleanup (); |
---|
[4e9101e] | 32 | |
---|
[7625d85] | 33 | if (new_aubio_pitch(0, win_s, hop_s, samplerate)) return 1; |
---|
| 34 | if (new_aubio_pitch("unknown", win_s, hop_s, samplerate)) return 1; |
---|
| 35 | if (new_aubio_pitch("default", win_s, 0, samplerate)) return 1; |
---|
| 36 | if (new_aubio_pitch("default", 0, hop_s, samplerate)) return 1; |
---|
| 37 | if (new_aubio_pitch("default", hop_s, win_s, samplerate)) return 1; |
---|
| 38 | if (new_aubio_pitch("default", win_s, hop_s, 0)) return 1; |
---|
| 39 | |
---|
| 40 | o = new_aubio_pitch("default", win_s, hop_s, samplerate); |
---|
| 41 | |
---|
| 42 | if (aubio_pitch_set_unit(o, "freq")) return 1; |
---|
| 43 | if (aubio_pitch_set_unit(o, "hertz")) return 1; |
---|
| 44 | if (aubio_pitch_set_unit(o, "Hertz")) return 1; |
---|
| 45 | if (aubio_pitch_set_unit(o, "Hz")) return 1; |
---|
| 46 | if (aubio_pitch_set_unit(o, "f0")) return 1; |
---|
| 47 | if (aubio_pitch_set_unit(o, "midi")) return 1; |
---|
| 48 | if (aubio_pitch_set_unit(o, "cent")) return 1; |
---|
| 49 | if (aubio_pitch_set_unit(o, "bin")) return 1; |
---|
| 50 | if (!aubio_pitch_set_unit(o, "unknown")) return 1; |
---|
| 51 | |
---|
| 52 | if (aubio_pitch_set_tolerance(o, 0.3)) return 1; |
---|
| 53 | if (aubio_pitch_set_silence(o, 0)) return 1; |
---|
| 54 | if (aubio_pitch_set_silence(o, -200)) return 1; |
---|
| 55 | if (!aubio_pitch_set_silence(o, -300)) return 1; |
---|
| 56 | del_aubio_pitch(o); |
---|
| 57 | |
---|
| 58 | // fft based might fail with non power of 2 |
---|
| 59 | o = new_aubio_pitch("yinfft", win_s + 1, hop_s, samplerate); |
---|
| 60 | if (o) del_aubio_pitch(o); |
---|
| 61 | o = new_aubio_pitch("yinfast", win_s + 1, hop_s, samplerate); |
---|
| 62 | if (o) del_aubio_pitch(o); |
---|
| 63 | o = new_aubio_pitch("fcomb", win_s + 1, hop_s, samplerate); |
---|
| 64 | if (o) del_aubio_pitch(o); |
---|
| 65 | o = new_aubio_pitch("mcomb", win_s + 1, hop_s, samplerate); |
---|
| 66 | if (o) del_aubio_pitch(o); |
---|
| 67 | o = new_aubio_pitch("specacf", win_s + 1, hop_s, samplerate); |
---|
| 68 | if (o) del_aubio_pitch(o); |
---|
| 69 | |
---|
[fe163ad] | 70 | return 0; |
---|
[4e9101e] | 71 | } |
---|