Changeset 423a427
- Timestamp:
- Dec 11, 2018, 3:30:49 PM (6 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
- Children:
- 6b84d81
- Parents:
- 54966f5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/src/spectral/test-mfcc.c
r54966f5 r423a427 1 1 #include <aubio.h> 2 #include "utils_tests.h" 2 3 3 int main (void) 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() 4 82 { 5 83 uint_t win_s = 512; // fft size … … 7 85 uint_t n_coeffs = 13; // number of coefficients 8 86 smpl_t samplerate = 16000.; // samplerate 9 cvec_t *in = new_cvec (win_s); // input buffer10 fvec_t *out = new_fvec (n_coeffs); // output coefficients11 87 12 88 if (new_aubio_mfcc( 0, n_filters, n_coeffs, samplerate)) return 1; … … 15 91 if (new_aubio_mfcc(win_s, n_filters, n_coeffs, 0)) return 1; 16 92 17 // create mfcc object 18 aubio_mfcc_t *o = new_aubio_mfcc (win_s, n_filters, n_coeffs, samplerate); 19 20 cvec_norm_set_all (in, 1.); 21 aubio_mfcc_do (o, in, out); 22 fvec_print (out); 23 24 cvec_norm_set_all (in, .5); 25 aubio_mfcc_do (o, in, out); 26 fvec_print (out); 27 28 // clean up 29 del_aubio_mfcc (o); 30 del_cvec (in); 31 del_fvec (out); 32 aubio_cleanup (); 33 34 return 0; 93 return run_on_default_source(main); 35 94 }
Note: See TracChangeset
for help on using the changeset viewer.