From 63b1c08073adefb93c9fe8e3a6fd9c1b99772b7e Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Tue, 5 Jun 2012 17:06:19 +0200 Subject: buildsys: fix rules for swresample-test Signed-off-by: Michael Niedermayer --- libswresample/Makefile | 2 +- libswresample/swresample-test.c | 410 ++++++++++++++++++++++++++++++++++++++++ libswresample/swresample_test.c | 410 ---------------------------------------- 3 files changed, 411 insertions(+), 411 deletions(-) create mode 100644 libswresample/swresample-test.c delete mode 100644 libswresample/swresample_test.c (limited to 'libswresample') diff --git a/libswresample/Makefile b/libswresample/Makefile index 5b4c286..0a5c5d2 100644 --- a/libswresample/Makefile +++ b/libswresample/Makefile @@ -11,4 +11,4 @@ OBJS = audioconvert.o \ resample.o \ swresample.o \ -TESTPROGS = swresample_test +TESTPROGS = swresample diff --git a/libswresample/swresample-test.c b/libswresample/swresample-test.c new file mode 100644 index 0000000..7af55b8 --- /dev/null +++ b/libswresample/swresample-test.c @@ -0,0 +1,410 @@ +/* + * Copyright (C) 2011 Michael Niedermayer (michaelni@gmx.at) + * Copyright (c) 2002 Fabrice Bellard + * + * 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" +#include "libavutil/common.h" +#include "libavutil/audioconvert.h" +#include "libavutil/opt.h" +#include "swresample.h" + +#undef time +#include "time.h" +#undef fprintf + +#define SAMPLES 1000 + +#define ASSERT_LEVEL 2 + +static double get(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f){ + const uint8_t *p; + if(av_sample_fmt_is_planar(f)){ + f= av_get_alt_sample_fmt(f, 0); + p= a[ch]; + }else{ + p= a[0]; + index= ch + index*ch_count; + } + + switch(f){ + case AV_SAMPLE_FMT_U8 : return ((const uint8_t*)p)[index]/127.0-1.0; + 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]; + default: av_assert0(0); + } +} + +static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v){ + uint8_t *p; + if(av_sample_fmt_is_planar(f)){ + f= av_get_alt_sample_fmt(f, 0); + p= a[ch]; + }else{ + p= a[0]; + index= ch + index*ch_count; + } + switch(f){ + case AV_SAMPLE_FMT_U8 : ((uint8_t*)p)[index]= av_clip_uint8 (lrint((v+1.0)*127)); break; + case AV_SAMPLE_FMT_S16: ((int16_t*)p)[index]= av_clip_int16 (lrint(v*32767)); break; + case AV_SAMPLE_FMT_S32: ((int32_t*)p)[index]= av_clipl_int32(lrint(v*2147483647)); break; + case AV_SAMPLE_FMT_FLT: ((float *)p)[index]= v; break; + case AV_SAMPLE_FMT_DBL: ((double *)p)[index]= v; break; + default: av_assert2(0); + } +} + +static void shift(uint8_t *a[], int index, int ch_count, enum AVSampleFormat f){ + int ch; + + if(av_sample_fmt_is_planar(f)){ + f= av_get_alt_sample_fmt(f, 0); + for(ch= 0; ch 1) { + if (!strcmp(argv[1], "-h")) { + av_log(NULL, AV_LOG_INFO, "Usage: swresample-test [[ ]] \n" + "num_tests Default is %d\n", num_tests); + return 0; + } + num_tests = strtol(argv[1], NULL, 0); + if(num_tests < 0) { + num_tests = -num_tests; + rand_seed = time(0); + } + if(num_tests<= 0 || num_tests>max_tests) + num_tests = max_tests; + if(argc > 2) { + specific_test = strtol(argv[1], NULL, 0); + } + } + + for(i=0; i>32; + FFSWAP(int, remaining_tests[r], remaining_tests[max_tests - test - 1]); + } + qsort(remaining_tests + max_tests - num_tests, num_tests, sizeof(remaining_tests[0]), (void*)cmp); + in_sample_rate=16000; + for(test=0; test%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)); + forw_ctx = swr_alloc_set_opts(forw_ctx, out_ch_layout, out_sample_fmt, out_sample_rate, + in_ch_layout, in_sample_fmt, in_sample_rate, + 0, 0); + backw_ctx = swr_alloc_set_opts(backw_ctx, in_ch_layout, in_sample_fmt, in_sample_rate, + out_ch_layout, out_sample_fmt, out_sample_rate, + 0, 0); + if(swr_init( forw_ctx) < 0) + fprintf(stderr, "swr_init(->) failed\n"); + if(swr_init(backw_ctx) < 0) + fprintf(stderr, "swr_init(<-) failed\n"); + if(!forw_ctx) + fprintf(stderr, "Failed to init forw_cts\n"); + if(!backw_ctx) + fprintf(stderr, "Failed to init backw_ctx\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); +#if 0 + for(ch=0; ch -0.00001) sse=0; //fix rounding error + + fprintf(stderr, "[e:%f c:%f max:%f] len:%5d\n", sqrt(sse/out_count), sum_ab/(sqrt(sum_aa*sum_bb)), maxdiff, out_count); + } + + 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 -0.00001) sse=0; //fix rounding error + + 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"); + } + + return 0; +} diff --git a/libswresample/swresample_test.c b/libswresample/swresample_test.c deleted file mode 100644 index 7af55b8..0000000 --- a/libswresample/swresample_test.c +++ /dev/null @@ -1,410 +0,0 @@ -/* - * Copyright (C) 2011 Michael Niedermayer (michaelni@gmx.at) - * Copyright (c) 2002 Fabrice Bellard - * - * 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" -#include "libavutil/common.h" -#include "libavutil/audioconvert.h" -#include "libavutil/opt.h" -#include "swresample.h" - -#undef time -#include "time.h" -#undef fprintf - -#define SAMPLES 1000 - -#define ASSERT_LEVEL 2 - -static double get(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f){ - const uint8_t *p; - if(av_sample_fmt_is_planar(f)){ - f= av_get_alt_sample_fmt(f, 0); - p= a[ch]; - }else{ - p= a[0]; - index= ch + index*ch_count; - } - - switch(f){ - case AV_SAMPLE_FMT_U8 : return ((const uint8_t*)p)[index]/127.0-1.0; - 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]; - default: av_assert0(0); - } -} - -static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v){ - uint8_t *p; - if(av_sample_fmt_is_planar(f)){ - f= av_get_alt_sample_fmt(f, 0); - p= a[ch]; - }else{ - p= a[0]; - index= ch + index*ch_count; - } - switch(f){ - case AV_SAMPLE_FMT_U8 : ((uint8_t*)p)[index]= av_clip_uint8 (lrint((v+1.0)*127)); break; - case AV_SAMPLE_FMT_S16: ((int16_t*)p)[index]= av_clip_int16 (lrint(v*32767)); break; - case AV_SAMPLE_FMT_S32: ((int32_t*)p)[index]= av_clipl_int32(lrint(v*2147483647)); break; - case AV_SAMPLE_FMT_FLT: ((float *)p)[index]= v; break; - case AV_SAMPLE_FMT_DBL: ((double *)p)[index]= v; break; - default: av_assert2(0); - } -} - -static void shift(uint8_t *a[], int index, int ch_count, enum AVSampleFormat f){ - int ch; - - if(av_sample_fmt_is_planar(f)){ - f= av_get_alt_sample_fmt(f, 0); - for(ch= 0; ch 1) { - if (!strcmp(argv[1], "-h")) { - av_log(NULL, AV_LOG_INFO, "Usage: swresample-test [[ ]] \n" - "num_tests Default is %d\n", num_tests); - return 0; - } - num_tests = strtol(argv[1], NULL, 0); - if(num_tests < 0) { - num_tests = -num_tests; - rand_seed = time(0); - } - if(num_tests<= 0 || num_tests>max_tests) - num_tests = max_tests; - if(argc > 2) { - specific_test = strtol(argv[1], NULL, 0); - } - } - - for(i=0; i>32; - FFSWAP(int, remaining_tests[r], remaining_tests[max_tests - test - 1]); - } - qsort(remaining_tests + max_tests - num_tests, num_tests, sizeof(remaining_tests[0]), (void*)cmp); - in_sample_rate=16000; - for(test=0; test%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)); - forw_ctx = swr_alloc_set_opts(forw_ctx, out_ch_layout, out_sample_fmt, out_sample_rate, - in_ch_layout, in_sample_fmt, in_sample_rate, - 0, 0); - backw_ctx = swr_alloc_set_opts(backw_ctx, in_ch_layout, in_sample_fmt, in_sample_rate, - out_ch_layout, out_sample_fmt, out_sample_rate, - 0, 0); - if(swr_init( forw_ctx) < 0) - fprintf(stderr, "swr_init(->) failed\n"); - if(swr_init(backw_ctx) < 0) - fprintf(stderr, "swr_init(<-) failed\n"); - if(!forw_ctx) - fprintf(stderr, "Failed to init forw_cts\n"); - if(!backw_ctx) - fprintf(stderr, "Failed to init backw_ctx\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); -#if 0 - for(ch=0; ch -0.00001) sse=0; //fix rounding error - - fprintf(stderr, "[e:%f c:%f max:%f] len:%5d\n", sqrt(sse/out_count), sum_ab/(sqrt(sum_aa*sum_bb)), maxdiff, out_count); - } - - 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 -0.00001) sse=0; //fix rounding error - - 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"); - } - - return 0; -} -- cgit v1.1