Commit 6bc7ac7c authored by Michel Kaempf's avatar Michel Kaempf

* Modification de l'input afin de spawner un d�codeur ac3 lorsqu'un tel flux

est d�tect� ;

* Impl�mentation du d�codeur ac3 ;

* Il est rewlz(ac3dec) - 2h00 :-)
parent b9dc0c52
......@@ -176,7 +176,14 @@ video_output_obj = video_output/video_output.o \
video_output/video_$(video).o \
video_output/video_yuv_c.o
ac3_decoder_obj = ac3_decoder/ac3_decoder.o
ac3_decoder_obj = ac3_decoder/ac3_decoder.o \
ac3_decoder/ac3_parse.o \
ac3_decoder/ac3_exponent.o \
ac3_decoder/ac3_bit_allocate.o \
ac3_decoder/ac3_mantissa.o \
ac3_decoder/ac3_rematrix.o \
ac3_decoder/ac3_imdct.o \
ac3_decoder/ac3_downmix.o
audio_decoder_obj = audio_decoder/audio_decoder.o \
audio_decoder/audio_math.o
......
void bit_allocate( ac3dec_thread_t * );
......@@ -3,6 +3,320 @@
* (c)1999 VideoLAN
*****************************************************************************/
/* Exponent strategy constants */
#define EXP_REUSE (0)
#define EXP_D15 (1)
#define EXP_D25 (2)
#define EXP_D45 (3)
/* Delta bit allocation constants */
#define DELTA_BIT_REUSE (0)
#define DELTA_BIT_NEW (1)
#define DELTA_BIT_NONE (2)
#define DELTA_BIT_RESERVED (3)
/* The following structures are filled in by their corresponding parse_*
* functions. See http://www.atsc.org/Standards/A52/a_52.pdf for
* full details on each field. Indented fields are used to denote
* conditional fields.
*/
typedef struct syncinfo_s
{
/* Sync word == 0x0B77 */
/* u16 syncword; */
/* crc for the first 5/8 of the sync block */
/* u16 crc1; */
/* Stream Sampling Rate (kHz) 0 = 48, 1 = 44.1, 2 = 32, 3 = reserved */
u16 fscod;
/* Frame size code */
u16 frmsizecod;
/* Information not in the AC-3 bitstream, but derived */
/* Frame size in 16 bit words */
u16 frame_size;
/* Bit rate in kilobits */
u16 bit_rate;
} syncinfo_t;
typedef struct bsi_s
{
/* Bit stream identification == 0x8 */
u16 bsid;
/* Bit stream mode */
u16 bsmod;
/* Audio coding mode */
u16 acmod;
/* If we're using the centre channel then */
/* centre mix level */
u16 cmixlev;
/* If we're using the surround channel then */
/* surround mix level */
u16 surmixlev;
/* If we're in 2/0 mode then */
/* Dolby surround mix level - NOT USED - */
u16 dsurmod;
/* Low frequency effects on */
u16 lfeon;
/* Dialogue Normalization level */
u16 dialnorm;
/* Compression exists */
u16 compre;
/* Compression level */
u16 compr;
/* Language code exists */
u16 langcode;
/* Language code */
u16 langcod;
/* Audio production info exists*/
u16 audprodie;
u16 mixlevel;
u16 roomtyp;
/* If we're in dual mono mode (acmod == 0) then extra stuff */
u16 dialnorm2;
u16 compr2e;
u16 compr2;
u16 langcod2e;
u16 langcod2;
u16 audprodi2e;
u16 mixlevel2;
u16 roomtyp2;
/* Copyright bit */
u16 copyrightb;
/* Original bit */
u16 origbs;
/* Timecode 1 exists */
u16 timecod1e;
/* Timecode 1 */
u16 timecod1;
/* Timecode 2 exists */
u16 timecod2e;
/* Timecode 2 */
u16 timecod2;
/* Additional bit stream info exists */
u16 addbsie;
/* Additional bit stream length - 1 (in bytes) */
u16 addbsil;
/* Additional bit stream information (max 64 bytes) */
u8 addbsi[64];
/* Information not in the AC-3 bitstream, but derived */
/* Number of channels (excluding LFE)
* Derived from acmod */
u16 nfchans;
} bsi_t;
/* more pain */
typedef struct audblk_s
{
/* block switch bit indexed by channel num */
u16 blksw[5];
/* dither enable bit indexed by channel num */
u16 dithflag[5];
/* dynamic range gain exists */
u16 dynrnge;
/* dynamic range gain */
u16 dynrng;
/* if acmod==0 then */
/* dynamic range 2 gain exists */
u16 dynrng2e;
/* dynamic range 2 gain */
u16 dynrng2;
/* coupling strategy exists */
u16 cplstre;
/* coupling in use */
u16 cplinu;
/* channel coupled */
u16 chincpl[5];
/* if acmod==2 then */
/* Phase flags in use */
u16 phsflginu;
/* coupling begin frequency code */
u16 cplbegf;
/* coupling end frequency code */
u16 cplendf;
/* coupling band structure bits */
u16 cplbndstrc[18];
/* Do coupling co-ords exist for this channel? */
u16 cplcoe[5];
/* Master coupling co-ordinate */
u16 mstrcplco[5];
/* Per coupling band coupling co-ordinates */
u16 cplcoexp[5][18];
u16 cplcomant[5][18];
/* Phase flags for dual mono */
u16 phsflg[18];
/* Is there a rematrixing strategy */
u16 rematstr;
/* Rematrixing bits */
u16 rematflg[4];
/* Coupling exponent strategy */
u16 cplexpstr;
/* Exponent strategy for full bandwidth channels */
u16 chexpstr[5];
/* Exponent strategy for lfe channel */
u16 lfeexpstr;
/* Channel bandwidth for independent channels */
u16 chbwcod[5];
/* The absolute coupling exponent */
u16 cplabsexp;
/* Coupling channel exponents (D15 mode gives 18 * 12 /3 encoded exponents */
u16 cplexps[18 * 12 / 3];
/* Sanity checking constant */
u32 magic2;
/* fbw channel exponents */
u16 exps[5][252 / 3];
/* channel gain range */
u16 gainrng[5];
/* low frequency exponents */
u16 lfeexps[3];
/* Bit allocation info */
u16 baie;
/* Slow decay code */
u16 sdcycod;
/* Fast decay code */
u16 fdcycod;
/* Slow gain code */
u16 sgaincod;
/* dB per bit code */
u16 dbpbcod;
/* masking floor code */
u16 floorcod;
/* SNR offset info */
u16 snroffste;
/* coarse SNR offset */
u16 csnroffst;
/* coupling fine SNR offset */
u16 cplfsnroffst;
/* coupling fast gain code */
u16 cplfgaincod;
/* fbw fine SNR offset */
u16 fsnroffst[5];
/* fbw fast gain code */
u16 fgaincod[5];
/* lfe fine SNR offset */
u16 lfefsnroffst;
/* lfe fast gain code */
u16 lfefgaincod;
/* Coupling leak info */
u16 cplleake;
/* coupling fast leak initialization */
u16 cplfleak;
/* coupling slow leak initialization */
u16 cplsleak;
/* delta bit allocation info */
u16 deltbaie;
/* coupling delta bit allocation exists */
u16 cpldeltbae;
/* fbw delta bit allocation exists */
u16 deltbae[5];
/* number of cpl delta bit segments */
u16 cpldeltnseg;
/* coupling delta bit allocation offset */
u16 cpldeltoffst[8];
/* coupling delta bit allocation length */
u16 cpldeltlen[8];
/* coupling delta bit allocation length */
u16 cpldeltba[8];
/* number of delta bit segments */
u16 deltnseg[5];
/* fbw delta bit allocation offset */
u16 deltoffst[5][8];
/* fbw delta bit allocation length */
u16 deltlen[5][8];
/* fbw delta bit allocation length */
u16 deltba[5][8];
/* skip length exists */
u16 skiple;
/* skip length */
u16 skipl;
/* channel mantissas */
// u16 chmant[5][256];
/* coupling mantissas */
float cplfbw[ 256 ];
// u16 cplmant[256];
/* coupling mantissas */
// u16 lfemant[7];
/* -- Information not in the bitstream, but derived thereof -- */
/* Number of coupling sub-bands */
u16 ncplsubnd;
/* Number of combined coupling sub-bands
* Derived from ncplsubnd and cplbndstrc */
u16 ncplbnd;
/* Number of exponent groups by channel
* Derived from strmant, endmant */
u16 nchgrps[5];
/* Number of coupling exponent groups
* Derived from cplbegf, cplendf, cplexpstr */
u16 ncplgrps;
/* End mantissa numbers of fbw channels */
u16 endmant[5];
/* Start and end mantissa numbers for the coupling channel */
u16 cplstrtmant;
u16 cplendmant;
/* Decoded exponent info */
u16 fbw_exp[5][256];
u16 cpl_exp[256];
u16 lfe_exp[7];
/* Bit allocation pointer results */
u16 fbw_bap[5][256];
//FIXME figure out exactly how many entries there should be (253-37?)
u16 cpl_bap[256];
u16 lfe_bap[7];
} audblk_t;
/* Everything you wanted to know about band structure */
/*
* The entire frequency domain is represented by 256 real
* floating point fourier coefficients. Only the lower 253
* coefficients are actually utilized however. We use arrays
* of 256 to be efficient in some cases.
*
* The 5 full bandwidth channels (fbw) can have their higher
* frequencies coupled together. These coupled channels then
* share their high frequency components.
*
* This coupling band is broken up into 18 sub-bands starting
* at mantissa number 37. Each sub-band is 12 bins wide.
*
* There are 50 bit allocation sub-bands which cover the entire
* frequency range. The sub-bands are of non-uniform width, and
* approximate a 1/6 octave scale.
*/
typedef struct stream_coeffs_s
{
float fbw[5][256];
float lfe[256];
} stream_coeffs_t;
typedef struct stream_samples_s
{
float channel[6][256];
} stream_samples_t;
#define AC3DEC_FRAME_SIZE (2*256)
/*****************************************************************************
......@@ -34,6 +348,13 @@ typedef struct ac3dec_thread_s
*/
unsigned int total_bits_read;
syncinfo_t syncinfo;
bsi_t bsi;
audblk_t audblk;
stream_coeffs_t coeffs;
stream_samples_t samples;
/*
* Output properties
*/
......
void downmix( ac3dec_thread_t *, s16 * );
#define UNPACK_FBW 1
#define UNPACK_CPL 2
#define UNPACK_LFE 4
void exponent_unpack( ac3dec_thread_t * );
void imdct( ac3dec_thread_t * p_ac3dec );
void imdct_init( void );
void mantissa_unpack( ac3dec_thread_t * );
void parse_syncinfo( ac3dec_thread_t * );
void parse_bsi( ac3dec_thread_t * );
void parse_audblk( ac3dec_thread_t * );
void parse_auxdata( ac3dec_thread_t * );
void rematrix( ac3dec_thread_t * );
......@@ -164,7 +164,7 @@ typedef struct
#define MPEG2_VIDEO_ES 0x02
#define MPEG1_AUDIO_ES 0x03
#define MPEG2_AUDIO_ES 0x04
#define AC3_AUDIO_ES 0x81
/******************************************************************************
* program_descriptor_t
......
#include <unistd.h> /* getpid() */
#include <stdio.h> /* "intf_msg.h" */
#include <stdlib.h> /* malloc(), free() */
#include <sys/soundcard.h> /* "audio_output.h" */
#include <sys/uio.h> /* "input.h" */
#include "common.h"
#include "config.h"
#include "mtime.h"
#include "vlc_thread.h"
#include "debug.h" /* "input_netlist.h" */
#include "intf_msg.h" /* intf_DbgMsg(), intf_ErrMsg() */
#include "input.h" /* pes_packet_t */
#include "input_netlist.h" /* input_NetlistFreePES() */
#include "decoder_fifo.h" /* DECODER_FIFO_(ISEMPTY|START|INCSTART)() */
#include "audio_output.h"
#include "ac3_decoder.h"
#include "ac3_bit_allocate.h"
/*
static inline s16 logadd(s16 a,s16 b);
static s16 calc_lowcomp(s16 a,s16 b0,s16 b1,s16 bin);
static inline u16 min(s16 a,s16 b);
static inline u16 max(s16 a,s16 b);
*/
static void ba_compute_psd(s16 start, s16 end, s16 exps[],
s16 psd[], s16 bndpsd[]);
static void ba_compute_excitation(s16 start, s16 end,s16 fgain,
s16 fastleak, s16 slowleak, s16 is_lfe, s16 bndpsd[],
s16 excite[]);
static void ba_compute_mask(s16 start, s16 end, u16 fscod,
u16 deltbae, u16 deltnseg, u16 deltoffst[], u16 deltba[],
u16 deltlen[], s16 excite[], s16 mask[]);
static void ba_compute_bap(s16 start, s16 end, s16 snroffset,
s16 psd[], s16 mask[], s16 bap[]);
/* Misc LUTs for bit allocation process */
static s16 slowdec[] = { 0x0f, 0x11, 0x13, 0x15 };
static s16 fastdec[] = { 0x3f, 0x53, 0x67, 0x7b };
static s16 slowgain[] = { 0x540, 0x4d8, 0x478, 0x410 };
static s16 dbpbtab[] = { 0x000, 0x700, 0x900, 0xb00 };
static u16 floortab[] = { 0x2f0, 0x2b0, 0x270, 0x230, 0x1f0, 0x170, 0x0f0, 0xf800 };
static s16 fastgain[] = { 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400 };
static s16 bndtab[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 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 };
static s16 bndsz[] = { 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, 3, 3,
3, 3, 3, 3, 3, 6, 6, 6, 6, 6,
6, 12, 12, 12, 12, 24, 24, 24, 24, 24 };
static s16 masktab[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 28, 28, 29,
29, 29, 30, 30, 30, 31, 31, 31, 32, 32, 32, 33, 33, 33, 34, 34,
34, 35, 35, 35, 35, 35, 35, 36, 36, 36, 36, 36, 36, 37, 37, 37,
37, 37, 37, 38, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 40,
40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
41, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 43, 43, 43,
43, 43, 43, 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 46, 46, 46,
46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 48, 48, 48,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 0, 0, 0 };
static s16 latab[] = { 0x0040, 0x003f, 0x003e, 0x003d, 0x003c, 0x003b, 0x003a, 0x0039,
0x0038, 0x0037, 0x0036, 0x0035, 0x0034, 0x0034, 0x0033, 0x0032,
0x0031, 0x0030, 0x002f, 0x002f, 0x002e, 0x002d, 0x002c, 0x002c,
0x002b, 0x002a, 0x0029, 0x0029, 0x0028, 0x0027, 0x0026, 0x0026,
0x0025, 0x0024, 0x0024, 0x0023, 0x0023, 0x0022, 0x0021, 0x0021,
0x0020, 0x0020, 0x001f, 0x001e, 0x001e, 0x001d, 0x001d, 0x001c,
0x001c, 0x001b, 0x001b, 0x001a, 0x001a, 0x0019, 0x0019, 0x0018,
0x0018, 0x0017, 0x0017, 0x0016, 0x0016, 0x0015, 0x0015, 0x0015,
0x0014, 0x0014, 0x0013, 0x0013, 0x0013, 0x0012, 0x0012, 0x0012,
0x0011, 0x0011, 0x0011, 0x0010, 0x0010, 0x0010, 0x000f, 0x000f,
0x000f, 0x000e, 0x000e, 0x000e, 0x000d, 0x000d, 0x000d, 0x000d,
0x000c, 0x000c, 0x000c, 0x000c, 0x000b, 0x000b, 0x000b, 0x000b,
0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x0009, 0x0009, 0x0009,
0x0009, 0x0009, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0006, 0x0006,
0x0006, 0x0006, 0x0006, 0x0006, 0x0006, 0x0006, 0x0005, 0x0005,
0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0004, 0x0004,
0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
0x0004, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0002,
0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
0x0002, 0x0002, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001,
0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001,
0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001,
0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001,
0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000};
static s16 hth[][50] = {{ 0x04d0, 0x04d0, 0x0440, 0x0400, 0x03e0, 0x03c0, 0x03b0, 0x03b0,
0x03a0, 0x03a0, 0x03a0, 0x03a0, 0x03a0, 0x0390, 0x0390, 0x0390,
0x0380, 0x0380, 0x0370, 0x0370, 0x0360, 0x0360, 0x0350, 0x0350,
0x0340, 0x0340, 0x0330, 0x0320, 0x0310, 0x0300, 0x02f0, 0x02f0,
0x02f0, 0x02f0, 0x0300, 0x0310, 0x0340, 0x0390, 0x03e0, 0x0420,
0x0460, 0x0490, 0x04a0, 0x0460, 0x0440, 0x0440, 0x0520, 0x0800,
0x0840, 0x0840 },
{ 0x04f0, 0x04f0, 0x0460, 0x0410, 0x03e0, 0x03d0, 0x03c0, 0x03b0,
0x03b0, 0x03a0, 0x03a0, 0x03a0, 0x03a0, 0x03a0, 0x0390, 0x0390,
0x0390, 0x0380, 0x0380, 0x0380, 0x0370, 0x0370, 0x0360, 0x0360,
0x0350, 0x0350, 0x0340, 0x0340, 0x0320, 0x0310, 0x0300, 0x02f0,
0x02f0, 0x02f0, 0x02f0, 0x0300, 0x0320, 0x0350, 0x0390, 0x03e0,
0x0420, 0x0450, 0x04a0, 0x0490, 0x0460, 0x0440, 0x0480, 0x0630,
0x0840, 0x0840 },
{ 0x0580, 0x0580, 0x04b0, 0x0450, 0x0420, 0x03f0, 0x03e0, 0x03d0,
0x03c0, 0x03b0, 0x03b0, 0x03b0, 0x03a0, 0x03a0, 0x03a0, 0x03a0,
0x03a0, 0x03a0, 0x03a0, 0x03a0, 0x0390, 0x0390, 0x0390, 0x0390,
0x0380, 0x0380, 0x0380, 0x0370, 0x0360, 0x0350, 0x0340, 0x0330,
0x0320, 0x0310, 0x0300, 0x02f0, 0x02f0, 0x02f0, 0x0300, 0x0310,
0x0330, 0x0350, 0x03c0, 0x0410, 0x0470, 0x04a0, 0x0460, 0x0440,
0x0450, 0x04e0 }};
static s16 baptab[] = { 0, 1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6,
6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10,
10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14,
14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15 };
static s16 sdecay;
static s16 fdecay;
static s16 sgain;
static s16 dbknee;
static s16 floor;
static s16 psd[256];
static s16 bndpsd[256];
static s16 excite[256];
static s16 mask[256];
static __inline__ u16 max( s16 a, s16 b )
{
return( a > b ? a : b );
}
static __inline__ u16 min( s16 a, s16 b )
{
return( a < b ? a : b );
}
static __inline__ s16 logadd( s16 a, s16 b )
{
s16 c;
if ( (c = a - b) >= 0 )
{
return( a + latab[min(((c) >> 1), 255)] );
}
else
{
return( b + latab[min(((-c) >> 1), 255)] );
}
}
static __inline__ s16 calc_lowcomp( s16 a, s16 b0, s16 b1, s16 bin )
{
if (bin < 7)
{
if ((b0 + 256) == b1)
a = 384;
else if (b0 > b1)
a = max(0, a - 64);
}
else if (bin < 20)
{
if ((b0 + 256) == b1)
a = 320;
else if (b0 > b1)
a = max(0, a - 64) ;
}
else
a = max(0, a - 128);
return(a);
}
void bit_allocate( ac3dec_thread_t * p_ac3dec )
{
u16 i;
s16 fgain;
s16 snroffset;
s16 start;
s16 end;
s16 fastleak;
s16 slowleak;
/* Only perform bit_allocation if the exponents have changed or we
* have new sideband information */
if (p_ac3dec->audblk.chexpstr[0] == 0 && p_ac3dec->audblk.chexpstr[1] == 0 &&
p_ac3dec->audblk.chexpstr[2] == 0 && p_ac3dec->audblk.chexpstr[3] == 0 &&
p_ac3dec->audblk.chexpstr[4] == 0 && p_ac3dec->audblk.cplexpstr == 0 &&
p_ac3dec->audblk.lfeexpstr == 0 && p_ac3dec->audblk.baie == 0 &&
p_ac3dec->audblk.snroffste == 0 && p_ac3dec->audblk.deltbaie == 0)
return;
/* Do some setup before we do the bit alloc */
sdecay = slowdec[p_ac3dec->audblk.sdcycod];
fdecay = fastdec[p_ac3dec->audblk.fdcycod];
sgain = slowgain[p_ac3dec->audblk.sgaincod];
dbknee = dbpbtab[p_ac3dec->audblk.dbpbcod];
floor = floortab[p_ac3dec->audblk.floorcod];
/* if all the SNR offset constants are zero then the whole block is zero */
if(!p_ac3dec->audblk.csnroffst && !p_ac3dec->audblk.fsnroffst[0] &&
!p_ac3dec->audblk.fsnroffst[1] && !p_ac3dec->audblk.fsnroffst[2] &&
!p_ac3dec->audblk.fsnroffst[3] && !p_ac3dec->audblk.fsnroffst[4] &&
!p_ac3dec->audblk.cplfsnroffst && !p_ac3dec->audblk.lfefsnroffst)
{
memset(p_ac3dec->audblk.fbw_bap,0,sizeof(u16) * 256 * 5);
memset(p_ac3dec->audblk.cpl_bap,0,sizeof(u16) * 256);
memset(p_ac3dec->audblk.lfe_bap,0,sizeof(u16) * 7);
return;
}
for(i = 0; i < p_ac3dec->bsi.nfchans; i++)
{
start = 0;
end = p_ac3dec->audblk.endmant[i] ;
fgain = fastgain[p_ac3dec->audblk.fgaincod[i]];
snroffset = (((p_ac3dec->audblk.csnroffst - 15) << 4) + p_ac3dec->audblk.fsnroffst[i]) << 2 ;
fastleak = 0;
slowleak = 0;
ba_compute_psd(start, end, p_ac3dec->audblk.fbw_exp[i], psd, bndpsd);
ba_compute_excitation(start, end , fgain, fastleak, slowleak, 0, bndpsd, excite);
// if ( p_ac3dec->audblk.deltnseg[i] >= 8 )
// fprintf( stderr, "ba debug: p_ac3dec->audblk.deltnseg[%i] == %i\n", i, p_ac3dec->audblk.deltnseg[i] );
ba_compute_mask(start, end, p_ac3dec->syncinfo.fscod, p_ac3dec->audblk.deltbae[i], p_ac3dec->audblk.deltnseg[i], p_ac3dec->audblk.deltoffst[i], p_ac3dec->audblk.deltba[i], p_ac3dec->audblk.deltlen[i], excite, mask);
ba_compute_bap(start, end, snroffset, psd, mask, p_ac3dec->audblk.fbw_bap[i]);
}
if(p_ac3dec->audblk.cplinu)
{
start = p_ac3dec->audblk.cplstrtmant;
end = p_ac3dec->audblk.cplendmant;
fgain = fastgain[p_ac3dec->audblk.cplfgaincod];
snroffset = (((p_ac3dec->audblk.csnroffst - 15) << 4) + p_ac3dec->audblk.cplfsnroffst) << 2 ;
fastleak = (p_ac3dec->audblk.cplfleak << 8) + 768;
slowleak = (p_ac3dec->audblk.cplsleak << 8) + 768;
ba_compute_psd(start, end, p_ac3dec->audblk.cpl_exp, psd, bndpsd);
ba_compute_excitation(start, end , fgain, fastleak, slowleak, 0, bndpsd, excite);
ba_compute_mask(start, end, p_ac3dec->syncinfo.fscod, p_ac3dec->audblk.cpldeltbae, p_ac3dec->audblk.cpldeltnseg, p_ac3dec->audblk.cpldeltoffst, p_ac3dec->audblk.cpldeltba, p_ac3dec->audblk.cpldeltlen, excite, mask);
ba_compute_bap(start, end, snroffset, psd, mask, p_ac3dec->audblk.cpl_bap);
}
if(p_ac3dec->bsi.lfeon)
{
start = 0;
end = 7;
fgain = fastgain[p_ac3dec->audblk.lfefgaincod];
snroffset = (((p_ac3dec->audblk.csnroffst - 15) << 4) + p_ac3dec->audblk.lfefsnroffst) << 2 ;
fastleak = 0;
slowleak = 0;
ba_compute_psd(start, end, p_ac3dec->audblk.lfe_exp, psd, bndpsd);
ba_compute_excitation(start, end , fgain, fastleak, slowleak, 1, bndpsd, excite);
ba_compute_mask(start, end, p_ac3dec->syncinfo.fscod, 2, 0, 0, 0, 0, excite, mask);
ba_compute_bap(start, end, snroffset, psd, mask, p_ac3dec->audblk.lfe_bap);
}
}
static void ba_compute_psd(s16 start, s16 end, s16 exps[],
s16 psd[], s16 bndpsd[])
{
int bin,i,j,k;
s16 lastbin = 0;
/* Map the exponents into dBs */
for (bin=start; bin<end; bin++)
{
psd[bin] = (3072 - (exps[bin] << 7));
}
/* Integrate the psd function over each bit allocation band */
j = start;
k = masktab[start];
do
{
lastbin = min(bndtab[k] + bndsz[k], end);
bndpsd[k] = psd[j];
j++;
for (i = j; i < lastbin; i++)