[FFmpeg-devel] [PATCH 2/5] libavcodec: Implementation of AC3 fixedpoint decoder

James Almer jamrial at gmail.com
Mon Mar 10 22:50:17 CET 2014


On 10/03/14 9:43 AM, Nedeljko Babic wrote:
> From: Nedeljko Babic <nbabic at mips.com>
> 
> Signed-off-by: Nedeljko Babic <nbabic at mips.com>
> ---
>  Changelog                 |   1 +
>  configure                 |   1 +
>  doc/general.texi          |   2 +-
>  libavcodec/Makefile       |   3 +-
>  libavcodec/ac3.h          |  46 +++++++++++
>  libavcodec/ac3dec.c       | 197 +++++++++++++++++++++++++---------------------
>  libavcodec/ac3dec.h       |  33 ++++----
>  libavcodec/ac3dec_fixed.c | 176 +++++++++++++++++++++++++++++++++++++++++
>  libavcodec/ac3dec_float.c |  89 +++++++++++++++++++++
>  libavcodec/ac3dsp.c       |  26 ++++++
>  libavcodec/ac3dsp.h       |   3 +
>  libavcodec/allcodecs.c    |   1 +
>  libavcodec/kbdwin.c       |  10 +++
>  libavcodec/kbdwin.h       |   1 +
>  libavcodec/version.h      |   2 +-
>  15 files changed, 483 insertions(+), 108 deletions(-)
>  create mode 100644 libavcodec/ac3dec_fixed.c
>  create mode 100644 libavcodec/ac3dec_float.c
> 
> diff --git a/Changelog b/Changelog
> index 7d50591..a4c3566b 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -7,6 +7,7 @@ version <next>
>  
>  version 2.2:
>  
> +- added AC3 fixed-point decoding

This should be under <next>.

[...]

> diff --git a/libavcodec/ac3dec_fixed.c b/libavcodec/ac3dec_fixed.c
> new file mode 100644
> index 0000000..aeb93e1
> --- /dev/null
> +++ b/libavcodec/ac3dec_fixed.c
> @@ -0,0 +1,176 @@
> +/*
> + * 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 at 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 FFT_FLOAT 0
> +#define CONFIG_AC3_FIXED 1
> +#define 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;
> +
> +    }
> +}
> +

I'm fairly certain this function can be optimized with simd. Maybe add it to AC3DSPContext?

> +/**
> + * 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).
> + */
> +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;
> +        }
> +    }
> +}
> +

I'd say the same for this one, but i assume there was a reason you didn't add it alongside 
the 32-bits one.

[...]

> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index 715837e..d93bb42 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -322,6 +322,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);

You could use the same name as the encoder, and REGISTER_ENCDEC()

>      REGISTER_ENCDEC (ALAC,              alac);
>      REGISTER_DECODER(ALS,               als);
>      REGISTER_DECODER(AMRNB,             amrnb);
> diff --git a/libavcodec/kbdwin.c b/libavcodec/kbdwin.c
> index 5a62e9d..bf32aeb 100644
> --- a/libavcodec/kbdwin.c
> +++ b/libavcodec/kbdwin.c
> @@ -45,3 +45,13 @@ 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;
> +    float local_window[FF_KBD_WINDOW_MAX];
> +
> +    ff_kbd_window_init(local_window, alpha, n);
> +    for (i = 0; i < n; i++)
> +        window[i] = (int)floor(2147483647.0 * local_window[i] + 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/libavcodec/version.h b/libavcodec/version.h
> index 61a7968..65124b2 100644
> --- a/libavcodec/version.h
> +++ b/libavcodec/version.h
> @@ -29,7 +29,7 @@
>  #include "libavutil/version.h"
>  
>  #define LIBAVCODEC_VERSION_MAJOR 55
> -#define LIBAVCODEC_VERSION_MINOR  52
> +#define LIBAVCODEC_VERSION_MINOR  53
>  #define LIBAVCODEC_VERSION_MICRO 102
>  
>  #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
> 



More information about the ffmpeg-devel mailing list