34 #define ASSERT_LEVEL 2
132 out[i]= in + i*plane_size;
139 static int cmp(
const int *
a,
const int *
b){
147 double v, f,
a, ampa;
153 #define PUT_SAMPLE set(data, ch, k, channels, sample_fmt, v);
154 #define uint_rand(x) (x = x * 1664525 + 1013904223)
155 #define dbl_rand(x) (uint_rand(x)*2.0 / (double)UINT_MAX - 1)
160 for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
162 for (ch = 0; ch < channels; ch++)
164 a +=
M_PI * 1000.0 * 2.0 / sample_rate;
169 for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
171 for (ch = 0; ch < channels; ch++)
173 f = 100.0 + (((10000.0 - 100.0) * i) / sample_rate);
178 for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) {
180 for (ch = 0; ch < channels; ch++)
185 for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) {
187 for (ch = 0; ch < channels; ch++)
192 for (ch = 0; ch < channels; ch++) {
197 for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
198 for (ch = 0; ch < channels; ch++) {
199 v = sin(taba[ch]) * 0.30;
201 f = tabf1[ch] + (((tabf2[ch] - tabf1[ch]) * i) /
sample_rate);
209 for (i = 0; i < 2 * sample_rate && k < nb_samples; i++, k++) {
210 for (ch = 0; ch < channels; ch++) {
211 double amp = (1.0 + sin(ampa)) * 0.15;
222 int main(
int argc,
char **argv){
223 int in_sample_rate, out_sample_rate, ch ,i, flush_count;
224 uint64_t in_ch_layout, out_ch_layout;
234 int num_tests = 10000;
236 uint32_t rand_seed = 0;
240 int specific_test= -1;
246 if (!strcmp(argv[1],
"-h") || !strcmp(argv[1],
"--help")) {
248 "num_tests Default is %d\n", num_tests);
251 num_tests = strtol(argv[1], NULL, 0);
253 num_tests = -num_tests;
256 if(num_tests<= 0 || num_tests>max_tests)
257 num_tests = max_tests;
259 specific_test = strtol(argv[1], NULL, 0);
263 for(i=0; i<max_tests; i++)
264 remaining_tests[i] = i;
266 for(test=0; test<num_tests; test++){
269 r = (seed * (uint64_t)(max_tests - test)) >>32;
270 FFSWAP(
int, remaining_tests[r], remaining_tests[max_tests - test - 1]);
272 qsort(remaining_tests + max_tests - num_tests, num_tests,
sizeof(remaining_tests[0]), (
void*)
cmp);
273 in_sample_rate=16000;
274 for(test=0; test<num_tests; test++){
275 char in_layout_string[256];
276 char out_layout_string[256];
277 unsigned vector= remaining_tests[max_tests - test - 1];
279 int out_count, mid_count, out_ch_count;
288 if(specific_test == 0){
289 if(out_sample_rate != in_sample_rate || in_ch_layout != out_ch_layout)
297 fprintf(stderr,
"TEST: %s->%s, rate:%5d->%5d, fmt:%s->%s\n",
298 in_layout_string, out_layout_string,
299 in_sample_rate, out_sample_rate,
301 forw_ctx =
swr_alloc_set_opts(forw_ctx, out_ch_layout, out_sample_fmt, out_sample_rate,
302 in_ch_layout, in_sample_fmt, in_sample_rate,
304 backw_ctx =
swr_alloc_set_opts(backw_ctx, in_ch_layout, in_sample_fmt, in_sample_rate,
305 out_ch_layout, out_sample_fmt, out_sample_rate,
308 fprintf(stderr,
"Failed to init forw_cts\n");
312 fprintf(stderr,
"Failed to init backw_ctx\n");
316 fprintf(stderr,
"swr_init(->) failed\n");
318 fprintf(stderr,
"swr_init(<-) failed\n");
324 for(ch=0; ch<in_ch_count; ch++){
326 set(ain, ch, i, in_ch_count, in_sample_fmt, sin(i*i*3/SAMPLES));
341 shift(ain, 1, in_ch_count, in_sample_fmt);
343 shift(amid, mid_count, out_ch_count, out_sample_fmt); tmp_count = mid_count;
345 shift(amid, mid_count-tmp_count, out_ch_count, out_sample_fmt); tmp_count = mid_count;
346 shift(ain, 2, in_ch_count, in_sample_fmt);
348 shift(amid, mid_count-tmp_count, out_ch_count, out_sample_fmt); tmp_count = mid_count;
349 shift(ain, -3, in_ch_count, in_sample_fmt);
351 shift(amid, -tmp_count, out_ch_count, out_sample_fmt);
355 for(ch=0; ch<in_ch_count; ch++){
356 double sse, maxdiff=0;
362 for(i=0; i<out_count; i++){
372 sse= sum_aa + sum_bb - 2*sum_ab;
373 if(sse < 0 && sse > -0.00001) sse=0;
375 fprintf(stderr,
"[e:%f c:%f max:%f] len:%5d\n", out_count ? sqrt(sse/out_count) : 0, sum_ab/(sqrt(sum_aa*sum_bb)), maxdiff, out_count);
380 flush_count =
swr_convert(backw_ctx,aout, flush_i, 0, 0);
381 shift(aout, flush_i, in_ch_count, in_sample_fmt);
383 shift(aout, -flush_i, in_ch_count, in_sample_fmt);
385 for(ch=0; ch<in_ch_count; ch++){
386 double sse, maxdiff=0;
392 for(i=0; i<flush_count; i++){
393 double a=
get(ain , ch, i+out_count, in_ch_count,
in_sample_fmt);
402 sse= sum_aa + sum_bb - 2*sum_ab;
403 if(sse < 0 && sse > -0.00001) sse=0;
405 fprintf(stderr,
"[e:%f c:%f max:%f] len:%5d F:%3d\n", sqrt(sse/flush_count), sum_ab/(sqrt(sum_aa*sum_bb)), maxdiff, flush_count, flush_i);
410 fprintf(stderr,
"\n");