2 #include "utils_tests.h"
4 int test_wrong_params(void);
6 int main(int argc, char **argv)
10 PRINT_ERR("not enough arguments, running tests\n");
11 err = test_wrong_params();
12 PRINT_MSG("read a wave file as a mono vector\n");
13 PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
14 PRINT_MSG("examples:\n");
15 PRINT_MSG(" - read file.wav at original samplerate\n");
16 PRINT_MSG(" %s file.wav\n", argv[0]);
17 PRINT_MSG(" - read file.wav at 32000Hz\n");
18 PRINT_MSG(" %s file.aif 32000\n", argv[0]);
19 PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
20 PRINT_MSG(" %s file.wav 0 4096 \n", argv[0]);
24 uint_t samplerate = 0;
25 uint_t hop_size = 256;
26 uint_t n_frames = 0, read = 0;
27 if ( argc >= 3 ) samplerate = atoi(argv[2]);
28 if ( argc >= 4 ) hop_size = atoi(argv[3]);
30 char_t *source_path = argv[1];
33 new_aubio_source(source_path, samplerate, hop_size);
34 fvec_t *vec = new_fvec(hop_size);
35 if (!s || !vec) { err = 1; goto beach; }
37 uint_t n_frames_expected = aubio_source_get_duration(s);
39 samplerate = aubio_source_get_samplerate(s);
42 aubio_source_do(s, vec, &read);
45 } while ( read == hop_size );
47 PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
48 n_frames, n_frames_expected, samplerate, n_frames / hop_size,
51 // close the file (optional)
52 aubio_source_close(s);
62 int test_wrong_params(void)
64 char_t *uri = DEFINEDSTRING(AUBIO_TESTS_SOURCE);
65 uint_t samplerate = 44100;
66 uint_t hop_size = 512;
67 uint_t channels, read = 0;
72 if (new_aubio_source(0, samplerate, hop_size)) return 1;
73 if (new_aubio_source('\0', samplerate, hop_size)) return 1;
74 if (new_aubio_source(uri, -1, hop_size)) return 1;
75 if (new_aubio_source(uri, 0, 0)) return 1;
77 s = new_aubio_source(uri, samplerate, hop_size);
79 channels = aubio_source_get_channels(s);
81 // vector to read downmixed samples
82 vec = new_fvec(hop_size);
83 // matrix to read individual channels
84 mat = new_fmat(channels, hop_size);
86 if (aubio_source_get_samplerate(s) != samplerate) return 1;
88 // read first hop_size frames
89 aubio_source_do(s, vec, &read);
90 if (read != hop_size) return 1;
93 if(aubio_source_seek(s, 0)) return 1;
95 // read again as multiple channels
96 aubio_source_do_multi(s, mat, &read);
97 if (read != hop_size) return 1;
99 // close the file (optional)
100 aubio_source_close(s);
101 // test closing the file a second time
102 aubio_source_close(s);
108 return run_on_default_source(main);