提交 0900a85f 编写于 作者: D Diego Biurrun

Remove internal liba52; external lib still works, native decoder coming up.

Originally committed as revision 7933 to svn://svn.ffmpeg.org/ffmpeg/trunk
上级 f70f03f6
...@@ -78,7 +78,6 @@ show_help(){ ...@@ -78,7 +78,6 @@ show_help(){
echo " --enable-x11grab enable X11 grabbing [default=no]" echo " --enable-x11grab enable X11 grabbing [default=no]"
echo " --enable-dc1394 enable IIDC-1394 grabbing using libdc1394" echo " --enable-dc1394 enable IIDC-1394 grabbing using libdc1394"
echo " and libraw1394 [default=no]" echo " and libraw1394 [default=no]"
echo " --enable-a52 enable GPLed liba52 support [default=no]"
echo " --enable-a52bin open liba52.so.0 at runtime [default=no]" echo " --enable-a52bin open liba52.so.0 at runtime [default=no]"
echo " --enable-avisynth allow reading AVISynth script files [default=no]" echo " --enable-avisynth allow reading AVISynth script files [default=no]"
echo " --enable-dts enable GPLed libdts support [default=no]" echo " --enable-dts enable GPLed libdts support [default=no]"
...@@ -486,7 +485,6 @@ CONFIG_LIST=' ...@@ -486,7 +485,6 @@ CONFIG_LIST='
ffserver ffserver
gpl gpl
ipv6 ipv6
liba52
liba52bin liba52bin
libdts libdts
libfaac libfaac
...@@ -576,7 +574,7 @@ zmbv_encoder_deps="zlib" ...@@ -576,7 +574,7 @@ zmbv_encoder_deps="zlib"
aac_decoder_deps="libfaad" aac_decoder_deps="libfaad"
mpeg4aac_decoder_deps="libfaad" mpeg4aac_decoder_deps="libfaad"
ac3_decoder_deps="liba52" ac3_decoder_deps="liba52bin"
amr_nb_decoder_deps_any="amr_nb amr_nb_fixed" amr_nb_decoder_deps_any="amr_nb amr_nb_fixed"
amr_nb_encoder_deps_any="amr_nb amr_nb_fixed" amr_nb_encoder_deps_any="amr_nb amr_nb_fixed"
amr_wb_decoder_deps="amr_wb" amr_wb_decoder_deps="amr_wb"
...@@ -741,7 +739,6 @@ avisynth="no" ...@@ -741,7 +739,6 @@ avisynth="no"
dc1394="no" dc1394="no"
dlfcn_h="no" dlfcn_h="no"
dlopen="no" dlopen="no"
liba52="no"
liba52bin="no" liba52bin="no"
libdts="no" libdts="no"
libfaac="no" libfaac="no"
...@@ -1040,9 +1037,7 @@ for opt do ...@@ -1040,9 +1037,7 @@ for opt do
;; ;;
--disable-zlib) zlib="no" --disable-zlib) zlib="no"
;; ;;
--enable-a52) liba52="yes" --enable-a52bin) liba52bin="yes"
;;
--enable-a52bin) liba52bin="yes"; liba52="yes"
;; ;;
--enable-dts) libdts="yes" --enable-dts) libdts="yes"
;; ;;
...@@ -1261,7 +1256,7 @@ if disabled gpl ; then ...@@ -1261,7 +1256,7 @@ if disabled gpl ; then
enabled_any $@ && die "$name is under GPL and --enable-gpl is not specified." enabled_any $@ && die "$name is under GPL and --enable-gpl is not specified."
} }
die_gpl_disabled "The Postprocessing code" pp die_gpl_disabled "The Postprocessing code" pp
die_gpl_disabled "liba52" liba52 liba52bin die_gpl_disabled "liba52" liba52bin
die_gpl_disabled "libxvidcore" xvid die_gpl_disabled "libxvidcore" xvid
die_gpl_disabled "x264" x264 die_gpl_disabled "x264" x264
die_gpl_disabled "libdts" libdts die_gpl_disabled "libdts" libdts
...@@ -1885,7 +1880,6 @@ if enabled sdl_too_old; then ...@@ -1885,7 +1880,6 @@ if enabled sdl_too_old; then
fi fi
echo "Sun medialib support $mlib" echo "Sun medialib support $mlib"
echo "AVISynth enabled $avisynth" echo "AVISynth enabled $avisynth"
echo "liba52 support $liba52"
echo "liba52 dlopened $liba52bin" echo "liba52 dlopened $liba52bin"
echo "libdts support $libdts" echo "libdts support $libdts"
echo "libfaac enabled $libfaac" echo "libfaac enabled $libfaac"
...@@ -2092,7 +2086,6 @@ if enabled source_path_used; then ...@@ -2092,7 +2086,6 @@ if enabled source_path_used; then
libavcodec/sparc \ libavcodec/sparc \
libavcodec/mlib \ libavcodec/mlib \
libavcodec/ppc \ libavcodec/ppc \
libavcodec/liba52 \
libavcodec/amr \ libavcodec/amr \
libavcodec/amr_float \ libavcodec/amr_float \
libavcodec/amrwb_float \ libavcodec/amrwb_float \
......
...@@ -248,14 +248,7 @@ OBJS-$(CONFIG_ADPCM_YAMAHA_DECODER) += adpcm.o ...@@ -248,14 +248,7 @@ OBJS-$(CONFIG_ADPCM_YAMAHA_DECODER) += adpcm.o
OBJS-$(CONFIG_ADPCM_YAMAHA_ENCODER) += adpcm.o OBJS-$(CONFIG_ADPCM_YAMAHA_ENCODER) += adpcm.o
# external codec libraries # external codec libraries
OBJS-$(CONFIG_LIBA52) += a52dec.o OBJS-$(CONFIG_LIBA52BIN) += a52dec.o
OBJS-$(CONFIG_LIBA52)$(CONFIG_LIBA52BIN) += liba52/bit_allocate.o \
liba52/bitstream.o \
liba52/downmix.o \
liba52/imdct.o \
liba52/parse.o \
liba52/crc.o \
liba52/resample.o
OBJS-$(CONFIG_LIBDTS) += dtsdec.o OBJS-$(CONFIG_LIBDTS) += dtsdec.o
OBJS-$(CONFIG_LIBFAAC) += faac.o OBJS-$(CONFIG_LIBFAAC) += faac.o
OBJS-$(CONFIG_LIBFAAD) += faad.o OBJS-$(CONFIG_LIBFAAD) += faad.o
...@@ -435,7 +428,6 @@ clean:: ...@@ -435,7 +428,6 @@ clean::
ps2/*.o ps2/*~ \ ps2/*.o ps2/*~ \
sh4/*.o sh4/*~ \ sh4/*.o sh4/*~ \
sparc/*.o sparc/*~ \ sparc/*.o sparc/*~ \
liba52/*.o liba52/*~ \
amr_float/*.o \ amr_float/*.o \
apiexample $(TESTS) apiexample $(TESTS)
-$(MAKE) -C amr clean -$(MAKE) -C amr clean
......
...@@ -25,12 +25,9 @@ ...@@ -25,12 +25,9 @@
*/ */
#include "avcodec.h" #include "avcodec.h"
#include "liba52/a52.h" #include <a52dec/a52.h>
#ifdef CONFIG_LIBA52BIN
#include <dlfcn.h> #include <dlfcn.h>
static const char* liba52name = "liba52.so.0"; static const char* liba52name = "liba52.so.0";
#endif
/** /**
* liba52 - Copyright (C) Aaron Holtzman * liba52 - Copyright (C) Aaron Holtzman
...@@ -70,7 +67,6 @@ typedef struct AC3DecodeState { ...@@ -70,7 +67,6 @@ typedef struct AC3DecodeState {
} AC3DecodeState; } AC3DecodeState;
#ifdef CONFIG_LIBA52BIN
static void* dlsymm(void* handle, const char* symbol) static void* dlsymm(void* handle, const char* symbol)
{ {
void* f = dlsym(handle, symbol); void* f = dlsym(handle, symbol);
...@@ -78,13 +74,11 @@ static void* dlsymm(void* handle, const char* symbol) ...@@ -78,13 +74,11 @@ static void* dlsymm(void* handle, const char* symbol)
av_log( NULL, AV_LOG_ERROR, "A52 Decoder - function '%s' can't be resolved\n", symbol); av_log( NULL, AV_LOG_ERROR, "A52 Decoder - function '%s' can't be resolved\n", symbol);
return f; return f;
} }
#endif
static int a52_decode_init(AVCodecContext *avctx) static int a52_decode_init(AVCodecContext *avctx)
{ {
AC3DecodeState *s = avctx->priv_data; AC3DecodeState *s = avctx->priv_data;
#ifdef CONFIG_LIBA52BIN
s->handle = dlopen(liba52name, RTLD_LAZY); s->handle = dlopen(liba52name, RTLD_LAZY);
if (!s->handle) if (!s->handle)
{ {
...@@ -103,16 +97,6 @@ static int a52_decode_init(AVCodecContext *avctx) ...@@ -103,16 +97,6 @@ static int a52_decode_init(AVCodecContext *avctx)
dlclose(s->handle); dlclose(s->handle);
return -1; return -1;
} }
#else
/* static linked version */
s->handle = 0;
s->a52_init = a52_init;
s->a52_samples = a52_samples;
s->a52_syncinfo = a52_syncinfo;
s->a52_frame = a52_frame;
s->a52_block = a52_block;
s->a52_free = a52_free;
#endif
s->state = s->a52_init(0); /* later use CPU flags */ s->state = s->a52_init(0); /* later use CPU flags */
s->samples = s->a52_samples(s->state); s->samples = s->a52_samples(s->state);
s->inbuf_ptr = s->inbuf; s->inbuf_ptr = s->inbuf;
...@@ -242,9 +226,7 @@ static int a52_decode_end(AVCodecContext *avctx) ...@@ -242,9 +226,7 @@ static int a52_decode_end(AVCodecContext *avctx)
{ {
AC3DecodeState *s = avctx->priv_data; AC3DecodeState *s = avctx->priv_data;
s->a52_free(s->state); s->a52_free(s->state);
#ifdef CONFIG_LIBA52BIN
dlclose(s->handle); dlclose(s->handle);
#endif
return 0; return 0;
} }
......
/*
* a52.h
* Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
* Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
*
* This file is part of a52dec, a free ATSC A-52 stream decoder.
* See http://liba52.sourceforge.net/ for updates.
*
* a52dec is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* a52dec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef A52_H
#define A52_H
#include "../avcodec.h"
#undef malloc
#undef free
#undef realloc
#if defined(LIBA52_FIXED)
typedef int32_t sample_t;
typedef int32_t level_t;
#elif defined(LIBA52_DOUBLE)
typedef double sample_t;
typedef double level_t;
#else
typedef float sample_t;
typedef float level_t;
#endif
typedef struct a52_state_s a52_state_t;
#define A52_CHANNEL 0
#define A52_MONO 1
#define A52_STEREO 2
#define A52_3F 3
#define A52_2F1R 4
#define A52_3F1R 5
#define A52_2F2R 6
#define A52_3F2R 7
#define A52_CHANNEL1 8
#define A52_CHANNEL2 9
#define A52_DOLBY 10
#define A52_CHANNEL_MASK 15
#define A52_LFE 16
#define A52_ADJUST_LEVEL 32
a52_state_t * a52_init (uint32_t mm_accel);
sample_t * a52_samples (a52_state_t * state);
int a52_syncinfo (uint8_t * buf, int * flags,
int * sample_rate, int * bit_rate);
int a52_frame (a52_state_t * state, uint8_t * buf, int * flags,
level_t * level, sample_t bias);
void a52_dynrng (a52_state_t * state,
level_t (* call) (level_t, void *), void * data);
int a52_block (a52_state_t * state);
void a52_free (a52_state_t * state);
#endif /* A52_H */
/*
* a52_internal.h
* Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
* Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
*
* This file is part of a52dec, a free ATSC A-52 stream decoder.
* See http://liba52.sourceforge.net/ for updates.
*
* a52dec is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* a52dec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
typedef struct {
uint8_t bai; /* fine SNR offset, fast gain */
uint8_t deltbae; /* delta bit allocation exists */
int8_t deltba[50]; /* per-band delta bit allocation */
} ba_t;
typedef struct {
uint8_t exp[256]; /* decoded channel exponents */
int8_t bap[256]; /* derived channel bit allocation */
} expbap_t;
struct a52_state_s {
uint8_t fscod; /* sample rate */
uint8_t halfrate; /* halfrate factor */
uint8_t acmod; /* coded channels */
uint8_t lfeon; /* coded lfe channel */
level_t clev; /* centre channel mix level */
level_t slev; /* surround channels mix level */
int output; /* type of output */
level_t level; /* output level */
sample_t bias; /* output bias */
int dynrnge; /* apply dynamic range */
level_t dynrng; /* dynamic range */
void * dynrngdata; /* dynamic range callback funtion and data */
level_t (* dynrngcall) (level_t range, void * dynrngdata);
uint8_t chincpl; /* channel coupled */
uint8_t phsflginu; /* phase flags in use (stereo only) */
uint8_t cplstrtmant; /* coupling channel start mantissa */
uint8_t cplendmant; /* coupling channel end mantissa */
uint32_t cplbndstrc; /* coupling band structure */
level_t cplco[5][18]; /* coupling coordinates */
/* derived information */
uint8_t cplstrtbnd; /* coupling start band (for bit allocation) */
uint8_t ncplbnd; /* number of coupling bands */
uint8_t rematflg; /* stereo rematrixing */
uint8_t endmant[5]; /* channel end mantissa */
uint16_t bai; /* bit allocation information */
uint32_t * buffer_start;
uint16_t lfsr_state; /* dither state */
uint32_t bits_left;
uint32_t current_word;
uint8_t csnroffst; /* coarse SNR offset */
ba_t cplba; /* coupling bit allocation parameters */
ba_t ba[5]; /* channel bit allocation parameters */
ba_t lfeba; /* lfe bit allocation parameters */
uint8_t cplfleak; /* coupling fast leak init */
uint8_t cplsleak; /* coupling slow leak init */
expbap_t cpl_expbap;
expbap_t fbw_expbap[5];
expbap_t lfe_expbap;
sample_t * samples;
int downmixed;
};
#define LEVEL_PLUS6DB 2.0
#define LEVEL_PLUS3DB 1.4142135623730951
#define LEVEL_3DB 0.7071067811865476
#define LEVEL_45DB 0.5946035575013605
#define LEVEL_6DB 0.5
#define EXP_REUSE (0)
#define EXP_D15 (1)
#define EXP_D25 (2)
#define EXP_D45 (3)
#define DELTA_BIT_REUSE (0)
#define DELTA_BIT_NEW (1)
#define DELTA_BIT_NONE (2)
#define DELTA_BIT_RESERVED (3)
void a52_bit_allocate (a52_state_t * state, ba_t * ba, int bndstart,
int start, int end, int fastleak, int slowleak,
expbap_t * expbap);
int a52_downmix_init (int input, int flags, level_t * level,
level_t clev, level_t slev);
int a52_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
level_t clev, level_t slev);
void a52_downmix (sample_t * samples, int acmod, int output, sample_t bias,
level_t clev, level_t slev);
void a52_upmix (sample_t * samples, int acmod, int output);
void a52_imdct_init (uint32_t mm_accel);
void a52_imdct_256 (sample_t * data, sample_t * delay, sample_t bias);
void a52_imdct_512 (sample_t * data, sample_t * delay, sample_t bias);
//extern void (* a52_imdct_256) (sample_t data[], sample_t delay[], sample_t bias);
//extern void (* a52_imdct_512) (sample_t data[], sample_t delay[], sample_t bias);
#define ROUND(x) ((int)((x) + ((x) > 0 ? 0.5 : -0.5)))
#ifndef LIBA52_FIXED
typedef sample_t quantizer_t;
#define SAMPLE(x) (x)
#define LEVEL(x) (x)
#define MUL(a,b) ((a) * (b))
#define MUL_L(a,b) ((a) * (b))
#define MUL_C(a,b) ((a) * (b))
#define DIV(a,b) ((a) / (b))
#define BIAS(x) ((x) + bias)
#else /* LIBA52_FIXED */
typedef int16_t quantizer_t;
#define SAMPLE(x) (sample_t)((x) * (1 << 30))
#define LEVEL(x) (level_t)((x) * (1 << 26))
#if 0
#define MUL(a,b) ((int)(((int64_t)(a) * (b) + (1 << 29)) >> 30))
#define MUL_L(a,b) ((int)(((int64_t)(a) * (b) + (1 << 25)) >> 26))
#elif 1
#define MUL(a,b) \
({ int32_t _ta=(a), _tb=(b), _tc; \
_tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)(((_tc >> 14))+ (((_ta >> 16)*(_tb >> 16)) << 2 )); })
#define MUL_L(a,b) \
({ int32_t _ta=(a), _tb=(b), _tc; \
_tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)((_tc >> 10) + (((_ta >> 16)*(_tb >> 16)) << 6)); })
#else
#define MUL(a,b) (((a) >> 15) * ((b) >> 15))
#define MUL_L(a,b) (((a) >> 13) * ((b) >> 13))
#endif
#define MUL_C(a,b) MUL_L (a, LEVEL (b))
#define DIV(a,b) ((((int64_t)LEVEL (a)) << 26) / (b))
#define BIAS(x) (x)
#endif
/*
* a52_util.h
* Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
* Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
*
* This file is part of a52dec, a free ATSC A-52 stream decoder.
* See http://liba52.sourceforge.net/ for updates.
*
* a52dec is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* a52dec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef A52_UTIL_H
#define A52_UTIL_H
uint16_t a52_crc16_block(uint8_t *data,uint32_t num_bytes);
void* a52_resample_init(uint32_t mm_accel,int flags,int chans);
extern int (* a52_resample) (float * _f, int16_t * s16);
#endif /* A52_H */
/*
* bit_allocate.c
* Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
* Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
*
* This file is part of a52dec, a free ATSC A-52 stream decoder.
* See http://liba52.sourceforge.net/ for updates.
*
* a52dec is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* a52dec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "a52.h"
#include "a52_internal.h"
static int hthtab[3][50] = {
{0x730, 0x730, 0x7c0, 0x800, 0x820, 0x840, 0x850, 0x850, 0x860, 0x860,
0x860, 0x860, 0x860, 0x870, 0x870, 0x870, 0x880, 0x880, 0x890, 0x890,
0x8a0, 0x8a0, 0x8b0, 0x8b0, 0x8c0, 0x8c0, 0x8d0, 0x8e0, 0x8f0, 0x900,
0x910, 0x910, 0x910, 0x910, 0x900, 0x8f0, 0x8c0, 0x870, 0x820, 0x7e0,
0x7a0, 0x770, 0x760, 0x7a0, 0x7c0, 0x7c0, 0x6e0, 0x400, 0x3c0, 0x3c0},
{0x710, 0x710, 0x7a0, 0x7f0, 0x820, 0x830, 0x840, 0x850, 0x850, 0x860,
0x860, 0x860, 0x860, 0x860, 0x870, 0x870, 0x870, 0x880, 0x880, 0x880,
0x890, 0x890, 0x8a0, 0x8a0, 0x8b0, 0x8b0, 0x8c0, 0x8c0, 0x8e0, 0x8f0,
0x900, 0x910, 0x910, 0x910, 0x910, 0x900, 0x8e0, 0x8b0, 0x870, 0x820,
0x7e0, 0x7b0, 0x760, 0x770, 0x7a0, 0x7c0, 0x780, 0x5d0, 0x3c0, 0x3c0},
{0x680, 0x680, 0x750, 0x7b0, 0x7e0, 0x810, 0x820, 0x830, 0x840, 0x850,
0x850, 0x850, 0x860, 0x860, 0x860, 0x860, 0x860, 0x860, 0x860, 0x860,
0x870, 0x870, 0x870, 0x870, 0x880, 0x880, 0x880, 0x890, 0x8a0, 0x8b0,
0x8c0, 0x8d0, 0x8e0, 0x8f0, 0x900, 0x910, 0x910, 0x910, 0x900, 0x8f0,
0x8d0, 0x8b0, 0x840, 0x7f0, 0x790, 0x760, 0x7a0, 0x7c0, 0x7b0, 0x720}
};
static int8_t baptab[305] = {
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, /* 93 padding elems */
16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 14, 14, 14, 14, 14, 14,
14, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9,
9, 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5,
5, 4, 4, -3, -3, 3, 3, 3, -2, -2, -1, -1, -1, -1, -1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0 /* 148 padding elems */
};
static int bndtab[30] = {21, 22, 23, 24, 25, 26, 27, 28, 31, 34,
37, 40, 43, 46, 49, 55, 61, 67, 73, 79,
85, 97, 109, 121, 133, 157, 181, 205, 229, 253};
static int8_t latab[256] = {
-64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54, -53,
-52, -52, -51, -50, -49, -48, -47, -47, -46, -45, -44, -44,
-43, -42, -41, -41, -40, -39, -38, -38, -37, -36, -36, -35,
-35, -34, -33, -33, -32, -32, -31, -30, -30, -29, -29, -28,
-28, -27, -27, -26, -26, -25, -25, -24, -24, -23, -23, -22,
-22, -21, -21, -21, -20, -20, -19, -19, -19, -18, -18, -18,
-17, -17, -17, -16, -16, -16, -15, -15, -15, -14, -14, -14,
-13, -13, -13, -13, -12, -12, -12, -12, -11, -11, -11, -11,
-10, -10, -10, -10, -10, -9, -9, -9, -9, -9, -8, -8,
-8, -8, -8, -8, -7, -7, -7, -7, -7, -7, -6, -6,
-6, -6, -6, -6, -6, -6, -5, -5, -5, -5, -5, -5,
-5, -5, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
-4, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3,
-3, -3, -3, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0
};
#define UPDATE_LEAK() \
do { \
fastleak += fdecay; \
if (fastleak > psd + fgain) \
fastleak = psd + fgain; \
slowleak += sdecay; \
if (slowleak > psd + sgain) \
slowleak = psd + sgain; \
} while (0)
#define COMPUTE_MASK() \
do { \
if (psd > dbknee) \
mask -= (psd - dbknee) >> 2; \
if (mask > hth [i >> halfrate]) \
mask = hth [i >> halfrate]; \
mask -= snroffset + 128 * deltba[i]; \
mask = (mask > 0) ? 0 : ((-mask) >> 5); \
mask -= floor; \
} while (0)
void a52_bit_allocate (a52_state_t * state, ba_t * ba, int bndstart,
int start, int end, int fastleak, int slowleak,
expbap_t * expbap)
{
static int slowgain[4] = {0x540, 0x4d8, 0x478, 0x410};
static int dbpbtab[4] = {0xc00, 0x500, 0x300, 0x100};
static int floortab[8] = {0x910, 0x950, 0x990, 0x9d0,
0xa10, 0xa90, 0xb10, 0x1400};
int i, j;
uint8_t * exp;
int8_t * bap;
int fdecay, fgain, sdecay, sgain, dbknee, floor, snroffset;
int psd, mask;
int8_t * deltba;
int * hth;
int halfrate;
halfrate = state->halfrate;
fdecay = (63 + 20 * ((state->bai >> 7) & 3)) >> halfrate; /* fdcycod */
fgain = 128 + 128 * (ba->bai & 7); /* fgaincod */
sdecay = (15 + 2 * (state->bai >> 9)) >> halfrate; /* sdcycod */
sgain = slowgain[(state->bai >> 5) & 3]; /* sgaincod */
dbknee = dbpbtab[(state->bai >> 3) & 3]; /* dbpbcod */
hth = hthtab[state->fscod];
/*
* if there is no delta bit allocation, make deltba point to an area
* known to contain zeroes. baptab+156 here.
*/
deltba = (ba->deltbae == DELTA_BIT_NONE) ? baptab + 156 : ba->deltba;
floor = floortab[state->bai & 7]; /* floorcod */
snroffset = 960 - 64 * state->csnroffst - 4 * (ba->bai >> 3) + floor;
floor >>= 5;
exp = expbap->exp;
bap = expbap->bap;
i = bndstart;
j = start;
if (start == 0) { /* not the coupling channel */
int lowcomp;
lowcomp = 0;
j = end - 1;
do {
if (i < j) {
if (exp[i+1] == exp[i] - 2)
lowcomp = 384;
else if (lowcomp && (exp[i+1] > exp[i]))
lowcomp -= 64;
}
psd = 128 * exp[i];
mask = psd + fgain + lowcomp;
COMPUTE_MASK ();
bap[i] = (baptab+156)[mask + 4 * exp[i]];
i++;
} while ((i < 3) || ((i < 7) && (exp[i] > exp[i-1])));
fastleak = psd + fgain;
slowleak = psd + sgain;
while (i < 7) {
if (i < j) {
if (exp[i+1] == exp[i] - 2)
lowcomp = 384;
else if (lowcomp && (exp[i+1] > exp[i]))
lowcomp -= 64;
}
psd = 128 * exp[i];
UPDATE_LEAK ();
mask = ((fastleak + lowcomp < slowleak) ?
fastleak + lowcomp : slowleak);
COMPUTE_MASK ();
bap[i] = (baptab+156)[mask + 4 * exp[i]];
i++;
}
if (end == 7) /* lfe channel */
return;
do {
if (exp[i+1] == exp[i] - 2)
lowcomp = 320;
else if (lowcomp && (exp[i+1] > exp[i]))
lowcomp -= 64;
psd = 128 * exp[i];
UPDATE_LEAK ();
mask = ((fastleak + lowcomp < slowleak) ?
fastleak + lowcomp : slowleak);
COMPUTE_MASK ();
bap[i] = (baptab+156)[mask + 4 * exp[i]];
i++;
} while (i < 20);
while (lowcomp > 128) { /* two iterations maximum */
lowcomp -= 128;
psd = 128 * exp[i];
UPDATE_LEAK ();
mask = ((fastleak + lowcomp < slowleak) ?
fastleak + lowcomp : slowleak);
COMPUTE_MASK ();
bap[i] = (baptab+156)[mask + 4 * exp[i]];
i++;
}
j = i;
}
do {
int startband, endband;
startband = j;
endband = (bndtab[i-20] < end) ? bndtab[i-20] : end;
psd = 128 * exp[j++];
while (j < endband) {
int next, delta;
next = 128 * exp[j++];
delta = next - psd;
switch (delta >> 9) {
case -6: case -5: case -4: case -3: case -2:
psd = next;
break;
case -1:
psd = next + latab[(-delta) >> 1];
break;
case 0:
psd += latab[delta >> 1];
break;
}
}
/* minpsd = -289 */
UPDATE_LEAK ();
mask = (fastleak < slowleak) ? fastleak : slowleak;
COMPUTE_MASK ();
i++;
j = startband;
do {
/* max(mask+4*exp)=147=-(minpsd+fgain-deltba-snroffset)>>5+4*exp */
/* min(mask+4*exp)=-156=-(sgain-deltba-snroffset)>>5 */
bap[j] = (baptab+156)[mask + 4 * exp[j]];
} while (++j < endband);
} while (j < end);
}
/*
* bitstream.c
* Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
* Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
*
* This file is part of a52dec, a free ATSC A-52 stream decoder.
* See http://liba52.sourceforge.net/ for updates.
*
* a52dec is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* a52dec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "a52.h"
#include "a52_internal.h"
#include "bitstream.h"
#define BUFFER_SIZE 4096
void a52_bitstream_set_ptr (a52_state_t * state, uint8_t * buf)
{
int align;
align = (long)buf & 3;
state->buffer_start = (uint32_t *) (buf - align);
state->bits_left = 0;
state->current_word = 0;
bitstream_get (state, align * 8);
}
static inline void bitstream_fill_current (a52_state_t * state)
{
uint32_t tmp;
tmp = *(state->buffer_start++);
state->current_word = swab32 (tmp);
}
/*
* The fast paths for _get is in the
* bitstream.h header file so it can be inlined.
*
* The "bottom half" of this routine is suffixed _bh
*
* -ah
*/
uint32_t a52_bitstream_get_bh (a52_state_t * state, uint32_t num_bits)
{
uint32_t result;
num_bits -= state->bits_left;
result = ((state->current_word << (32 - state->bits_left)) >>
(32 - state->bits_left));
bitstream_fill_current (state);
if (num_bits != 0)
result = (result << num_bits) | (state->current_word >> (32 - num_bits));
state->bits_left = 32 - num_bits;
return result;
}
int32_t a52_bitstream_get_bh_2 (a52_state_t * state, uint32_t num_bits)
{
int32_t result;
num_bits -= state->bits_left;
result = ((((int32_t)state->current_word) << (32 - state->bits_left)) >>
(32 - state->bits_left));
bitstream_fill_current(state);
if (num_bits != 0)
result = (result << num_bits) | (state->current_word >> (32 - num_bits));
state->bits_left = 32 - num_bits;
return result;
}
/*
* bitstream.h
* Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
* Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
*
* This file is part of a52dec, a free ATSC A-52 stream decoder.
* See http://liba52.sourceforge.net/ for updates.
*
* a52dec is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* a52dec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* (stolen from the kernel) */
#ifdef WORDS_BIGENDIAN
# define swab32(x) (x)
#else
# if 0 && defined (__i386__)
# define swab32(x) __i386_swab32(x)
static inline const uint32_t __i386_swab32(uint32_t x)
{
__asm__("bswap %0" : "=r" (x) : "0" (x));
return x;
}
# else
# define swab32(x)\
((((uint8_t*)&x)[0] << 24) | (((uint8_t*)&x)[1] << 16) | \
(((uint8_t*)&x)[2] << 8) | (((uint8_t*)&x)[3]))
# endif
#endif
void a52_bitstream_set_ptr (a52_state_t * state, uint8_t * buf);
uint32_t a52_bitstream_get_bh (a52_state_t * state, uint32_t num_bits);
int32_t a52_bitstream_get_bh_2 (a52_state_t * state, uint32_t num_bits);
static inline uint32_t bitstream_get (a52_state_t * state, uint32_t num_bits)
{
uint32_t result;
if (num_bits < state->bits_left) {
result = (state->current_word << (32 - state->bits_left)) >> (32 - num_bits);
state->bits_left -= num_bits;
return result;
}
return a52_bitstream_get_bh (state, num_bits);
}
static inline int32_t bitstream_get_2 (a52_state_t * state, uint32_t num_bits)
{
int32_t result;
if (num_bits < state->bits_left) {
result = (((int32_t)state->current_word) << (32 - state->bits_left)) >> (32 - num_bits);
state->bits_left -= num_bits;
return result;
}
return a52_bitstream_get_bh_2 (state, num_bits);
}
/*
* crc.c
*
* Copyright (C) Aaron Holtzman - May 1999
*
* This file is part of ac3dec, a free Dolby AC-3 stream decoder.
*
* ac3dec is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* ac3dec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
static const uint16_t crc_lut[256] =
{
0x0000,0x8005,0x800f,0x000a,0x801b,0x001e,0x0014,0x8011,
0x8033,0x0036,0x003c,0x8039,0x0028,0x802d,0x8027,0x0022,
0x8063,0x0066,0x006c,0x8069,0x0078,0x807d,0x8077,0x0072,
0x0050,0x8055,0x805f,0x005a,0x804b,0x004e,0x0044,0x8041,
0x80c3,0x00c6,0x00cc,0x80c9,0x00d8,0x80dd,0x80d7,0x00d2,
0x00f0,0x80f5,0x80ff,0x00fa,0x80eb,0x00ee,0x00e4,0x80e1,
0x00a0,0x80a5,0x80af,0x00aa,0x80bb,0x00be,0x00b4,0x80b1,
0x8093,0x0096,0x009c,0x8099,0x0088,0x808d,0x8087,0x0082,
0x8183,0x0186,0x018c,0x8189,0x0198,0x819d,0x8197,0x0192,
0x01b0,0x81b5,0x81bf,0x01ba,0x81ab,0x01ae,0x01a4,0x81a1,
0x01e0,0x81e5,0x81ef,0x01ea,0x81fb,0x01fe,0x01f4,0x81f1,
0x81d3,0x01d6,0x01dc,0x81d9,0x01c8,0x81cd,0x81c7,0x01c2,
0x0140,0x8145,0x814f,0x014a,0x815b,0x015e,0x0154,0x8151,
0x8173,0x0176,0x017c,0x8179,0x0168,0x816d,0x8167,0x0162,
0x8123,0x0126,0x012c,0x8129,0x0138,0x813d,0x8137,0x0132,
0x0110,0x8115,0x811f,0x011a,0x810b,0x010e,0x0104,0x8101,
0x8303,0x0306,0x030c,0x8309,0x0318,0x831d,0x8317,0x0312,
0x0330,0x8335,0x833f,0x033a,0x832b,0x032e,0x0324,0x8321,
0x0360,0x8365,0x836f,0x036a,0x837b,0x037e,0x0374,0x8371,
0x8353,0x0356,0x035c,0x8359,0x0348,0x834d,0x8347,0x0342,
0x03c0,0x83c5,0x83cf,0x03ca,0x83db,0x03de,0x03d4,0x83d1,
0x83f3,0x03f6,0x03fc,0x83f9,0x03e8,0x83ed,0x83e7,0x03e2,
0x83a3,0x03a6,0x03ac,0x83a9,0x03b8,0x83bd,0x83b7,0x03b2,
0x0390,0x8395,0x839f,0x039a,0x838b,0x038e,0x0384,0x8381,
0x0280,0x8285,0x828f,0x028a,0x829b,0x029e,0x0294,0x8291,
0x82b3,0x02b6,0x02bc,0x82b9,0x02a8,0x82ad,0x82a7,0x02a2,
0x82e3,0x02e6,0x02ec,0x82e9,0x02f8,0x82fd,0x82f7,0x02f2,
0x02d0,0x82d5,0x82df,0x02da,0x82cb,0x02ce,0x02c4,0x82c1,
0x8243,0x0246,0x024c,0x8249,0x0258,0x825d,0x8257,0x0252,
0x0270,0x8275,0x827f,0x027a,0x826b,0x026e,0x0264,0x8261,
0x0220,0x8225,0x822f,0x022a,0x823b,0x023e,0x0234,0x8231,
0x8213,0x0216,0x021c,0x8219,0x0208,0x820d,0x8207,0x0202
};
uint16_t a52_crc16_block(uint8_t *data,uint32_t num_bytes)
{
uint32_t i;
uint16_t state=0;
for(i=0;i<num_bytes;i++)
state = crc_lut[data[i] ^ (state>>8)] ^ (state<<8);
return state;
}
/*
* downmix.c
* Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
* Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
*
* This file is part of a52dec, a free ATSC A-52 stream decoder.
* See http://liba52.sourceforge.net/ for updates.
*
* a52dec is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* a52dec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "a52.h"
#include "a52_internal.h"
#define CONVERT(acmod,output) (((output) << 3) + (acmod))
int a52_downmix_init (int input, int flags, level_t * level,
level_t clev, level_t slev)
{
static uint8_t table[11][8] = {
{A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
A52_STEREO, A52_STEREO, A52_STEREO, A52_STEREO},
{A52_MONO, A52_MONO, A52_MONO, A52_MONO,
A52_MONO, A52_MONO, A52_MONO, A52_MONO},
{A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
A52_STEREO, A52_STEREO, A52_STEREO, A52_STEREO},
{A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F,
A52_STEREO, A52_3F, A52_STEREO, A52_3F},
{A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
A52_2F1R, A52_2F1R, A52_2F1R, A52_2F1R},
{A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
A52_2F1R, A52_3F1R, A52_2F1R, A52_3F1R},
{A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F,
A52_2F2R, A52_2F2R, A52_2F2R, A52_2F2R},
{A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F,
A52_2F2R, A52_3F2R, A52_2F2R, A52_3F2R},
{A52_CHANNEL1, A52_MONO, A52_MONO, A52_MONO,
A52_MONO, A52_MONO, A52_MONO, A52_MONO},
{A52_CHANNEL2, A52_MONO, A52_MONO, A52_MONO,
A52_MONO, A52_MONO, A52_MONO, A52_MONO},
{A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_DOLBY,
A52_DOLBY, A52_DOLBY, A52_DOLBY, A52_DOLBY}
};
int output;
output = flags & A52_CHANNEL_MASK;
if (output > A52_DOLBY)
return -1;
output = table[output][input & 7];
if (output == A52_STEREO &&
(input == A52_DOLBY || (input == A52_3F && clev == LEVEL (LEVEL_3DB))))
output = A52_DOLBY;
if (flags & A52_ADJUST_LEVEL) {
level_t adjust;
switch (CONVERT (input & 7, output)) {
case CONVERT (A52_3F, A52_MONO):
adjust = DIV (LEVEL_3DB, LEVEL (1) + clev);
break;
case CONVERT (A52_STEREO, A52_MONO):
case CONVERT (A52_2F2R, A52_2F1R):
case CONVERT (A52_3F2R, A52_3F1R):
level_3db:
adjust = LEVEL (LEVEL_3DB);
break;
case CONVERT (A52_3F2R, A52_2F1R):
if (clev < LEVEL (LEVEL_PLUS3DB - 1))
goto level_3db;
/* break thru */
case CONVERT (A52_3F, A52_STEREO):
case CONVERT (A52_3F1R, A52_2F1R):
case CONVERT (A52_3F1R, A52_2F2R):
case CONVERT (A52_3F2R, A52_2F2R):
adjust = DIV (1, LEVEL (1) + clev);
break;
case CONVERT (A52_2F1R, A52_MONO):
adjust = DIV (LEVEL_PLUS3DB, LEVEL (2) + slev);
break;
case CONVERT (A52_2F1R, A52_STEREO):
case CONVERT (A52_3F1R, A52_3F):
adjust = DIV (1, LEVEL (1) + MUL_C (slev, LEVEL_3DB));
break;
case CONVERT (A52_3F1R, A52_MONO):
adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + MUL_C (slev, 0.5));
break;
case CONVERT (A52_3F1R, A52_STEREO):
adjust = DIV (1, LEVEL (1) + clev + MUL_C (slev, LEVEL_3DB));
break;
case CONVERT (A52_2F2R, A52_MONO):
adjust = DIV (LEVEL_3DB, LEVEL (1) + slev);
break;
case CONVERT (A52_2F2R, A52_STEREO):
case CONVERT (A52_3F2R, A52_3F):
adjust = DIV (1, LEVEL (1) + slev);
break;
case CONVERT (A52_3F2R, A52_MONO):
adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + slev);
break;
case CONVERT (A52_3F2R, A52_STEREO):
adjust = DIV (1, LEVEL (1) + clev + slev);
break;
case CONVERT (A52_MONO, A52_DOLBY):
adjust = LEVEL (LEVEL_PLUS3DB);
break;
case CONVERT (A52_3F, A52_DOLBY):
case CONVERT (A52_2F1R, A52_DOLBY):
adjust = LEVEL (1 / (1 + LEVEL_3DB));
break;
case CONVERT (A52_3F1R, A52_DOLBY):
case CONVERT (A52_2F2R, A52_DOLBY):
adjust = LEVEL (1 / (1 + 2 * LEVEL_3DB));
break;
case CONVERT (A52_3F2R, A52_DOLBY):
adjust = LEVEL (1 / (1 + 3 * LEVEL_3DB));
break;
default:
return output;
}
*level = MUL_L (*level, adjust);
}
return output;
}
int a52_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
level_t clev, level_t slev)
{
level_t level_3db;
level_3db = MUL_C (level, LEVEL_3DB);
switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
case CONVERT (A52_CHANNEL, A52_CHANNEL):
case CONVERT (A52_MONO, A52_MONO):
case CONVERT (A52_STEREO, A52_STEREO):
case CONVERT (A52_3F, A52_3F):
case CONVERT (A52_2F1R, A52_2F1R):
case CONVERT (A52_3F1R, A52_3F1R):
case CONVERT (A52_2F2R, A52_2F2R):
case CONVERT (A52_3F2R, A52_3F2R):
case CONVERT (A52_STEREO, A52_DOLBY):
coeff[0] = coeff[1] = coeff[2] = coeff[3] = coeff[4] = level;
return 0;
case CONVERT (A52_CHANNEL, A52_MONO):
coeff[0] = coeff[1] = MUL_C (level, LEVEL_6DB);
return 3;
case CONVERT (A52_STEREO, A52_MONO):
coeff[0] = coeff[1] = level_3db;
return 3;
case CONVERT (A52_3F, A52_MONO):
coeff[0] = coeff[2] = level_3db;
coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
return 7;
case CONVERT (A52_2F1R, A52_MONO):
coeff[0] = coeff[1] = level_3db;
coeff[2] = MUL_L (level_3db, slev);
return 7;
case CONVERT (A52_2F2R, A52_MONO):
coeff[0] = coeff[1] = level_3db;
coeff[2] = coeff[3] = MUL_L (level_3db, slev);
return 15;
case CONVERT (A52_3F1R, A52_MONO):
coeff[0] = coeff[2] = level_3db;
coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
coeff[3] = MUL_L (level_3db, slev);
return 15;
case CONVERT (A52_3F2R, A52_MONO):
coeff[0] = coeff[2] = level_3db;
coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
coeff[3] = coeff[4] = MUL_L (level_3db, slev);
return 31;
case CONVERT (A52_MONO, A52_DOLBY):
coeff[0] = level_3db;
return 0;
case CONVERT (A52_3F, A52_DOLBY):
coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
coeff[1] = level_3db;
return 7;
case CONVERT (A52_3F, A52_STEREO):
case CONVERT (A52_3F1R, A52_2F1R):
case CONVERT (A52_3F2R, A52_2F2R):
coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
coeff[1] = MUL_L (level, clev);
return 7;
case CONVERT (A52_2F1R, A52_DOLBY):
coeff[0] = coeff[1] = level;
coeff[2] = level_3db;
return 7;
case CONVERT (A52_2F1R, A52_STEREO):
coeff[0] = coeff[1] = level;
coeff[2] = MUL_L (level_3db, slev);
return 7;
case CONVERT (A52_3F1R, A52_DOLBY):
coeff[0] = coeff[2] = level;
coeff[1] = coeff[3] = level_3db;
return 15;
case CONVERT (A52_3F1R, A52_STEREO):
coeff[0] = coeff[2] = level;
coeff[1] = MUL_L (level, clev);
coeff[3] = MUL_L (level_3db, slev);
return 15;
case CONVERT (A52_2F2R, A52_DOLBY):
coeff[0] = coeff[1] = level;
coeff[2] = coeff[3] = level_3db;
return 15;
case CONVERT (A52_2F2R, A52_STEREO):
coeff[0] = coeff[1] = level;
coeff[2] = coeff[3] = MUL_L (level, slev);
return 15;
case CONVERT (A52_3F2R, A52_DOLBY):
coeff[0] = coeff[2] = level;
coeff[1] = coeff[3] = coeff[4] = level_3db;
return 31;
case CONVERT (A52_3F2R, A52_2F1R):
coeff[0] = coeff[2] = level;
coeff[1] = MUL_L (level, clev);
coeff[3] = coeff[4] = level_3db;
return 31;
case CONVERT (A52_3F2R, A52_STEREO):
coeff[0] = coeff[2] = level;
coeff[1] = MUL_L (level, clev);
coeff[3] = coeff[4] = MUL_L (level, slev);
return 31;
case CONVERT (A52_3F1R, A52_3F):
coeff[0] = coeff[1] = coeff[2] = level;
coeff[3] = MUL_L (level_3db, slev);
return 13;
case CONVERT (A52_3F2R, A52_3F):
coeff[0] = coeff[1] = coeff[2] = level;
coeff[3] = coeff[4] = MUL_L (level, slev);
return 29;
case CONVERT (A52_2F2R, A52_2F1R):
coeff[0] = coeff[1] = level;
coeff[2] = coeff[3] = level_3db;
return 12;
case CONVERT (A52_3F2R, A52_3F1R):
coeff[0] = coeff[1] = coeff[2] = level;
coeff[3] = coeff[4] = level_3db;
return 24;
case CONVERT (A52_2F1R, A52_2F2R):
coeff[0] = coeff[1] = level;
coeff[2] = level_3db;
return 0;
case CONVERT (A52_3F1R, A52_2F2R):
coeff[0] = coeff[2] = level;
coeff[1] = MUL_L (level, clev);
coeff[3] = level_3db;
return 7;
case CONVERT (A52_3F1R, A52_3F2R):
coeff[0] = coeff[1] = coeff[2] = level;
coeff[3] = level_3db;
return 0;
case CONVERT (A52_CHANNEL, A52_CHANNEL1):
coeff[0] = level;
coeff[1] = 0;
return 0;
case CONVERT (A52_CHANNEL, A52_CHANNEL2):
coeff[0] = 0;
coeff[1] = level;
return 0;
}
return -1; /* NOTREACHED */
}
static void mix2to1 (sample_t * dest, sample_t * src, sample_t bias)
{
int i;
for (i = 0; i < 256; i++)
dest[i] += BIAS (src[i]);
}
static void mix3to1 (sample_t * samples, sample_t bias)
{
int i;
for (i = 0; i < 256; i++)
samples[i] += BIAS (samples[i + 256] + samples[i + 512]);
}
static void mix4to1 (sample_t * samples, sample_t bias)
{
int i;
for (i = 0; i < 256; i++)
samples[i] += BIAS (samples[i + 256] + samples[i + 512] +
samples[i + 768]);
}
static void mix5to1 (sample_t * samples, sample_t bias)
{
int i;
for (i = 0; i < 256; i++)
samples[i] += BIAS (samples[i + 256] + samples[i + 512] +
samples[i + 768] + samples[i + 1024]);
}
static void mix3to2 (sample_t * samples, sample_t bias)
{
int i;
sample_t common;
for (i = 0; i < 256; i++) {
common = BIAS (samples[i + 256]);
samples[i] += common;
samples[i + 256] = samples[i + 512] + common;
}
}
static void mix21to2 (sample_t * left, sample_t * right, sample_t bias)
{
int i;
sample_t common;
for (i = 0; i < 256; i++) {
common = BIAS (right[i + 256]);
left[i] += common;
right[i] += common;
}
}
static void mix21toS (sample_t * samples, sample_t bias)
{
int i;
sample_t surround;
for (i = 0; i < 256; i++) {
surround = samples[i + 512];
samples[i] += BIAS (-surround);
samples[i + 256] += BIAS (surround);
}
}
static void mix31to2 (sample_t * samples, sample_t bias)
{
int i;
sample_t common;
for (i = 0; i < 256; i++) {
common = BIAS (samples[i + 256] + samples[i + 768]);
samples[i] += common;
samples[i + 256] = samples[i + 512] + common;
}
}
static void mix31toS (sample_t * samples, sample_t bias)
{
int i;
sample_t common, surround;
for (i = 0; i < 256; i++) {
common = BIAS (samples[i + 256]);
surround = samples[i + 768];
samples[i] += common - surround;
samples[i + 256] = samples[i + 512] + common + surround;
}
}
static void mix22toS (sample_t * samples, sample_t bias)
{
int i;
sample_t surround;
for (i = 0; i < 256; i++) {
surround = samples[i + 512] + samples[i + 768];
samples[i] += BIAS (-surround);
samples[i + 256] += BIAS (surround);
}
}
static void mix32to2 (sample_t * samples, sample_t bias)
{
int i;
sample_t common;
for (i = 0; i < 256; i++) {
common = BIAS (samples[i + 256]);
samples[i] += common + samples[i + 768];
samples[i + 256] = common + samples[i + 512] + samples[i + 1024];
}
}
static void mix32toS (sample_t * samples, sample_t bias)
{
int i;
sample_t common, surround;
for (i = 0; i < 256; i++) {
common = BIAS (samples[i + 256]);
surround = samples[i + 768] + samples[i + 1024];
samples[i] += common - surround;
samples[i + 256] = samples[i + 512] + common + surround;
}
}
static void move2to1 (sample_t * src, sample_t * dest, sample_t bias)
{
int i;
for (i = 0; i < 256; i++)
dest[i] = BIAS (src[i] + src[i + 256]);
}
static void zero (sample_t * samples)
{
int i;
for (i = 0; i < 256; i++)
samples[i] = 0;
}
void a52_downmix (sample_t * samples, int acmod, int output, sample_t bias,
level_t clev, level_t slev)
{
switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
case CONVERT (A52_CHANNEL, A52_CHANNEL2):
memcpy (samples, samples + 256, 256 * sizeof (sample_t));
break;
case CONVERT (A52_CHANNEL, A52_MONO):
case CONVERT (A52_STEREO, A52_MONO):
mix_2to1:
mix2to1 (samples, samples + 256, bias);
break;
case CONVERT (A52_2F1R, A52_MONO):
if (slev == 0)
goto mix_2to1;
case CONVERT (A52_3F, A52_MONO):
mix_3to1:
mix3to1 (samples, bias);
break;
case CONVERT (A52_3F1R, A52_MONO):
if (slev == 0)
goto mix_3to1;
case CONVERT (A52_2F2R, A52_MONO):
if (slev == 0)
goto mix_2to1;
mix4to1 (samples, bias);
break;
case CONVERT (A52_3F2R, A52_MONO):
if (slev == 0)
goto mix_3to1;
mix5to1 (samples, bias);
break;
case CONVERT (A52_MONO, A52_DOLBY):
memcpy (samples + 256, samples, 256 * sizeof (sample_t));
break;
case CONVERT (A52_3F, A52_STEREO):
case CONVERT (A52_3F, A52_DOLBY):
mix_3to2:
mix3to2 (samples, bias);
break;
case CONVERT (A52_2F1R, A52_STEREO):
if (slev == 0)
break;
mix21to2 (samples, samples + 256, bias);
break;
case CONVERT (A52_2F1R, A52_DOLBY):
mix21toS (samples, bias);
break;
case CONVERT (A52_3F1R, A52_STEREO):
if (slev == 0)
goto mix_3to2;
mix31to2 (samples, bias);
break;
case CONVERT (A52_3F1R, A52_DOLBY):
mix31toS (samples, bias);
break;
case CONVERT (A52_2F2R, A52_STEREO):
if (slev == 0)
break;
mix2to1 (samples, samples + 512, bias);
mix2to1 (samples + 256, samples + 768, bias);
break;
case CONVERT (A52_2F2R, A52_DOLBY):
mix22toS (samples, bias);
break;
case CONVERT (A52_3F2R, A52_STEREO):
if (slev == 0)
goto mix_3to2;
mix32to2 (samples, bias);
break;
case CONVERT (A52_3F2R, A52_DOLBY):
mix32toS (samples, bias);
break;
case CONVERT (A52_3F1R, A52_3F):
if (slev == 0)
break;
mix21to2 (samples, samples + 512, bias);
break;
case CONVERT (A52_3F2R, A52_3F):
if (slev == 0)
break;
mix2to1 (samples, samples + 768, bias);
mix2to1 (samples + 512, samples + 1024, bias);
break;
case CONVERT (A52_3F1R, A52_2F1R):
mix3to2 (samples, bias);
memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
break;
case CONVERT (A52_2F2R, A52_2F1R):
mix2to1 (samples + 512, samples + 768, bias);
break;
case CONVERT (A52_3F2R, A52_2F1R):
mix3to2 (samples, bias);
move2to1 (samples + 768, samples + 512, bias);
break;
case CONVERT (A52_3F2R, A52_3F1R):
mix2to1 (samples + 768, samples + 1024, bias);
break;
case CONVERT (A52_2F1R, A52_2F2R):
memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
break;
case CONVERT (A52_3F1R, A52_2F2R):
mix3to2 (samples, bias);
memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
break;
case CONVERT (A52_3F2R, A52_2F2R):
mix3to2 (samples, bias);
memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
memcpy (samples + 768, samples + 1024, 256 * sizeof (sample_t));
break;
case CONVERT (A52_3F1R, A52_3F2R):
memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
break;
}
}
void a52_upmix (sample_t * samples, int acmod, int output)
{
switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
case CONVERT (A52_CHANNEL, A52_CHANNEL2):
memcpy (samples + 256, samples, 256 * sizeof (sample_t));
break;
case CONVERT (A52_3F2R, A52_MONO):
zero (samples + 1024);
case CONVERT (A52_3F1R, A52_MONO):
case CONVERT (A52_2F2R, A52_MONO):
zero (samples + 768);
case CONVERT (A52_3F, A52_MONO):
case CONVERT (A52_2F1R, A52_MONO):
zero (samples + 512);
case CONVERT (A52_CHANNEL, A52_MONO):
case CONVERT (A52_STEREO, A52_MONO):
zero (samples + 256);
break;
case CONVERT (A52_3F2R, A52_STEREO):
case CONVERT (A52_3F2R, A52_DOLBY):
zero (samples + 1024);
case CONVERT (A52_3F1R, A52_STEREO):
case CONVERT (A52_3F1R, A52_DOLBY):
zero (samples + 768);
case CONVERT (A52_3F, A52_STEREO):
case CONVERT (A52_3F, A52_DOLBY):
mix_3to2:
memcpy (samples + 512, samples + 256, 256 * sizeof (sample_t));
zero (samples + 256);
break;
case CONVERT (A52_2F2R, A52_STEREO):
case CONVERT (A52_2F2R, A52_DOLBY):
zero (samples + 768);
case CONVERT (A52_2F1R, A52_STEREO):
case CONVERT (A52_2F1R, A52_DOLBY):
zero (samples + 512);
break;
case CONVERT (A52_3F2R, A52_3F):
zero (samples + 1024);
case CONVERT (A52_3F1R, A52_3F):
case CONVERT (A52_2F2R, A52_2F1R):
zero (samples + 768);
break;
case CONVERT (A52_3F2R, A52_3F1R):
zero (samples + 1024);
break;
case CONVERT (A52_3F2R, A52_2F1R):
zero (samples + 1024);
case CONVERT (A52_3F1R, A52_2F1R):
mix_31to21:
memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
goto mix_3to2;
case CONVERT (A52_3F2R, A52_2F2R):
memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
goto mix_31to21;
}
}
/*
* imdct.c
* Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
* Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
*
* The ifft algorithms in this file have been largely inspired by Dan
* Bernstein's work, djbfft, available at http://cr.yp.to/djbfft.html
*
* This file is part of a52dec, a free ATSC A-52 stream decoder.
* See http://liba52.sourceforge.net/ for updates.
*
* a52dec is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* a52dec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "a52.h"
#include "a52_internal.h"
#include "mm_accel.h"
typedef struct complex_s {
sample_t real;
sample_t imag;
} complex_t;
static uint8_t fftorder[] = {
0,128, 64,192, 32,160,224, 96, 16,144, 80,208,240,112, 48,176,
8,136, 72,200, 40,168,232,104,248,120, 56,184, 24,152,216, 88,
4,132, 68,196, 36,164,228,100, 20,148, 84,212,244,116, 52,180,
252,124, 60,188, 28,156,220, 92, 12,140, 76,204,236,108, 44,172,
2,130, 66,194, 34,162,226, 98, 18,146, 82,210,242,114, 50,178,
10,138, 74,202, 42,170,234,106,250,122, 58,186, 26,154,218, 90,
254,126, 62,190, 30,158,222, 94, 14,142, 78,206,238,110, 46,174,
6,134, 70,198, 38,166,230,102,246,118, 54,182, 22,150,214, 86
};
/* Root values for IFFT */
static sample_t roots16[3];
static sample_t roots32[7];
static sample_t roots64[15];
static sample_t roots128[31];
/* Twiddle factors for IMDCT */
static complex_t pre1[128];
static complex_t post1[64];
static complex_t pre2[64];
static complex_t post2[32];
static sample_t a52_imdct_window[256];
static void (* ifft128) (complex_t * buf);
static void (* ifft64) (complex_t * buf);
static inline void ifft2 (complex_t * buf)
{
sample_t r, i;
r = buf[0].real;
i = buf[0].imag;
buf[0].real += buf[1].real;
buf[0].imag += buf[1].imag;
buf[1].real = r - buf[1].real;
buf[1].imag = i - buf[1].imag;
}
static inline void ifft4 (complex_t * buf)
{
sample_t tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
tmp1 = buf[0].real + buf[1].real;
tmp2 = buf[3].real + buf[2].real;
tmp3 = buf[0].imag + buf[1].imag;
tmp4 = buf[2].imag + buf[3].imag;
tmp5 = buf[0].real - buf[1].real;
tmp6 = buf[0].imag - buf[1].imag;
tmp7 = buf[2].imag - buf[3].imag;
tmp8 = buf[3].real - buf[2].real;
buf[0].real = tmp1 + tmp2;
buf[0].imag = tmp3 + tmp4;
buf[2].real = tmp1 - tmp2;
buf[2].imag = tmp3 - tmp4;
buf[1].real = tmp5 + tmp7;
buf[1].imag = tmp6 + tmp8;
buf[3].real = tmp5 - tmp7;
buf[3].imag = tmp6 - tmp8;
}
/* basic radix-2 ifft butterfly */
#define BUTTERFLY_0(t0,t1,W0,W1,d0,d1) do { \
t0 = MUL (W1, d1) + MUL (W0, d0); \
t1 = MUL (W0, d1) - MUL (W1, d0); \
} while (0)
/* radix-2 ifft butterfly with bias */
#define BUTTERFLY_B(t0,t1,W0,W1,d0,d1) do { \
t0 = BIAS (MUL (d1, W1) + MUL (d0, W0)); \
t1 = BIAS (MUL (d1, W0) - MUL (d0, W1)); \
} while (0)
/* the basic split-radix ifft butterfly */
#define BUTTERFLY(a0,a1,a2,a3,wr,wi) do { \
BUTTERFLY_0 (tmp5, tmp6, wr, wi, a2.real, a2.imag); \
BUTTERFLY_0 (tmp8, tmp7, wr, wi, a3.imag, a3.real); \
tmp1 = tmp5 + tmp7; \
tmp2 = tmp6 + tmp8; \
tmp3 = tmp6 - tmp8; \
tmp4 = tmp7 - tmp5; \
a2.real = a0.real - tmp1; \
a2.imag = a0.imag - tmp2; \
a3.real = a1.real - tmp3; \
a3.imag = a1.imag - tmp4; \
a0.real += tmp1; \
a0.imag += tmp2; \
a1.real += tmp3; \
a1.imag += tmp4; \
} while (0)
/* split-radix ifft butterfly, specialized for wr=1 wi=0 */
#define BUTTERFLY_ZERO(a0,a1,a2,a3) do { \
tmp1 = a2.real + a3.real; \
tmp2 = a2.imag + a3.imag; \
tmp3 = a2.imag - a3.imag; \
tmp4 = a3.real - a2.real; \
a2.real = a0.real - tmp1; \
a2.imag = a0.imag - tmp2; \
a3.real = a1.real - tmp3; \
a3.imag = a1.imag - tmp4; \
a0.real += tmp1; \
a0.imag += tmp2; \
a1.real += tmp3; \
a1.imag += tmp4; \
} while (0)
/* split-radix ifft butterfly, specialized for wr=wi */
#define BUTTERFLY_HALF(a0,a1,a2,a3,w) do { \
tmp5 = MUL (a2.real + a2.imag, w); \
tmp6 = MUL (a2.imag - a2.real, w); \
tmp7 = MUL (a3.real - a3.imag, w); \
tmp8 = MUL (a3.imag + a3.real, w); \
tmp1 = tmp5 + tmp7; \
tmp2 = tmp6 + tmp8; \
tmp3 = tmp6 - tmp8; \
tmp4 = tmp7 - tmp5; \
a2.real = a0.real - tmp1; \
a2.imag = a0.imag - tmp2; \
a3.real = a1.real - tmp3; \
a3.imag = a1.imag - tmp4; \
a0.real += tmp1; \
a0.imag += tmp2; \
a1.real += tmp3; \
a1.imag += tmp4; \
} while (0)
static inline void ifft8 (complex_t * buf)
{
sample_t tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
ifft4 (buf);
ifft2 (buf + 4);
ifft2 (buf + 6);
BUTTERFLY_ZERO (buf[0], buf[2], buf[4], buf[6]);
BUTTERFLY_HALF (buf[1], buf[3], buf[5], buf[7], roots16[1]);
}
static void ifft_pass (complex_t * buf, sample_t * weight, int n)
{
complex_t * buf1;
complex_t * buf2;
complex_t * buf3;
sample_t tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
int i;
buf++;
buf1 = buf + n;
buf2 = buf + 2 * n;
buf3 = buf + 3 * n;
BUTTERFLY_ZERO (buf[-1], buf1[-1], buf2[-1], buf3[-1]);
i = n - 1;
do {
BUTTERFLY (buf[0], buf1[0], buf2[0], buf3[0],
weight[0], weight[2*i-n]);
buf++;
buf1++;
buf2++;
buf3++;
weight++;
} while (--i);
}
static void ifft16 (complex_t * buf)
{
ifft8 (buf);
ifft4 (buf + 8);
ifft4 (buf + 12);
ifft_pass (buf, roots16, 4);
}
static void ifft32 (complex_t * buf)
{
ifft16 (buf);
ifft8 (buf + 16);
ifft8 (buf + 24);
ifft_pass (buf, roots32, 8);
}
static void ifft64_c (complex_t * buf)
{
ifft32 (buf);
ifft16 (buf + 32);
ifft16 (buf + 48);
ifft_pass (buf, roots64, 16);
}
static void ifft128_c (complex_t * buf)
{
ifft32 (buf);
ifft16 (buf + 32);
ifft16 (buf + 48);
ifft_pass (buf, roots64, 16);
ifft32 (buf + 64);
ifft32 (buf + 96);
ifft_pass (buf, roots128, 32);
}
void a52_imdct_512 (sample_t * data, sample_t * delay, sample_t bias)
{
int i, k;
sample_t t_r, t_i, a_r, a_i, b_r, b_i, w_1, w_2;
const sample_t * window = a52_imdct_window;
complex_t buf[128];
for (i = 0; i < 128; i++) {
k = fftorder[i];
t_r = pre1[i].real;
t_i = pre1[i].imag;
BUTTERFLY_0 (buf[i].real, buf[i].imag, t_r, t_i, data[k], data[255-k]);
}
ifft128 (buf);
/* Post IFFT complex multiply plus IFFT complex conjugate*/
/* Window and convert to real valued signal */
for (i = 0; i < 64; i++) {
/* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */
t_r = post1[i].real;
t_i = post1[i].imag;
BUTTERFLY_0 (a_r, a_i, t_i, t_r, buf[i].imag, buf[i].real);
BUTTERFLY_0 (b_r, b_i, t_r, t_i, buf[127-i].imag, buf[127-i].real);
w_1 = window[2*i];
w_2 = window[255-2*i];
BUTTERFLY_B (data[255-2*i], data[2*i], w_2, w_1, a_r, delay[2*i]);
delay[2*i] = a_i;
w_1 = window[2*i+1];
w_2 = window[254-2*i];
BUTTERFLY_B (data[2*i+1], data[254-2*i], w_1, w_2, b_r, delay[2*i+1]);
delay[2*i+1] = b_i;
}
}
void a52_imdct_256 (sample_t * data, sample_t * delay, sample_t bias)
{
int i, k;
sample_t t_r, t_i, a_r, a_i, b_r, b_i, c_r, c_i, d_r, d_i, w_1, w_2;
const sample_t * window = a52_imdct_window;
complex_t buf1[64], buf2[64];
/* Pre IFFT complex multiply plus IFFT cmplx conjugate */
for (i = 0; i < 64; i++) {
k = fftorder[i];
t_r = pre2[i].real;
t_i = pre2[i].imag;
BUTTERFLY_0 (buf1[i].real, buf1[i].imag, t_r, t_i, data[k], data[254-k]);
BUTTERFLY_0 (buf2[i].real, buf2[i].imag, t_r, t_i, data[k+1], data[255-k]);
}
ifft64 (buf1);
ifft64 (buf2);
/* Post IFFT complex multiply */
/* Window and convert to real valued signal */
for (i = 0; i < 32; i++) {
/* y1[n] = z1[n] * (xcos2[n] + j * xs in2[n]) ; */
t_r = post2[i].real;
t_i = post2[i].imag;
BUTTERFLY_0 (a_r, a_i, t_i, t_r, buf1[i].imag, buf1[i].real);
BUTTERFLY_0 (b_r, b_i, t_r, t_i, buf1[63-i].imag, buf1[63-i].real);
BUTTERFLY_0 (c_r, c_i, t_i, t_r, buf2[i].imag, buf2[i].real);
BUTTERFLY_0 (d_r, d_i, t_r, t_i, buf2[63-i].imag, buf2[63-i].real);
w_1 = window[2*i];
w_2 = window[255-2*i];
BUTTERFLY_B (data[255-2*i], data[2*i], w_2, w_1, a_r, delay[2*i]);
delay[2*i] = c_i;
w_1 = window[128+2*i];
w_2 = window[127-2*i];
BUTTERFLY_B (data[128+2*i], data[127-2*i], w_1, w_2, a_i, delay[127-2*i]);
delay[127-2*i] = c_r;
w_1 = window[2*i+1];
w_2 = window[254-2*i];
BUTTERFLY_B (data[254-2*i], data[2*i+1], w_2, w_1, b_i, delay[2*i+1]);
delay[2*i+1] = d_r;
w_1 = window[129+2*i];
w_2 = window[126-2*i];
BUTTERFLY_B (data[129+2*i], data[126-2*i], w_1, w_2, b_r, delay[126-2*i]);
delay[126-2*i] = d_i;
}
}
static double besselI0 (double x)
{
double bessel = 1;
int i = 100;
do
bessel = bessel * x / (i * i) + 1;
while (--i);
return bessel;
}
void a52_imdct_init (uint32_t mm_accel)
{
int i, k;
double sum;
double local_imdct_window[256];
/* compute imdct window - kaiser-bessel derived window, alpha = 5.0 */
sum = 0;
for (i = 0; i < 256; i++) {
sum += besselI0 (i * (256 - i) * (5 * M_PI / 256) * (5 * M_PI / 256));
local_imdct_window[i] = sum;
}
sum++;
for (i = 0; i < 256; i++)
a52_imdct_window[i] = SAMPLE (sqrt (local_imdct_window[i] / sum));
for (i = 0; i < 3; i++)
roots16[i] = SAMPLE (cos ((M_PI / 8) * (i + 1)));
for (i = 0; i < 7; i++)
roots32[i] = SAMPLE (cos ((M_PI / 16) * (i + 1)));
for (i = 0; i < 15; i++)
roots64[i] = SAMPLE (cos ((M_PI / 32) * (i + 1)));
for (i = 0; i < 31; i++)
roots128[i] = SAMPLE (cos ((M_PI / 64) * (i + 1)));
for (i = 0; i < 64; i++) {
k = fftorder[i] / 2 + 64;
pre1[i].real = SAMPLE (cos ((M_PI / 256) * (k - 0.25)));
pre1[i].imag = SAMPLE (sin ((M_PI / 256) * (k - 0.25)));
}
for (i = 64; i < 128; i++) {
k = fftorder[i] / 2 + 64;
pre1[i].real = SAMPLE (-cos ((M_PI / 256) * (k - 0.25)));
pre1[i].imag = SAMPLE (-sin ((M_PI / 256) * (k - 0.25)));
}
for (i = 0; i < 64; i++) {
post1[i].real = SAMPLE (cos ((M_PI / 256) * (i + 0.5)));
post1[i].imag = SAMPLE (sin ((M_PI / 256) * (i + 0.5)));
}
for (i = 0; i < 64; i++) {
k = fftorder[i] / 4;
pre2[i].real = SAMPLE (cos ((M_PI / 128) * (k - 0.25)));
pre2[i].imag = SAMPLE (sin ((M_PI / 128) * (k - 0.25)));
}
for (i = 0; i < 32; i++) {
post2[i].real = SAMPLE (cos ((M_PI / 128) * (i + 0.5)));
post2[i].imag = SAMPLE (sin ((M_PI / 128) * (i + 0.5)));
}
#ifdef LIBA52_DJBFFT
if (mm_accel & MM_ACCEL_DJBFFT) {
ifft128 = (void (*) (complex_t *)) fftc4_un128;
ifft64 = (void (*) (complex_t *)) fftc4_un64;
} else
#endif
{
ifft128 = ifft128_c;
ifft64 = ifft64_c;
}
}
/*
* mm_accel.h
* Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
* Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
*
* This file is part of a52dec, a free ATSC A-52 stream decoder.
* See http://liba52.sourceforge.net/ for updates.
*
* a52dec is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* a52dec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MM_ACCEL_H
#define MM_ACCEL_H
/* generic accelerations */
#define MM_ACCEL_DJBFFT 0x00000001
/* x86 accelerations */
#define MM_ACCEL_X86_MMX 0x80000000
#define MM_ACCEL_X86_3DNOW 0x40000000
#define MM_ACCEL_X86_MMXEXT 0x20000000
#define MM_ACCEL_X86_SSE 0x10000000
#define MM_ACCEL_X86_3DNOWEXT 0x08000000
/* PPC accelerations */
#define MM_ACCEL_PPC_ALTIVEC 0x00010000
uint32_t mm_accel (void);
#endif /* MM_ACCEL_H */
此差异已折叠。
/*
* copyright (C) 2001 Arpad Gereoffy
*
* This file is part of a52dec, a free ATSC A-52 stream decoder.
* See http://liba52.sourceforge.net/ for updates.
*
* a52dec is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* a52dec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
// a52_resample_init should find the requested converter (from type flags ->
// given number of channels) and set up some function pointers...
// a52_resample() should do the conversion.
#include "a52.h"
#include "mm_accel.h"
#include "config.h"
#include "../../libpostproc/mangle.h"
int (* a52_resample) (float * _f, int16_t * s16)=NULL;
#include "resample_c.c"
#ifdef ARCH_X86_32
#include "resample_mmx.c"
#endif
void* a52_resample_init(uint32_t mm_accel,int flags,int chans){
void* tmp;
#ifdef ARCH_X86_32
if(mm_accel&MM_ACCEL_X86_MMX){
tmp=a52_resample_MMX(flags,chans);
if(tmp){
if(a52_resample==NULL) av_log(NULL, AV_LOG_INFO, "Using MMX optimized resampler\n");
a52_resample=tmp;
return tmp;
}
}
#endif
tmp=a52_resample_C(flags,chans);
if(tmp){
if(a52_resample==NULL) av_log(NULL, AV_LOG_INFO, "No accelerated resampler found\n");
a52_resample=tmp;
return tmp;
}
av_log(NULL, AV_LOG_ERROR, "Unimplemented resampler for mode 0x%X -> %d channels conversion - Contact MPlayer developers!\n", flags, chans);
return NULL;
}
/*
* this code is based on a52dec/libao/audio_out_oss.c
* copyright (C) 2001 Arpad Gereoffy
*
* This file is part of a52dec, a free ATSC A-52 stream decoder.
* See http://liba52.sourceforge.net/ for updates.
*
* a52dec is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* a52dec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
static inline int16_t convert (int32_t i)
{
if (i > 0x43c07fff)
return 32767;
else if (i < 0x43bf8000)
return -32768;
else
return i - 0x43c00000;
}
static int a52_resample_MONO_to_5_C(float * _f, int16_t * s16){
int i;
int32_t * f = (int32_t *) _f;
for (i = 0; i < 256; i++) {
s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0;
s16[5*i+4] = convert (f[i]);
}
return 5*256;
}
static int a52_resample_MONO_to_1_C(float * _f, int16_t * s16){
int i;
int32_t * f = (int32_t *) _f;
for (i = 0; i < 256; i++) {
s16[i] = convert (f[i]);
}
return 1*256;
}
static int a52_resample_STEREO_to_2_C(float * _f, int16_t * s16){
int i;
int32_t * f = (int32_t *) _f;
for (i = 0; i < 256; i++) {
s16[2*i] = convert (f[i]);
s16[2*i+1] = convert (f[i+256]);
}
return 2*256;
}
static int a52_resample_3F_to_5_C(float * _f, int16_t * s16){
int i;
int32_t * f = (int32_t *) _f;
for (i = 0; i < 256; i++) {
s16[5*i] = convert (f[i]);
s16[5*i+1] = convert (f[i+512]);
s16[5*i+2] = s16[5*i+3] = 0;
s16[5*i+4] = convert (f[i+256]);
}
return 5*256;
}
static int a52_resample_2F_2R_to_4_C(float * _f, int16_t * s16){
int i;
int32_t * f = (int32_t *) _f;
for (i = 0; i < 256; i++) {
s16[4*i] = convert (f[i]);
s16[4*i+1] = convert (f[i+256]);
s16[4*i+2] = convert (f[i+512]);
s16[4*i+3] = convert (f[i+768]);
}
return 4*256;
}
static int a52_resample_3F_2R_to_5_C(float * _f, int16_t * s16){
int i;
int32_t * f = (int32_t *) _f;
for (i = 0; i < 256; i++) {
s16[5*i] = convert (f[i]);
s16[5*i+1] = convert (f[i+512]);
s16[5*i+2] = convert (f[i+768]);
s16[5*i+3] = convert (f[i+1024]);
s16[5*i+4] = convert (f[i+256]);
}
return 5*256;
}
static int a52_resample_MONO_LFE_to_6_C(float * _f, int16_t * s16){
int i;
int32_t * f = (int32_t *) _f;
for (i = 0; i < 256; i++) {
s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0;
s16[6*i+4] = convert (f[i+256]);
s16[6*i+5] = convert (f[i]);
}
return 6*256;
}
static int a52_resample_STEREO_LFE_to_6_C(float * _f, int16_t * s16){
int i;
int32_t * f = (int32_t *) _f;
for (i = 0; i < 256; i++) {
s16[6*i] = convert (f[i+256]);
s16[6*i+1] = convert (f[i+512]);
s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0;
s16[6*i+5] = convert (f[i]);
}
return 6*256;
}
static int a52_resample_3F_LFE_to_6_C(float * _f, int16_t * s16){
int i;
int32_t * f = (int32_t *) _f;
for (i = 0; i < 256; i++) {
s16[6*i] = convert (f[i+256]);
s16[6*i+1] = convert (f[i+768]);
s16[6*i+2] = s16[6*i+3] = 0;
s16[6*i+4] = convert (f[i+512]);
s16[6*i+5] = convert (f[i]);
}
return 6*256;
}
static int a52_resample_2F_2R_LFE_to_6_C(float * _f, int16_t * s16){
int i;
int32_t * f = (int32_t *) _f;
for (i = 0; i < 256; i++) {
s16[6*i] = convert (f[i+256]);
s16[6*i+1] = convert (f[i+512]);
s16[6*i+2] = convert (f[i+768]);
s16[6*i+3] = convert (f[i+1024]);
s16[6*i+4] = 0;
s16[6*i+5] = convert (f[i]);
}
return 6*256;
}
static int a52_resample_3F_2R_LFE_to_6_C(float * _f, int16_t * s16){
int i;
int32_t * f = (int32_t *) _f;
for (i = 0; i < 256; i++) {
s16[6*i] = convert (f[i+256]);
s16[6*i+1] = convert (f[i+768]);
s16[6*i+2] = convert (f[i+1024]);
s16[6*i+3] = convert (f[i+1280]);
s16[6*i+4] = convert (f[i+512]);
s16[6*i+5] = convert (f[i]);
}
return 6*256;
}
static void* a52_resample_C(int flags, int ch){
switch (flags) {
case A52_MONO:
if(ch==5) return a52_resample_MONO_to_5_C;
if(ch==1) return a52_resample_MONO_to_1_C;
break;
case A52_CHANNEL:
case A52_STEREO:
case A52_DOLBY:
if(ch==2) return a52_resample_STEREO_to_2_C;
break;
case A52_3F:
if(ch==5) return a52_resample_3F_to_5_C;
break;
case A52_2F2R:
if(ch==4) return a52_resample_2F_2R_to_4_C;
break;
case A52_3F2R:
if(ch==5) return a52_resample_3F_2R_to_5_C;
break;
case A52_MONO | A52_LFE:
if(ch==6) return a52_resample_MONO_LFE_to_6_C;
break;
case A52_CHANNEL | A52_LFE:
case A52_STEREO | A52_LFE:
case A52_DOLBY | A52_LFE:
if(ch==6) return a52_resample_STEREO_LFE_to_6_C;
break;
case A52_3F | A52_LFE:
if(ch==6) return a52_resample_3F_LFE_to_6_C;
break;
case A52_2F2R | A52_LFE:
if(ch==6) return a52_resample_2F_2R_LFE_to_6_C;
break;
case A52_3F2R | A52_LFE:
if(ch==6) return a52_resample_3F_2R_LFE_to_6_C;
break;
}
return NULL;
}
/*
* resample_mmx.c
* Copyright (C) 2003 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of a52dec, a free ATSC A-52 stream decoder.
* See http://liba52.sourceforge.net/ for updates.
*
* a52dec is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* a52dec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* optimization TODO / NOTES
movntq is slightly faster (0.5% with the current test.c benchmark)
(but thats just test.c so that needs to be testd in reallity)
and it would mean (C / MMX2 / MMX / 3DNOW) versions
*/
static uint64_t __attribute__((aligned(8))) attribute_used magicF2W= 0x43c0000043c00000LL;
static uint64_t __attribute__((aligned(8))) attribute_used wm1010= 0xFFFF0000FFFF0000LL;
static uint64_t __attribute__((aligned(8))) attribute_used wm0101= 0x0000FFFF0000FFFFLL;
static uint64_t __attribute__((aligned(8))) attribute_used wm1100= 0xFFFFFFFF00000000LL;
static int a52_resample_MONO_to_5_MMX(float * _f, int16_t * s16){
int32_t * f = (int32_t *) _f;
asm volatile(
"movl $-512, %%esi \n\t"
"movq "MANGLE(magicF2W)", %%mm7 \n\t"
"movq "MANGLE(wm1100)", %%mm3 \n\t"
"movq "MANGLE(wm0101)", %%mm4 \n\t"
"movq "MANGLE(wm1010)", %%mm5 \n\t"
"pxor %%mm6, %%mm6 \n\t"
"1: \n\t"
"movq (%1, %%esi, 2), %%mm0 \n\t"
"movq 8(%1, %%esi, 2), %%mm1 \n\t"
"leal (%%esi, %%esi, 4), %%edi \n\t"
"psubd %%mm7, %%mm0 \n\t"
"psubd %%mm7, %%mm1 \n\t"
"packssdw %%mm1, %%mm0 \n\t"
"movq %%mm0, %%mm1 \n\t"
"pand %%mm4, %%mm0 \n\t"
"pand %%mm5, %%mm1 \n\t"
"movq %%mm6, (%0, %%edi) \n\t" // 0 0 0 0
"movd %%mm0, 8(%0, %%edi) \n\t" // A 0
"pand %%mm3, %%mm0 \n\t"
"movd %%mm6, 12(%0, %%edi) \n\t" // 0 0
"movd %%mm1, 16(%0, %%edi) \n\t" // 0 B
"pand %%mm3, %%mm1 \n\t"
"movd %%mm6, 20(%0, %%edi) \n\t" // 0 0
"movq %%mm0, 24(%0, %%edi) \n\t" // 0 0 C 0
"movq %%mm1, 32(%0, %%edi) \n\t" // 0 0 0 B
"addl $8, %%esi \n\t"
" jnz 1b \n\t"
"emms \n\t"
:: "r" (s16+1280), "r" (f+256)
:"%esi", "%edi", "memory"
);
return 5*256;
}
static int a52_resample_STEREO_to_2_MMX(float * _f, int16_t * s16){
int32_t * f = (int32_t *) _f;
/* benchmark scores are 0.3% better with SSE but we would need to set bias=0 and premultiply it
#ifdef HAVE_SSE
asm volatile(
"movl $-1024, %%esi \n\t"
"1: \n\t"
"cvtps2pi (%1, %%esi), %%mm0 \n\t"
"cvtps2pi 1024(%1, %%esi), %%mm2\n\t"
"movq %%mm0, %%mm1 \n\t"
"punpcklwd %%mm2, %%mm0 \n\t"
"punpckhwd %%mm2, %%mm1 \n\t"
"movq %%mm0, (%0, %%esi) \n\t"
"movq %%mm1, 8(%0, %%esi) \n\t"
"addl $16, %%esi \n\t"
" jnz 1b \n\t"
"emms \n\t"
:: "r" (s16+512), "r" (f+256)
:"%esi", "memory"
);*/
asm volatile(
"movl $-1024, %%esi \n\t"
"movq "MANGLE(magicF2W)", %%mm7 \n\t"
"1: \n\t"
"movq (%1, %%esi), %%mm0 \n\t"
"movq 8(%1, %%esi), %%mm1 \n\t"
"movq 1024(%1, %%esi), %%mm2 \n\t"
"movq 1032(%1, %%esi), %%mm3 \n\t"
"psubd %%mm7, %%mm0 \n\t"
"psubd %%mm7, %%mm1 \n\t"
"psubd %%mm7, %%mm2 \n\t"
"psubd %%mm7, %%mm3 \n\t"
"packssdw %%mm1, %%mm0 \n\t"
"packssdw %%mm3, %%mm2 \n\t"
"movq %%mm0, %%mm1 \n\t"
"punpcklwd %%mm2, %%mm0 \n\t"
"punpckhwd %%mm2, %%mm1 \n\t"
"movq %%mm0, (%0, %%esi) \n\t"
"movq %%mm1, 8(%0, %%esi) \n\t"
"addl $16, %%esi \n\t"
" jnz 1b \n\t"
"emms \n\t"
:: "r" (s16+512), "r" (f+256)
:"%esi", "memory"
);
return 2*256;
}
static int a52_resample_3F_to_5_MMX(float * _f, int16_t * s16){
int32_t * f = (int32_t *) _f;
asm volatile(
"movl $-1024, %%esi \n\t"
"movq "MANGLE(magicF2W)", %%mm7 \n\t"
"pxor %%mm6, %%mm6 \n\t"
"movq %%mm7, %%mm5 \n\t"
"punpckldq %%mm6, %%mm5 \n\t"
"1: \n\t"
"movd (%1, %%esi), %%mm0 \n\t"
"punpckldq 2048(%1, %%esi), %%mm0\n\t"
"movd 1024(%1, %%esi), %%mm1 \n\t"
"punpckldq 4(%1, %%esi), %%mm1 \n\t"
"movd 2052(%1, %%esi), %%mm2 \n\t"
"movq %%mm7, %%mm3 \n\t"
"punpckldq 1028(%1, %%esi), %%mm3\n\t"
"movd 8(%1, %%esi), %%mm4 \n\t"
"punpckldq 2056(%1, %%esi), %%mm4\n\t"
"leal (%%esi, %%esi, 4), %%edi \n\t"
"sarl $1, %%edi \n\t"
"psubd %%mm7, %%mm0 \n\t"
"psubd %%mm7, %%mm1 \n\t"
"psubd %%mm5, %%mm2 \n\t"
"psubd %%mm7, %%mm3 \n\t"
"psubd %%mm7, %%mm4 \n\t"
"packssdw %%mm6, %%mm0 \n\t"
"packssdw %%mm2, %%mm1 \n\t"
"packssdw %%mm4, %%mm3 \n\t"
"movq %%mm0, (%0, %%edi) \n\t"
"movq %%mm1, 8(%0, %%edi) \n\t"
"movq %%mm3, 16(%0, %%edi) \n\t"
"movd 1032(%1, %%esi), %%mm1 \n\t"
"punpckldq 12(%1, %%esi), %%mm1\n\t"
"movd 2060(%1, %%esi), %%mm2 \n\t"
"movq %%mm7, %%mm3 \n\t"
"punpckldq 1036(%1, %%esi), %%mm3\n\t"
"pxor %%mm0, %%mm0 \n\t"
"psubd %%mm7, %%mm1 \n\t"
"psubd %%mm5, %%mm2 \n\t"
"psubd %%mm7, %%mm3 \n\t"
"packssdw %%mm1, %%mm0 \n\t"
"packssdw %%mm3, %%mm2 \n\t"
"movq %%mm0, 24(%0, %%edi) \n\t"
"movq %%mm2, 32(%0, %%edi) \n\t"
"addl $16, %%esi \n\t"
" jnz 1b \n\t"
"emms \n\t"
:: "r" (s16+1280), "r" (f+256)
:"%esi", "%edi", "memory"
);
return 5*256;
}
static int a52_resample_2F_2R_to_4_MMX(float * _f, int16_t * s16){
int32_t * f = (int32_t *) _f;
asm volatile(
"movl $-1024, %%esi \n\t"
"movq "MANGLE(magicF2W)", %%mm7 \n\t"
"1: \n\t"
"movq (%1, %%esi), %%mm0 \n\t"
"movq 8(%1, %%esi), %%mm1 \n\t"
"movq 1024(%1, %%esi), %%mm2 \n\t"
"movq 1032(%1, %%esi), %%mm3 \n\t"
"psubd %%mm7, %%mm0 \n\t"
"psubd %%mm7, %%mm1 \n\t"
"psubd %%mm7, %%mm2 \n\t"
"psubd %%mm7, %%mm3 \n\t"
"packssdw %%mm1, %%mm0 \n\t"
"packssdw %%mm3, %%mm2 \n\t"
"movq 2048(%1, %%esi), %%mm3 \n\t"
"movq 2056(%1, %%esi), %%mm4 \n\t"
"movq 3072(%1, %%esi), %%mm5 \n\t"
"movq 3080(%1, %%esi), %%mm6 \n\t"
"psubd %%mm7, %%mm3 \n\t"
"psubd %%mm7, %%mm4 \n\t"
"psubd %%mm7, %%mm5 \n\t"
"psubd %%mm7, %%mm6 \n\t"
"packssdw %%mm4, %%mm3 \n\t"
"packssdw %%mm6, %%mm5 \n\t"
"movq %%mm0, %%mm1 \n\t"
"movq %%mm3, %%mm4 \n\t"
"punpcklwd %%mm2, %%mm0 \n\t"
"punpckhwd %%mm2, %%mm1 \n\t"
"punpcklwd %%mm5, %%mm3 \n\t"
"punpckhwd %%mm5, %%mm4 \n\t"
"movq %%mm0, %%mm2 \n\t"
"movq %%mm1, %%mm5 \n\t"
"punpckldq %%mm3, %%mm0 \n\t"
"punpckhdq %%mm3, %%mm2 \n\t"
"punpckldq %%mm4, %%mm1 \n\t"
"punpckhdq %%mm4, %%mm5 \n\t"
"movq %%mm0, (%0, %%esi,2) \n\t"
"movq %%mm2, 8(%0, %%esi,2) \n\t"
"movq %%mm1, 16(%0, %%esi,2) \n\t"
"movq %%mm5, 24(%0, %%esi,2) \n\t"
"addl $16, %%esi \n\t"
" jnz 1b \n\t"
"emms \n\t"
:: "r" (s16+1024), "r" (f+256)
:"%esi", "memory"
);
return 4*256;
}
static int a52_resample_3F_2R_to_5_MMX(float * _f, int16_t * s16){
int32_t * f = (int32_t *) _f;
asm volatile(
"movl $-1024, %%esi \n\t"
"movq "MANGLE(magicF2W)", %%mm7 \n\t"
"1: \n\t"
"movd (%1, %%esi), %%mm0 \n\t"
"punpckldq 2048(%1, %%esi), %%mm0\n\t"
"movd 3072(%1, %%esi), %%mm1 \n\t"
"punpckldq 4096(%1, %%esi), %%mm1\n\t"
"movd 1024(%1, %%esi), %%mm2 \n\t"
"punpckldq 4(%1, %%esi), %%mm2 \n\t"
"movd 2052(%1, %%esi), %%mm3 \n\t"
"punpckldq 3076(%1, %%esi), %%mm3\n\t"
"movd 4100(%1, %%esi), %%mm4 \n\t"
"punpckldq 1028(%1, %%esi), %%mm4\n\t"
"movd 8(%1, %%esi), %%mm5 \n\t"
"punpckldq 2056(%1, %%esi), %%mm5\n\t"
"leal (%%esi, %%esi, 4), %%edi \n\t"
"sarl $1, %%edi \n\t"
"psubd %%mm7, %%mm0 \n\t"
"psubd %%mm7, %%mm1 \n\t"
"psubd %%mm7, %%mm2 \n\t"
"psubd %%mm7, %%mm3 \n\t"
"psubd %%mm7, %%mm4 \n\t"
"psubd %%mm7, %%mm5 \n\t"
"packssdw %%mm1, %%mm0 \n\t"
"packssdw %%mm3, %%mm2 \n\t"
"packssdw %%mm5, %%mm4 \n\t"
"movq %%mm0, (%0, %%edi) \n\t"
"movq %%mm2, 8(%0, %%edi) \n\t"
"movq %%mm4, 16(%0, %%edi) \n\t"
"movd 3080(%1, %%esi), %%mm0 \n\t"
"punpckldq 4104(%1, %%esi), %%mm0\n\t"
"movd 1032(%1, %%esi), %%mm1 \n\t"
"punpckldq 12(%1, %%esi), %%mm1\n\t"
"movd 2060(%1, %%esi), %%mm2 \n\t"
"punpckldq 3084(%1, %%esi), %%mm2\n\t"
"movd 4108(%1, %%esi), %%mm3 \n\t"
"punpckldq 1036(%1, %%esi), %%mm3\n\t"
"psubd %%mm7, %%mm0 \n\t"
"psubd %%mm7, %%mm1 \n\t"
"psubd %%mm7, %%mm2 \n\t"
"psubd %%mm7, %%mm3 \n\t"
"packssdw %%mm1, %%mm0 \n\t"
"packssdw %%mm3, %%mm2 \n\t"
"movq %%mm0, 24(%0, %%edi) \n\t"
"movq %%mm2, 32(%0, %%edi) \n\t"
"addl $16, %%esi \n\t"
" jnz 1b \n\t"
"emms \n\t"
:: "r" (s16+1280), "r" (f+256)
:"%esi", "%edi", "memory"
);
return 5*256;
}
static int a52_resample_MONO_LFE_to_6_MMX(float * _f, int16_t * s16){
int32_t * f = (int32_t *) _f;
asm volatile(
"movl $-1024, %%esi \n\t"
"movq "MANGLE(magicF2W)", %%mm7 \n\t"
"pxor %%mm6, %%mm6 \n\t"
"1: \n\t"
"movq 1024(%1, %%esi), %%mm0 \n\t"
"movq 1032(%1, %%esi), %%mm1 \n\t"
"movq (%1, %%esi), %%mm2 \n\t"
"movq 8(%1, %%esi), %%mm3 \n\t"
"psubd %%mm7, %%mm0 \n\t"
"psubd %%mm7, %%mm1 \n\t"
"psubd %%mm7, %%mm2 \n\t"
"psubd %%mm7, %%mm3 \n\t"
"packssdw %%mm1, %%mm0 \n\t"
"packssdw %%mm3, %%mm2 \n\t"
"movq %%mm0, %%mm1 \n\t"
"punpcklwd %%mm2, %%mm0 \n\t"
"punpckhwd %%mm2, %%mm1 \n\t"
"leal (%%esi, %%esi, 2), %%edi \n\t"
"movq %%mm6, (%0, %%edi) \n\t"
"movd %%mm0, 8(%0, %%edi) \n\t"
"punpckhdq %%mm0, %%mm0 \n\t"
"movq %%mm6, 12(%0, %%edi) \n\t"
"movd %%mm0, 20(%0, %%edi) \n\t"
"movq %%mm6, 24(%0, %%edi) \n\t"
"movd %%mm1, 32(%0, %%edi) \n\t"
"punpckhdq %%mm1, %%mm1 \n\t"
"movq %%mm6, 36(%0, %%edi) \n\t"
"movd %%mm1, 44(%0, %%edi) \n\t"
"addl $16, %%esi \n\t"
" jnz 1b \n\t"
"emms \n\t"
:: "r" (s16+1536), "r" (f+256)
:"%esi", "%edi", "memory"
);
return 6*256;
}
static int a52_resample_STEREO_LFE_to_6_MMX(float * _f, int16_t * s16){
int32_t * f = (int32_t *) _f;
asm volatile(
"movl $-1024, %%esi \n\t"
"movq "MANGLE(magicF2W)", %%mm7 \n\t"
"pxor %%mm6, %%mm6 \n\t"
"1: \n\t"
"movq 1024(%1, %%esi), %%mm0 \n\t"
"movq 2048(%1, %%esi), %%mm1 \n\t"
"movq (%1, %%esi), %%mm5 \n\t"
"psubd %%mm7, %%mm0 \n\t"
"psubd %%mm7, %%mm1 \n\t"
"psubd %%mm7, %%mm5 \n\t"
"leal (%%esi, %%esi, 2), %%edi \n\t"
"pxor %%mm4, %%mm4 \n\t"
"packssdw %%mm5, %%mm0 \n\t" // FfAa
"packssdw %%mm4, %%mm1 \n\t" // 00Bb
"punpckhwd %%mm0, %%mm4 \n\t" // F0f0
"punpcklwd %%mm1, %%mm0 \n\t" // BAba
"movq %%mm0, %%mm1 \n\t" // BAba
"punpckldq %%mm4, %%mm3 \n\t" // f0XX
"punpckldq %%mm6, %%mm0 \n\t" // 00ba
"punpckhdq %%mm1, %%mm3 \n\t" // BAf0
"movq %%mm0, (%0, %%edi) \n\t" // 00ba
"punpckhdq %%mm4, %%mm0 \n\t" // F000
"movq %%mm3, 8(%0, %%edi) \n\t" // BAf0
"movq %%mm0, 16(%0, %%edi) \n\t" // F000
"addl $8, %%esi \n\t"
" jnz 1b \n\t"
"emms \n\t"
:: "r" (s16+1536), "r" (f+256)
:"%esi", "%edi", "memory"
);
return 6*256;
}
static int a52_resample_3F_LFE_to_6_MMX(float * _f, int16_t * s16){
int32_t * f = (int32_t *) _f;
asm volatile(
"movl $-1024, %%esi \n\t"
"movq "MANGLE(magicF2W)", %%mm7 \n\t"
"pxor %%mm6, %%mm6 \n\t"
"1: \n\t"
"movq 1024(%1, %%esi), %%mm0 \n\t"
"movq 3072(%1, %%esi), %%mm1 \n\t"
"movq 2048(%1, %%esi), %%mm4 \n\t"
"movq (%1, %%esi), %%mm5 \n\t"
"psubd %%mm7, %%mm0 \n\t"
"psubd %%mm7, %%mm1 \n\t"
"psubd %%mm7, %%mm4 \n\t"
"psubd %%mm7, %%mm5 \n\t"
"leal (%%esi, %%esi, 2), %%edi \n\t"
"packssdw %%mm4, %%mm0 \n\t" // EeAa
"packssdw %%mm5, %%mm1 \n\t" // FfBb
"movq %%mm0, %%mm2 \n\t" // EeAa
"punpcklwd %%mm1, %%mm0 \n\t" // BAba
"punpckhwd %%mm1, %%mm2 \n\t" // FEfe
"movq %%mm0, %%mm1 \n\t" // BAba
"punpckldq %%mm6, %%mm0 \n\t" // 00ba
"punpckhdq %%mm1, %%mm1 \n\t" // BABA
"movq %%mm0, (%0, %%edi) \n\t"
"punpckhdq %%mm2, %%mm0 \n\t" // FE00
"punpckldq %%mm1, %%mm2 \n\t" // BAfe
"movq %%mm2, 8(%0, %%edi) \n\t"
"movq %%mm0, 16(%0, %%edi) \n\t"
"addl $8, %%esi \n\t"
" jnz 1b \n\t"
"emms \n\t"
:: "r" (s16+1536), "r" (f+256)
:"%esi", "%edi", "memory"
);
return 6*256;
}
static int a52_resample_2F_2R_LFE_to_6_MMX(float * _f, int16_t * s16){
int32_t * f = (int32_t *) _f;
asm volatile(
"movl $-1024, %%esi \n\t"
"movq "MANGLE(magicF2W)", %%mm7 \n\t"
// "pxor %%mm6, %%mm6 \n\t"
"1: \n\t"
"movq 1024(%1, %%esi), %%mm0 \n\t"
"movq 2048(%1, %%esi), %%mm1 \n\t"
"movq 3072(%1, %%esi), %%mm2 \n\t"
"movq 4096(%1, %%esi), %%mm3 \n\t"
"movq (%1, %%esi), %%mm5 \n\t"
"psubd %%mm7, %%mm0 \n\t"
"psubd %%mm7, %%mm1 \n\t"
"psubd %%mm7, %%mm2 \n\t"
"psubd %%mm7, %%mm3 \n\t"
"psubd %%mm7, %%mm5 \n\t"
"leal (%%esi, %%esi, 2), %%edi \n\t"
"packssdw %%mm2, %%mm0 \n\t" // CcAa
"packssdw %%mm3, %%mm1 \n\t" // DdBb
"packssdw %%mm5, %%mm5 \n\t" // FfFf
"movq %%mm0, %%mm2 \n\t" // CcAa
"punpcklwd %%mm1, %%mm0 \n\t" // BAba
"punpckhwd %%mm1, %%mm2 \n\t" // DCdc
"pxor %%mm4, %%mm4 \n\t" // 0000
"punpcklwd %%mm5, %%mm4 \n\t" // F0f0
"movq %%mm0, %%mm1 \n\t" // BAba
"movq %%mm4, %%mm3 \n\t" // F0f0
"punpckldq %%mm2, %%mm0 \n\t" // dcba
"punpckhdq %%mm1, %%mm1 \n\t" // BABA
"punpckldq %%mm1, %%mm4 \n\t" // BAf0
"punpckhdq %%mm3, %%mm2 \n\t" // F0DC
"movq %%mm0, (%0, %%edi) \n\t"
"movq %%mm4, 8(%0, %%edi) \n\t"
"movq %%mm2, 16(%0, %%edi) \n\t"
"addl $8, %%esi \n\t"
" jnz 1b \n\t"
"emms \n\t"
:: "r" (s16+1536), "r" (f+256)
:"%esi", "%edi", "memory"
);
return 6*256;
}
static int a52_resample_3F_2R_LFE_to_6_MMX(float * _f, int16_t * s16){
int32_t * f = (int32_t *) _f;
asm volatile(
"movl $-1024, %%esi \n\t"
"movq "MANGLE(magicF2W)", %%mm7 \n\t"
// "pxor %%mm6, %%mm6 \n\t"
"1: \n\t"
"movq 1024(%1, %%esi), %%mm0 \n\t"
"movq 3072(%1, %%esi), %%mm1 \n\t"
"movq 4096(%1, %%esi), %%mm2 \n\t"
"movq 5120(%1, %%esi), %%mm3 \n\t"
"movq 2048(%1, %%esi), %%mm4 \n\t"
"movq (%1, %%esi), %%mm5 \n\t"
"psubd %%mm7, %%mm0 \n\t"
"psubd %%mm7, %%mm1 \n\t"
"psubd %%mm7, %%mm2 \n\t"
"psubd %%mm7, %%mm3 \n\t"
"psubd %%mm7, %%mm4 \n\t"
"psubd %%mm7, %%mm5 \n\t"
"leal (%%esi, %%esi, 2), %%edi \n\t"
"packssdw %%mm2, %%mm0 \n\t" // CcAa
"packssdw %%mm3, %%mm1 \n\t" // DdBb
"packssdw %%mm4, %%mm4 \n\t" // EeEe
"packssdw %%mm5, %%mm5 \n\t" // FfFf
"movq %%mm0, %%mm2 \n\t" // CcAa
"punpcklwd %%mm1, %%mm0 \n\t" // BAba
"punpckhwd %%mm1, %%mm2 \n\t" // DCdc
"punpcklwd %%mm5, %%mm4 \n\t" // FEfe
"movq %%mm0, %%mm1 \n\t" // BAba
"movq %%mm4, %%mm3 \n\t" // FEfe
"punpckldq %%mm2, %%mm0 \n\t" // dcba
"punpckhdq %%mm1, %%mm1 \n\t" // BABA
"punpckldq %%mm1, %%mm4 \n\t" // BAfe
"punpckhdq %%mm3, %%mm2 \n\t" // FEDC
"movq %%mm0, (%0, %%edi) \n\t"
"movq %%mm4, 8(%0, %%edi) \n\t"
"movq %%mm2, 16(%0, %%edi) \n\t"
"addl $8, %%esi \n\t"
" jnz 1b \n\t"
"emms \n\t"
:: "r" (s16+1536), "r" (f+256)
:"%esi", "%edi", "memory"
);
return 6*256;
}
static void* a52_resample_MMX(int flags, int ch){
switch (flags) {
case A52_MONO:
if(ch==5) return a52_resample_MONO_to_5_MMX;
break;
case A52_CHANNEL:
case A52_STEREO:
case A52_DOLBY:
if(ch==2) return a52_resample_STEREO_to_2_MMX;
break;
case A52_3F:
if(ch==5) return a52_resample_3F_to_5_MMX;
break;
case A52_2F2R:
if(ch==4) return a52_resample_2F_2R_to_4_MMX;
break;
case A52_3F2R:
if(ch==5) return a52_resample_3F_2R_to_5_MMX;
break;
case A52_MONO | A52_LFE:
if(ch==6) return a52_resample_MONO_LFE_to_6_MMX;
break;
case A52_CHANNEL | A52_LFE:
case A52_STEREO | A52_LFE:
case A52_DOLBY | A52_LFE:
if(ch==6) return a52_resample_STEREO_LFE_to_6_MMX;
break;
case A52_3F | A52_LFE:
if(ch==6) return a52_resample_3F_LFE_to_6_MMX;
break;
case A52_2F2R | A52_LFE:
if(ch==6) return a52_resample_2F_2R_LFE_to_6_MMX;
break;
case A52_3F2R | A52_LFE:
if(ch==6) return a52_resample_3F_2R_LFE_to_6_MMX;
break;
}
return NULL;
}
/*
* tables.h
* Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
* Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
*
* This file is part of a52dec, a free ATSC A-52 stream decoder.
* See http://liba52.sourceforge.net/ for updates.
*
* a52dec is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* a52dec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
static const int8_t exp_1[128] = {
-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
25,25,25
};
static const int8_t exp_2[128] = {
-2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
-2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
-2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
-2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
-2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
25,25,25
};
static const int8_t exp_3[128] = {
-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
25,25,25
};
#define Q(x) ROUND (32768.0 * x)
#define Q0 Q (-2/3)
#define Q1 Q (0)
#define Q2 Q (2/3)
static const quantizer_t q_1_0[32] = {
Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0,
Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1,
Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2,
0, 0, 0, 0, 0
};
static const quantizer_t q_1_1[32] = {
Q0, Q0, Q0, Q1, Q1, Q1, Q2, Q2, Q2,
Q0, Q0, Q0, Q1, Q1, Q1, Q2, Q2, Q2,
Q0, Q0, Q0, Q1, Q1, Q1, Q2, Q2, Q2,
0, 0, 0, 0, 0
};
static const quantizer_t q_1_2[32] = {
Q0, Q1, Q2, Q0, Q1, Q2, Q0, Q1, Q2,
Q0, Q1, Q2, Q0, Q1, Q2, Q0, Q1, Q2,
Q0, Q1, Q2, Q0, Q1, Q2, Q0, Q1, Q2,
0, 0, 0, 0, 0
};
#undef Q0
#undef Q1
#undef Q2
#define Q0 Q (-4/5)
#define Q1 Q (-2/5)
#define Q2 Q (0)
#define Q3 Q (2/5)
#define Q4 Q (4/5)
static const quantizer_t q_2_0[128] = {
Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,
Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,
Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,
Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,
Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,
0,0,0
};
static const quantizer_t q_2_1[128] = {
Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4,
Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4,
Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4,
Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4,
Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4,
0,0,0
};
static const quantizer_t q_2_2[128] = {
Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,
Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,
Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,
Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,
Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,
0,0,0
};
#undef Q0
#undef Q1
#undef Q2
#undef Q3
#undef Q4
static const quantizer_t q_3[8] = {
Q (-6/7), Q (-4/7), Q (-2/7), Q (0), Q (2/7), Q (4/7), Q (6/7), 0
};
#define Q0 Q (-10/11)
#define Q1 Q (-8/11)
#define Q2 Q (-6/11)
#define Q3 Q (-4/11)
#define Q4 Q (-2/11)
#define Q5 Q (0)
#define Q6 Q (2/11)
#define Q7 Q (4/11)
#define Q8 Q (6/11)
#define Q9 Q (8/11)
#define QA Q (10/11)
static const quantizer_t q_4_0[128] = {
Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0,
Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1,
Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2,
Q3, Q3, Q3, Q3, Q3, Q3, Q3, Q3, Q3, Q3, Q3,
Q4, Q4, Q4, Q4, Q4, Q4, Q4, Q4, Q4, Q4, Q4,
Q5, Q5, Q5, Q5, Q5, Q5, Q5, Q5, Q5, Q5, Q5,
Q6, Q6, Q6, Q6, Q6, Q6, Q6, Q6, Q6, Q6, Q6,
Q7, Q7, Q7, Q7, Q7, Q7, Q7, Q7, Q7, Q7, Q7,
Q8, Q8, Q8, Q8, Q8, Q8, Q8, Q8, Q8, Q8, Q8,
Q9, Q9, Q9, Q9, Q9, Q9, Q9, Q9, Q9, Q9, Q9,
QA, QA, QA, QA, QA, QA, QA, QA, QA, QA, QA,
0, 0, 0, 0, 0, 0, 0
};
static const quantizer_t q_4_1[128] = {
Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
0, 0, 0, 0, 0, 0, 0
};
#undef Q0
#undef Q1
#undef Q2
#undef Q3
#undef Q4
#undef Q5
#undef Q6
#undef Q7
#undef Q8
#undef Q9
#undef QA
static const quantizer_t q_5[16] = {
Q (-14/15), Q (-12/15), Q (-10/15), Q (-8/15), Q (-6/15),
Q (-4/15), Q (-2/15), Q (0), Q (2/15), Q (4/15),
Q (6/15), Q (8/15), Q (10/15), Q (12/15), Q (14/15), 0
};
#ifndef LIBA52_FIXED
static const sample_t scale_factor[25] = {
0.000030517578125,
0.0000152587890625,
0.00000762939453125,
0.000003814697265625,
0.0000019073486328125,
0.00000095367431640625,
0.000000476837158203125,
0.0000002384185791015625,
0.00000011920928955078125,
0.000000059604644775390625,
0.0000000298023223876953125,
0.00000001490116119384765625,
0.000000007450580596923828125,
0.0000000037252902984619140625,
0.00000000186264514923095703125,
0.000000000931322574615478515625,
0.0000000004656612873077392578125,
0.00000000023283064365386962890625,
0.000000000116415321826934814453125,
0.0000000000582076609134674072265625,
0.00000000002910383045673370361328125,
0.000000000014551915228366851806640625,
0.0000000000072759576141834259033203125,
0.00000000000363797880709171295166015625,
0.000000000001818989403545856475830078125
};
#endif
static const uint16_t dither_lut[256] = {
0x0000, 0xa011, 0xe033, 0x4022, 0x6077, 0xc066, 0x8044, 0x2055,
0xc0ee, 0x60ff, 0x20dd, 0x80cc, 0xa099, 0x0088, 0x40aa, 0xe0bb,
0x21cd, 0x81dc, 0xc1fe, 0x61ef, 0x41ba, 0xe1ab, 0xa189, 0x0198,
0xe123, 0x4132, 0x0110, 0xa101, 0x8154, 0x2145, 0x6167, 0xc176,
0x439a, 0xe38b, 0xa3a9, 0x03b8, 0x23ed, 0x83fc, 0xc3de, 0x63cf,
0x8374, 0x2365, 0x6347, 0xc356, 0xe303, 0x4312, 0x0330, 0xa321,
0x6257, 0xc246, 0x8264, 0x2275, 0x0220, 0xa231, 0xe213, 0x4202,
0xa2b9, 0x02a8, 0x428a, 0xe29b, 0xc2ce, 0x62df, 0x22fd, 0x82ec,
0x8734, 0x2725, 0x6707, 0xc716, 0xe743, 0x4752, 0x0770, 0xa761,
0x47da, 0xe7cb, 0xa7e9, 0x07f8, 0x27ad, 0x87bc, 0xc79e, 0x678f,
0xa6f9, 0x06e8, 0x46ca, 0xe6db, 0xc68e, 0x669f, 0x26bd, 0x86ac,
0x6617, 0xc606, 0x8624, 0x2635, 0x0660, 0xa671, 0xe653, 0x4642,
0xc4ae, 0x64bf, 0x249d, 0x848c, 0xa4d9, 0x04c8, 0x44ea, 0xe4fb,
0x0440, 0xa451, 0xe473, 0x4462, 0x6437, 0xc426, 0x8404, 0x2415,
0xe563, 0x4572, 0x0550, 0xa541, 0x8514, 0x2505, 0x6527, 0xc536,
0x258d, 0x859c, 0xc5be, 0x65af, 0x45fa, 0xe5eb, 0xa5c9, 0x05d8,
0xae79, 0x0e68, 0x4e4a, 0xee5b, 0xce0e, 0x6e1f, 0x2e3d, 0x8e2c,
0x6e97, 0xce86, 0x8ea4, 0x2eb5, 0x0ee0, 0xaef1, 0xeed3, 0x4ec2,
0x8fb4, 0x2fa5, 0x6f87, 0xcf96, 0xefc3, 0x4fd2, 0x0ff0, 0xafe1,
0x4f5a, 0xef4b, 0xaf69, 0x0f78, 0x2f2d, 0x8f3c, 0xcf1e, 0x6f0f,
0xede3, 0x4df2, 0x0dd0, 0xadc1, 0x8d94, 0x2d85, 0x6da7, 0xcdb6,
0x2d0d, 0x8d1c, 0xcd3e, 0x6d2f, 0x4d7a, 0xed6b, 0xad49, 0x0d58,
0xcc2e, 0x6c3f, 0x2c1d, 0x8c0c, 0xac59, 0x0c48, 0x4c6a, 0xec7b,
0x0cc0, 0xacd1, 0xecf3, 0x4ce2, 0x6cb7, 0xcca6, 0x8c84, 0x2c95,
0x294d, 0x895c, 0xc97e, 0x696f, 0x493a, 0xe92b, 0xa909, 0x0918,
0xe9a3, 0x49b2, 0x0990, 0xa981, 0x89d4, 0x29c5, 0x69e7, 0xc9f6,
0x0880, 0xa891, 0xe8b3, 0x48a2, 0x68f7, 0xc8e6, 0x88c4, 0x28d5,
0xc86e, 0x687f, 0x285d, 0x884c, 0xa819, 0x0808, 0x482a, 0xe83b,
0x6ad7, 0xcac6, 0x8ae4, 0x2af5, 0x0aa0, 0xaab1, 0xea93, 0x4a82,
0xaa39, 0x0a28, 0x4a0a, 0xea1b, 0xca4e, 0x6a5f, 0x2a7d, 0x8a6c,
0x4b1a, 0xeb0b, 0xab29, 0x0b38, 0x2b6d, 0x8b7c, 0xcb5e, 0x6b4f,
0x8bf4, 0x2be5, 0x6bc7, 0xcbd6, 0xeb83, 0x4b92, 0x0bb0, 0xaba1
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册