1 | #include <aubio.h> |
---|
2 | #include "utils_tests.h" |
---|
3 | |
---|
4 | int test_wrong_params(void); |
---|
5 | |
---|
6 | int main (int argc, char** argv) |
---|
7 | { |
---|
8 | sint_t err = 0; |
---|
9 | |
---|
10 | if (argc < 2) { |
---|
11 | err = 2; |
---|
12 | PRINT_WRN("no arguments, running tests\n"); |
---|
13 | err = test_wrong_params(); |
---|
14 | PRINT_MSG("usage: %s <input_path> [samplerate] [hop_size]\n", argv[0]); |
---|
15 | return err; |
---|
16 | } |
---|
17 | |
---|
18 | uint_t win_s; // fft size |
---|
19 | uint_t hop_s = 256; // block size |
---|
20 | uint_t samplerate = 0; // samplerate |
---|
21 | uint_t n_filters = 40; // number of filters |
---|
22 | uint_t n_coeffs = 13; // number of coefficients |
---|
23 | uint_t read = 0; |
---|
24 | |
---|
25 | char_t *source_path = argv[1]; |
---|
26 | |
---|
27 | if ( argc >= 3 ) samplerate = atoi(argv[2]); |
---|
28 | if ( argc >= 4 ) hop_s = atoi(argv[3]); |
---|
29 | |
---|
30 | win_s = 2 * hop_s; |
---|
31 | |
---|
32 | aubio_source_t *source = 0; |
---|
33 | aubio_pvoc_t *pv = 0; |
---|
34 | aubio_mfcc_t *mfcc = 0; |
---|
35 | |
---|
36 | fvec_t *in = new_fvec (win_s); // input buffer |
---|
37 | cvec_t *fftgrain = new_cvec (win_s); // input buffer |
---|
38 | fvec_t *out = new_fvec (n_coeffs); // output coefficients |
---|
39 | |
---|
40 | if (!in || !fftgrain || !out) { err = 1; goto failure; } |
---|
41 | |
---|
42 | // source |
---|
43 | source = new_aubio_source(source_path, samplerate, hop_s); |
---|
44 | if (!source) { err = 1; goto failure; } |
---|
45 | if (samplerate == 0) samplerate = aubio_source_get_samplerate(source); |
---|
46 | |
---|
47 | // phase vocoder |
---|
48 | pv = new_aubio_pvoc(win_s, hop_s); |
---|
49 | if (!pv) { err = 1; goto failure; } |
---|
50 | |
---|
51 | // mfcc object |
---|
52 | mfcc = new_aubio_mfcc (win_s, n_filters, n_coeffs, samplerate); |
---|
53 | if (!mfcc) { err = 1; goto failure; } |
---|
54 | |
---|
55 | // processing loop |
---|
56 | do { |
---|
57 | aubio_source_do(source, in, &read); |
---|
58 | aubio_pvoc_do(pv, in, fftgrain); |
---|
59 | aubio_mfcc_do(mfcc, fftgrain, out); |
---|
60 | fvec_print(out); |
---|
61 | } while (read == hop_s); |
---|
62 | |
---|
63 | failure: |
---|
64 | |
---|
65 | if (mfcc) |
---|
66 | del_aubio_mfcc(mfcc); |
---|
67 | if (pv) |
---|
68 | del_aubio_pvoc(pv); |
---|
69 | if (source) |
---|
70 | del_aubio_source(source); |
---|
71 | if (in) |
---|
72 | del_fvec(in); |
---|
73 | if (fftgrain) |
---|
74 | del_cvec(fftgrain); |
---|
75 | if (out) |
---|
76 | del_fvec(out); |
---|
77 | aubio_cleanup(); |
---|
78 | return err; |
---|
79 | } |
---|
80 | |
---|
81 | int test_wrong_params() |
---|
82 | { |
---|
83 | uint_t win_s = 512; // fft size |
---|
84 | uint_t n_filters = 40; // number of filters |
---|
85 | uint_t n_coeffs = 13; // number of coefficients |
---|
86 | smpl_t samplerate = 16000.; // samplerate |
---|
87 | |
---|
88 | if (new_aubio_mfcc( 0, n_filters, n_coeffs, samplerate)) return 1; |
---|
89 | if (new_aubio_mfcc(win_s, 0, n_coeffs, samplerate)) return 1; |
---|
90 | if (new_aubio_mfcc(win_s, n_filters, 0, samplerate)) return 1; |
---|
91 | if (new_aubio_mfcc(win_s, n_filters, n_coeffs, 0)) return 1; |
---|
92 | |
---|
93 | return run_on_default_source(main); |
---|
94 | } |
---|