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
27
28 #undef time
30 #undef fprintf
31
33
35
36 #define ASSERT_LEVEL 2
37
43 }else{
46 }
47
48 switch(f){
55 }
56 }
57
63 }else{
66 }
67 switch(f){
74 }
75 }
76
78 int ch;
79
84 }else{
86 }
87 }
88
100 };
101
103 8000,
104 11025,
105 16000,
106 22050,
107 32000,
108 48000,
109 };
110
126 };
127
130 int i;
132 format&=0xFF;
134 out[i]= in + i*plane_size;
135 }
136 }else{
138 }
139 }
140
141 static int cmp(
const int *
a,
const int *
b){
143 }
144
147 {
148 int i, ch, k;
149 double v, f,
a, ampa;
153 unsigned static rnd;
154
155 #define PUT_SAMPLE set(data, ch, k, channels, sample_fmt, v);
156 #define uint_rand(x) ((x) = (x) * 1664525 + 1013904223)
157 #define dbl_rand(x) (uint_rand(x)*2.0 / (double)UINT_MAX - 1)
158 k = 0;
159
160 /* 1 second of single freq sinus at 1000 Hz */
161 a = 0;
162 for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
163 v = sin(a) * 0.30;
164 for (ch = 0; ch < channels; ch++)
166 a +=
M_PI * 1000.0 * 2.0 / sample_rate;
167 }
168
169 /* 1 second of varying frequency between 100 and 10000 Hz */
170 a = 0;
171 for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
172 v = sin(a) * 0.30;
173 for (ch = 0; ch < channels; ch++)
175 f = 100.0 + (((10000.0 - 100.0) * i) / sample_rate);
177 }
178
179 /* 0.5 second of low amplitude white noise */
180 for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) {
182 for (ch = 0; ch < channels; ch++)
184 }
185
186 /* 0.5 second of high amplitude white noise */
187 for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) {
189 for (ch = 0; ch < channels; ch++)
191 }
192
193 /* 1 second of unrelated ramps for each channel */
194 for (ch = 0; ch < channels; ch++) {
195 taba[ch] = 0;
198 }
199 for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
200 for (ch = 0; ch < channels; ch++) {
201 v = sin(taba[ch]) * 0.30;
203 f = tabf1[ch] + (((tabf2[ch] - tabf1[ch]) * i) /
sample_rate);
205 }
206 }
207
208 /* 2 seconds of 500 Hz with varying volume */
209 a = 0;
210 ampa = 0;
211 for (i = 0; i < 2 * sample_rate && k < nb_samples; i++, k++) {
212 for (ch = 0; ch < channels; ch++) {
213 double amp = (1.0 + sin(ampa)) * 0.15;
214 if (ch & 1)
215 amp = 0.30 - amp;
216 v = sin(a) * amp;
220 }
221 }
222 }
223
224 int main(
int argc,
char **argv){
225 int in_sample_rate, out_sample_rate, ch ,i, flush_count;
226 uint64_t in_ch_layout, out_ch_layout;
234 int flush_i=0;
236 int num_tests = 10000;
238 uint32_t rand_seed = 0;
242 int specific_test= -1;
243
246
247 if (argc > 1) {
248 if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
250 "num_tests Default is %d\n", num_tests);
251 return 0;
252 }
253 num_tests = strtol(argv[1],
NULL, 0);
254 if(num_tests < 0) {
255 num_tests = -num_tests;
256 rand_seed = time(0);
257 }
258 if(num_tests<= 0 || num_tests>max_tests)
259 num_tests = max_tests;
260 if(argc > 2) {
261 specific_test = strtol(argv[1],
NULL, 0);
262 }
263 }
264
265 for(i=0; i<max_tests; i++)
266 remaining_tests[i] = i;
267
268 for(test=0; test<num_tests; test++){
271 r = (seed * (uint64_t)(max_tests - test)) >>32;
272 FFSWAP(
int, remaining_tests[r], remaining_tests[max_tests - test - 1]);
273 }
274 qsort(remaining_tests + max_tests - num_tests, num_tests,
sizeof(remaining_tests[0]), (
void*)
cmp);
275 in_sample_rate=16000;
276 for(test=0; test<num_tests; test++){
277 char in_layout_string[256];
278 char out_layout_string[256];
279 unsigned vector= remaining_tests[max_tests - test - 1];
280 int in_ch_count;
281 int out_count, mid_count, out_ch_count;
282
289
290 if(specific_test == 0){
291 if(out_sample_rate != in_sample_rate || in_ch_layout != out_ch_layout)
292 continue;
293 }
294
299 fprintf(stderr, "TEST: %s->%s, rate:%5d->%5d, fmt:%s->%s\n",
300 in_layout_string, out_layout_string,
301 in_sample_rate, out_sample_rate,
303 forw_ctx =
swr_alloc_set_opts(forw_ctx, out_ch_layout, out_sample_fmt, out_sample_rate,
304 in_ch_layout, in_sample_fmt, in_sample_rate,
305 0, 0);
306 backw_ctx =
swr_alloc_set_opts(backw_ctx, in_ch_layout, in_sample_fmt, in_sample_rate,
307 out_ch_layout, out_sample_fmt, out_sample_rate,
308 0, 0);
309 if(!forw_ctx) {
310 fprintf(stderr, "Failed to init forw_cts\n");
311 return 1;
312 }
313 if(!backw_ctx) {
314 fprintf(stderr, "Failed to init backw_ctx\n");
315 return 1;
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++){
328 set(ain, ch, i, in_ch_count, in_sample_fmt, sin(i*i*3/SAMPLES));
329 }
330 #else
332 #endif
334 if(mode==0 /*|| out_sample_rate == in_sample_rate*/) {
336 } else if(mode==1){
339 } else {
340 int tmp_count;
343 shift(ain, 1, in_ch_count, in_sample_fmt);
345 shift(amid, mid_count, out_ch_count, out_sample_fmt); tmp_count = mid_count;
347 shift(amid, mid_count-tmp_count, out_ch_count, out_sample_fmt); tmp_count = mid_count;
348 shift(ain, 2, in_ch_count, in_sample_fmt);
350 shift(amid, mid_count-tmp_count, out_ch_count, out_sample_fmt); tmp_count = mid_count;
351 shift(ain, -3, in_ch_count, in_sample_fmt);
353 shift(amid, -tmp_count, out_ch_count, out_sample_fmt);
354 }
356
357 for(ch=0; ch<in_ch_count; ch++){
358 double sse, maxdiff=0;
359 double sum_a= 0;
360 double sum_b= 0;
361 double sum_aa= 0;
362 double sum_bb= 0;
363 double sum_ab= 0;
364 for(i=0; i<out_count; i++){
373 }
374 sse= sum_aa + sum_bb - 2*sum_ab;
375 if(sse < 0 && sse > -0.00001) sse=0; //fix rounding error
376
377 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);
378 }
379
380 flush_i++;
381 flush_i%=21;
382 flush_count =
swr_convert(backw_ctx,aout, flush_i, 0, 0);
383 shift(aout, flush_i, in_ch_count, in_sample_fmt);
385 shift(aout, -flush_i, in_ch_count, in_sample_fmt);
386 if(flush_count){
387 for(ch=0; ch<in_ch_count; ch++){
388 double sse, maxdiff=0;
389 double sum_a= 0;
390 double sum_b= 0;
391 double sum_aa= 0;
392 double sum_bb= 0;
393 double sum_ab= 0;
394 for(i=0; i<flush_count; i++){
395 double a=
get(ain , ch, i+out_count, in_ch_count,
in_sample_fmt);
403 }
404 sse= sum_aa + sum_bb - 2*sum_ab;
405 if(sse < 0 && sse > -0.00001) sse=0; //fix rounding error
406
407 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);
408 }
409 }
410
411
412 fprintf(stderr, "\n");
413 }
414
415 return 0;
416 }