FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
swresample-test.c
Go to the documentation of this file.
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"
24 #include "libavutil/common.h"
25 #include "libavutil/opt.h"
26 #include "swresample.h"
27 
28 #undef time
29 #include "time.h"
30 #undef fprintf
31 
32 #define SAMPLES 1000
33 
34 #define SWR_CH_MAX 32
35 
36 #define ASSERT_LEVEL 2
37 
38 static double get(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f){
39  const uint8_t *p;
41  f= av_get_alt_sample_fmt(f, 0);
42  p= a[ch];
43  }else{
44  p= a[0];
45  index= ch + index*ch_count;
46  }
47 
48  switch(f){
49  case AV_SAMPLE_FMT_U8 : return ((const uint8_t*)p)[index]/127.0-1.0;
50  case AV_SAMPLE_FMT_S16: return ((const int16_t*)p)[index]/32767.0;
51  case AV_SAMPLE_FMT_S32: return ((const int32_t*)p)[index]/2147483647.0;
52  case AV_SAMPLE_FMT_FLT: return ((const float *)p)[index];
53  case AV_SAMPLE_FMT_DBL: return ((const double *)p)[index];
54  default: av_assert0(0);
55  }
56 }
57 
58 static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v){
59  uint8_t *p;
61  f= av_get_alt_sample_fmt(f, 0);
62  p= a[ch];
63  }else{
64  p= a[0];
65  index= ch + index*ch_count;
66  }
67  switch(f){
68  case AV_SAMPLE_FMT_U8 : ((uint8_t*)p)[index]= av_clip_uint8 (lrint((v+1.0)*127)); break;
69  case AV_SAMPLE_FMT_S16: ((int16_t*)p)[index]= av_clip_int16 (lrint(v*32767)); break;
70  case AV_SAMPLE_FMT_S32: ((int32_t*)p)[index]= av_clipl_int32(llrint(v*2147483647)); break;
71  case AV_SAMPLE_FMT_FLT: ((float *)p)[index]= v; break;
72  case AV_SAMPLE_FMT_DBL: ((double *)p)[index]= v; break;
73  default: av_assert2(0);
74  }
75 }
76 
77 static void shift(uint8_t *a[], int index, int ch_count, enum AVSampleFormat f){
78  int ch;
79 
81  f= av_get_alt_sample_fmt(f, 0);
82  for(ch= 0; ch<ch_count; ch++)
83  a[ch] += index*av_get_bytes_per_sample(f);
84  }else{
85  a[0] += index*ch_count*av_get_bytes_per_sample(f);
86  }
87 }
88 
89 static const enum AVSampleFormat formats[] = {
100 };
101 
102 static const int rates[] = {
103  8000,
104  11025,
105  16000,
106  22050,
107  32000,
108  48000,
109 };
110 
111 static const uint64_t layouts[]={
126 };
127 
128 static void setup_array(uint8_t *out[SWR_CH_MAX], uint8_t *in, enum AVSampleFormat format, int samples){
129  if(av_sample_fmt_is_planar(format)){
130  int i;
131  int plane_size= av_get_bytes_per_sample(format&0xFF)*samples;
132  format&=0xFF;
133  for(i=0; i<SWR_CH_MAX; i++){
134  out[i]= in + i*plane_size;
135  }
136  }else{
137  out[0]= in;
138  }
139 }
140 
141 static int cmp(const void *a, const void *b){
142  return *(const int *)a - *(const int *)b;
143 }
144 
145 static void audiogen(void *data, enum AVSampleFormat sample_fmt,
146  int channels, int sample_rate, int nb_samples)
147 {
148  int i, ch, k;
149  double v, f, a, ampa;
150  double tabf1[SWR_CH_MAX];
151  double tabf2[SWR_CH_MAX];
152  double taba[SWR_CH_MAX];
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++)
165  PUT_SAMPLE
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++)
174  PUT_SAMPLE
175  f = 100.0 + (((10000.0 - 100.0) * i) / sample_rate);
176  a += M_PI * f * 2.0 / 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++) {
181  v = dbl_rand(rnd) * 0.30;
182  for (ch = 0; ch < channels; ch++)
183  PUT_SAMPLE
184  }
185 
186  /* 0.5 second of high amplitude white noise */
187  for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) {
188  v = dbl_rand(rnd);
189  for (ch = 0; ch < channels; ch++)
190  PUT_SAMPLE
191  }
192 
193  /* 1 second of unrelated ramps for each channel */
194  for (ch = 0; ch < channels; ch++) {
195  taba[ch] = 0;
196  tabf1[ch] = 100 + uint_rand(rnd) % 5000;
197  tabf2[ch] = 100 + uint_rand(rnd) % 5000;
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;
202  PUT_SAMPLE
203  f = tabf1[ch] + (((tabf2[ch] - tabf1[ch]) * i) / sample_rate);
204  taba[ch] += M_PI * f * 2.0 / 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;
217  PUT_SAMPLE
218  a += M_PI * 500.0 * 2.0 / sample_rate;
219  ampa += M_PI * 2.0 / sample_rate;
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;
227  enum AVSampleFormat in_sample_fmt, out_sample_fmt;
228  uint8_t array_in[SAMPLES*8*8];
229  uint8_t array_mid[SAMPLES*8*8*3];
230  uint8_t array_out[SAMPLES*8*8+100];
231  uint8_t *ain[SWR_CH_MAX];
232  uint8_t *aout[SWR_CH_MAX];
233  uint8_t *amid[SWR_CH_MAX];
234  int flush_i=0;
235  int mode;
236  int num_tests = 10000;
237  uint32_t seed = 0;
238  uint32_t rand_seed = 0;
240  int max_tests = FF_ARRAY_ELEMS(remaining_tests);
241  int test;
242  int specific_test= -1;
243 
244  struct SwrContext * forw_ctx= NULL;
245  struct SwrContext *backw_ctx= NULL;
246 
247  if (argc > 1) {
248  if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
249  av_log(NULL, AV_LOG_INFO, "Usage: swresample-test [<num_tests>[ <test>]] \n"
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++){
269  unsigned r;
270  uint_rand(seed);
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]), 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 
283  in_ch_layout = layouts[vector % FF_ARRAY_ELEMS(layouts)]; vector /= FF_ARRAY_ELEMS(layouts);
284  out_ch_layout = layouts[vector % FF_ARRAY_ELEMS(layouts)]; vector /= FF_ARRAY_ELEMS(layouts);
285  in_sample_fmt = formats[vector % FF_ARRAY_ELEMS(formats)]; vector /= FF_ARRAY_ELEMS(formats);
286  out_sample_fmt = formats[vector % FF_ARRAY_ELEMS(formats)]; vector /= FF_ARRAY_ELEMS(formats);
287  out_sample_rate = rates [vector % FF_ARRAY_ELEMS(rates )]; vector /= FF_ARRAY_ELEMS(rates);
288  av_assert0(!vector);
289 
290  if(specific_test == 0){
291  if(out_sample_rate != in_sample_rate || in_ch_layout != out_ch_layout)
292  continue;
293  }
294 
295  in_ch_count= av_get_channel_layout_nb_channels(in_ch_layout);
296  out_ch_count= av_get_channel_layout_nb_channels(out_ch_layout);
297  av_get_channel_layout_string( in_layout_string, sizeof( in_layout_string), in_ch_count, in_ch_layout);
298  av_get_channel_layout_string(out_layout_string, sizeof(out_layout_string), out_ch_count, out_ch_layout);
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,
302  av_get_sample_fmt_name(in_sample_fmt), av_get_sample_fmt_name(out_sample_fmt));
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  }
317  if (uint_rand(rand_seed) % 3 == 0)
318  av_opt_set_int(forw_ctx, "ich", 0, 0);
319  if (uint_rand(rand_seed) % 3 == 0)
320  av_opt_set_int(forw_ctx, "och", 0, 0);
321 
322  if(swr_init( forw_ctx) < 0)
323  fprintf(stderr, "swr_init(->) failed\n");
324  if(swr_init(backw_ctx) < 0)
325  fprintf(stderr, "swr_init(<-) failed\n");
326  //FIXME test planar
327  setup_array(ain , array_in , in_sample_fmt, SAMPLES);
328  setup_array(amid, array_mid, out_sample_fmt, 3*SAMPLES);
329  setup_array(aout, array_out, in_sample_fmt , SAMPLES);
330 #if 0
331  for(ch=0; ch<in_ch_count; ch++){
332  for(i=0; i<SAMPLES; i++)
333  set(ain, ch, i, in_ch_count, in_sample_fmt, sin(i*i*3/SAMPLES));
334  }
335 #else
336  audiogen(ain, in_sample_fmt, in_ch_count, SAMPLES/6+1, SAMPLES);
337 #endif
338  mode = uint_rand(rand_seed) % 3;
339  if(mode==0 /*|| out_sample_rate == in_sample_rate*/) {
340  mid_count= swr_convert(forw_ctx, amid, 3*SAMPLES, (const uint8_t **)ain, SAMPLES);
341  } else if(mode==1){
342  mid_count= swr_convert(forw_ctx, amid, 0, (const uint8_t **)ain, SAMPLES);
343  mid_count+=swr_convert(forw_ctx, amid, 3*SAMPLES, (const uint8_t **)ain, 0);
344  } else {
345  int tmp_count;
346  mid_count= swr_convert(forw_ctx, amid, 0, (const uint8_t **)ain, 1);
347  av_assert0(mid_count==0);
348  shift(ain, 1, in_ch_count, in_sample_fmt);
349  mid_count+=swr_convert(forw_ctx, amid, 3*SAMPLES, (const uint8_t **)ain, 0);
350  shift(amid, mid_count, out_ch_count, out_sample_fmt); tmp_count = mid_count;
351  mid_count+=swr_convert(forw_ctx, amid, 2, (const uint8_t **)ain, 2);
352  shift(amid, mid_count-tmp_count, out_ch_count, out_sample_fmt); tmp_count = mid_count;
353  shift(ain, 2, in_ch_count, in_sample_fmt);
354  mid_count+=swr_convert(forw_ctx, amid, 1, (const uint8_t **)ain, SAMPLES-3);
355  shift(amid, mid_count-tmp_count, out_ch_count, out_sample_fmt); tmp_count = mid_count;
356  shift(ain, -3, in_ch_count, in_sample_fmt);
357  mid_count+=swr_convert(forw_ctx, amid, 3*SAMPLES, (const uint8_t **)ain, 0);
358  shift(amid, -tmp_count, out_ch_count, out_sample_fmt);
359  }
360  out_count= swr_convert(backw_ctx,aout, SAMPLES, (const uint8_t **)amid, mid_count);
361 
362  for(ch=0; ch<in_ch_count; ch++){
363  double sse, maxdiff=0;
364  double sum_a= 0;
365  double sum_b= 0;
366  double sum_aa= 0;
367  double sum_bb= 0;
368  double sum_ab= 0;
369  for(i=0; i<out_count; i++){
370  double a= get(ain , ch, i, in_ch_count, in_sample_fmt);
371  double b= get(aout, ch, i, in_ch_count, in_sample_fmt);
372  sum_a += a;
373  sum_b += b;
374  sum_aa+= a*a;
375  sum_bb+= b*b;
376  sum_ab+= a*b;
377  maxdiff= FFMAX(maxdiff, fabs(a-b));
378  }
379  sse= sum_aa + sum_bb - 2*sum_ab;
380  if(sse < 0 && sse > -0.00001) sse=0; //fix rounding error
381 
382  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);
383  }
384 
385  flush_i++;
386  flush_i%=21;
387  flush_count = swr_convert(backw_ctx,aout, flush_i, 0, 0);
388  shift(aout, flush_i, in_ch_count, in_sample_fmt);
389  flush_count+= swr_convert(backw_ctx,aout, SAMPLES-flush_i, 0, 0);
390  shift(aout, -flush_i, in_ch_count, in_sample_fmt);
391  if(flush_count){
392  for(ch=0; ch<in_ch_count; ch++){
393  double sse, maxdiff=0;
394  double sum_a= 0;
395  double sum_b= 0;
396  double sum_aa= 0;
397  double sum_bb= 0;
398  double sum_ab= 0;
399  for(i=0; i<flush_count; i++){
400  double a= get(ain , ch, i+out_count, in_ch_count, in_sample_fmt);
401  double b= get(aout, ch, i, in_ch_count, in_sample_fmt);
402  sum_a += a;
403  sum_b += b;
404  sum_aa+= a*a;
405  sum_bb+= b*b;
406  sum_ab+= a*b;
407  maxdiff= FFMAX(maxdiff, fabs(a-b));
408  }
409  sse= sum_aa + sum_bb - 2*sum_ab;
410  if(sse < 0 && sse > -0.00001) sse=0; //fix rounding error
411 
412  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);
413  }
414  }
415 
416 
417  fprintf(stderr, "\n");
418  }
419 
420  return 0;
421 }
float, planar
Definition: samplefmt.h:69
#define NULL
Definition: coverity.c:32
#define AV_CH_LAYOUT_7POINT1
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v)
#define AV_CH_LAYOUT_SURROUND
static int cmp(const void *a, const void *b)
const char * b
Definition: vf_curves.c:109
double, planar
Definition: samplefmt.h:70
static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride)
#define AV_CH_LAYOUT_4POINT0
#define AV_CH_LAYOUT_7POINT0
#define AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_5POINT0
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
static void shift(uint8_t *a[], int index, int ch_count, enum AVSampleFormat f)
uint8_t
AV_SAMPLE_FMT_U8
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:63
mode
Definition: f_perms.c:27
AVOptions.
static void sum_a(const int *input, int *output, int len)
Definition: dcadct.c:26
static enum AVSampleFormat formats[]
int main(int argc, char **argv)
signed 32 bits
Definition: samplefmt.h:62
#define av_log(a,...)
static const uint64_t layouts[]
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:110
static const int rates[]
#define AV_CH_LAYOUT_5POINT1
libswresample public header
static void sum_b(const int *input, int *output, int len)
Definition: dcadct.c:34
The libswresample context.
const char * r
Definition: vf_curves.c:107
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:534
simple assert() macros that are a bit more flexible than ISO C assert().
#define AV_CH_LAYOUT_QUAD
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:47
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_YASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out-> ch_count
Definition: audioconvert.c:56
#define FFMAX(a, b)
Definition: common.h:94
#define uint_rand(x)
#define AV_CH_LAYOUT_2_1
#define AV_CH_LAYOUT_2_2
audio channel layout utility functions
static void test(const char *pattern, const char *host)
Definition: noproxy-test.c:23
#define dbl_rand(x)
signed 32 bits, planar
Definition: samplefmt.h:68
#define SWR_CH_MAX
int32_t
struct SwrContext * swr_alloc_set_opts(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, int log_offset, void *log_ctx)
Allocate SwrContext if needed and set/reset common parameters.
Definition: swresample.c:59
unsigned 8 bits, planar
Definition: samplefmt.h:66
#define AV_CH_LAYOUT_5POINT1_BACK
#define FF_ARRAY_ELEMS(a)
FILE * out
Definition: movenc-test.c:54
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
sample_rate
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
static const char * format
Definition: movenc-test.c:47
static unsigned int seed
Definition: videogen.c:78
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
#define llrint(x)
Definition: libm.h:394
int index
Definition: gxfenc.c:89
#define AV_CH_LAYOUT_5POINT0_BACK
enum AVSampleFormat in_sample_fmt
input sample format
int attribute_align_arg swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_count, const uint8_t *in_arg[SWR_CH_MAX], int in_count)
Definition: swresample.c:695
#define AV_CH_LAYOUT_7POINT1_WIDE
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:104
enum AVSampleFormat av_get_alt_sample_fmt(enum AVSampleFormat sample_fmt, int planar)
Return the planar<->packed alternative form of the given sample format, or AV_SAMPLE_FMT_NONE on erro...
Definition: samplefmt.c:64
#define PUT_SAMPLE
common internal and external API header
signed 16 bits
Definition: samplefmt.h:61
#define rnd()
Definition: checkasm.h:66
static void setup_array(uint8_t *out[SWR_CH_MAX], uint8_t *in, enum AVSampleFormat format, int samples)
static void audiogen(void *data, enum AVSampleFormat sample_fmt, int channels, int sample_rate, int nb_samples)
#define lrint
Definition: tablegen.h:53
signed 16 bits, planar
Definition: samplefmt.h:67
#define M_PI
Definition: mathematics.h:46
#define FFSWAP(type, a, b)
Definition: common.h:99
#define AV_CH_LAYOUT_MONO
av_cold int swr_init(struct SwrContext *s)
Initialize context after user parameters have been set.
Definition: swresample.c:155
#define SAMPLES