1 // this should be included *after* custom functions have been defined
3 #ifndef aubio_source_custom
4 #define aubio_source_custom "undefined"
5 #endif /* aubio_source_custom */
7 #ifdef HAVE_AUBIO_SOURCE_CUSTOM
8 int test_wrong_params(void);
10 int base_main(int argc, char **argv)
14 PRINT_ERR("not enough arguments, running tests\n");
15 err = test_wrong_params();
16 PRINT_MSG("read a wave file as a mono vector\n");
17 PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
18 PRINT_MSG("examples:\n");
19 PRINT_MSG(" - read file.wav at original samplerate\n");
20 PRINT_MSG(" %s file.wav\n", argv[0]);
21 PRINT_MSG(" - read file.wav at 32000Hz\n");
22 PRINT_MSG(" %s file.aif 32000\n", argv[0]);
23 PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
24 PRINT_MSG(" %s file.wav 0 4096 \n", argv[0]);
28 uint_t samplerate = 0;
29 uint_t hop_size = 256;
30 uint_t n_frames = 0, read = 0;
31 if ( argc >= 3 ) samplerate = atoi(argv[2]);
32 if ( argc >= 4 ) hop_size = atoi(argv[3]);
34 char_t *source_path = argv[1];
36 aubio_source_custom_t * s =
37 new_aubio_source_custom(source_path, samplerate, hop_size);
38 fvec_t *vec = new_fvec(hop_size);
39 if (!s || !vec) { err = 1; goto beach; }
41 uint_t n_frames_expected = aubio_source_custom_get_duration(s);
43 samplerate = aubio_source_custom_get_samplerate(s);
46 aubio_source_custom_do(s, vec, &read);
49 } while ( read == hop_size );
51 PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
52 n_frames, n_frames_expected, samplerate, n_frames / hop_size,
55 // close the file (optional)
56 aubio_source_custom_close(s);
62 del_aubio_source_custom(s);
66 int test_wrong_params(void)
68 char_t *uri = DEFINEDSTRING(AUBIO_TESTS_SOURCE);
69 uint_t samplerate = 44100;
70 uint_t hop_size = 512;
71 uint_t channels, read = 0;
74 aubio_source_custom_t *s;
76 if (new_aubio_source_custom(0, samplerate, hop_size)) return 1;
77 if (new_aubio_source_custom("\0", samplerate, hop_size)) return 1;
78 if (new_aubio_source_custom(uri, -1, hop_size)) return 1;
79 if (new_aubio_source_custom(uri, 0, 0)) return 1;
81 s = new_aubio_source_custom(uri, samplerate, hop_size);
83 channels = aubio_source_custom_get_channels(s);
85 // vector to read downmixed samples
86 vec = new_fvec(hop_size);
87 // matrix to read individual channels
88 mat = new_fmat(channels, hop_size);
90 if (aubio_source_custom_get_samplerate(s) != samplerate) return 1;
92 // read first hop_size frames
93 aubio_source_custom_do(s, vec, &read);
94 if (read != hop_size) return 1;
97 if(aubio_source_custom_seek(s, 0)) return 1;
99 // read again as multiple channels
100 aubio_source_custom_do_multi(s, mat, &read);
101 if (read != hop_size) return 1;
103 // close the file (optional)
104 aubio_source_custom_close(s);
105 // test closing the file a second time
106 aubio_source_custom_close(s);
108 del_aubio_source_custom(s);
112 return run_on_default_source(base_main);
115 #else /* HAVE_AUBIO_SOURCE_CUSTOM */
117 int base_main(int argc, char** argv)
119 PRINT_ERR("aubio was not compiled with aubio_source_"
120 aubio_source_custom ", failed running %s with %d args\n",
125 #endif /* HAVE_AUBIO_SOURCE_CUSTOM */