diff options
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/iirfilter-test.c | 52 | ||||
-rw-r--r-- | libavcodec/iirfilter.c | 32 | ||||
-rw-r--r-- | libavcodec/rangecoder-test.c | 64 | ||||
-rw-r--r-- | libavcodec/rangecoder.c | 44 |
4 files changed, 116 insertions, 76 deletions
diff --git a/libavcodec/iirfilter-test.c b/libavcodec/iirfilter-test.c new file mode 100644 index 0000000000..139a35d505 --- /dev/null +++ b/libavcodec/iirfilter-test.c @@ -0,0 +1,52 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <math.h> +#include <stdint.h> +#include <stdio.h> + +#include "iirfilter.h" + +#define FILT_ORDER 4 +#define SIZE 1024 + +int main(void) +{ + struct FFIIRFilterCoeffs *fcoeffs = NULL; + struct FFIIRFilterState *fstate = NULL; + float cutoff_coeff = 0.4; + int16_t x[SIZE], y[SIZE]; + int i; + + fcoeffs = ff_iir_filter_init_coeffs(NULL, FF_FILTER_TYPE_BUTTERWORTH, + FF_FILTER_MODE_LOWPASS, FILT_ORDER, + cutoff_coeff, 0.0, 0.0); + fstate = ff_iir_filter_init_state(FILT_ORDER); + + for (i = 0; i < SIZE; i++) + x[i] = lrint(0.75 * INT16_MAX * sin(0.5 * M_PI * i * i / SIZE)); + + ff_iir_filter(fcoeffs, fstate, SIZE, x, 1, y, 1); + + for (i = 0; i < SIZE; i++) + printf("%6d %6d\n", x[i], y[i]); + + ff_iir_filter_free_coeffs(fcoeffs); + ff_iir_filter_free_state(fstate); + return 0; +} diff --git a/libavcodec/iirfilter.c b/libavcodec/iirfilter.c index fba4ac800a..442c837338 100644 --- a/libavcodec/iirfilter.c +++ b/libavcodec/iirfilter.c @@ -315,35 +315,3 @@ av_cold void ff_iir_filter_free_coeffs(struct FFIIRFilterCoeffs *coeffs) } av_free(coeffs); } - -#ifdef TEST -#include <stdio.h> - -#define FILT_ORDER 4 -#define SIZE 1024 -int main(void) -{ - struct FFIIRFilterCoeffs *fcoeffs = NULL; - struct FFIIRFilterState *fstate = NULL; - float cutoff_coeff = 0.4; - int16_t x[SIZE], y[SIZE]; - int i; - - fcoeffs = ff_iir_filter_init_coeffs(NULL, FF_FILTER_TYPE_BUTTERWORTH, - FF_FILTER_MODE_LOWPASS, FILT_ORDER, - cutoff_coeff, 0.0, 0.0); - fstate = ff_iir_filter_init_state(FILT_ORDER); - - for (i = 0; i < SIZE; i++) - x[i] = lrint(0.75 * INT16_MAX * sin(0.5 * M_PI * i * i / SIZE)); - - ff_iir_filter(fcoeffs, fstate, SIZE, x, 1, y, 1); - - for (i = 0; i < SIZE; i++) - printf("%6d %6d\n", x[i], y[i]); - - ff_iir_filter_free_coeffs(fcoeffs); - ff_iir_filter_free_state(fstate); - return 0; -} -#endif /* TEST */ diff --git a/libavcodec/rangecoder-test.c b/libavcodec/rangecoder-test.c new file mode 100644 index 0000000000..f4c76c01f0 --- /dev/null +++ b/libavcodec/rangecoder-test.c @@ -0,0 +1,64 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <stdint.h> +#include <string.h> + +#include "libavutil/lfg.h" +#include "libavutil/log.h" + +#include "rangecoder.h" + +#define SIZE 10240 + +int main(void) +{ + RangeCoder c; + uint8_t b[9 * SIZE]; + uint8_t r[9 * SIZE]; + int i; + uint8_t state[10]; + AVLFG prng; + + av_lfg_init(&prng, 1); + + ff_init_range_encoder(&c, b, SIZE); + ff_build_rac_states(&c, 0.05 * (1LL << 32), 128 + 64 + 32 + 16); + + memset(state, 128, sizeof(state)); + + for (i = 0; i < SIZE; i++) + r[i] = av_lfg_get(&prng) % 7; + + for (i = 0; i < SIZE; i++) + put_rac(&c, state, r[i] & 1); + + ff_rac_terminate(&c); + + ff_init_range_decoder(&c, b, SIZE); + + memset(state, 128, sizeof(state)); + + for (i = 0; i < SIZE; i++) + if ((r[i] & 1) != get_rac(&c, state)) { + av_log(NULL, AV_LOG_ERROR, "rac failure at %d\n", i); + return 1; + } + + return 0; +} diff --git a/libavcodec/rangecoder.c b/libavcodec/rangecoder.c index 86bc362e48..4c4731dd4e 100644 --- a/libavcodec/rangecoder.c +++ b/libavcodec/rangecoder.c @@ -113,47 +113,3 @@ int ff_rac_terminate(RangeCoder *c) return c->bytestream - c->bytestream_start; } - -#ifdef TEST -#define SIZE 10240 - -#include "libavutil/lfg.h" -#include "libavutil/log.h" - -int main(void) -{ - RangeCoder c; - uint8_t b[9 * SIZE]; - uint8_t r[9 * SIZE]; - int i; - uint8_t state[10]; - AVLFG prng; - - av_lfg_init(&prng, 1); - - ff_init_range_encoder(&c, b, SIZE); - ff_build_rac_states(&c, 0.05 * (1LL << 32), 128 + 64 + 32 + 16); - - memset(state, 128, sizeof(state)); - - for (i = 0; i < SIZE; i++) - r[i] = av_lfg_get(&prng) % 7; - - for (i = 0; i < SIZE; i++) - put_rac(&c, state, r[i] & 1); - - ff_rac_terminate(&c); - - ff_init_range_decoder(&c, b, SIZE); - - memset(state, 128, sizeof(state)); - - for (i = 0; i < SIZE; i++) - if ((r[i] & 1) != get_rac(&c, state)) { - av_log(NULL, AV_LOG_ERROR, "rac failure at %d\n", i); - return 1; - } - - return 0; -} -#endif /* TEST */ |