2 #include "utils_tests.h"
4 int test_wrong_params(void);
6 int main (int argc, char **argv)
12 PRINT_WRN("no arguments, running tests\n");
13 if (test_wrong_params() != 0) {
14 PRINT_ERR("tests failed!\n");
19 PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
23 uint_t samplerate = 0;
24 uint_t win_size = 1024;
25 uint_t hop_size = 512;
26 uint_t n_frames = 0, read = 0;
28 char_t *source_path = argv[1];
29 char_t *sink_path = argv[2];
31 if ( argc >= 4 ) samplerate = atoi(argv[3]);
32 if ( argc >= 5 ) hop_size = atoi(argv[4]);
35 PRINT_ERR("too many arguments\n");
39 fvec_t *vec = new_fvec(hop_size);
40 fvec_t *out = new_fvec(hop_size); // output buffer
41 fvec_t *scale = new_fvec(hop_size);
42 cvec_t *fftgrain = new_cvec(win_size); // fft norm and phase
43 if (!vec) { err = 1; goto beach_fvec; }
45 aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
46 if (!i) { err = 1; goto beach_source; }
48 if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
50 aubio_sink_t *o = new_aubio_sink(sink_path, samplerate);
51 if (!o) { err = 1; goto beach_sink; }
53 aubio_pvoc_t *pv = new_aubio_pvoc(win_size, hop_size);
55 aubio_spectral_whitening_t *awhitening =
56 new_aubio_spectral_whitening (win_size, hop_size, samplerate);
58 aubio_spectral_whitening_set_relax_time(awhitening, 20.);
59 fvec_set_all(scale, 3.);
61 PRINT_MSG("spectral whitening relaxation time is %f\n",
62 aubio_spectral_whitening_get_relax_time(awhitening));
65 aubio_source_do(i, vec, &read);
66 aubio_pvoc_do(pv, vec, fftgrain);
67 // apply spectral whitening
68 aubio_spectral_whitening_do(awhitening, fftgrain);
70 aubio_pvoc_rdo(pv, fftgrain, out);
72 fvec_weight(out, scale);
73 // make sure we dont saturate
76 aubio_sink_do(o, out, read);
78 } while ( read == hop_size );
80 PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
81 n_frames, samplerate, n_frames / hop_size,
82 source_path, sink_path);
93 int test_wrong_params(void)
95 uint_t buf_size = 512;
96 uint_t hop_size = 256;
97 uint_t samplerate = 44100;
98 aubio_spectral_whitening_t *o;
100 if (new_aubio_spectral_whitening( 0, hop_size, samplerate)) return 1;
101 if (new_aubio_spectral_whitening(buf_size, 0, samplerate)) return 1;
102 if (new_aubio_spectral_whitening(buf_size, hop_size, 0)) return 1;
104 o = new_aubio_spectral_whitening(buf_size, hop_size, samplerate);
106 aubio_spectral_whitening_get_relax_time(o);
107 aubio_spectral_whitening_get_floor(o);
109 del_aubio_spectral_whitening(o);