1 /*
2 * Copyright (C) 2011-2012 Michael Niedermayer (michaelni@gmx.at)
3 * Copyright (c) 2002 Fabrice Bellard
4 *
5 * This file is part of libswresample
6 *
7 * libswresample is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * libswresample is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with libswresample; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
26
28
29 #undef time
31 #undef fprintf
32
34
36
37 #define ASSERT_LEVEL 2
38
40 const uint8_t *p;
44 }else{
47 }
48
56 }
57 }
58
60 uint8_t *p;
64 }else{
67 }
75 }
76 }
77
79 int ch;
80
83 for(ch= 0; ch<ch_count; ch++)
85 }else{
87 }
88 }
89
101 };
102
104 8000,
105 11025,
106 16000,
107 22050,
108 32000,
109 48000,
110 };
111
127 };
128
136 }
137 }else{
139 }
140 }
141
142 static int cmp(
const void *
a,
const void *
b){
143 return *(
const int *)
a - *(
const int *)
b;
144 }
145
148 {
150 double v,
f,
a, ampa;
155
156 #define PUT_SAMPLE set(data, ch, k, channels, sample_fmt, v);
157 #define uint_rand(x) ((x) = (x) * 1664525 + 1013904223)
158 #define dbl_rand(x) (uint_rand(x)*2.0 / (double)UINT_MAX - 1)
159 k = 0;
160
161 /* 1 second of single freq sinus at 1000 Hz */
168 }
169
170 /* 1 second of varying frequency between 100 and 10000 Hz */
178 }
179
180 /* 0.5 second of low amplitude white noise */
185 }
186
187 /* 0.5 second of high amplitude white noise */
192 }
193
194 /* 1 second of unrelated ramps for each channel */
196 taba[ch] = 0;
199 }
202 v = sin(taba[ch]) * 0.30;
204 f = tabf1[ch] + (((tabf2[ch] - tabf1[ch]) *
i) /
sample_rate);
206 }
207 }
208
209 /* 2 seconds of 500 Hz with varying volume */
211 ampa = 0;
214 double amp = (1.0 + sin(ampa)) * 0.15;
215 if (ch & 1)
216 amp = 0.30 - amp;
221 }
222 }
223 }
224
225 int main(
int argc,
char **argv){
230 uint8_t array_mid[
SAMPLES*8*8*3];
231 uint8_t array_out[
SAMPLES*8*8+100];
235 int flush_i=0;
237 int num_tests = 10000;
239 uint32_t rand_seed = 0;
243 int specific_test= -1;
244
247
248 if (argc > 1) {
249 if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
251 "num_tests Default is %d\n", num_tests);
252 return 0;
253 }
254 num_tests = strtol(argv[1],
NULL, 0);
255 if(num_tests < 0) {
256 num_tests = -num_tests;
257 rand_seed = time(0);
258 }
259 if(num_tests<= 0 || num_tests>max_tests)
260 num_tests = max_tests;
261 if(argc > 2) {
262 specific_test = strtol(argv[1],
NULL, 0);
263 }
264 }
265
266 for(
i=0;
i<max_tests;
i++)
267 remaining_tests[
i] =
i;
268
272 r = (
seed * (uint64_t)(max_tests -
test)) >>32;
273 FFSWAP(
int, remaining_tests[
r], remaining_tests[max_tests -
test - 1]);
274 }
275 qsort(remaining_tests + max_tests - num_tests, num_tests,
sizeof(remaining_tests[0]),
cmp);
278 char in_layout_string[256];
279 char out_layout_string[256];
280 unsigned vector= remaining_tests[max_tests -
test - 1];
281 int in_ch_count;
282 int out_count, mid_count, out_ch_count;
283
290
291 if(specific_test == 0){
293 continue;
294 }
295
300 fprintf(stderr, "TEST: %s->%s, rate:%5d->%5d, fmt:%s->%s\n",
301 in_layout_string, out_layout_string,
306 0, 0) < 0) {
307 fprintf(stderr, "Failed to init forw_cts\n");
308 return 1;
309 }
312 0, 0) < 0) {
313 fprintf(stderr, "Failed to init backw_ctx\n");
314 return 1;
315 }
316
318 fprintf(stderr, "swr_init(->) failed\n");
320 fprintf(stderr, "swr_init(<-) failed\n");
321 //FIXME test planar
325 #if 0
326 for(ch=0; ch<in_ch_count; ch++){
329 }
330 #else
332 #endif
334 if(
mode==0
/*|| out_sample_rate == in_sample_rate*/) {
339 } else {
340 int tmp_count;
341 mid_count=
swr_convert(forw_ctx, amid, 0, (
const uint8_t **)ain, 1);
346 mid_count+=
swr_convert(forw_ctx, amid, 2, (
const uint8_t **)ain, 2);
354 }
356
357 for(ch=0; ch<in_ch_count; ch++){
358 double sse, maxdiff=0;
359 double sum_aa= 0;
360 double sum_bb= 0;
361 double sum_ab= 0;
362 for(
i=0;
i<out_count;
i++){
369 }
370 sse= sum_aa + sum_bb - 2*sum_ab;
371 if(sse < 0 && sse > -0.00001)
sse=0;
//fix rounding error
372
373 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);
374 }
375
376 flush_i++;
377 flush_i%=21;
378 flush_count =
swr_convert(backw_ctx,aout, flush_i, 0, 0);
382 if(flush_count){
383 for(ch=0; ch<in_ch_count; ch++){
384 double sse, maxdiff=0;
385 double sum_aa= 0;
386 double sum_bb= 0;
387 double sum_ab= 0;
388 for(
i=0;
i<flush_count;
i++){
395 }
396 sse= sum_aa + sum_bb - 2*sum_ab;
397 if(sse < 0 && sse > -0.00001)
sse=0;
//fix rounding error
398
399 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);
400 }
401 }
402
403
404 fprintf(stderr, "\n");
405 }
406
407 return 0;
408 }