FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libswresample/tests/swresample.c
Date: 2026-09-30 10:56:58
Exec Total Coverage
Lines: 201 223 90.1%
Functions: 7 7 100.0%
Branches: 99 130 76.2%

Line Branch Exec Source
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
22 #include "libavutil/avassert.h"
23 #include "libavutil/channel_layout.h"
24 #include "libavutil/common.h"
25 #include "libavutil/mem_internal.h"
26 #include "libavutil/opt.h"
27
28 #include "libswresample/swresample.h"
29
30 #include <time.h>
31
32 #define SAMPLES 1000
33
34 #define SWR_CH_MAX 32
35
36 9362622 static double get(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f){
37 const uint8_t *p;
38
2/2
✓ Branch 1 taken 4709624 times.
✓ Branch 2 taken 4652998 times.
9362622 if(av_sample_fmt_is_planar(f)){
39 4709624 f= av_get_alt_sample_fmt(f, 0);
40 4709624 p= a[ch];
41 }else{
42 4652998 p= a[0];
43 4652998 index= ch + index*ch_count;
44 }
45
46
5/6
✓ Branch 0 taken 1893122 times.
✓ Branch 1 taken 1815286 times.
✓ Branch 2 taken 1642030 times.
✓ Branch 3 taken 2178636 times.
✓ Branch 4 taken 1833548 times.
✗ Branch 5 not taken.
9362622 switch(f){
47 1893122 case AV_SAMPLE_FMT_U8 : return ((const uint8_t*)p)[index]/127.0-1.0;
48 1815286 case AV_SAMPLE_FMT_S16: return ((const int16_t*)p)[index]/32767.0;
49 1642030 case AV_SAMPLE_FMT_S32: return ((const int32_t*)p)[index]/2147483647.0;
50 2178636 case AV_SAMPLE_FMT_FLT: return ((const float *)p)[index];
51 1833548 case AV_SAMPLE_FMT_DBL: return ((const double *)p)[index];
52 ✗ default: av_assert0(0);
53 }
54 }
55
56 4762000 static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v){
57 uint8_t *p;
58
2/2
✓ Branch 1 taken 2396000 times.
✓ Branch 2 taken 2366000 times.
4762000 if(av_sample_fmt_is_planar(f)){
59 2396000 f= av_get_alt_sample_fmt(f, 0);
60 2396000 p= a[ch];
61 }else{
62 2366000 p= a[0];
63 2366000 index= ch + index*ch_count;
64 }
65
5/6
✓ Branch 0 taken 963000 times.
✓ Branch 1 taken 923000 times.
✓ Branch 2 taken 835000 times.
✓ Branch 3 taken 1108000 times.
✓ Branch 4 taken 933000 times.
✗ Branch 5 not taken.
4762000 switch(f){
66 963000 case AV_SAMPLE_FMT_U8 : ((uint8_t*)p)[index]= av_clip_uint8 (lrint((v+1.0)*127)); break;
67 923000 case AV_SAMPLE_FMT_S16: ((int16_t*)p)[index]= av_clip_int16 (lrint(v*32767)); break;
68 835000 case AV_SAMPLE_FMT_S32: ((int32_t*)p)[index]= av_clipl_int32(llrint(v*2147483647)); break;
69 1108000 case AV_SAMPLE_FMT_FLT: ((float *)p)[index]= v; break;
70 933000 case AV_SAMPLE_FMT_DBL: ((double *)p)[index]= v; break;
71 ✗ default: av_assert0(0);
72 }
73 4762000 }
74
75 4233 static void shift(uint8_t *a[], int index, int ch_count, enum AVSampleFormat f){
76 int ch;
77
78
2/2
✓ Branch 1 taken 2168 times.
✓ Branch 2 taken 2065 times.
4233 if(av_sample_fmt_is_planar(f)){
79 2168 f= av_get_alt_sample_fmt(f, 0);
80
2/2
✓ Branch 0 taken 10379 times.
✓ Branch 1 taken 2168 times.
12547 for(ch= 0; ch<ch_count; ch++)
81 10379 a[ch] += index*av_get_bytes_per_sample(f);
82 }else{
83 2065 a[0] += index*ch_count*av_get_bytes_per_sample(f);
84 }
85 4233 }
86
87 static const enum AVSampleFormat formats[] = {
88 AV_SAMPLE_FMT_S16,
89 AV_SAMPLE_FMT_FLTP,
90 AV_SAMPLE_FMT_S16P,
91 AV_SAMPLE_FMT_FLT,
92 AV_SAMPLE_FMT_S32P,
93 AV_SAMPLE_FMT_S32,
94 AV_SAMPLE_FMT_U8P,
95 AV_SAMPLE_FMT_U8,
96 AV_SAMPLE_FMT_DBLP,
97 AV_SAMPLE_FMT_DBL,
98 };
99
100 static const int rates[] = {
101 8000,
102 11025,
103 16000,
104 22050,
105 32000,
106 48000,
107 };
108
109 static const AVChannelLayout layouts[]={
110 AV_CHANNEL_LAYOUT_MONO ,
111 AV_CHANNEL_LAYOUT_STEREO ,
112 AV_CHANNEL_LAYOUT_2_1 ,
113 AV_CHANNEL_LAYOUT_SURROUND ,
114 AV_CHANNEL_LAYOUT_4POINT0 ,
115 AV_CHANNEL_LAYOUT_2_2 ,
116 AV_CHANNEL_LAYOUT_QUAD ,
117 AV_CHANNEL_LAYOUT_5POINT0 ,
118 AV_CHANNEL_LAYOUT_5POINT1 ,
119 AV_CHANNEL_LAYOUT_5POINT0_BACK ,
120 AV_CHANNEL_LAYOUT_5POINT1_BACK ,
121 AV_CHANNEL_LAYOUT_7POINT0 ,
122 AV_CHANNEL_LAYOUT_7POINT1 ,
123 AV_CHANNEL_LAYOUT_7POINT1_WIDE ,
124 };
125
126 3000 static void setup_array(uint8_t *out[SWR_CH_MAX], uint8_t *in, enum AVSampleFormat format, int samples){
127
2/2
✓ Branch 1 taken 1527 times.
✓ Branch 2 taken 1473 times.
3000 if(av_sample_fmt_is_planar(format)){
128 int i;
129 1527 int plane_size= av_get_bytes_per_sample(format&0xFF)*samples;
130 1527 format&=0xFF;
131
2/2
✓ Branch 0 taken 48864 times.
✓ Branch 1 taken 1527 times.
50391 for(i=0; i<SWR_CH_MAX; i++){
132 48864 out[i]= in + i*plane_size;
133 }
134 }else{
135 1473 out[0]= in;
136 }
137 3000 }
138
139 8669 static int cmp(const void *a, const void *b){
140 8669 return *(const int *)a - *(const int *)b;
141 }
142
143 1000 static void audiogen(void *data, enum AVSampleFormat sample_fmt,
144 int channels, int sample_rate, int nb_samples)
145 {
146 int i, ch, k;
147 double v, f, a, ampa;
148 double tabf1[SWR_CH_MAX];
149 double tabf2[SWR_CH_MAX];
150 double taba[SWR_CH_MAX];
151 unsigned static rnd;
152
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)
156 1000 k = 0;
157
158 /* 1 second of single freq sinus at 1000 Hz */
159 1000 a = 0;
160
3/4
✓ Branch 0 taken 167000 times.
✓ Branch 1 taken 1000 times.
✓ Branch 2 taken 167000 times.
✗ Branch 3 not taken.
168000 for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
161 167000 v = sin(a) * 0.30;
162
2/2
✓ Branch 0 taken 795254 times.
✓ Branch 1 taken 167000 times.
962254 for (ch = 0; ch < channels; ch++)
163 795254 PUT_SAMPLE
164 167000 a += M_PI * 1000.0 * 2.0 / sample_rate;
165 }
166
167 /* 1 second of varying frequency between 100 and 10000 Hz */
168 1000 a = 0;
169
3/4
✓ Branch 0 taken 167000 times.
✓ Branch 1 taken 1000 times.
✓ Branch 2 taken 167000 times.
✗ Branch 3 not taken.
168000 for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
170 167000 v = sin(a) * 0.30;
171
2/2
✓ Branch 0 taken 795254 times.
✓ Branch 1 taken 167000 times.
962254 for (ch = 0; ch < channels; ch++)
172 795254 PUT_SAMPLE
173 167000 f = 100.0 + (((10000.0 - 100.0) * i) / sample_rate);
174 167000 a += M_PI * f * 2.0 / sample_rate;
175 }
176
177 /* 0.5 second of low amplitude white noise */
178
3/4
✓ Branch 0 taken 83000 times.
✓ Branch 1 taken 1000 times.
✓ Branch 2 taken 83000 times.
✗ Branch 3 not taken.
84000 for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) {
179 83000 v = dbl_rand(rnd) * 0.30;
180
2/2
✓ Branch 0 taken 395246 times.
✓ Branch 1 taken 83000 times.
478246 for (ch = 0; ch < channels; ch++)
181 395246 PUT_SAMPLE
182 }
183
184 /* 0.5 second of high amplitude white noise */
185
3/4
✓ Branch 0 taken 83000 times.
✓ Branch 1 taken 1000 times.
✓ Branch 2 taken 83000 times.
✗ Branch 3 not taken.
84000 for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) {
186 83000 v = dbl_rand(rnd);
187
2/2
✓ Branch 0 taken 395246 times.
✓ Branch 1 taken 83000 times.
478246 for (ch = 0; ch < channels; ch++)
188 395246 PUT_SAMPLE
189 }
190
191 /* 1 second of unrelated ramps for each channel */
192
2/2
✓ Branch 0 taken 4762 times.
✓ Branch 1 taken 1000 times.
5762 for (ch = 0; ch < channels; ch++) {
193 4762 taba[ch] = 0;
194 4762 tabf1[ch] = 100 + uint_rand(rnd) % 5000;
195 4762 tabf2[ch] = 100 + uint_rand(rnd) % 5000;
196 }
197
3/4
✓ Branch 0 taken 167000 times.
✓ Branch 1 taken 1000 times.
✓ Branch 2 taken 167000 times.
✗ Branch 3 not taken.
168000 for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
198
2/2
✓ Branch 0 taken 795254 times.
✓ Branch 1 taken 167000 times.
962254 for (ch = 0; ch < channels; ch++) {
199 795254 v = sin(taba[ch]) * 0.30;
200 795254 PUT_SAMPLE
201 795254 f = tabf1[ch] + (((tabf2[ch] - tabf1[ch]) * i) / sample_rate);
202 795254 taba[ch] += M_PI * f * 2.0 / sample_rate;
203 }
204 }
205
206 /* 2 seconds of 500 Hz with varying volume */
207 1000 a = 0;
208 1000 ampa = 0;
209
3/4
✓ Branch 0 taken 334000 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 333000 times.
✓ Branch 3 taken 1000 times.
334000 for (i = 0; i < 2 * sample_rate && k < nb_samples; i++, k++) {
210
2/2
✓ Branch 0 taken 1585746 times.
✓ Branch 1 taken 333000 times.
1918746 for (ch = 0; ch < channels; ch++) {
211 1585746 double amp = (1.0 + sin(ampa)) * 0.15;
212
2/2
✓ Branch 0 taken 721611 times.
✓ Branch 1 taken 864135 times.
1585746 if (ch & 1)
213 721611 amp = 0.30 - amp;
214 1585746 v = sin(a) * amp;
215 1585746 PUT_SAMPLE
216 1585746 a += M_PI * 500.0 * 2.0 / sample_rate;
217 1585746 ampa += M_PI * 2.0 / sample_rate;
218 }
219 }
220 1000 }
221
222 1 int main(int argc, char **argv){
223 int in_sample_rate, out_sample_rate, ch ,i, flush_count;
224 1 AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 };
225 enum AVSampleFormat in_sample_fmt, out_sample_fmt;
226 1 LOCAL_ALIGNED(32, uint8_t, array_in, [SAMPLES*8*8]);
227 1 LOCAL_ALIGNED(32, uint8_t, array_mid, [SAMPLES*8*8*3]);
228 1 LOCAL_ALIGNED(32, uint8_t, array_out, [SAMPLES*8*8+100]);
229 uint8_t *ain[SWR_CH_MAX];
230 uint8_t *aout[SWR_CH_MAX];
231 uint8_t *amid[SWR_CH_MAX];
232 1 int flush_i=0;
233 int mode;
234 1 int num_tests = 10000;
235 1 uint32_t seed = 0;
236 1 uint32_t rand_seed = 0;
237 int remaining_tests[FF_ARRAY_ELEMS(rates) * FF_ARRAY_ELEMS(layouts) * FF_ARRAY_ELEMS(formats) * FF_ARRAY_ELEMS(layouts) * FF_ARRAY_ELEMS(formats)];
238 1 int max_tests = FF_ARRAY_ELEMS(remaining_tests);
239 int test;
240 1 int specific_test= -1;
241 1 int ret = 0;
242
243 1 struct SwrContext * forw_ctx= NULL;
244 1 struct SwrContext *backw_ctx= NULL;
245
246
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (argc > 1) {
247
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
248 ✗ av_log(NULL, AV_LOG_INFO, "Usage: swresample-test [<num_tests>[ <test>]] \n"
249 "num_tests Default is %d\n", num_tests);
250 ✗ return 0;
251 }
252 1 num_tests = strtol(argv[1], NULL, 0);
253
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(num_tests < 0) {
254 ✗ num_tests = -num_tests;
255 ✗ rand_seed = time(0);
256 }
257
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if(num_tests<= 0 || num_tests>max_tests)
258 ✗ num_tests = max_tests;
259
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(argc > 2) {
260 ✗ specific_test = strtol(argv[1], NULL, 0);
261 }
262 }
263
264
2/2
✓ Branch 0 taken 117600 times.
✓ Branch 1 taken 1 times.
117601 for(i=0; i<max_tests; i++)
265 117600 remaining_tests[i] = i;
266
267
2/2
✓ Branch 0 taken 1000 times.
✓ Branch 1 taken 1 times.
1001 for(test=0; test<num_tests; test++){
268 unsigned r;
269 1000 uint_rand(seed);
270 1000 r = (seed * (uint64_t)(max_tests - test)) >>32;
271 1000 FFSWAP(int, remaining_tests[r], remaining_tests[max_tests - test - 1]);
272 }
273 1 qsort(remaining_tests + max_tests - num_tests, num_tests, sizeof(remaining_tests[0]), cmp);
274 1 in_sample_rate=16000;
275
2/2
✓ Branch 0 taken 1000 times.
✓ Branch 1 taken 1 times.
1001 for(test=0; test<num_tests; test++){
276 char in_layout_string[256];
277 char out_layout_string[256];
278 1000 unsigned vector= remaining_tests[max_tests - test - 1];
279 int in_ch_count;
280 int out_count, mid_count, out_ch_count;
281
282 1000 av_channel_layout_copy(&in_ch_layout, &layouts[vector % FF_ARRAY_ELEMS(layouts)]); vector /= FF_ARRAY_ELEMS(layouts);
283 1000 av_channel_layout_copy(&out_ch_layout, &layouts[vector % FF_ARRAY_ELEMS(layouts)]); vector /= FF_ARRAY_ELEMS(layouts);
284 1000 in_sample_fmt = formats[vector % FF_ARRAY_ELEMS(formats)]; vector /= FF_ARRAY_ELEMS(formats);
285 1000 out_sample_fmt = formats[vector % FF_ARRAY_ELEMS(formats)]; vector /= FF_ARRAY_ELEMS(formats);
286 1000 out_sample_rate = rates [vector % FF_ARRAY_ELEMS(rates )]; vector /= FF_ARRAY_ELEMS(rates);
287
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1000 times.
1000 av_assert0(!vector);
288
289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1000 times.
1000 if(specific_test == 0){
290 ✗ if(out_sample_rate != in_sample_rate || av_channel_layout_compare(&in_ch_layout, &out_ch_layout))
291 ✗ continue;
292 }
293
294 1000 in_ch_count= in_ch_layout.nb_channels;
295 1000 out_ch_count= out_ch_layout.nb_channels;
296 1000 av_channel_layout_describe(&in_ch_layout, in_layout_string, sizeof( in_layout_string));
297 1000 av_channel_layout_describe(&out_ch_layout, out_layout_string, sizeof(out_layout_string));
298 1000 fprintf(stderr, "TEST: %s->%s, rate:%5d->%5d, fmt:%s->%s\n",
299 in_layout_string, out_layout_string,
300 in_sample_rate, out_sample_rate,
301 av_get_sample_fmt_name(in_sample_fmt), av_get_sample_fmt_name(out_sample_fmt));
302
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1000 times.
1000 if (swr_alloc_set_opts2(&forw_ctx, &out_ch_layout, out_sample_fmt, out_sample_rate,
303 &in_ch_layout, in_sample_fmt, in_sample_rate,
304 0, 0) < 0) {
305 ✗ fprintf(stderr, "Failed to init forw_cts\n");
306 ✗ ret = 1;
307 ✗ goto end;
308 }
309
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1000 times.
1000 if (swr_alloc_set_opts2(&backw_ctx, &in_ch_layout, in_sample_fmt, in_sample_rate,
310 &out_ch_layout, out_sample_fmt, out_sample_rate,
311 0, 0) < 0) {
312 ✗ fprintf(stderr, "Failed to init backw_ctx\n");
313 ✗ ret = 1;
314 ✗ goto end;
315 }
316
317
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1000 times.
1000 if (swr_init(forw_ctx) < 0) {
318 ✗ fprintf(stderr, "swr_init(->) failed\n");
319 ✗ ret = 1;
320 ✗ goto end;
321 }
322
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1000 times.
1000 if (swr_init(backw_ctx) < 0) {
323 ✗ fprintf(stderr, "swr_init(<-) failed\n");
324 ✗ ret = 1;
325 ✗ goto end;
326 }
327 //FIXME test planar
328 1000 setup_array(ain , array_in , in_sample_fmt, SAMPLES);
329 1000 setup_array(amid, array_mid, out_sample_fmt, 3*SAMPLES);
330 1000 setup_array(aout, array_out, in_sample_fmt , SAMPLES);
331 #if 0
332 for(ch=0; ch<in_ch_count; ch++){
333 for(i=0; i<SAMPLES; i++)
334 set(ain, ch, i, in_ch_count, in_sample_fmt, sin(i*i*3/SAMPLES));
335 }
336 #else
337 1000 audiogen(ain, in_sample_fmt, in_ch_count, SAMPLES/6+1, SAMPLES);
338 #endif
339 1000 mode = uint_rand(rand_seed) % 3;
340
2/2
✓ Branch 0 taken 357 times.
✓ Branch 1 taken 643 times.
1000 if(mode==0 /*|| out_sample_rate == in_sample_rate*/) {
341 357 mid_count= swr_convert(forw_ctx, amid, 3*SAMPLES, (const uint8_t **)ain, SAMPLES);
342
2/2
✓ Branch 0 taken 324 times.
✓ Branch 1 taken 319 times.
643 } else if(mode==1){
343 324 mid_count= swr_convert(forw_ctx, amid, 0, (const uint8_t **)ain, SAMPLES);
344 324 mid_count+=swr_convert(forw_ctx, amid, 3*SAMPLES, (const uint8_t **)ain, 0);
345 } else {
346 int tmp_count;
347 319 mid_count= swr_convert(forw_ctx, amid, 0, (const uint8_t **)ain, 1);
348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 319 times.
319 av_assert0(mid_count==0);
349 319 shift(ain, 1, in_ch_count, in_sample_fmt);
350 319 mid_count+=swr_convert(forw_ctx, amid, 3*SAMPLES, (const uint8_t **)ain, 0);
351 319 shift(amid, mid_count, out_ch_count, out_sample_fmt); tmp_count = mid_count;
352 319 mid_count+=swr_convert(forw_ctx, amid, 2, (const uint8_t **)ain, 2);
353 319 shift(amid, mid_count-tmp_count, out_ch_count, out_sample_fmt); tmp_count = mid_count;
354 319 shift(ain, 2, in_ch_count, in_sample_fmt);
355 319 mid_count+=swr_convert(forw_ctx, amid, 1, (const uint8_t **)ain, SAMPLES-3);
356 319 shift(amid, mid_count-tmp_count, out_ch_count, out_sample_fmt); tmp_count = mid_count;
357 319 shift(ain, -3, in_ch_count, in_sample_fmt);
358 319 mid_count+=swr_convert(forw_ctx, amid, 3*SAMPLES, (const uint8_t **)ain, 0);
359 319 shift(amid, -tmp_count, out_ch_count, out_sample_fmt);
360 }
361 1000 out_count= swr_convert(backw_ctx,aout, SAMPLES, (const uint8_t **)amid, mid_count);
362
363
2/2
✓ Branch 0 taken 4762 times.
✓ Branch 1 taken 1000 times.
5762 for(ch=0; ch<in_ch_count; ch++){
364 4762 double sse, maxdiff=0;
365 4762 double sum_aa= 0;
366 4762 double sum_bb= 0;
367 4762 double sum_ab= 0;
368
2/2
✓ Branch 0 taken 4598776 times.
✓ Branch 1 taken 4762 times.
4603538 for(i=0; i<out_count; i++){
369 4598776 double a= get(ain , ch, i, in_ch_count, in_sample_fmt);
370 4598776 double b= get(aout, ch, i, in_ch_count, in_sample_fmt);
371 4598776 sum_aa+= a*a;
372 4598776 sum_bb+= b*b;
373 4598776 sum_ab+= a*b;
374
2/2
✓ Branch 0 taken 4277571 times.
✓ Branch 1 taken 321205 times.
4598776 maxdiff= FFMAX(maxdiff, fabs(a-b));
375 }
376 4762 sse= sum_aa + sum_bb - 2*sum_ab;
377
3/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 4744 times.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
4762 if(sse < 0 && sse > -0.00001) sse=0; //fix rounding error
378
379
1/2
✓ Branch 0 taken 4762 times.
✗ Branch 1 not taken.
4762 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 }
381
382 1000 flush_i++;
383 1000 flush_i%=21;
384 1000 flush_count = swr_convert(backw_ctx,aout, flush_i, 0, 0);
385 1000 shift(aout, flush_i, in_ch_count, in_sample_fmt);
386 1000 flush_count+= swr_convert(backw_ctx,aout, SAMPLES-flush_i, 0, 0);
387 1000 shift(aout, -flush_i, in_ch_count, in_sample_fmt);
388
2/2
✓ Branch 0 taken 823 times.
✓ Branch 1 taken 177 times.
1000 if(flush_count){
389
2/2
✓ Branch 0 taken 3973 times.
✓ Branch 1 taken 823 times.
4796 for(ch=0; ch<in_ch_count; ch++){
390 3973 double sse, maxdiff=0;
391 3973 double sum_aa= 0;
392 3973 double sum_bb= 0;
393 3973 double sum_ab= 0;
394
2/2
✓ Branch 0 taken 82535 times.
✓ Branch 1 taken 3973 times.
86508 for(i=0; i<flush_count; i++){
395 82535 double a= get(ain , ch, i+out_count, in_ch_count, in_sample_fmt);
396 82535 double b= get(aout, ch, i, in_ch_count, in_sample_fmt);
397 82535 sum_aa+= a*a;
398 82535 sum_bb+= b*b;
399 82535 sum_ab+= a*b;
400
2/2
✓ Branch 0 taken 50753 times.
✓ Branch 1 taken 31782 times.
82535 maxdiff= FFMAX(maxdiff, fabs(a-b));
401 }
402 3973 sse= sum_aa + sum_bb - 2*sum_ab;
403
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3973 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3973 if(sse < 0 && sse > -0.00001) sse=0; //fix rounding error
404
405 3973 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);
406 }
407 }
408
409
410 1000 fprintf(stderr, "\n");
411 }
412
413 1 end:
414 1 swr_free(&forw_ctx);
415 1 swr_free(&backw_ctx);
416 1 av_channel_layout_uninit(&in_ch_layout);
417 1 av_channel_layout_uninit(&out_ch_layout);
418 1 return ret;
419 }
420