Implementations of fixed point AC3 decoder and 32bit fixed point FFT
Hi, Requested changes are made to patch that implements ac3 fixed point decoder and the patch is resubmitted. I am also resubmitting patch with implementation of 32bit fixed point FFT since it is needed for ac3 fixed point decoder to work and it is not reviewed yet. Regards, -Nedeljko
From: Nedeljko Babic <nbabic@mips.com> Iterative implementation of 32 bit fixed point split-radix FFT. Max FFT that can be calculated currently is 2^12. Signed-off-by: Nedeljko Babic <nbabic@mips.com> --- doc/mips.txt | 5 + libavcodec/Makefile | 4 +- libavcodec/fft-fixed32-test.c | 21 ++++ libavcodec/fft-internal.h | 21 ++++- libavcodec/fft-test.c | 4 + libavcodec/fft.c | 181 ++++++++++++++++++++++++++++++++++- libavcodec/fft.h | 19 +++- libavcodec/fft_fixed.c | 1 + libavcodec/fft_fixed_32.c | 52 ++++++++++ libavcodec/fft_float.c | 1 + libavcodec/fft_init_table.c | 200 ++++++++++++++++++++++++++++++++++++++ libavcodec/fft_table.h | 66 +++++++++++++ libavcodec/mdct.c | 4 + libavcodec/mdct_fixed.c | 1 + libavcodec/mdct_fixed_32.c | 52 ++++++++++ libavcodec/mdct_float.c | 1 + libavcodec/mips/Makefile | 1 - libavcodec/mips/fft_init_table.c | 67 ------------- libavcodec/mips/fft_mips.c | 2 +- libavcodec/mips/fft_table.h | 63 ------------ tests/fate/fft.mak | 21 ++++- 21 files changed, 647 insertions(+), 140 deletions(-) create mode 100644 libavcodec/fft-fixed32-test.c create mode 100644 libavcodec/fft_fixed_32.c create mode 100644 libavcodec/fft_init_table.c create mode 100644 libavcodec/fft_table.h create mode 100644 libavcodec/mdct_fixed_32.c delete mode 100644 libavcodec/mips/fft_init_table.c delete mode 100644 libavcodec/mips/fft_table.h diff --git a/doc/mips.txt b/doc/mips.txt index 051b819..8c6779f 100644 --- a/doc/mips.txt +++ b/doc/mips.txt @@ -47,6 +47,11 @@ Files that have MIPS copyright notice in them: * libavutil/mips/ float_dsp_mips.c libm_mips.h +* libavcodec/ + fft_fixed_32.c + fft_init_table.c + fft_table.h + mdct_fixed_32.c * libavcodec/mips/ aaccoder_mips.c aacpsy_mips.h diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 357ac48..0c1b370 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -44,6 +44,7 @@ OBJS-$(CONFIG_ENCODERS) += faandct.o jfdctfst.o jfdctint.o OBJS-$(CONFIG_ERROR_RESILIENCE) += error_resilience.o FFT-OBJS-$(CONFIG_HARDCODED_TABLES) += cos_tables.o cos_fixed_tables.o OBJS-$(CONFIG_FFT) += avfft.o fft_fixed.o fft_float.o \ + fft_fixed_32.o fft_init_table.o \ $(FFT-OBJS-yes) OBJS-$(CONFIG_GOLOMB) += golomb.o OBJS-$(CONFIG_H264CHROMA) += h264chroma.o @@ -55,7 +56,7 @@ OBJS-$(CONFIG_HUFFMAN) += huffman.o OBJS-$(CONFIG_LIBXVID) += libxvid_rc.o OBJS-$(CONFIG_LPC) += lpc.o OBJS-$(CONFIG_LSP) += lsp.o -OBJS-$(CONFIG_MDCT) += mdct_fixed.o mdct_float.o +OBJS-$(CONFIG_MDCT) += mdct_fixed.o mdct_float.o mdct_fixed_32.o OBJS-$(CONFIG_MPEGAUDIO) += mpegaudio.o mpegaudiodata.o \ mpegaudiodecheader.o OBJS-$(CONFIG_MPEGAUDIODSP) += mpegaudiodsp.o \ @@ -801,6 +802,7 @@ TESTPROGS = cabac \ dct \ fft \ fft-fixed \ + fft-fixed32 \ golomb \ iirfilter \ imgconvert \ diff --git a/libavcodec/fft-fixed32-test.c b/libavcodec/fft-fixed32-test.c new file mode 100644 index 0000000..89cd47c --- /dev/null +++ b/libavcodec/fft-fixed32-test.c @@ -0,0 +1,21 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#define CONFIG_FFT_FLOAT 0 +#define CONFIG_FFT_FIXED_32 1 +#include "fft-test.c" diff --git a/libavcodec/fft-internal.h b/libavcodec/fft-internal.h index d66731f..065eecc 100644 --- a/libavcodec/fft-internal.h +++ b/libavcodec/fft-internal.h @@ -36,12 +36,29 @@ #else +#define SCALE_FLOAT(a, bits) lrint((a) * (double)(1 << (bits))) + +#if CONFIG_FFT_FIXED_32 + +#define CMUL(dre, dim, are, aim, bre, bim) do { \ + int64_t accu; \ + (accu) = (int64_t)(bre) * (are); \ + (accu) -= (int64_t)(bim) * (aim); \ + (dre) = (int)(((accu) + 0x40000000) >> 31); \ + (accu) = (int64_t)(bre) * (aim); \ + (accu) += (int64_t)(bim) * (are); \ + (dim) = (int)(((accu) + 0x40000000) >> 31); \ + } while (0) + +#define FIX15(a) av_clip(SCALE_FLOAT(a, 31), -2147483647, 2147483647) + +#else /* CONFIG_FFT_FIXED_32 */ + #include "fft.h" #include "mathops.h" void ff_mdct_calcw_c(FFTContext *s, FFTDouble *output, const FFTSample *input); -#define SCALE_FLOAT(a, bits) lrint((a) * (double)(1 << (bits))) #define FIX15(a) av_clip(SCALE_FLOAT(a, 15), -32767, 32767) #define sqrthalf ((int16_t)((1<<15)*M_SQRT1_2)) @@ -62,6 +79,8 @@ void ff_mdct_calcw_c(FFTContext *s, FFTDouble *output, const FFTSample *input); #define CMULL(dre, dim, are, aim, bre, bim) \ CMULS(dre, dim, are, aim, bre, bim, 0) +#endif /* CONFIG_FFT_FIXED_32 */ + #endif /* CONFIG_FFT_FLOAT */ #define ff_imdct_calc_c FFT_NAME(ff_imdct_calc_c) diff --git a/libavcodec/fft-test.c b/libavcodec/fft-test.c index 66474ce..9831b2c 100644 --- a/libavcodec/fft-test.c +++ b/libavcodec/fft-test.c @@ -54,6 +54,10 @@ # define RANGE 1.0 # define REF_SCALE(x, bits) (x) # define FMT "%10.6f" +#elif CONFIG_FFT_FIXED_32 +# define RANGE 8388608 +# define REF_SCALE(x, bits) (x) +# define FMT "%6d" #else # define RANGE 16384 # define REF_SCALE(x, bits) ((x) / (1<<(bits))) diff --git a/libavcodec/fft.c b/libavcodec/fft.c index 00c434a..d8e5993 100644 --- a/libavcodec/fft.c +++ b/libavcodec/fft.c @@ -32,6 +32,10 @@ #include "fft.h" #include "fft-internal.h" +#if CONFIG_FFT_FIXED_32 +#include "fft_table.h" +#else /* CONFIG_FFT_FIXED_32 */ + /* cos(2*pi*x/n) for 0<=x<=n/4, followed by its reverse */ #if !CONFIG_HARDCODED_TABLES COSTABLE(16); @@ -65,6 +69,8 @@ COSTABLE_CONST FFTSample * const FFT_NAME(ff_cos_tabs)[] = { FFT_NAME(ff_cos_65536), }; +#endif /* CONFIG_FFT_FIXED_32 */ + static void ff_fft_permute_c(FFTContext *s, FFTComplex *z); static void ff_fft_calc_c(FFTContext *s, FFTComplex *z); @@ -81,7 +87,7 @@ static int split_radix_permutation(int i, int n, int inverse) av_cold void ff_init_ff_cos_tabs(int index) { -#if !CONFIG_HARDCODED_TABLES +#if (!CONFIG_HARDCODED_TABLES) && (!CONFIG_FFT_FIXED_32) int i; int m = 1<<index; double freq = 2*M_PI/m; @@ -157,6 +163,12 @@ av_cold int ff_fft_init(FFTContext *s, int nbits, int inverse) s->mdct_calc = ff_mdct_calc_c; #endif +#if CONFIG_FFT_FIXED_32 + { + int n=0; + ff_fft_lut_init(fft_offsets_lut, 0, 1 << 16, &n); + } +#else /* CONFIG_FFT_FIXED_32 */ #if CONFIG_FFT_FLOAT if (ARCH_ARM) ff_fft_init_arm(s); if (HAVE_ALTIVEC) ff_fft_init_altivec(s); @@ -167,10 +179,11 @@ av_cold int ff_fft_init(FFTContext *s, int nbits, int inverse) if (CONFIG_MDCT) s->mdct_calcw = ff_mdct_calcw_c; if (ARCH_ARM) ff_fft_fixed_init_arm(s); #endif - for(j=4; j<=nbits; j++) { ff_init_ff_cos_tabs(j); } +#endif /* CONFIG_FFT_FIXED_32 */ + if (s->fft_permutation == FF_FFT_PERM_AVX) { fft_perm_avx(s); @@ -206,6 +219,169 @@ av_cold void ff_fft_end(FFTContext *s) av_freep(&s->tmp_buf); } +#if CONFIG_FFT_FIXED_32 + +static void ff_fft_calc_c(FFTContext *s, FFTComplex *z) { + + int nbits, i, n, num_transforms, offset, step; + int n4, n2, n34; + FFTSample tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8; + FFTComplex *tmpz; + FFTSample w_re, w_im; + FFTSample *w_re_ptr, *w_im_ptr; + const int fft_size = (1 << s->nbits); + int64_t accu; + + num_transforms = (0x2aab >> (16 - s->nbits)) | 1; + + for (n=0; n<num_transforms; n++){ + offset = fft_offsets_lut[n] << 2; + tmpz = z + offset; + + tmp1 = tmpz[0].re + tmpz[1].re; + tmp5 = tmpz[2].re + tmpz[3].re; + tmp2 = tmpz[0].im + tmpz[1].im; + tmp6 = tmpz[2].im + tmpz[3].im; + tmp3 = tmpz[0].re - tmpz[1].re; + tmp8 = tmpz[2].im - tmpz[3].im; + tmp4 = tmpz[0].im - tmpz[1].im; + tmp7 = tmpz[2].re - tmpz[3].re; + + tmpz[0].re = tmp1 + tmp5; + tmpz[2].re = tmp1 - tmp5; + tmpz[0].im = tmp2 + tmp6; + tmpz[2].im = tmp2 - tmp6; + tmpz[1].re = tmp3 + tmp8; + tmpz[3].re = tmp3 - tmp8; + tmpz[1].im = tmp4 - tmp7; + tmpz[3].im = tmp4 + tmp7; + } + + if (fft_size < 8) + return; + + num_transforms = (num_transforms >> 1) | 1; + + for (n=0; n<num_transforms; n++){ + offset = fft_offsets_lut[n] << 3; + tmpz = z + offset; + + tmp1 = tmpz[4].re + tmpz[5].re; + tmp3 = tmpz[6].re + tmpz[7].re; + tmp2 = tmpz[4].im + tmpz[5].im; + tmp4 = tmpz[6].im + tmpz[7].im; + tmp5 = tmp1 + tmp3; + tmp7 = tmp1 - tmp3; + tmp6 = tmp2 + tmp4; + tmp8 = tmp2 - tmp4; + + tmp1 = tmpz[4].re - tmpz[5].re; + tmp2 = tmpz[4].im - tmpz[5].im; + tmp3 = tmpz[6].re - tmpz[7].re; + tmp4 = tmpz[6].im - tmpz[7].im; + + tmpz[4].re = tmpz[0].re - tmp5; + tmpz[0].re = tmpz[0].re + tmp5; + tmpz[4].im = tmpz[0].im - tmp6; + tmpz[0].im = tmpz[0].im + tmp6; + tmpz[6].re = tmpz[2].re - tmp8; + tmpz[2].re = tmpz[2].re + tmp8; + tmpz[6].im = tmpz[2].im + tmp7; + tmpz[2].im = tmpz[2].im - tmp7; + + accu = (int64_t)Q31(M_SQRT1_2)*(tmp1 + tmp2); + tmp5 = (int32_t)((accu + 0x40000000) >> 31); + accu = (int64_t)Q31(M_SQRT1_2)*(tmp3 - tmp4); + tmp7 = (int32_t)((accu + 0x40000000) >> 31); + accu = (int64_t)Q31(M_SQRT1_2)*(tmp2 - tmp1); + tmp6 = (int32_t)((accu + 0x40000000) >> 31); + accu = (int64_t)Q31(M_SQRT1_2)*(tmp3 + tmp4); + tmp8 = (int32_t)((accu + 0x40000000) >> 31); + tmp1 = tmp5 + tmp7; + tmp3 = tmp5 - tmp7; + tmp2 = tmp6 + tmp8; + tmp4 = tmp6 - tmp8; + + tmpz[5].re = tmpz[1].re - tmp1; + tmpz[1].re = tmpz[1].re + tmp1; + tmpz[5].im = tmpz[1].im - tmp2; + tmpz[1].im = tmpz[1].im + tmp2; + tmpz[7].re = tmpz[3].re - tmp4; + tmpz[3].re = tmpz[3].re + tmp4; + tmpz[7].im = tmpz[3].im + tmp3; + tmpz[3].im = tmpz[3].im - tmp3; + } + + step = 1 << ((MAX_LOG2_NFFT-4) - 4); + n4 = 4; + + for (nbits=4; nbits<=s->nbits; nbits++){ + n2 = 2*n4; + n34 = 3*n4; + num_transforms = (num_transforms >> 1) | 1; + + for (n=0; n<num_transforms; n++){ + offset = fft_offsets_lut[n] << nbits; + tmpz = z + offset; + + tmp5 = tmpz[ n2].re + tmpz[n34].re; + tmp1 = tmpz[ n2].re - tmpz[n34].re; + tmp6 = tmpz[ n2].im + tmpz[n34].im; + tmp2 = tmpz[ n2].im - tmpz[n34].im; + + tmpz[ n2].re = tmpz[ 0].re - tmp5; + tmpz[ 0].re = tmpz[ 0].re + tmp5; + tmpz[ n2].im = tmpz[ 0].im - tmp6; + tmpz[ 0].im = tmpz[ 0].im + tmp6; + tmpz[n34].re = tmpz[n4].re - tmp2; + tmpz[ n4].re = tmpz[n4].re + tmp2; + tmpz[n34].im = tmpz[n4].im + tmp1; + tmpz[ n4].im = tmpz[n4].im - tmp1; + + w_re_ptr = w_tab_sr + step; + w_im_ptr = w_tab_sr + MAX_FFT_SIZE/(4*16) - step; + + for (i=1; i<n4; i++){ + w_re = w_re_ptr[0]; + w_im = w_im_ptr[0]; + accu = (int64_t)w_re*tmpz[ n2+i].re; + accu += (int64_t)w_im*tmpz[ n2+i].im; + tmp1 = (int32_t)((accu + 0x40000000) >> 31); + accu = (int64_t)w_re*tmpz[ n2+i].im; + accu -= (int64_t)w_im*tmpz[ n2+i].re; + tmp2 = (int32_t)((accu + 0x40000000) >> 31); + accu = (int64_t)w_re*tmpz[n34+i].re; + accu -= (int64_t)w_im*tmpz[n34+i].im; + tmp3 = (int32_t)((accu + 0x40000000) >> 31); + accu = (int64_t)w_re*tmpz[n34+i].im; + accu += (int64_t)w_im*tmpz[n34+i].re; + tmp4 = (int32_t)((accu + 0x40000000) >> 31); + + tmp5 = tmp1 + tmp3; + tmp1 = tmp1 - tmp3; + tmp6 = tmp2 + tmp4; + tmp2 = tmp2 - tmp4; + + tmpz[ n2+i].re = tmpz[ i].re - tmp5; + tmpz[ i].re = tmpz[ i].re + tmp5; + tmpz[ n2+i].im = tmpz[ i].im - tmp6; + tmpz[ i].im = tmpz[ i].im + tmp6; + tmpz[n34+i].re = tmpz[n4+i].re - tmp2; + tmpz[ n4+i].re = tmpz[n4+i].re + tmp2; + tmpz[n34+i].im = tmpz[n4+i].im + tmp1; + tmpz[ n4+i].im = tmpz[n4+i].im - tmp1; + + w_re_ptr += step; + w_im_ptr -= step; + } + } + step >>= 1; + n4 <<= 1; + } +} + +#else /* CONFIG_FFT_FIXED_32 */ + #define BUTTERFLIES(a0,a1,a2,a3) {\ BF(t3, t5, t5, t1);\ BF(a2.re, a0.re, a0.re, t5);\ @@ -351,3 +527,4 @@ static void ff_fft_calc_c(FFTContext *s, FFTComplex *z) { fft_dispatch[s->nbits-2](z); } +#endif /* CONFIG_FFT_FIXED_32 */ diff --git a/libavcodec/fft.h b/libavcodec/fft.h index 9d92b2c..05a02dc 100644 --- a/libavcodec/fft.h +++ b/libavcodec/fft.h @@ -26,6 +26,10 @@ #define CONFIG_FFT_FLOAT 1 #endif +#ifndef CONFIG_FFT_FIXED_32 +#define CONFIG_FFT_FIXED_32 0 +#endif + #include <stdint.h> #include "config.h" #include "libavutil/mem.h" @@ -40,15 +44,26 @@ typedef float FFTDouble; #else +#if CONFIG_FFT_FIXED_32 + +#define Q31(x) (int)((x)*2147483648.0 + 0.5) +#define FFT_NAME(x) x ## _fixed_32 + +typedef int32_t FFTSample; + +#else /* CONFIG_FFT_FIXED_32 */ + #define FFT_NAME(x) x ## _fixed typedef int16_t FFTSample; -typedef int FFTDouble; + +#endif /* CONFIG_FFT_FIXED_32 */ typedef struct FFTComplex { - int16_t re, im; + FFTSample re, im; } FFTComplex; +typedef int FFTDouble; typedef struct FFTContext FFTContext; #endif /* CONFIG_FFT_FLOAT */ diff --git a/libavcodec/fft_fixed.c b/libavcodec/fft_fixed.c index 3955efe..153b7d8 100644 --- a/libavcodec/fft_fixed.c +++ b/libavcodec/fft_fixed.c @@ -17,4 +17,5 @@ */ #define CONFIG_FFT_FLOAT 0 +#define CONFIG_FFT_FIXED_32 0 #include "fft.c" diff --git a/libavcodec/fft_fixed_32.c b/libavcodec/fft_fixed_32.c new file mode 100644 index 0000000..f2954d7 --- /dev/null +++ b/libavcodec/fft_fixed_32.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2012 + * MIPS Technologies, Inc., California. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Authors: Stanislav Ocovaj (socovaj@mips.com) + * Goran Cordasic (goran@mips.com) + * Djordje Pesut (djordje@mips.com) + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#define CONFIG_FFT_FLOAT 0 +#define CONFIG_FFT_FIXED_32 1 +#include "fft.c" diff --git a/libavcodec/fft_float.c b/libavcodec/fft_float.c index 2149646..011dc45 100644 --- a/libavcodec/fft_float.c +++ b/libavcodec/fft_float.c @@ -17,4 +17,5 @@ */ #define CONFIG_FFT_FLOAT 1 +#define CONFIG_FFT_FIXED_32 0 #include "fft.c" diff --git a/libavcodec/fft_init_table.c b/libavcodec/fft_init_table.c new file mode 100644 index 0000000..7511dbe --- /dev/null +++ b/libavcodec/fft_init_table.c @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2012 + * MIPS Technologies, Inc., California. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Authors: Stanislav Ocovaj (socovaj@mips.com) + * Goran Cordasic (goran@mips.com) + * Djordje Pesut (djordje@mips.com) + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * definitions and initialization of LUT table for FFT + */ +#include "libavcodec/fft_table.h" + +int32_t w_tab_sr[MAX_FFT_SIZE/(4*16)] = { + 2147483647, 2147481121, 2147473542, 2147460908, 2147443222, 2147420483, 2147392690, 2147359845, + 2147321946, 2147278995, 2147230991, 2147177934, 2147119825, 2147056664, 2146988450, 2146915184, + 2146836866, 2146753497, 2146665076, 2146571603, 2146473080, 2146369505, 2146260881, 2146147205, + 2146028480, 2145904705, 2145775880, 2145642006, 2145503083, 2145359112, 2145210092, 2145056025, + 2144896910, 2144732748, 2144563539, 2144389283, 2144209982, 2144025635, 2143836244, 2143641807, + 2143442326, 2143237802, 2143028234, 2142813624, 2142593971, 2142369276, 2142139541, 2141904764, + 2141664948, 2141420092, 2141170197, 2140915264, 2140655293, 2140390284, 2140120240, 2139845159, + 2139565043, 2139279892, 2138989708, 2138694490, 2138394240, 2138088958, 2137778644, 2137463301, + 2137142927, 2136817525, 2136487095, 2136151637, 2135811153, 2135465642, 2135115107, 2134759548, + 2134398966, 2134033361, 2133662734, 2133287087, 2132906420, 2132520734, 2132130030, 2131734309, + 2131333572, 2130927819, 2130517052, 2130101272, 2129680480, 2129254676, 2128823862, 2128388038, + 2127947206, 2127501367, 2127050522, 2126594672, 2126133817, 2125667960, 2125197100, 2124721240, + 2124240380, 2123754522, 2123263666, 2122767814, 2122266967, 2121761126, 2121250292, 2120734467, + 2120213651, 2119687847, 2119157054, 2118621275, 2118080511, 2117534762, 2116984031, 2116428319, + 2115867626, 2115301954, 2114731305, 2114155680, 2113575080, 2112989506, 2112398960, 2111803444, + 2111202959, 2110597505, 2109987085, 2109371700, 2108751352, 2108126041, 2107495770, 2106860540, + 2106220352, 2105575208, 2104925109, 2104270057, 2103610054, 2102945101, 2102275199, 2101600350, + 2100920556, 2100235819, 2099546139, 2098851519, 2098151960, 2097447464, 2096738032, 2096023667, + 2095304370, 2094580142, 2093850985, 2093116901, 2092377892, 2091633960, 2090885105, 2090131331, + 2089372638, 2088609029, 2087840505, 2087067068, 2086288720, 2085505463, 2084717298, 2083924228, + 2083126254, 2082323379, 2081515603, 2080702930, 2079885360, 2079062896, 2078235540, 2077403294, + 2076566160, 2075724139, 2074877233, 2074025446, 2073168777, 2072307231, 2071440808, 2070569511, + 2069693342, 2068812302, 2067926394, 2067035621, 2066139983, 2065239484, 2064334124, 2063423908, + 2062508835, 2061588910, 2060664133, 2059734508, 2058800036, 2057860719, 2056916560, 2055967560, + 2055013723, 2054055050, 2053091544, 2052123207, 2051150040, 2050172048, 2049189231, 2048201592, + 2047209133, 2046211857, 2045209767, 2044202863, 2043191150, 2042174628, 2041153301, 2040127172, + 2039096241, 2038060512, 2037019988, 2035974670, 2034924562, 2033869665, 2032809982, 2031745516, + 2030676269, 2029602243, 2028523442, 2027439867, 2026351522, 2025258408, 2024160529, 2023057887, + 2021950484, 2020838323, 2019721407, 2018599739, 2017473321, 2016342155, 2015206245, 2014065592, + 2012920201, 2011770073, 2010615210, 2009455617, 2008291295, 2007122248, 2005948478, 2004769987, + 2003586779, 2002398857, 2001206222, 2000008879, 1998806829, 1997600076, 1996388622, 1995172471, + 1993951625, 1992726087, 1991495860, 1990260946, 1989021350, 1987777073, 1986528118, 1985274489, + 1984016189, 1982753220, 1981485585, 1980213288, 1978936331, 1977654717, 1976368450, 1975077532, + 1973781967, 1972481757, 1971176906, 1969867417, 1968553292, 1967234535, 1965911148, 1964583136, + 1963250501, 1961913246, 1960571375, 1959224890, 1957873796, 1956518093, 1955157788, 1953792881, + 1952423377, 1951049279, 1949670589, 1948287312, 1946899451, 1945507008, 1944109987, 1942708392, + 1941302225, 1939891490, 1938476190, 1937056329, 1935631910, 1934202936, 1932769411, 1931331338, + 1929888720, 1928441561, 1926989864, 1925533633, 1924072871, 1922607581, 1921137767, 1919663432, + 1918184581, 1916701216, 1915213340, 1913720958, 1912224073, 1910722688, 1909216806, 1907706433, + 1906191570, 1904672222, 1903148392, 1901620084, 1900087301, 1898550047, 1897008325, 1895462140, + 1893911494, 1892356392, 1890796837, 1889232832, 1887664383, 1886091491, 1884514161, 1882932397, + 1881346202, 1879755580, 1878160535, 1876561070, 1874957189, 1873348897, 1871736196, 1870119091, + 1868497586, 1866871683, 1865241388, 1863606704, 1861967634, 1860324183, 1858676355, 1857024153, + 1855367581, 1853706643, 1852041343, 1850371686, 1848697674, 1847019312, 1845336604, 1843649553, + 1841958164, 1840262441, 1838562388, 1836858008, 1835149306, 1833436286, 1831718951, 1829997307, + 1828271356, 1826541103, 1824806552, 1823067707, 1821324572, 1819577151, 1817825449, 1816069469, + 1814309216, 1812544694, 1810775906, 1809002858, 1807225553, 1805443995, 1803658189, 1801868139, + 1800073849, 1798275323, 1796472565, 1794665580, 1792854372, 1791038946, 1789219305, 1787395453, + 1785567396, 1783735137, 1781898681, 1780058032, 1778213194, 1776364172, 1774510970, 1772653593, + 1770792044, 1768926328, 1767056450, 1765182414, 1763304224, 1761421885, 1759535401, 1757644777, + 1755750017, 1753851126, 1751948107, 1750040966, 1748129707, 1746214334, 1744294853, 1742371267, + 1740443581, 1738511799, 1736575927, 1734635968, 1732691928, 1730743810, 1728791620, 1726835361, + 1724875040, 1722910659, 1720942225, 1718969740, 1716993211, 1715012642, 1713028037, 1711039401, + 1709046739, 1707050055, 1705049355, 1703044642, 1701035922, 1699023199, 1697006479, 1694985765, + 1692961062, 1690932376, 1688899711, 1686863072, 1684822463, 1682777890, 1680729357, 1678676870, + 1676620432, 1674560049, 1672495725, 1670427466, 1668355276, 1666279161, 1664199124, 1662115172, + 1660027308, 1657935539, 1655839867, 1653740300, 1651636841, 1649529496, 1647418269, 1645303166, + 1643184191, 1641061349, 1638934646, 1636804087, 1634669676, 1632531418, 1630389319, 1628243383, + 1626093616, 1623940023, 1621782608, 1619621377, 1617456335, 1615287487, 1613114838, 1610938393, + 1608758157, 1606574136, 1604386335, 1602194758, 1599999411, 1597800299, 1595597428, 1593390801, + 1591180426, 1588966306, 1586748447, 1584526854, 1582301533, 1580072489, 1577839726, 1575603251, + 1573363068, 1571119183, 1568871601, 1566620327, 1564365367, 1562106725, 1559844408, 1557578421, + 1555308768, 1553035455, 1550758488, 1548477872, 1546193612, 1543905714, 1541614183, 1539319024, + 1537020244, 1534717846, 1532411837, 1530102222, 1527789007, 1525472197, 1523151797, 1520827813, + 1518500250, 1516169114, 1513834411, 1511496145, 1509154322, 1506808949, 1504460029, 1502107570, + 1499751576, 1497392053, 1495029006, 1492662441, 1490292364, 1487918781, 1485541696, 1483161115, + 1480777044, 1478389489, 1475998456, 1473603949, 1471205974, 1468804538, 1466399645, 1463991302, + 1461579514, 1459164286, 1456745625, 1454323536, 1451898025, 1449469098, 1447036760, 1444601017, + 1442161874, 1439719338, 1437273414, 1434824109, 1432371426, 1429915374, 1427455956, 1424993180, + 1422527051, 1420057574, 1417584755, 1415108601, 1412629117, 1410146309, 1407660183, 1405170745, + 1402678000, 1400181954, 1397682613, 1395179984, 1392674072, 1390164882, 1387652422, 1385136696, + 1382617710, 1380095472, 1377569986, 1375041258, 1372509294, 1369974101, 1367435685, 1364894050, + 1362349204, 1359801152, 1357249901, 1354695455, 1352137822, 1349577007, 1347013017, 1344445857, + 1341875533, 1339302052, 1336725419, 1334145641, 1331562723, 1328976672, 1326387494, 1323795195, + 1321199781, 1318601257, 1315999631, 1313394909, 1310787095, 1308176198, 1305562222, 1302945174, + 1300325060, 1297701886, 1295075659, 1292446384, 1289814068, 1287178717, 1284540337, 1281898935, + 1279254516, 1276607086, 1273956653, 1271303222, 1268646800, 1265987392, 1263325005, 1260659646, + 1257991320, 1255320034, 1252645794, 1249968606, 1247288478, 1244605414, 1241919421, 1239230506, + 1236538675, 1233843935, 1231146291, 1228445750, 1225742318, 1223036002, 1220326809, 1217614743, + 1214899813, 1212182024, 1209461382, 1206737894, 1204011567, 1201282407, 1198550419, 1195815612, + 1193077991, 1190337562, 1187594332, 1184848308, 1182099496, 1179347902, 1176593533, 1173836395, + 1171076495, 1168313840, 1165548435, 1162780288, 1160009405, 1157235792, 1154459456, 1151680403, + 1148898640, 1146114174, 1143327011, 1140537158, 1137744621, 1134949406, 1132151521, 1129350972, + 1126547765, 1123741908, 1120933406, 1118122267, 1115308496, 1112492101, 1109673089, 1106851465, + 1104027237, 1101200410, 1098370993, 1095538991, 1092704411, 1089867259, 1087027544, 1084185270, + 1081340445, 1078493076, 1075643169, 1072790730, 1069935768, 1067078288, 1064218296, 1061355801, + 1058490808, 1055623324, 1052753357, 1049880912, 1047005996, 1044128617, 1041248781, 1038366495, + 1035481766, 1032594600, 1029705004, 1026812985, 1023918550, 1021021705, 1018122458, 1015220816, + 1012316784, 1009410370, 1006501581, 1003590424, 1000676905, 997761031, 994842810, 991922248, + 988999351, 986074127, 983146583, 980216726, 977284562, 974350098, 971413342, 968474300, + 965532978, 962589385, 959643527, 956695411, 953745043, 950792431, 947837582, 944880503, + 941921200, 938959681, 935995952, 933030021, 930061894, 927091579, 924119082, 921144411, + 918167572, 915188572, 912207419, 909224120, 906238681, 903251110, 900261413, 897269597, + 894275671, 891279640, 888281512, 885281293, 882278992, 879274614, 876268167, 873259659, + 870249095, 867236484, 864221832, 861205147, 858186435, 855165703, 852142959, 849118210, + 846091463, 843062726, 840032004, 836999305, 833964638, 830928007, 827889422, 824848888, + 821806413, 818762005, 815715670, 812667415, 809617249, 806565177, 803511207, 800455346, + 797397602, 794337982, 791276492, 788213141, 785147934, 782080880, 779011986, 775941259, + 772868706, 769794334, 766718151, 763640164, 760560380, 757478806, 754395449, 751310318, + 748223418, 745134758, 742044345, 738952186, 735858287, 732762657, 729665303, 726566232, + 723465451, 720362968, 717258790, 714152924, 711045377, 707936158, 704825272, 701712728, + 698598533, 695482694, 692365218, 689246113, 686125387, 683003045, 679879097, 676753549, + 673626408, 670497682, 667367379, 664235505, 661102068, 657967075, 654830535, 651692453, + 648552838, 645411696, 642269036, 639124865, 635979190, 632832018, 629683357, 626533215, + 623381598, 620228514, 617073971, 613917975, 610760536, 607601658, 604441352, 601279623, + 598116479, 594951927, 591785976, 588618632, 585449903, 582279796, 579108320, 575935480, + 572761285, 569585743, 566408860, 563230645, 560051104, 556870245, 553688076, 550504604, + 547319836, 544133781, 540946445, 537757837, 534567963, 531376831, 528184449, 524990824, + 521795963, 518599875, 515402566, 512204045, 509004318, 505803394, 502601279, 499397982, + 496193509, 492987869, 489781069, 486573117, 483364019, 480153784, 476942419, 473729932, + 470516330, 467301622, 464085813, 460868912, 457650927, 454431865, 451211734, 447990541, + 444768294, 441545000, 438320667, 435095303, 431868915, 428641511, 425413098, 422183684, + 418953276, 415721883, 412489512, 409256170, 406021865, 402786604, 399550396, 396313247, + 393075166, 389836160, 386596237, 383355404, 380113669, 376871039, 373627523, 370383128, + 367137861, 363891730, 360644742, 357396906, 354148230, 350898719, 347648383, 344397230, + 341145265, 337892498, 334638936, 331384586, 328129457, 324873555, 321616889, 318359466, + 315101295, 311842381, 308582734, 305322361, 302061269, 298799466, 295536961, 292273760, + 289009871, 285745302, 282480061, 279214155, 275947592, 272680379, 269412525, 266144038, + 262874923, 259605191, 256334847, 253063900, 249792358, 246520228, 243247518, 239974235, + 236700388, 233425984, 230151030, 226875535, 223599506, 220322951, 217045878, 213768293, + 210490206, 207211624, 203932553, 200653003, 197372981, 194092495, 190811551, 187530159, + 184248325, 180966058, 177683365, 174400254, 171116733, 167832808, 164548489, 161263783, + 157978697, 154693240, 151407418, 148121241, 144834714, 141547847, 138260647, 134973122, + 131685278, 128397125, 125108670, 121819921, 118530885, 115241570, 111951983, 108662134, + 105372028, 102081675, 98791081, 95500255, 92209205, 88917937, 85626460, 82334782, + 79042909, 75750851, 72458615, 69166208, 65873638, 62580914, 59288042, 55995030, + 52701887, 49408620, 46115236, 42821744, 39528151, 36234466, 32940695, 29646846, + 26352928, 23058947, 19764913, 16470832, 13176712, 9882561, 6588387, 3294197 +}; + +uint16_t fft_offsets_lut[0x2aab]; + +void ff_fft_lut_init(uint16_t *table, int off, int size, int *index) +{ + if (size < 16) { + table[*index] = off >> 2; + (*index)++; + } + else { + ff_fft_lut_init(table, off, size>>1, index); + ff_fft_lut_init(table, off+(size>>1), size>>2, index); + ff_fft_lut_init(table, off+3*(size>>2), size>>2, index); + } +} diff --git a/libavcodec/fft_table.h b/libavcodec/fft_table.h new file mode 100644 index 0000000..687e5b9 --- /dev/null +++ b/libavcodec/fft_table.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2012 + * MIPS Technologies, Inc., California. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Authors: Stanislav Ocovaj (socovaj@mips.com) + * Goran Cordasic (goran@mips.com) + * Djordje Pesut (djordje@mips.com) + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * definitions and tables for FFT + */ +#ifndef AVCODEC_FFT_TABLE_H +#define AVCODEC_FFT_TABLE_H + +#include "libavcodec/fft.h" + +#define MAX_LOG2_NFFT 16 //!< Specifies maxiumum allowed fft size +#define MAX_FFT_SIZE (1 << MAX_LOG2_NFFT) + +extern int32_t w_tab_sr[]; +extern uint16_t fft_offsets_lut[]; +void ff_fft_lut_init(uint16_t *table, int off, int size, int *index); + +#endif /* AVCODEC_FFT_TABLE_H */ diff --git a/libavcodec/mdct.c b/libavcodec/mdct.c index 2232024..922d577 100644 --- a/libavcodec/mdct.c +++ b/libavcodec/mdct.c @@ -34,7 +34,11 @@ #if CONFIG_FFT_FLOAT # define RSCALE(x) (x) #else +#if CONFIG_FFT_FIXED_32 +# define RSCALE(x) (((x) + 32) >> 6) +#else /* CONFIG_FFT_FIXED_32 */ # define RSCALE(x) ((x) >> 1) +#endif /* CONFIG_FFT_FIXED_32 */ #endif /** diff --git a/libavcodec/mdct_fixed.c b/libavcodec/mdct_fixed.c index 794a3e0..33a266d 100644 --- a/libavcodec/mdct_fixed.c +++ b/libavcodec/mdct_fixed.c @@ -17,6 +17,7 @@ */ #define CONFIG_FFT_FLOAT 0 +#define CONFIG_FFT_FIXED_32 0 #include "mdct.c" /* same as ff_mdct_calcw_c with double-width unscaled output */ diff --git a/libavcodec/mdct_fixed_32.c b/libavcodec/mdct_fixed_32.c new file mode 100644 index 0000000..66226f3 --- /dev/null +++ b/libavcodec/mdct_fixed_32.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2012 + * MIPS Technologies, Inc., California. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Authors: Stanislav Ocovaj (socovaj@mips.com) + * Goran Cordasic (goran@mips.com) + * Djordje Pesut (djordje@mips.com) + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#define CONFIG_FFT_FLOAT 0 +#define CONFIG_FFT_FIXED_32 1 +#include "mdct.c" diff --git a/libavcodec/mdct_float.c b/libavcodec/mdct_float.c index ec4f486..fec18ba 100644 --- a/libavcodec/mdct_float.c +++ b/libavcodec/mdct_float.c @@ -17,4 +17,5 @@ */ #define CONFIG_FFT_FLOAT 1 +#define CONFIG_FFT_FIXED_32 0 #include "mdct.c" diff --git a/libavcodec/mips/Makefile b/libavcodec/mips/Makefile index a2ea412..6537b43 100644 --- a/libavcodec/mips/Makefile +++ b/libavcodec/mips/Makefile @@ -9,7 +9,6 @@ MIPSFPU-OBJS-$(CONFIG_AMRWB_DECODER) += mips/acelp_filters_mips.o \ mips/acelp_vectors_mips.o MIPSFPU-OBJS-$(CONFIG_MPEGAUDIODSP) += mips/mpegaudiodsp_mips_float.o MIPSDSPR1-OBJS-$(CONFIG_MPEGAUDIODSP) += mips/mpegaudiodsp_mips_fixed.o -OBJS-$(CONFIG_FFT) += mips/fft_init_table.o MIPSFPU-OBJS-$(CONFIG_FFT) += mips/fft_mips.o MIPSFPU-OBJS += mips/fmtconvert_mips.o OBJS-$(CONFIG_AC3DSP) += mips/ac3dsp_mips.o diff --git a/libavcodec/mips/fft_init_table.c b/libavcodec/mips/fft_init_table.c deleted file mode 100644 index 9c2e998..0000000 --- a/libavcodec/mips/fft_init_table.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2012 - * MIPS Technologies, Inc., California. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Author: Stanislav Ocovaj (socovaj@mips.com) - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file - * definitions and initialization of LUT table for MIPS FFT - */ -#include "fft_table.h" - -uint16_t fft_offsets_lut[0x2aab]; - -void ff_fft_lut_init(uint16_t *table, int off, int size, int *index) -{ - if (size < 16) { - table[*index] = off >> 2; - (*index)++; - } - else { - ff_fft_lut_init(table, off, size>>1, index); - ff_fft_lut_init(table, off+(size>>1), size>>2, index); - ff_fft_lut_init(table, off+3*(size>>2), size>>2, index); - } -} diff --git a/libavcodec/mips/fft_mips.c b/libavcodec/mips/fft_mips.c index ae4ed30..d240f1f 100644 --- a/libavcodec/mips/fft_mips.c +++ b/libavcodec/mips/fft_mips.c @@ -49,7 +49,7 @@ */ #include "config.h" #include "libavcodec/fft.h" -#include "fft_table.h" +#include "libavcodec/fft_table.h" /** * FFT transform diff --git a/libavcodec/mips/fft_table.h b/libavcodec/mips/fft_table.h deleted file mode 100644 index dd52eaf..0000000 --- a/libavcodec/mips/fft_table.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2012 - * MIPS Technologies, Inc., California. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Author: Stanislav Ocovaj (socovaj@mips.com) - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file - * definitions and LUT table for MIPS FFT - */ -#ifndef AVCODEC_MIPS_FFT_TABLE_H -#define AVCODEC_MIPS_FFT_TABLE_H - -#include "libavcodec/fft.h" - -#define MAX_LOG2_NFFT 16 //!< Specifies maxiumum allowed fft size -#define MAX_FFT_SIZE (1 << MAX_LOG2_NFFT) - -extern uint16_t fft_offsets_lut[]; -void ff_fft_lut_init(uint16_t *table, int off, int size, int *index); - -#endif /* AVCODEC_MIPS_FFT_TABLE_H */ diff --git a/tests/fate/fft.mak b/tests/fate/fft.mak index 20d5638..2413415 100644 --- a/tests/fate/fft.mak +++ b/tests/fate/fft.mak @@ -38,5 +38,22 @@ $(FATE_FFT_FIXED): libavcodec/fft-fixed-test$(EXESUF) $(FATE_FFT_FIXED): CMD = run libavcodec/fft-fixed-test $(CPUFLAGS:%=-c%) $(ARGS) $(FATE_FFT_FIXED): REF = /dev/null -FATE-$(call ALLYES, AVCODEC FFT) += $(FATE_FFT) $(FATE_FFT_FIXED) -fate-fft: $(FATE_FFT) $(FATE_FFT_FIXED) +define DEF_FFT_FIXED32 +FATE_FFT_FIXED32 += fate-fft-fixed32-$(1) fate-ifft-fixed32-$(1) \ + fate-mdct-fixed32-$(1) fate-imdct-fixed32-$(1) + +fate-fft-fixed32-$(1): ARGS = -n$(1) +fate-ifft-fixed32-$(1): ARGS = -n$(1) -i +#fate-mdct-fixed32-$(1): ARGS = -n$(1) -m +fate-imdct-fixed32-$(1): ARGS = -n$(1) -m -i +endef + +$(foreach N, 4 5 6 7 8 9 10 11 12, $(eval $(call DEF_FFT_FIXED32,$(N)))) + +fate-fft-fixed32-test: $(FATE_FFT_FIXED32) +$(FATE_FFT_FIXED32): libavcodec/fft-fixed32-test$(EXESUF) +$(FATE_FFT_FIXED32): CMD = run libavcodec/fft-fixed32-test $(CPUFLAGS:%=-c%) $(ARGS) +$(FATE_FFT_FIXED32): REF = /dev/null + +FATE-$(call ALLYES, AVCODEC FFT) += $(FATE_FFT) $(FATE_FFT_FIXED) $(FATE_FFT_FIXED32) +fate-fft: $(FATE_FFT) $(FATE_FFT_FIXED) $(FATE_FFT_FIXED32) -- 1.7.3.4
Hello, Has anybody looked at this implementation? Can it be integrated in FFmpeg or should we make some additonal changes? Thanks, - Nedeljko
From: Nedeljko Babic <nbabic@mips.com> Signed-off-by: Nedeljko Babic <nbabic@mips.com> --- libavcodec/Makefile | 3 +- libavcodec/ac3.h | 62 +++++++++++-- libavcodec/ac3dec.c | 225 +++++++++++++++++++++++++++------------------ libavcodec/ac3dec.h | 39 +++++---- libavcodec/ac3dec_fixed.c | 155 +++++++++++++++++++++++++++++++ libavcodec/ac3dec_float.c | 89 ++++++++++++++++++ libavcodec/ac3dsp.c | 26 +++++ libavcodec/ac3dsp.h | 2 + libavcodec/allcodecs.c | 1 + libavcodec/kbdwin.c | 23 +++++ libavcodec/kbdwin.h | 1 + libavutil/Makefile | 1 + libavutil/fixed_dsp.c | 74 +++++++++++++++ libavutil/fixed_dsp.h | 108 ++++++++++++++++++++++ 14 files changed, 691 insertions(+), 118 deletions(-) create mode 100644 libavcodec/ac3dec_fixed.c create mode 100644 libavcodec/ac3dec_float.c create mode 100644 libavutil/fixed_dsp.c create mode 100644 libavutil/fixed_dsp.h diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 0c1b370..78fcf66 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -88,7 +88,8 @@ OBJS-$(CONFIG_AAC_ENCODER) += aacenc.o aaccoder.o \ psymodel.o iirfilter.o \ mpeg4audio.o kbdwin.o OBJS-$(CONFIG_AASC_DECODER) += aasc.o msrledec.o -OBJS-$(CONFIG_AC3_DECODER) += ac3dec.o ac3dec_data.o ac3.o kbdwin.o +OBJS-$(CONFIG_AC3_DECODER) += ac3dec_float.o ac3dec_data.o ac3.o kbdwin.o +OBJS-$(CONFIG_AC3FIXED_DECODER) += ac3dec_fixed.o ac3dec_data.o ac3.o kbdwin.o OBJS-$(CONFIG_AC3_ENCODER) += ac3enc_float.o ac3enc.o ac3tab.o \ ac3.o kbdwin.o OBJS-$(CONFIG_AC3_FIXED_ENCODER) += ac3enc_fixed.o ac3enc.o ac3tab.o ac3.o diff --git a/libavcodec/ac3.h b/libavcodec/ac3.h index e609bb5..adf68a3 100644 --- a/libavcodec/ac3.h +++ b/libavcodec/ac3.h @@ -51,16 +51,60 @@ #define EXP_D25 2 #define EXP_D45 3 +#ifndef CONFIG_AC3_FIXED +#define CONFIG_AC3_FIXED 0 +#endif + +#if CONFIG_AC3_FIXED + +#define CONFIG_FFT_FLOAT 0 + +#define FIXR(a) ((int)((a) * 0 + 0.5)) +#define FIXR12(a) ((int)((a) * 4096 + 0.5)) +#define FIXR15(a) ((int)((a) * 32768 + 0.5)) +#define ROUND15(x) ((x) + 16384) >> 15 + +#define AC3_RENAME(x) x ## _fixed +#define AC3_NORM(norm) (1<<24)/(norm) +#define AC3_MUL(a,b) ((((int64_t) (a)) * (b))>>12) +#define AC3_DYNAMIC_RANGE(x) (x) +#define AC3_SPX_BLEND(x) (x) +#define AC3_DYNAMIC_RANGE1 0 + +#define INTFLOAT int +#define SHORTFLOAT int16_t + +#else /* CONFIG_AC3_FIXED */ + +#define FIXR(x) ((float)(x)) +#define FIXR12(x) ((float)(x)) +#define FIXR15(x) ((float)(x)) +#define ROUND15(x) (x) + +#define AC3_RENAME(x) x +#define AC3_NORM(norm) (1.0f/(norm)) +#define AC3_MUL(a,b) ((a) * (b)) +#define AC3_DYNAMIC_RANGE(x) ((dynamic_range_tab[x] - 1.0) * s->drc_scale) + 1.0 +#define AC3_SPX_BLEND(x) (x)* (1.0f/32) +#define AC3_DYNAMIC_RANGE1 1.0f + +#define INTFLOAT float +#define SHORTFLOAT float + +#endif /* CONFIG_AC3_FIXED */ + +#define AC3_LEVEL(x) ROUND15((x) * FIXR15(0.7071067811865476)) + /* pre-defined gain values */ -#define LEVEL_PLUS_3DB 1.4142135623730950 -#define LEVEL_PLUS_1POINT5DB 1.1892071150027209 -#define LEVEL_MINUS_1POINT5DB 0.8408964152537145 -#define LEVEL_MINUS_3DB 0.7071067811865476 -#define LEVEL_MINUS_4POINT5DB 0.5946035575013605 -#define LEVEL_MINUS_6DB 0.5000000000000000 -#define LEVEL_MINUS_9DB 0.3535533905932738 -#define LEVEL_ZERO 0.0000000000000000 -#define LEVEL_ONE 1.0000000000000000 +#define LEVEL_PLUS_3DB FIXR12(1.4142135623730950) +#define LEVEL_PLUS_1POINT5DB FIXR12(1.1892071150027209) +#define LEVEL_MINUS_1POINT5DB FIXR12(0.8408964152537145) +#define LEVEL_MINUS_3DB FIXR12(0.7071067811865476) +#define LEVEL_MINUS_4POINT5DB FIXR12(0.5946035575013605) +#define LEVEL_MINUS_6DB FIXR12(0.5000000000000000) +#define LEVEL_MINUS_9DB FIXR12(0.3535533905932738) +#define LEVEL_ZERO FIXR12(0.0000000000000000) +#define LEVEL_ONE FIXR12(1.0000000000000000) /** Delta bit allocation strategy */ typedef enum { diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index a70d92a..2089856 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -64,7 +64,7 @@ static const uint8_t quantization_tab[16] = { static float dynamic_range_tab[256]; /** Adjustments in dB gain */ -static const float gain_levels[9] = { +static const INTFLOAT AC3_RENAME(gain_levels)[9] = { LEVEL_PLUS_3DB, LEVEL_PLUS_1POINT5DB, LEVEL_ONE, @@ -168,14 +168,22 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx) ac3_tables_init(); ff_mdct_init(&s->imdct_256, 8, 1, 1.0); ff_mdct_init(&s->imdct_512, 9, 1, 1.0); - ff_kbd_window_init(s->window, 5.0, 256); + AC3_RENAME(ff_kbd_window_init)(s->window, 5.0, 256); ff_dsputil_init(&s->dsp, avctx); +#if CONFIG_AC3_FIXED + avpriv_fixed_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); +#else avpriv_float_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); +#endif ff_ac3dsp_init(&s->ac3dsp, avctx->flags & CODEC_FLAG_BITEXACT); ff_fmt_convert_init(&s->fmt_conv, avctx); av_lfg_init(&s->dith_state, 0); +#if CONFIG_AC3_FIXED + avctx->sample_fmt = AV_SAMPLE_FMT_S16P; +#else avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; +#endif /* allow downmixing to stereo or mono */ if (avctx->channels > 0 && avctx->request_channels > 0 && @@ -301,20 +309,20 @@ static int parse_frame_header(AC3DecodeContext *s) static void set_downmix_coeffs(AC3DecodeContext *s) { int i; - float cmix = gain_levels[s-> center_mix_level]; - float smix = gain_levels[s->surround_mix_level]; - float norm0, norm1; + SHORTFLOAT cmix = AC3_RENAME(gain_levels)[s-> center_mix_level]; + SHORTFLOAT smix = AC3_RENAME(gain_levels)[s->surround_mix_level]; + INTFLOAT norm0, norm1; for (i = 0; i < s->fbw_channels; i++) { - s->downmix_coeffs[i][0] = gain_levels[ac3_default_coeffs[s->channel_mode][i][0]]; - s->downmix_coeffs[i][1] = gain_levels[ac3_default_coeffs[s->channel_mode][i][1]]; + s->downmix_coeffs[i][0] = AC3_RENAME(gain_levels)[ac3_default_coeffs[s->channel_mode][i][0]]; + s->downmix_coeffs[i][1] = AC3_RENAME(gain_levels)[ac3_default_coeffs[s->channel_mode][i][1]]; } if (s->channel_mode > 1 && s->channel_mode & 1) { s->downmix_coeffs[1][0] = s->downmix_coeffs[1][1] = cmix; } if (s->channel_mode == AC3_CHMODE_2F1R || s->channel_mode == AC3_CHMODE_3F1R) { int nf = s->channel_mode - 2; - s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf][1] = smix * LEVEL_MINUS_3DB; + s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf][1] = AC3_LEVEL(smix); } if (s->channel_mode == AC3_CHMODE_2F2R || s->channel_mode == AC3_CHMODE_3F2R) { int nf = s->channel_mode - 4; @@ -322,22 +330,23 @@ static void set_downmix_coeffs(AC3DecodeContext *s) } /* renormalize */ - norm0 = norm1 = 0.0; + norm0 = norm1 = FIXR(0.0); for (i = 0; i < s->fbw_channels; i++) { norm0 += s->downmix_coeffs[i][0]; norm1 += s->downmix_coeffs[i][1]; } - norm0 = 1.0f / norm0; - norm1 = 1.0f / norm1; + + norm0 = AC3_NORM(norm0); + norm1 = AC3_NORM(norm1); + for (i = 0; i < s->fbw_channels; i++) { - s->downmix_coeffs[i][0] *= norm0; - s->downmix_coeffs[i][1] *= norm1; + s->downmix_coeffs[i][0] = (SHORTFLOAT)AC3_MUL(s->downmix_coeffs[i][0],norm0); + s->downmix_coeffs[i][1] = (SHORTFLOAT)AC3_MUL(s->downmix_coeffs[i][1],norm1); } if (s->output_mode == AC3_CHMODE_MONO) { for (i = 0; i < s->fbw_channels; i++) - s->downmix_coeffs[i][0] = (s->downmix_coeffs[i][0] + - s->downmix_coeffs[i][1]) * LEVEL_MINUS_3DB; + s->downmix_coeffs[i][0] = AC3_LEVEL(s->downmix_coeffs[i][0] + s->downmix_coeffs[i][1]); } } @@ -601,25 +610,66 @@ static inline void do_imdct(AC3DecodeContext *s, int channels) for (ch = 1; ch <= channels; ch++) { if (s->block_switch[ch]) { int i; - float *x = s->tmp_output + 128; + FFTSample *x = s->tmp_output + 128; for (i = 0; i < 128; i++) x[i] = s->transform_coeffs[ch][2 * i]; s->imdct_256.imdct_half(&s->imdct_256, s->tmp_output, x); +#if CONFIG_AC3_FIXED + s->fdsp.vector_fmul_window_fixed(s->outptr[ch - 1], s->delay[ch - 1], + s->tmp_output, s->window, 128, 8); +#else s->fdsp.vector_fmul_window(s->outptr[ch - 1], s->delay[ch - 1], s->tmp_output, s->window, 128); +#endif for (i = 0; i < 128; i++) x[i] = s->transform_coeffs[ch][2 * i + 1]; s->imdct_256.imdct_half(&s->imdct_256, s->delay[ch - 1], x); } else { s->imdct_512.imdct_half(&s->imdct_512, s->tmp_output, s->transform_coeffs[ch]); +#if CONFIG_AC3_FIXED + s->fdsp.vector_fmul_window_fixed(s->outptr[ch - 1], s->delay[ch - 1], + s->tmp_output, s->window, 128, 8); +#else s->fdsp.vector_fmul_window(s->outptr[ch - 1], s->delay[ch - 1], s->tmp_output, s->window, 128); - memcpy(s->delay[ch - 1], s->tmp_output + 128, 128 * sizeof(float)); +#endif + memcpy(s->delay[ch - 1], s->tmp_output + 128, 128 * sizeof(FFTSample)); } } } /** + * Downmix samples from original signal to stereo or mono (this is for 16-bit samples + * and fixed point decoder - original (for 32-bit samples) is in ac3dsp.c). + */ +#if CONFIG_AC3_FIXED +static void ac3_downmix_c_fixed16(int16_t **samples, int16_t (*matrix)[2], + int out_ch, int in_ch, int len) +{ + int i, j; + int v0, v1; + if (out_ch == 2) { + for (i = 0; i < len; i++) { + v0 = v1 = 0; + for (j = 0; j < in_ch; j++) { + v0 += samples[j][i] * matrix[j][0]; + v1 += samples[j][i] * matrix[j][1]; + } + samples[0][i] = (v0+2048)>>12; + samples[1][i] = (v1+2048)>>12; + } + } else if (out_ch == 1) { + for (i = 0; i < len; i++) { + v0 = 0; + for (j = 0; j < in_ch; j++) + v0 += samples[j][i] * matrix[j][0]; + samples[0][i] = (v0+2048)>>12; + } + } +} +#endif + +/** * Upmix delay samples from stereo to original channel layout. */ static void ac3_upmix_delay(AC3DecodeContext *s) @@ -747,10 +797,9 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) i = !s->channel_mode; do { if (get_bits1(gbc)) { - s->dynamic_range[i] = ((dynamic_range_tab[get_bits(gbc, 8)] - 1.0) * - s->drc_scale) + 1.0; + s->dynamic_range[i] = AC3_DYNAMIC_RANGE(get_bits(gbc, 8)); } else if (blk == 0) { - s->dynamic_range[i] = 1.0f; + s->dynamic_range[i] = AC3_DYNAMIC_RANGE1; } } while (i--); @@ -776,6 +825,10 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) if (start_subband > 7) start_subband += start_subband - 7; end_subband = get_bits(gbc, 3) + 5; +#if CONFIG_AC3_FIXED + s->spx_dst_end_freq = end_freq_inv_tab[end_subband]; + end_subband += 5; +#endif if (end_subband > 7) end_subband += end_subband - 7; dst_start_freq = dst_start_freq * 12 + 25; @@ -796,7 +849,9 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) s->spx_dst_start_freq = dst_start_freq; s->spx_src_start_freq = src_start_freq; +#if !CONFIG_AC3_FIXED s->spx_dst_end_freq = dst_end_freq; +#endif decode_band_structure(gbc, blk, s->eac3, 0, start_subband, end_subband, @@ -816,18 +871,40 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) for (ch = 1; ch <= fbw_channels; ch++) { if (s->channel_uses_spx[ch]) { if (s->first_spx_coords[ch] || get_bits1(gbc)) { - float spx_blend; + INTFLOAT spx_blend; int bin, master_spx_coord; s->first_spx_coords[ch] = 0; - spx_blend = get_bits(gbc, 5) * (1.0f/32); + spx_blend = AC3_SPX_BLEND(get_bits(gbc, 5)); master_spx_coord = get_bits(gbc, 2) * 3; bin = s->spx_src_start_freq; for (bnd = 0; bnd < s->num_spx_bands; bnd++) { int bandsize; int spx_coord_exp, spx_coord_mant; - float nratio, sblend, nblend, spx_coord; + INTFLOAT nratio, sblend, nblend; +#if CONFIG_AC3_FIXED + int64_t accu; + /* calculate blending factors */ + bandsize = s->spx_band_sizes[bnd]; + accu = (int64_t)((bin << 23) + (bandsize << 22)) * s->spx_dst_end_freq; + nratio = (int)(accu >> 32); + nratio -= spx_blend << 18; + + if (nratio < 0) { + nblend = 0; + sblend = 0x800000; + } else if (nratio > 0x7fffff) { + nblend = 0x800000; + sblend = 0; + } else { + nblend = fp12_fixed_sqrt(nratio); + accu = (int64_t)nblend * 1859775393; + nblend = (int)((accu + (1<<29)) >> 30); + sblend = fp12_fixed_sqrt(0x800000 - nratio); + } +#else + float spx_coord; /* calculate blending factors */ bandsize = s->spx_band_sizes[bnd]; @@ -836,6 +913,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) nblend = sqrtf(3.0f * nratio); // noise is scaled by sqrt(3) // to give unity variance sblend = sqrtf(1.0f - nratio); +#endif bin += bandsize; /* decode spx coordinates */ @@ -844,11 +922,18 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) if (spx_coord_exp == 15) spx_coord_mant <<= 1; else spx_coord_mant += 4; spx_coord_mant <<= (25 - spx_coord_exp - master_spx_coord); - spx_coord = spx_coord_mant * (1.0f / (1 << 23)); /* multiply noise and signal blending factors by spx coordinate */ +#if CONFIG_AC3_FIXED + accu = (int64_t)nblend * spx_coord_mant; + s->spx_noise_blend[ch][bnd] = (int)((accu + (1<<22)) >> 23); + accu = (int64_t)sblend * spx_coord_mant; + s->spx_signal_blend[ch][bnd] = (int)((accu + (1<<22)) >> 23); +#else + spx_coord = spx_coord_mant * (1.0f / (1 << 23)); s->spx_noise_blend [ch][bnd] = nblend * spx_coord; s->spx_signal_blend[ch][bnd] = sblend * spx_coord; +#endif } } } else { @@ -1203,6 +1288,17 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) if (s->channel_mode == AC3_CHMODE_STEREO) do_rematrixing(s); +#if CONFIG_AC3_FIXED + for (ch = 1; ch <= s->channels; ch++) { + int gain; + if(s->channel_mode == AC3_CHMODE_DUALMONO) { + gain = s->dynamic_range[2-ch]; + } else { + gain = s->dynamic_range[0]; + } + scale_coefs(s->transform_coeffs[ch], s->fixed_coeffs[ch], gain, 256); + } +#else /* apply scaling to coefficients (headroom, dynrng) */ for (ch = 1; ch <= s->channels; ch++) { float gain = 1.0 / 4194304.0f; @@ -1214,6 +1310,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) s->fmt_conv.int32_to_float_fmul_scalar(s->transform_coeffs[ch], s->fixed_coeffs[ch], gain, 256); } +#endif /* apply spectral extension to high frequency bins */ if (s->spx_in_use && CONFIG_EAC3_DECODER) { @@ -1235,23 +1332,26 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) } do_imdct(s, s->channels); - if (downmix_output) { +#if CONFIG_AC3_FIXED + ac3_downmix_c_fixed16(s->outptr, s->downmix_coeffs, + s->out_channels, s->fbw_channels, 256); +#else s->ac3dsp.downmix(s->outptr, s->downmix_coeffs, s->out_channels, s->fbw_channels, 256); +#endif } } else { if (downmix_output) { - s->ac3dsp.downmix(s->xcfptr + 1, s->downmix_coeffs, + s->ac3dsp.AC3_RENAME(downmix)(s->xcfptr + 1, s->downmix_coeffs, s->out_channels, s->fbw_channels, 256); } if (downmix_output && !s->downmixed) { s->downmixed = 1; - s->ac3dsp.downmix(s->dlyptr, s->downmix_coeffs, s->out_channels, + s->ac3dsp.AC3_RENAME(downmix)(s->dlyptr, s->downmix_coeffs, s->out_channels, s->fbw_channels, 128); } - do_imdct(s, s->out_channels); } @@ -1270,7 +1370,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, AC3DecodeContext *s = avctx->priv_data; int blk, ch, err, ret; const uint8_t *channel_map; - const float *output[AC3_MAX_CHANNELS]; + const SHORTFLOAT *output[AC3_MAX_CHANNELS]; /* copy input buffer to decoder context to avoid reading past the end of the buffer, which can be caused by a damaged input stream. */ @@ -1353,8 +1453,8 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, avctx->channels = s->out_channels; avctx->channel_layout = s->channel_layout; - s->loro_center_mix_level = gain_levels[s-> center_mix_level]; - s->loro_surround_mix_level = gain_levels[s->surround_mix_level]; + s->loro_center_mix_level = AC3_RENAME(gain_levels)[s-> center_mix_level]; + s->loro_surround_mix_level = AC3_RENAME(gain_levels)[s->surround_mix_level]; s->ltrt_center_mix_level = LEVEL_MINUS_3DB; s->ltrt_surround_mix_level = LEVEL_MINUS_3DB; /* set downmixing coefficients if needed */ @@ -1386,7 +1486,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, } for (ch = 0; ch < s->channels; ch++) { if (ch < s->out_channels) - s->outptr[channel_map[ch]] = (float *)frame->data[ch]; + s->outptr[channel_map[ch]] = (SHORTFLOAT *)frame->data[ch]; } for (blk = 0; blk < s->num_blocks; blk++) { if (!err && decode_audio_block(s, blk)) { @@ -1395,7 +1495,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, } if (err) for (ch = 0; ch < s->out_channels; ch++) - memcpy(((float*)frame->data[ch]) + AC3_BLOCK_SIZE*blk, output[ch], 1024); + memcpy(((SHORTFLOAT*)frame->data[ch]) + AC3_BLOCK_SIZE*blk, output[ch], AC3_BLOCK_SIZE*sizeof(SHORTFLOAT)); for (ch = 0; ch < s->out_channels; ch++) output[ch] = s->outptr[channel_map[ch]]; for (ch = 0; ch < s->out_channels; ch++) { @@ -1408,7 +1508,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, /* keep last block for error concealment in next frame */ for (ch = 0; ch < s->out_channels; ch++) - memcpy(s->output[ch], output[ch], 1024); + memcpy(s->output[ch], output[ch], AC3_BLOCK_SIZE*sizeof(SHORTFLOAT)); *got_frame_ptr = 1; @@ -1429,60 +1529,3 @@ static av_cold int ac3_decode_end(AVCodecContext *avctx) #define OFFSET(x) offsetof(AC3DecodeContext, x) #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM) -static const AVOption options[] = { - { "drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 1.0, PAR }, - -{"dmix_mode", "Preferred Stereo Downmix Mode", OFFSET(preferred_stereo_downmix), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 2, 0, "dmix_mode"}, -{"ltrt_cmixlev", "Lt/Rt Center Mix Level", OFFSET(ltrt_center_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, -{"ltrt_surmixlev", "Lt/Rt Surround Mix Level", OFFSET(ltrt_surround_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, -{"loro_cmixlev", "Lo/Ro Center Mix Level", OFFSET(loro_center_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, -{"loro_surmixlev", "Lo/Ro Surround Mix Level", OFFSET(loro_surround_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, - - { NULL}, -}; - -static const AVClass ac3_decoder_class = { - .class_name = "AC3 decoder", - .item_name = av_default_item_name, - .option = options, - .version = LIBAVUTIL_VERSION_INT, -}; - -AVCodec ff_ac3_decoder = { - .name = "ac3", - .type = AVMEDIA_TYPE_AUDIO, - .id = AV_CODEC_ID_AC3, - .priv_data_size = sizeof (AC3DecodeContext), - .init = ac3_decode_init, - .close = ac3_decode_end, - .decode = ac3_decode_frame, - .capabilities = CODEC_CAP_DR1, - .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"), - .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, - AV_SAMPLE_FMT_NONE }, - .priv_class = &ac3_decoder_class, -}; - -#if CONFIG_EAC3_DECODER -static const AVClass eac3_decoder_class = { - .class_name = "E-AC3 decoder", - .item_name = av_default_item_name, - .option = options, - .version = LIBAVUTIL_VERSION_INT, -}; - -AVCodec ff_eac3_decoder = { - .name = "eac3", - .type = AVMEDIA_TYPE_AUDIO, - .id = AV_CODEC_ID_EAC3, - .priv_data_size = sizeof (AC3DecodeContext), - .init = ac3_decode_init, - .close = ac3_decode_end, - .decode = ac3_decode_frame, - .capabilities = CODEC_CAP_DR1, - .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52B (AC-3, E-AC-3)"), - .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, - AV_SAMPLE_FMT_NONE }, - .priv_class = &eac3_decoder_class, -}; -#endif diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h index 6c99ef6..e6a2e62 100644 --- a/libavcodec/ac3dec.h +++ b/libavcodec/ac3dec.h @@ -51,6 +51,7 @@ #define AVCODEC_AC3DEC_H #include "libavutil/float_dsp.h" +#include "libavutil/fixed_dsp.h" #include "libavutil/lfg.h" #include "ac3.h" #include "ac3dsp.h" @@ -90,10 +91,10 @@ typedef struct AC3DecodeContext { ///@} int preferred_stereo_downmix; - float ltrt_center_mix_level; - float ltrt_surround_mix_level; - float loro_center_mix_level; - float loro_surround_mix_level; + SHORTFLOAT ltrt_center_mix_level; + SHORTFLOAT ltrt_surround_mix_level; + SHORTFLOAT loro_center_mix_level; + SHORTFLOAT loro_surround_mix_level; ///@name Frame syntax parameters int snr_offset_strategy; ///< SNR offset strategy (snroffststr) @@ -130,8 +131,8 @@ typedef struct AC3DecodeContext { int num_spx_bands; ///< number of spx bands (nspxbnds) uint8_t spx_band_sizes[SPX_MAX_BANDS]; ///< number of bins in each spx band uint8_t first_spx_coords[AC3_MAX_CHANNELS]; ///< first spx coordinates states (firstspxcos) - float spx_noise_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS]; ///< spx noise blending factor (nblendfact) - float spx_signal_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS];///< spx signal blending factor (sblendfact) + INTFLOAT spx_noise_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS]; ///< spx noise blending factor (nblendfact) + INTFLOAT spx_signal_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS];///< spx signal blending factor (sblendfact) ///@} ///@name Adaptive hybrid transform @@ -143,15 +144,15 @@ typedef struct AC3DecodeContext { int fbw_channels; ///< number of full-bandwidth channels int channels; ///< number of total channels int lfe_ch; ///< index of LFE channel - float downmix_coeffs[AC3_MAX_CHANNELS][2]; ///< stereo downmix coefficients + SHORTFLOAT downmix_coeffs[AC3_MAX_CHANNELS][2]; ///< stereo downmix coefficients int downmixed; ///< indicates if coeffs are currently downmixed int output_mode; ///< output channel configuration int out_channels; ///< number of output channels ///@} ///@name Dynamic range - float dynamic_range[2]; ///< dynamic range - float drc_scale; ///< percentage of dynamic range compression to be applied + INTFLOAT dynamic_range[2]; ///< dynamic range + INTFLOAT drc_scale; ///< percentage of dynamic range compression to be applied ///@} ///@name Bandwidth @@ -199,22 +200,26 @@ typedef struct AC3DecodeContext { ///@name Optimization DSPContext dsp; ///< for optimization +#if CONFIG_AC3_FIXED + AVFixedDSPContext fdsp; +#else AVFloatDSPContext fdsp; +#endif AC3DSPContext ac3dsp; FmtConvertContext fmt_conv; ///< optimized conversion functions ///@} - float *outptr[AC3_MAX_CHANNELS]; - float *xcfptr[AC3_MAX_CHANNELS]; - float *dlyptr[AC3_MAX_CHANNELS]; + SHORTFLOAT *outptr[AC3_MAX_CHANNELS]; + INTFLOAT *xcfptr[AC3_MAX_CHANNELS]; + INTFLOAT *dlyptr[AC3_MAX_CHANNELS]; ///@name Aligned arrays DECLARE_ALIGNED(16, int, fixed_coeffs)[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< fixed-point transform coefficients - DECLARE_ALIGNED(32, float, transform_coeffs)[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< transform coefficients - DECLARE_ALIGNED(32, float, delay)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< delay - added to the next block - DECLARE_ALIGNED(32, float, window)[AC3_BLOCK_SIZE]; ///< window coefficients - DECLARE_ALIGNED(32, float, tmp_output)[AC3_BLOCK_SIZE]; ///< temporary storage for output before windowing - DECLARE_ALIGNED(32, float, output)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< output after imdct transform and windowing + DECLARE_ALIGNED(32, INTFLOAT, transform_coeffs)[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< transform coefficients + DECLARE_ALIGNED(32, INTFLOAT, delay)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< delay - added to the next block + DECLARE_ALIGNED(32, INTFLOAT, window)[AC3_BLOCK_SIZE]; ///< window coefficients + DECLARE_ALIGNED(32, INTFLOAT, tmp_output)[AC3_BLOCK_SIZE]; ///< temporary storage for output before windowing + DECLARE_ALIGNED(32, SHORTFLOAT, output)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< output after imdct transform and windowing DECLARE_ALIGNED(32, uint8_t, input_buffer)[AC3_FRAME_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; ///< temp buffer to prevent overread ///@} } AC3DecodeContext; diff --git a/libavcodec/ac3dec_fixed.c b/libavcodec/ac3dec_fixed.c new file mode 100644 index 0000000..31fee8c --- /dev/null +++ b/libavcodec/ac3dec_fixed.c @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2012 + * MIPS Technologies, Inc., California. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Author: Stanislav Ocovaj (socovaj@mips.com) + * + * AC3 fixed-point decoder for MIPS platforms + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#define CONFIG_FFT_FLOAT 0 +#define CONFIG_AC3_FIXED 1 +#define CONFIG_FFT_FIXED_32 1 +#include "ac3dec.h" + + +/** + * Table for center mix levels + * reference: Section 5.4.2.4 cmixlev + */ +static const uint8_t center_levels[4] = { 4, 5, 6, 5 }; + +/** + * Table for surround mix levels + * reference: Section 5.4.2.5 surmixlev + */ +static const uint8_t surround_levels[4] = { 4, 6, 7, 6 }; + +int end_freq_inv_tab[8] = +{ + 50529027, 44278013, 39403370, 32292987, 27356480, 23729101, 20951060, 18755316 +}; + +static void scale_coefs ( + int32_t *dst, + const int32_t *src, + int dynrng, + int len) +{ + int i, shift, round; + int16_t mul; + int temp, temp1, temp2, temp3, temp4, temp5, temp6, temp7; + + mul = (dynrng & 0x1f) + 0x20; + shift = 4 - ((dynrng << 24) >> 29); + round = 1 << (shift-1); + for (i=0; i<len; i+=8) { + + temp = src[i] * mul; + temp1 = src[i+1] * mul; + temp = temp + round; + temp2 = src[i+2] * mul; + + temp1 = temp1 + round; + dst[i] = temp >> shift; + temp3 = src[i+3] * mul; + temp2 = temp2 + round; + + dst[i+1] = temp1 >> shift; + temp4 = src[i + 4] * mul; + temp3 = temp3 + round; + dst[i+2] = temp2 >> shift; + + temp5 = src[i+5] * mul; + temp4 = temp4 + round; + dst[i+3] = temp3 >> shift; + temp6 = src[i+6] * mul; + + dst[i+4] = temp4 >> shift; + temp5 = temp5 + round; + temp7 = src[i+7] * mul; + temp6 = temp6 + round; + + dst[i+5] = temp5 >> shift; + temp7 = temp7 + round; + dst[i+6] = temp6 >> shift; + dst[i+7] = temp7 >> shift; + + } +} + +#include "ac3dec.c" + +static const AVOption options[] = { + { "drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, PAR }, + +{"dmix_mode", "Preferred Stereo Downmix Mode", OFFSET(preferred_stereo_downmix), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 2, 0, "dmix_mode"}, +{"ltrt_cmixlev", "Lt/Rt Center Mix Level", OFFSET(ltrt_center_mix_level), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 2, 0}, +{"ltrt_surmixlev", "Lt/Rt Surround Mix Level", OFFSET(ltrt_surround_mix_level), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 2, 0}, +{"loro_cmixlev", "Lo/Ro Center Mix Level", OFFSET(loro_center_mix_level), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 2, 0}, +{"loro_surmixlev", "Lo/Ro Surround Mix Level", OFFSET(loro_surround_mix_level), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 2, 0}, + + { NULL}, +}; + +static const AVClass ac3_decoder_class = { + .class_name = "Fixed-Point AC-3 Decoder", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + +AVCodec ff_ac3fixed_decoder = { + .name = "ac3fixed", + .type = AVMEDIA_TYPE_AUDIO, + .id = CODEC_ID_AC3, + .priv_data_size = sizeof (AC3DecodeContext), + .init = ac3_decode_init, + .close = ac3_decode_end, + .decode = ac3_decode_frame, + .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"), + .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P, + AV_SAMPLE_FMT_NONE }, + .priv_class = &ac3_decoder_class, +}; diff --git a/libavcodec/ac3dec_float.c b/libavcodec/ac3dec_float.c new file mode 100644 index 0000000..227c273 --- /dev/null +++ b/libavcodec/ac3dec_float.c @@ -0,0 +1,89 @@ +/* + * AC-3 Audio Decoder + * This code was developed as part of Google Summer of Code 2006. + * E-AC-3 support was added as part of Google Summer of Code 2007. + * + * Copyright (c) 2006 Kartikey Mahendra BHATT (bhattkm at gmail dot com) + * Copyright (c) 2007-2008 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com> + * Copyright (c) 2007 Justin Ruggles <justin.ruggles@gmail.com> + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * Upmix delay samples from stereo to original channel layout. + */ +#include "ac3dec.h" +#include "ac3dec.c" + +static const AVOption options[] = { + { "drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 1.0, PAR }, + +{"dmix_mode", "Preferred Stereo Downmix Mode", OFFSET(preferred_stereo_downmix), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 2, 0, "dmix_mode"}, +{"ltrt_cmixlev", "Lt/Rt Center Mix Level", OFFSET(ltrt_center_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, +{"ltrt_surmixlev", "Lt/Rt Surround Mix Level", OFFSET(ltrt_surround_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, +{"loro_cmixlev", "Lo/Ro Center Mix Level", OFFSET(loro_center_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, +{"loro_surmixlev", "Lo/Ro Surround Mix Level", OFFSET(loro_surround_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, + + { NULL}, +}; + +static const AVClass ac3_decoder_class = { + .class_name = "AC3 decoder", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + +AVCodec ff_ac3_decoder = { + .name = "ac3", + .type = AVMEDIA_TYPE_AUDIO, + .id = AV_CODEC_ID_AC3, + .priv_data_size = sizeof (AC3DecodeContext), + .init = ac3_decode_init, + .close = ac3_decode_end, + .decode = ac3_decode_frame, + .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"), + .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, + AV_SAMPLE_FMT_NONE }, + .priv_class = &ac3_decoder_class, +}; + +#if CONFIG_EAC3_DECODER +static const AVClass eac3_decoder_class = { + .class_name = "E-AC3 decoder", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + +AVCodec ff_eac3_decoder = { + .name = "eac3", + .type = AVMEDIA_TYPE_AUDIO, + .id = AV_CODEC_ID_EAC3, + .priv_data_size = sizeof (AC3DecodeContext), + .init = ac3_decode_init, + .close = ac3_decode_end, + .decode = ac3_decode_frame, + .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52B (AC-3, E-AC-3)"), + .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, + AV_SAMPLE_FMT_NONE }, + .priv_class = &eac3_decoder_class, +}; +#endif diff --git a/libavcodec/ac3dsp.c b/libavcodec/ac3dsp.c index 6df3a68..7176928 100644 --- a/libavcodec/ac3dsp.c +++ b/libavcodec/ac3dsp.c @@ -239,6 +239,31 @@ static void ac3_downmix_c(float **samples, float (*matrix)[2], } } +static void ac3_downmix_c_fixed(int32_t **samples, int16_t (*matrix)[2], + int out_ch, int in_ch, int len) +{ + int i, j; + int64_t v0, v1; + if (out_ch == 2) { + for (i = 0; i < len; i++) { + v0 = v1 = 0; + for (j = 0; j < in_ch; j++) { + v0 += (int64_t)samples[j][i] * matrix[j][0]; + v1 += (int64_t)samples[j][i] * matrix[j][1]; + } + samples[0][i] = (v0+2048)>>12; + samples[1][i] = (v1+2048)>>12; + } + } else if (out_ch == 1) { + for (i = 0; i < len; i++) { + v0 = 0; + for (j = 0; j < in_ch; j++) + v0 += (int64_t)samples[j][i] * matrix[j][0]; + samples[0][i] = (v0+2048)>>12; + } + } +} + av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact) { c->ac3_exponent_min = ac3_exponent_min_c; @@ -253,6 +278,7 @@ av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact) c->sum_square_butterfly_int32 = ac3_sum_square_butterfly_int32_c; c->sum_square_butterfly_float = ac3_sum_square_butterfly_float_c; c->downmix = ac3_downmix_c; + c->downmix_fixed = ac3_downmix_c_fixed; if (ARCH_ARM) ff_ac3dsp_init_arm(c, bit_exact); diff --git a/libavcodec/ac3dsp.h b/libavcodec/ac3dsp.h index bafbc89..8ec4a69 100644 --- a/libavcodec/ac3dsp.h +++ b/libavcodec/ac3dsp.h @@ -134,6 +134,8 @@ typedef struct AC3DSPContext { void (*downmix)(float **samples, float (*matrix)[2], int out_ch, int in_ch, int len); + void (*downmix_fixed)(int32_t **samples, int16_t (*matrix)[2], int out_ch, + int in_ch, int len); } AC3DSPContext; void ff_ac3dsp_init (AC3DSPContext *c, int bit_exact); diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index b06e9a5..9ff6975 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -310,6 +310,7 @@ void avcodec_register_all(void) REGISTER_DECODER(AAC_LATM, aac_latm); REGISTER_ENCDEC (AC3, ac3); REGISTER_ENCODER(AC3_FIXED, ac3_fixed); + REGISTER_DECODER(AC3FIXED, ac3fixed); REGISTER_ENCDEC (ALAC, alac); REGISTER_DECODER(ALS, als); REGISTER_DECODER(AMRNB, amrnb); diff --git a/libavcodec/kbdwin.c b/libavcodec/kbdwin.c index 5a62e9d..c6cdabc 100644 --- a/libavcodec/kbdwin.c +++ b/libavcodec/kbdwin.c @@ -45,3 +45,26 @@ av_cold void ff_kbd_window_init(float *window, float alpha, int n) for (i = 0; i < n; i++) window[i] = sqrt(local_window[i] / sum); } + +av_cold void ff_kbd_window_init_fixed(int32_t *window, float alpha, int n) +{ + int i, j; + double sum = 0.0, bessel, tmp; + double local_window[FF_KBD_WINDOW_MAX]; + double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n); + + av_assert0(n <= FF_KBD_WINDOW_MAX); + + for (i = 0; i < n; i++) { + tmp = i * (n - i) * alpha2; + bessel = 1.0; + for (j = BESSEL_I0_ITER; j > 0; j--) + bessel = bessel * tmp / (j * j) + 1; + sum += bessel; + local_window[i] = sum; + } + + sum++; + for (i = 0; i < n; i++) + window[i] = (int)floor(2147483648.0 * sqrt(local_window[i] / sum) + 0.5); +} diff --git a/libavcodec/kbdwin.h b/libavcodec/kbdwin.h index 4b93975..2e02e10 100644 --- a/libavcodec/kbdwin.h +++ b/libavcodec/kbdwin.h @@ -31,5 +31,6 @@ * @param n size of half window, max FF_KBD_WINDOW_MAX */ void ff_kbd_window_init(float *window, float alpha, int n); +void ff_kbd_window_init_fixed(int32_t *window, float alpha, int n); #endif /* AVCODEC_KBDWIN_H */ diff --git a/libavutil/Makefile b/libavutil/Makefile index 33f82ed..a6f0053 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -79,6 +79,7 @@ OBJS = adler32.o \ fifo.o \ file.o \ float_dsp.o \ + fixed_dsp.o \ frame.o \ hmac.o \ imgutils.o \ diff --git a/libavutil/fixed_dsp.c b/libavutil/fixed_dsp.c new file mode 100644 index 0000000..bc090a0 --- /dev/null +++ b/libavutil/fixed_dsp.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2012 + * MIPS Technologies, Inc., California. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Author: Nedeljko Babic (nbabic@mips.com) + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "fixed_dsp.h" + +static void vector_fmul_window_fixed_c(int16_t *dst, const int32_t *src0, + const int32_t *src1, const int32_t *win, + int len, uint8_t bits) +{ + int32_t s0, s1, wi, wj, i,j, round; + + dst += len; + win += len; + src0+= len; + round = bits? 1 << (bits-1) : 0; + + for (i=-len, j=len-1; i<0; i++, j--) { + s0 = src0[i]; + s1 = src1[j]; + wi = win[i]; + wj = win[j]; + dst[i] = av_clip_int16_c(((((int64_t)s0*wj - (int64_t)s1*wi + 0x40000000) >> 31) + round) >> bits); + dst[j] = av_clip_int16_c(((((int64_t)s0*wi + (int64_t)s1*wj + 0x40000000) >> 31) + round) >> bits); + } +} + +void avpriv_fixed_dsp_init(AVFixedDSPContext *fdsp, int bit_exact) +{ + fdsp->vector_fmul_window_fixed = vector_fmul_window_fixed_c; +} diff --git a/libavutil/fixed_dsp.h b/libavutil/fixed_dsp.h new file mode 100644 index 0000000..c0e5168 --- /dev/null +++ b/libavutil/fixed_dsp.h @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2012 + * MIPS Technologies, Inc., California. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Author: Nedeljko Babic (nbabic@mips.com) + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVUTIL_FIXED_DSP_H +#define AVUTIL_FIXED_DSP_H + +#include <stdint.h> +#include "attributes.h" +#include "common.h" + +typedef struct AVFixedDSPContext { + /** + * Overlap/add with window function. + * Used primarily by MDCT-based audio codecs. + * Source and destination vectors must overlap exactly or not at all. + * + * @param dst result vector + * constraints: 16-byte aligned + * @param src0 first source vector + * constraints: 16-byte aligned + * @param src1 second source vector + * constraints: 16-byte aligned + * @param win half-window vector + * constraints: 16-byte aligned + * @param len length of vector + * constraints: multiple of 4 + * @param bits scaling parameter + * + */ + void (*vector_fmul_window_fixed)(int16_t *dst, const int32_t *src0, const int32_t *src1, const int32_t *win, int len, uint8_t bits); +} AVFixedDSPContext; + +/** + * Initialize a fixed DSP context. + * + * @param fdsp fixed DSP context + * @param strict setting to non-zero avoids using functions which may not be IEEE-754 compliant + */ +void avpriv_fixed_dsp_init(AVFixedDSPContext *fdsp, int strict); + +static av_always_inline int fp12_fixed_sqrt(int x) +{ + int retval; + int bit_mask; + int guess; + int square; + int i; + int64_t accu; + + retval = 0; + bit_mask = 0x400000; + + for (i=0; i<23; i++){ + guess = retval + bit_mask; + accu = (int64_t)guess * guess; + square = (int)(accu >> 23); + if (x >= square) + retval += bit_mask; + bit_mask >>= 1; + } + return retval; +} + +#endif /* AVUTIL_FIXED_DSP_H */ -- 1.7.3.4
Hello, Has somebody had a time to do a review of these patches? Do we need to make some additinal changes to ac3 implementation? Thanks, - Nedeljko ________________________________________ Od: ffmpeg-devel-bounces@ffmpeg.org [ffmpeg-devel-bounces@ffmpeg.org] u ime korisnika Nedeljko Babic Poslato: 18. april 2013 14:16 Za: ffmpeg-devel@ffmpeg.org Cc: Zeljko Lukac Tema: [FFmpeg-devel] Implementations of fixed point AC3 decoder and 32bit fixed point FFT Hi, Requested changes are made to patch that implements ac3 fixed point decoder and the patch is resubmitted. I am also resubmitting patch with implementation of 32bit fixed point FFT since it is needed for ac3 fixed point decoder to work and it is not reviewed yet. Regards, -Nedeljko _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
participants (1)
-
Nedeljko Babic