2011-09-19 04:13:30 +00:00
|
|
|
/*
|
2012-09-06 19:23:09 +00:00
|
|
|
* Copyright (C) 2011-2012 Michael Niedermayer (michaelni@gmx.at)
|
2012-04-26 18:21:22 +00:00
|
|
|
* Copyright (c) 2002 Fabrice Bellard
|
2011-09-19 04:13:30 +00:00
|
|
|
*
|
|
|
|
* This file is part of libswresample
|
|
|
|
*
|
|
|
|
* libswresample is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* libswresample is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with libswresample; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libavutil/avassert.h"
|
2012-11-13 13:16:48 +00:00
|
|
|
#include "libavutil/channel_layout.h"
|
2011-09-19 04:13:30 +00:00
|
|
|
#include "libavutil/common.h"
|
2012-04-10 17:53:43 +00:00
|
|
|
#include "libavutil/opt.h"
|
2016-06-22 11:44:29 +00:00
|
|
|
|
|
|
|
#include "libswresample/swresample.h"
|
2012-05-01 11:16:13 +00:00
|
|
|
|
|
|
|
#undef time
|
2016-06-22 12:00:08 +00:00
|
|
|
#include <time.h>
|
2011-09-19 04:13:30 +00:00
|
|
|
#undef fprintf
|
|
|
|
|
|
|
|
#define SAMPLES 1000
|
|
|
|
|
2014-08-09 23:10:45 +00:00
|
|
|
#define SWR_CH_MAX 32
|
|
|
|
|
2011-09-19 04:13:30 +00:00
|
|
|
#define ASSERT_LEVEL 2
|
|
|
|
|
2011-12-02 23:46:46 +00:00
|
|
|
static double get(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f){
|
2011-09-29 02:55:53 +00:00
|
|
|
const uint8_t *p;
|
2011-11-24 03:30:32 +00:00
|
|
|
if(av_sample_fmt_is_planar(f)){
|
|
|
|
f= av_get_alt_sample_fmt(f, 0);
|
2011-09-29 02:55:53 +00:00
|
|
|
p= a[ch];
|
|
|
|
}else{
|
|
|
|
p= a[0];
|
|
|
|
index= ch + index*ch_count;
|
|
|
|
}
|
|
|
|
|
2011-09-19 04:13:30 +00:00
|
|
|
switch(f){
|
2012-04-26 17:45:30 +00:00
|
|
|
case AV_SAMPLE_FMT_U8 : return ((const uint8_t*)p)[index]/127.0-1.0;
|
2011-09-19 04:13:30 +00:00
|
|
|
case AV_SAMPLE_FMT_S16: return ((const int16_t*)p)[index]/32767.0;
|
|
|
|
case AV_SAMPLE_FMT_S32: return ((const int32_t*)p)[index]/2147483647.0;
|
|
|
|
case AV_SAMPLE_FMT_FLT: return ((const float *)p)[index];
|
|
|
|
case AV_SAMPLE_FMT_DBL: return ((const double *)p)[index];
|
2011-11-16 19:39:16 +00:00
|
|
|
default: av_assert0(0);
|
2011-09-19 04:13:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 02:55:53 +00:00
|
|
|
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v){
|
|
|
|
uint8_t *p;
|
2011-11-24 03:30:32 +00:00
|
|
|
if(av_sample_fmt_is_planar(f)){
|
|
|
|
f= av_get_alt_sample_fmt(f, 0);
|
2011-09-29 02:55:53 +00:00
|
|
|
p= a[ch];
|
|
|
|
}else{
|
|
|
|
p= a[0];
|
|
|
|
index= ch + index*ch_count;
|
|
|
|
}
|
2011-09-19 04:13:30 +00:00
|
|
|
switch(f){
|
2012-04-26 17:45:30 +00:00
|
|
|
case AV_SAMPLE_FMT_U8 : ((uint8_t*)p)[index]= av_clip_uint8 (lrint((v+1.0)*127)); break;
|
2012-04-26 17:39:40 +00:00
|
|
|
case AV_SAMPLE_FMT_S16: ((int16_t*)p)[index]= av_clip_int16 (lrint(v*32767)); break;
|
2013-02-04 02:55:56 +00:00
|
|
|
case AV_SAMPLE_FMT_S32: ((int32_t*)p)[index]= av_clipl_int32(llrint(v*2147483647)); break;
|
2012-04-26 17:39:40 +00:00
|
|
|
case AV_SAMPLE_FMT_FLT: ((float *)p)[index]= v; break;
|
|
|
|
case AV_SAMPLE_FMT_DBL: ((double *)p)[index]= v; break;
|
2011-09-19 04:13:30 +00:00
|
|
|
default: av_assert2(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-25 03:37:26 +00:00
|
|
|
static void shift(uint8_t *a[], int index, int ch_count, enum AVSampleFormat f){
|
2012-04-01 20:24:06 +00:00
|
|
|
int ch;
|
2012-03-25 03:37:26 +00:00
|
|
|
|
|
|
|
if(av_sample_fmt_is_planar(f)){
|
|
|
|
f= av_get_alt_sample_fmt(f, 0);
|
|
|
|
for(ch= 0; ch<ch_count; ch++)
|
|
|
|
a[ch] += index*av_get_bytes_per_sample(f);
|
|
|
|
}else{
|
|
|
|
a[0] += index*ch_count*av_get_bytes_per_sample(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-26 07:54:01 +00:00
|
|
|
static const enum AVSampleFormat formats[] = {
|
|
|
|
AV_SAMPLE_FMT_S16,
|
|
|
|
AV_SAMPLE_FMT_FLTP,
|
|
|
|
AV_SAMPLE_FMT_S16P,
|
|
|
|
AV_SAMPLE_FMT_FLT,
|
|
|
|
AV_SAMPLE_FMT_S32P,
|
|
|
|
AV_SAMPLE_FMT_S32,
|
|
|
|
AV_SAMPLE_FMT_U8P,
|
|
|
|
AV_SAMPLE_FMT_U8,
|
|
|
|
AV_SAMPLE_FMT_DBLP,
|
|
|
|
AV_SAMPLE_FMT_DBL,
|
|
|
|
};
|
|
|
|
|
2012-04-26 07:57:02 +00:00
|
|
|
static const int rates[] = {
|
|
|
|
8000,
|
|
|
|
11025,
|
|
|
|
16000,
|
|
|
|
22050,
|
|
|
|
32000,
|
|
|
|
48000,
|
|
|
|
};
|
|
|
|
|
2021-08-27 03:37:53 +00:00
|
|
|
static const AVChannelLayout layouts[]={
|
|
|
|
AV_CHANNEL_LAYOUT_MONO ,
|
|
|
|
AV_CHANNEL_LAYOUT_STEREO ,
|
|
|
|
AV_CHANNEL_LAYOUT_2_1 ,
|
|
|
|
AV_CHANNEL_LAYOUT_SURROUND ,
|
|
|
|
AV_CHANNEL_LAYOUT_4POINT0 ,
|
|
|
|
AV_CHANNEL_LAYOUT_2_2 ,
|
|
|
|
AV_CHANNEL_LAYOUT_QUAD ,
|
|
|
|
AV_CHANNEL_LAYOUT_5POINT0 ,
|
|
|
|
AV_CHANNEL_LAYOUT_5POINT1 ,
|
|
|
|
AV_CHANNEL_LAYOUT_5POINT0_BACK ,
|
|
|
|
AV_CHANNEL_LAYOUT_5POINT1_BACK ,
|
|
|
|
AV_CHANNEL_LAYOUT_7POINT0 ,
|
|
|
|
AV_CHANNEL_LAYOUT_7POINT1 ,
|
|
|
|
AV_CHANNEL_LAYOUT_7POINT1_WIDE ,
|
2011-09-19 04:13:30 +00:00
|
|
|
};
|
|
|
|
|
2011-09-29 02:55:53 +00:00
|
|
|
static void setup_array(uint8_t *out[SWR_CH_MAX], uint8_t *in, enum AVSampleFormat format, int samples){
|
2011-11-24 03:30:32 +00:00
|
|
|
if(av_sample_fmt_is_planar(format)){
|
2011-09-29 02:55:53 +00:00
|
|
|
int i;
|
|
|
|
int plane_size= av_get_bytes_per_sample(format&0xFF)*samples;
|
|
|
|
format&=0xFF;
|
|
|
|
for(i=0; i<SWR_CH_MAX; i++){
|
|
|
|
out[i]= in + i*plane_size;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
out[0]= in;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-25 00:59:05 +00:00
|
|
|
static int cmp(const void *a, const void *b){
|
|
|
|
return *(const int *)a - *(const int *)b;
|
2012-04-26 10:14:28 +00:00
|
|
|
}
|
|
|
|
|
2012-04-26 18:21:22 +00:00
|
|
|
static void audiogen(void *data, enum AVSampleFormat sample_fmt,
|
|
|
|
int channels, int sample_rate, int nb_samples)
|
|
|
|
{
|
|
|
|
int i, ch, k;
|
|
|
|
double v, f, a, ampa;
|
|
|
|
double tabf1[SWR_CH_MAX];
|
|
|
|
double tabf2[SWR_CH_MAX];
|
|
|
|
double taba[SWR_CH_MAX];
|
2012-04-27 10:23:40 +00:00
|
|
|
unsigned static rnd;
|
2012-04-26 18:21:22 +00:00
|
|
|
|
|
|
|
#define PUT_SAMPLE set(data, ch, k, channels, sample_fmt, v);
|
2015-02-16 21:55:17 +00:00
|
|
|
#define uint_rand(x) ((x) = (x) * 1664525 + 1013904223)
|
2012-04-27 10:23:40 +00:00
|
|
|
#define dbl_rand(x) (uint_rand(x)*2.0 / (double)UINT_MAX - 1)
|
2012-04-26 18:21:22 +00:00
|
|
|
k = 0;
|
|
|
|
|
|
|
|
/* 1 second of single freq sinus at 1000 Hz */
|
|
|
|
a = 0;
|
|
|
|
for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
|
|
|
|
v = sin(a) * 0.30;
|
|
|
|
for (ch = 0; ch < channels; ch++)
|
|
|
|
PUT_SAMPLE
|
|
|
|
a += M_PI * 1000.0 * 2.0 / sample_rate;
|
|
|
|
}
|
|
|
|
|
2014-06-03 02:46:04 +00:00
|
|
|
/* 1 second of varying frequency between 100 and 10000 Hz */
|
2012-04-26 18:21:22 +00:00
|
|
|
a = 0;
|
|
|
|
for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
|
|
|
|
v = sin(a) * 0.30;
|
|
|
|
for (ch = 0; ch < channels; ch++)
|
|
|
|
PUT_SAMPLE
|
|
|
|
f = 100.0 + (((10000.0 - 100.0) * i) / sample_rate);
|
|
|
|
a += M_PI * f * 2.0 / sample_rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 0.5 second of low amplitude white noise */
|
|
|
|
for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) {
|
|
|
|
v = dbl_rand(rnd) * 0.30;
|
|
|
|
for (ch = 0; ch < channels; ch++)
|
|
|
|
PUT_SAMPLE
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 0.5 second of high amplitude white noise */
|
|
|
|
for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) {
|
|
|
|
v = dbl_rand(rnd);
|
|
|
|
for (ch = 0; ch < channels; ch++)
|
|
|
|
PUT_SAMPLE
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 1 second of unrelated ramps for each channel */
|
|
|
|
for (ch = 0; ch < channels; ch++) {
|
|
|
|
taba[ch] = 0;
|
2012-04-27 10:23:40 +00:00
|
|
|
tabf1[ch] = 100 + uint_rand(rnd) % 5000;
|
|
|
|
tabf2[ch] = 100 + uint_rand(rnd) % 5000;
|
2012-04-26 18:21:22 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
|
|
|
|
for (ch = 0; ch < channels; ch++) {
|
|
|
|
v = sin(taba[ch]) * 0.30;
|
|
|
|
PUT_SAMPLE
|
|
|
|
f = tabf1[ch] + (((tabf2[ch] - tabf1[ch]) * i) / sample_rate);
|
|
|
|
taba[ch] += M_PI * f * 2.0 / sample_rate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 2 seconds of 500 Hz with varying volume */
|
|
|
|
a = 0;
|
|
|
|
ampa = 0;
|
|
|
|
for (i = 0; i < 2 * sample_rate && k < nb_samples; i++, k++) {
|
|
|
|
for (ch = 0; ch < channels; ch++) {
|
|
|
|
double amp = (1.0 + sin(ampa)) * 0.15;
|
|
|
|
if (ch & 1)
|
|
|
|
amp = 0.30 - amp;
|
|
|
|
v = sin(a) * amp;
|
|
|
|
PUT_SAMPLE
|
|
|
|
a += M_PI * 500.0 * 2.0 / sample_rate;
|
|
|
|
ampa += M_PI * 2.0 / sample_rate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-19 04:13:30 +00:00
|
|
|
int main(int argc, char **argv){
|
2012-04-26 21:44:50 +00:00
|
|
|
int in_sample_rate, out_sample_rate, ch ,i, flush_count;
|
2021-08-27 03:37:53 +00:00
|
|
|
AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 };
|
2011-09-19 04:13:30 +00:00
|
|
|
enum AVSampleFormat in_sample_fmt, out_sample_fmt;
|
|
|
|
uint8_t array_in[SAMPLES*8*8];
|
|
|
|
uint8_t array_mid[SAMPLES*8*8*3];
|
|
|
|
uint8_t array_out[SAMPLES*8*8+100];
|
2011-09-29 02:55:53 +00:00
|
|
|
uint8_t *ain[SWR_CH_MAX];
|
|
|
|
uint8_t *aout[SWR_CH_MAX];
|
|
|
|
uint8_t *amid[SWR_CH_MAX];
|
2012-03-25 03:37:26 +00:00
|
|
|
int flush_i=0;
|
2012-05-01 11:15:46 +00:00
|
|
|
int mode;
|
2012-04-26 10:14:28 +00:00
|
|
|
int num_tests = 10000;
|
|
|
|
uint32_t seed = 0;
|
2012-05-01 11:15:46 +00:00
|
|
|
uint32_t rand_seed = 0;
|
2012-10-06 11:48:47 +00:00
|
|
|
int remaining_tests[FF_ARRAY_ELEMS(rates) * FF_ARRAY_ELEMS(layouts) * FF_ARRAY_ELEMS(formats) * FF_ARRAY_ELEMS(layouts) * FF_ARRAY_ELEMS(formats)];
|
|
|
|
int max_tests = FF_ARRAY_ELEMS(remaining_tests);
|
2012-04-26 10:14:28 +00:00
|
|
|
int test;
|
2012-05-05 16:22:48 +00:00
|
|
|
int specific_test= -1;
|
2011-09-29 02:55:53 +00:00
|
|
|
|
2011-09-19 04:13:30 +00:00
|
|
|
struct SwrContext * forw_ctx= NULL;
|
|
|
|
struct SwrContext *backw_ctx= NULL;
|
|
|
|
|
2012-04-26 10:14:28 +00:00
|
|
|
if (argc > 1) {
|
2012-06-05 15:12:50 +00:00
|
|
|
if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
|
2012-05-05 16:22:48 +00:00
|
|
|
av_log(NULL, AV_LOG_INFO, "Usage: swresample-test [<num_tests>[ <test>]] \n"
|
|
|
|
"num_tests Default is %d\n", num_tests);
|
2012-04-26 10:14:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
num_tests = strtol(argv[1], NULL, 0);
|
2012-05-01 11:16:13 +00:00
|
|
|
if(num_tests < 0) {
|
|
|
|
num_tests = -num_tests;
|
|
|
|
rand_seed = time(0);
|
|
|
|
}
|
2012-04-26 10:14:28 +00:00
|
|
|
if(num_tests<= 0 || num_tests>max_tests)
|
|
|
|
num_tests = max_tests;
|
2012-05-05 16:22:48 +00:00
|
|
|
if(argc > 2) {
|
|
|
|
specific_test = strtol(argv[1], NULL, 0);
|
|
|
|
}
|
2012-04-26 10:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0; i<max_tests; i++)
|
|
|
|
remaining_tests[i] = i;
|
|
|
|
|
|
|
|
for(test=0; test<num_tests; test++){
|
|
|
|
unsigned r;
|
2012-05-01 11:15:15 +00:00
|
|
|
uint_rand(seed);
|
2012-04-26 10:14:28 +00:00
|
|
|
r = (seed * (uint64_t)(max_tests - test)) >>32;
|
|
|
|
FFSWAP(int, remaining_tests[r], remaining_tests[max_tests - test - 1]);
|
|
|
|
}
|
2015-10-25 00:59:05 +00:00
|
|
|
qsort(remaining_tests + max_tests - num_tests, num_tests, sizeof(remaining_tests[0]), cmp);
|
2011-09-19 04:13:30 +00:00
|
|
|
in_sample_rate=16000;
|
2012-04-26 10:14:28 +00:00
|
|
|
for(test=0; test<num_tests; test++){
|
2012-04-26 10:17:29 +00:00
|
|
|
char in_layout_string[256];
|
|
|
|
char out_layout_string[256];
|
2012-04-26 10:14:28 +00:00
|
|
|
unsigned vector= remaining_tests[max_tests - test - 1];
|
2012-04-26 21:48:57 +00:00
|
|
|
int in_ch_count;
|
|
|
|
int out_count, mid_count, out_ch_count;
|
2012-04-26 10:14:28 +00:00
|
|
|
|
2021-08-27 03:37:53 +00:00
|
|
|
av_channel_layout_copy(&in_ch_layout, &layouts[vector % FF_ARRAY_ELEMS(layouts)]); vector /= FF_ARRAY_ELEMS(layouts);
|
|
|
|
av_channel_layout_copy(&out_ch_layout, &layouts[vector % FF_ARRAY_ELEMS(layouts)]); vector /= FF_ARRAY_ELEMS(layouts);
|
2012-04-26 10:14:28 +00:00
|
|
|
in_sample_fmt = formats[vector % FF_ARRAY_ELEMS(formats)]; vector /= FF_ARRAY_ELEMS(formats);
|
|
|
|
out_sample_fmt = formats[vector % FF_ARRAY_ELEMS(formats)]; vector /= FF_ARRAY_ELEMS(formats);
|
|
|
|
out_sample_rate = rates [vector % FF_ARRAY_ELEMS(rates )]; vector /= FF_ARRAY_ELEMS(rates);
|
|
|
|
av_assert0(!vector);
|
|
|
|
|
2012-05-05 16:22:48 +00:00
|
|
|
if(specific_test == 0){
|
2021-08-27 03:37:53 +00:00
|
|
|
if(out_sample_rate != in_sample_rate || av_channel_layout_compare(&in_ch_layout, &out_ch_layout))
|
2012-05-05 16:22:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-08-27 03:37:53 +00:00
|
|
|
in_ch_count= in_ch_layout.nb_channels;
|
|
|
|
out_ch_count= out_ch_layout.nb_channels;
|
|
|
|
av_channel_layout_describe(&in_ch_layout, in_layout_string, sizeof( in_layout_string));
|
|
|
|
av_channel_layout_describe(&out_ch_layout, out_layout_string, sizeof(out_layout_string));
|
2012-04-26 21:43:45 +00:00
|
|
|
fprintf(stderr, "TEST: %s->%s, rate:%5d->%5d, fmt:%s->%s\n",
|
|
|
|
in_layout_string, out_layout_string,
|
|
|
|
in_sample_rate, out_sample_rate,
|
|
|
|
av_get_sample_fmt_name(in_sample_fmt), av_get_sample_fmt_name(out_sample_fmt));
|
2021-08-27 03:37:53 +00:00
|
|
|
if (swr_alloc_set_opts2(&forw_ctx, &out_ch_layout, out_sample_fmt, out_sample_rate,
|
|
|
|
&in_ch_layout, in_sample_fmt, in_sample_rate,
|
|
|
|
0, 0) < 0) {
|
2012-10-16 17:38:08 +00:00
|
|
|
fprintf(stderr, "Failed to init forw_cts\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2021-08-27 03:37:53 +00:00
|
|
|
if (swr_alloc_set_opts2(&backw_ctx, &in_ch_layout, in_sample_fmt, in_sample_rate,
|
|
|
|
&out_ch_layout, out_sample_fmt, out_sample_rate,
|
|
|
|
0, 0) < 0) {
|
2012-10-16 17:38:08 +00:00
|
|
|
fprintf(stderr, "Failed to init backw_ctx\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2015-04-12 20:08:52 +00:00
|
|
|
|
2012-04-26 21:43:45 +00:00
|
|
|
if(swr_init( forw_ctx) < 0)
|
|
|
|
fprintf(stderr, "swr_init(->) failed\n");
|
|
|
|
if(swr_init(backw_ctx) < 0)
|
|
|
|
fprintf(stderr, "swr_init(<-) failed\n");
|
|
|
|
//FIXME test planar
|
|
|
|
setup_array(ain , array_in , in_sample_fmt, SAMPLES);
|
|
|
|
setup_array(amid, array_mid, out_sample_fmt, 3*SAMPLES);
|
|
|
|
setup_array(aout, array_out, in_sample_fmt , SAMPLES);
|
2012-04-26 18:21:22 +00:00
|
|
|
#if 0
|
2012-04-26 21:43:45 +00:00
|
|
|
for(ch=0; ch<in_ch_count; ch++){
|
|
|
|
for(i=0; i<SAMPLES; i++)
|
|
|
|
set(ain, ch, i, in_ch_count, in_sample_fmt, sin(i*i*3/SAMPLES));
|
|
|
|
}
|
2012-04-26 18:21:22 +00:00
|
|
|
#else
|
2012-04-26 21:43:45 +00:00
|
|
|
audiogen(ain, in_sample_fmt, in_ch_count, SAMPLES/6+1, SAMPLES);
|
2012-04-26 18:21:22 +00:00
|
|
|
#endif
|
2012-05-01 11:15:46 +00:00
|
|
|
mode = uint_rand(rand_seed) % 3;
|
2012-04-26 21:43:45 +00:00
|
|
|
if(mode==0 /*|| out_sample_rate == in_sample_rate*/) {
|
2012-04-26 21:47:32 +00:00
|
|
|
mid_count= swr_convert(forw_ctx, amid, 3*SAMPLES, (const uint8_t **)ain, SAMPLES);
|
2012-04-26 21:43:45 +00:00
|
|
|
} else if(mode==1){
|
2012-04-26 21:47:32 +00:00
|
|
|
mid_count= swr_convert(forw_ctx, amid, 0, (const uint8_t **)ain, SAMPLES);
|
|
|
|
mid_count+=swr_convert(forw_ctx, amid, 3*SAMPLES, (const uint8_t **)ain, 0);
|
2012-04-26 21:43:45 +00:00
|
|
|
} else {
|
|
|
|
int tmp_count;
|
2012-04-26 21:47:32 +00:00
|
|
|
mid_count= swr_convert(forw_ctx, amid, 0, (const uint8_t **)ain, 1);
|
2012-04-26 21:43:45 +00:00
|
|
|
av_assert0(mid_count==0);
|
|
|
|
shift(ain, 1, in_ch_count, in_sample_fmt);
|
2012-04-26 21:47:32 +00:00
|
|
|
mid_count+=swr_convert(forw_ctx, amid, 3*SAMPLES, (const uint8_t **)ain, 0);
|
2012-04-26 21:43:45 +00:00
|
|
|
shift(amid, mid_count, out_ch_count, out_sample_fmt); tmp_count = mid_count;
|
2012-04-26 21:47:32 +00:00
|
|
|
mid_count+=swr_convert(forw_ctx, amid, 2, (const uint8_t **)ain, 2);
|
2012-04-26 21:43:45 +00:00
|
|
|
shift(amid, mid_count-tmp_count, out_ch_count, out_sample_fmt); tmp_count = mid_count;
|
|
|
|
shift(ain, 2, in_ch_count, in_sample_fmt);
|
2012-04-26 21:47:32 +00:00
|
|
|
mid_count+=swr_convert(forw_ctx, amid, 1, (const uint8_t **)ain, SAMPLES-3);
|
2012-04-26 21:43:45 +00:00
|
|
|
shift(amid, mid_count-tmp_count, out_ch_count, out_sample_fmt); tmp_count = mid_count;
|
|
|
|
shift(ain, -3, in_ch_count, in_sample_fmt);
|
2012-04-26 21:47:32 +00:00
|
|
|
mid_count+=swr_convert(forw_ctx, amid, 3*SAMPLES, (const uint8_t **)ain, 0);
|
2012-04-26 21:43:45 +00:00
|
|
|
shift(amid, -tmp_count, out_ch_count, out_sample_fmt);
|
|
|
|
}
|
2012-04-26 21:47:32 +00:00
|
|
|
out_count= swr_convert(backw_ctx,aout, SAMPLES, (const uint8_t **)amid, mid_count);
|
2012-04-26 21:43:45 +00:00
|
|
|
|
|
|
|
for(ch=0; ch<in_ch_count; ch++){
|
2012-04-26 21:44:50 +00:00
|
|
|
double sse, maxdiff=0;
|
2012-04-26 21:43:45 +00:00
|
|
|
double sum_aa= 0;
|
|
|
|
double sum_bb= 0;
|
|
|
|
double sum_ab= 0;
|
|
|
|
for(i=0; i<out_count; i++){
|
|
|
|
double a= get(ain , ch, i, in_ch_count, in_sample_fmt);
|
|
|
|
double b= get(aout, ch, i, in_ch_count, in_sample_fmt);
|
|
|
|
sum_aa+= a*a;
|
|
|
|
sum_bb+= b*b;
|
|
|
|
sum_ab+= a*b;
|
2015-10-12 05:30:22 +00:00
|
|
|
maxdiff= FFMAX(maxdiff, fabs(a-b));
|
2012-04-26 21:43:45 +00:00
|
|
|
}
|
|
|
|
sse= sum_aa + sum_bb - 2*sum_ab;
|
2012-05-03 12:42:37 +00:00
|
|
|
if(sse < 0 && sse > -0.00001) sse=0; //fix rounding error
|
2012-04-26 21:43:45 +00:00
|
|
|
|
2012-10-16 17:40:57 +00:00
|
|
|
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);
|
2012-04-26 21:43:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
flush_i++;
|
|
|
|
flush_i%=21;
|
|
|
|
flush_count = swr_convert(backw_ctx,aout, flush_i, 0, 0);
|
|
|
|
shift(aout, flush_i, in_ch_count, in_sample_fmt);
|
|
|
|
flush_count+= swr_convert(backw_ctx,aout, SAMPLES-flush_i, 0, 0);
|
|
|
|
shift(aout, -flush_i, in_ch_count, in_sample_fmt);
|
|
|
|
if(flush_count){
|
|
|
|
for(ch=0; ch<in_ch_count; ch++){
|
2012-04-26 21:44:50 +00:00
|
|
|
double sse, maxdiff=0;
|
2012-04-26 21:43:45 +00:00
|
|
|
double sum_aa= 0;
|
|
|
|
double sum_bb= 0;
|
|
|
|
double sum_ab= 0;
|
|
|
|
for(i=0; i<flush_count; i++){
|
|
|
|
double a= get(ain , ch, i+out_count, in_ch_count, in_sample_fmt);
|
|
|
|
double b= get(aout, ch, i, in_ch_count, in_sample_fmt);
|
|
|
|
sum_aa+= a*a;
|
|
|
|
sum_bb+= b*b;
|
|
|
|
sum_ab+= a*b;
|
2015-10-12 05:30:22 +00:00
|
|
|
maxdiff= FFMAX(maxdiff, fabs(a-b));
|
2012-04-26 21:43:45 +00:00
|
|
|
}
|
|
|
|
sse= sum_aa + sum_bb - 2*sum_ab;
|
2012-05-03 12:42:37 +00:00
|
|
|
if(sse < 0 && sse > -0.00001) sse=0; //fix rounding error
|
2012-04-26 21:43:45 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
2011-09-19 04:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|