1 // this should be included *after* custom functions have been defined
3 #ifndef aubio_sink_custom
4 #define aubio_sink_custom "undefined"
5 #endif /* aubio_sink_custom */
7 #ifdef HAVE_AUBIO_SINK_CUSTOM
8 int test_wrong_params(void);
10 int base_main(int argc, char **argv)
13 if (argc < 3 || argc >= 6) {
14 PRINT_ERR("wrong number of arguments, running tests\n");
15 err = test_wrong_params();
16 PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n",
21 uint_t samplerate = 0;
22 uint_t hop_size = 512;
23 uint_t n_frames = 0, read = 0;
25 char_t *source_path = argv[1];
26 char_t *sink_path = argv[2];
28 aubio_source_t *i = NULL;
29 aubio_sink_custom_t *o = NULL;
31 if ( argc >= 4 ) samplerate = atoi(argv[3]);
32 if ( argc >= 5 ) hop_size = atoi(argv[4]);
34 fvec_t *vec = new_fvec(hop_size);
35 if (!vec) { err = 1; goto failure; }
37 i = new_aubio_source(source_path, samplerate, hop_size);
38 if (!i) { err = 1; goto failure; }
39 if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
41 o = new_aubio_sink_custom(sink_path, samplerate);
42 if (!o) { err = 1; goto failure; }
45 aubio_source_do(i, vec, &read);
46 aubio_sink_custom_do(o, vec, read);
48 } while ( read == hop_size );
50 PRINT_MSG("%d frames at %dHz (%d blocks) read from %s, wrote to %s\n",
51 n_frames, samplerate, n_frames / hop_size,
52 source_path, sink_path);
54 // close sink now (optional)
55 aubio_sink_custom_close(o);
59 del_aubio_sink_custom(o);
68 int test_wrong_params(void)
72 aubio_sink_custom_t *s;
73 char_t sink_path[PATH_MAX] = "tmp_aubio_XXXXXX";
74 uint_t samplerate = 44100;
75 uint_t hop_size = 256;
76 uint_t oversized_hop_size = 4097;
77 uint_t oversized_samplerate = 192000 * 8 + 1;
79 uint_t oversized_channels = 1025;
81 int fd = create_temp_sink(sink_path);
85 if (new_aubio_sink_custom( 0, samplerate)) return 1;
86 if (new_aubio_sink_custom("\0", samplerate)) return 1;
87 if (new_aubio_sink_custom(sink_path, -1)) return 1;
89 s = new_aubio_sink_custom(sink_path, 0);
91 // check setting wrong parameters fails
92 if (!aubio_sink_custom_preset_samplerate(s, oversized_samplerate)) return 1;
93 if (!aubio_sink_custom_preset_channels(s, oversized_channels)) return 1;
94 if (!aubio_sink_custom_preset_channels(s, -1)) return 1;
96 // check setting valid parameters passes
97 if (aubio_sink_custom_preset_samplerate(s, samplerate)) return 1;
98 if (aubio_sink_custom_preset_channels(s, 1)) return 1;
100 // check writing a vector with valid length
101 vec = new_fvec(hop_size);
102 aubio_sink_custom_do(s, vec, hop_size);
103 // check writing more than in the input
104 aubio_sink_custom_do(s, vec, hop_size+1);
105 // check write 0 frames
106 aubio_sink_custom_do(s, vec, 0);
109 // check writing an oversized vector
110 vec = new_fvec(oversized_hop_size);
111 aubio_sink_custom_do(s, vec, oversized_hop_size);
114 // test delete without closing
115 del_aubio_sink_custom(s);
117 s = new_aubio_sink_custom(sink_path, 0);
119 // preset channels first
120 if (aubio_sink_custom_preset_channels(s, channels)) return 1;
121 if (aubio_sink_custom_preset_samplerate(s, samplerate)) return 1;
123 if (aubio_sink_custom_get_samplerate(s) != samplerate) return 1;
124 if (aubio_sink_custom_get_channels(s) != channels) return 1;
126 mat = new_fmat(channels, hop_size);
127 // check writing a vector with valid length
128 aubio_sink_custom_do_multi(s, mat, hop_size);
129 // check writing 0 frames
130 aubio_sink_custom_do_multi(s, mat, 0);
131 // check writing more than in the input
132 aubio_sink_custom_do_multi(s, mat, hop_size+1);
135 // check writing oversized input
136 mat = new_fmat(channels, oversized_hop_size);
137 aubio_sink_custom_do_multi(s, mat, oversized_hop_size);
140 // check writing undersized input
141 mat = new_fmat(channels - 1, hop_size);
142 aubio_sink_custom_do_multi(s, mat, hop_size);
145 aubio_sink_custom_close(s);
146 // test closing twice
147 aubio_sink_custom_close(s);
149 del_aubio_sink_custom(s);
152 close_temp_sink(sink_path, fd);
154 return run_on_default_source_and_sink(base_main);
157 #else /* HAVE_AUBIO_SINK_CUSTOM */
159 int base_main(int argc, char** argv)
161 PRINT_ERR("aubio was not compiled with aubio_sink_"
162 aubio_sink_custom ", failed running %s with %d args\n",
167 #endif /* HAVE_AUBIO_SINK_CUSTOM */