Commit a5e77c46 authored by Michel Lespinasse's avatar Michel Lespinasse

Created a small&clean public interface for the ac3 decoder (see ac3_decoder.h)

Modified ac3_decoder_thread to use this interface

Find ac3 sync words not by scanning the ac3 stream but by using the magic
bytes at the start of the ac3 pes packets
parent c6313a9b
/***************************************************************************** /*****************************************************************************
* ac3_decoder.h : ac3 decoder thread interface * ac3_decoder.h : ac3 decoder interface
* (c)1999 VideoLAN * (c)1999 VideoLAN
*****************************************************************************/ *****************************************************************************/
/* Exponent strategy constants */ /**** ac3 decoder API - public ac3 decoder structures */
#define EXP_REUSE (0)
#define EXP_D15 (1)
#define EXP_D25 (2)
#define EXP_D45 (3)
/* Delta bit allocation constants */ typedef struct ac3dec_s ac3dec_t;
#define DELTA_BIT_REUSE (0)
#define DELTA_BIT_NEW (1) typedef struct ac3_sync_info_s {
#define DELTA_BIT_NONE (2) int sample_rate; /* sample rate in Hz */
#define DELTA_BIT_RESERVED (3) int frame_size; /* frame size in bytes */
int bit_rate; /* nominal bit rate in kbps */
} ac3_sync_info_t;
typedef struct ac3_byte_stream_s {
u8 * p_byte;
u8 * p_end;
void * info;
} ac3_byte_stream_t;
/**** ac3 decoder API - functions publically provided by the ac3 decoder ****/
int ac3_init (ac3dec_t * p_ac3dec);
int ac3_sync_frame (ac3dec_t * p_ac3dec, ac3_sync_info_t * p_sync_info);
int ac3_decode_frame (ac3dec_t * p_ac3dec, s16 * buffer);
static ac3_byte_stream_t * ac3_byte_stream (ac3dec_t * p_ac3dec);
/**** ac3 decoder API - user functions to be provided to the ac3 decoder ****/
void ac3_byte_stream_next (ac3_byte_stream_t * p_byte_stream);
/**** EVERYTHING AFTER THIS POINT IS PRIVATE ! DO NOT USE DIRECTLY ****/
/**** ac3 decoder internal structures ****/
/* The following structures are filled in by their corresponding parse_* /* The following structures are filled in by their corresponding parse_*
* functions. See http://www.atsc.org/Standards/A52/a_52.pdf for * functions. See http://www.atsc.org/Standards/A52/a_52.pdf for
...@@ -21,8 +40,7 @@ ...@@ -21,8 +40,7 @@
* conditional fields. * conditional fields.
*/ */
typedef struct syncinfo_s typedef struct syncinfo_s {
{
/* Sync word == 0x0B77 */ /* Sync word == 0x0B77 */
/* u16 syncword; */ /* u16 syncword; */
/* crc for the first 5/8 of the sync block */ /* crc for the first 5/8 of the sync block */
...@@ -36,12 +54,10 @@ typedef struct syncinfo_s ...@@ -36,12 +54,10 @@ typedef struct syncinfo_s
/* Frame size in 16 bit words */ /* Frame size in 16 bit words */
u16 frame_size; u16 frame_size;
/* Bit rate in kilobits */ /* Bit rate in kilobits */
u16 bit_rate; //u16 bit_rate;
} syncinfo_t; } syncinfo_t;
typedef struct bsi_s typedef struct bsi_s {
{
/* Bit stream identification == 0x8 */ /* Bit stream identification == 0x8 */
u16 bsid; u16 bsid;
/* Bit stream mode */ /* Bit stream mode */
...@@ -105,12 +121,10 @@ typedef struct bsi_s ...@@ -105,12 +121,10 @@ typedef struct bsi_s
/* Number of channels (excluding LFE) /* Number of channels (excluding LFE)
* Derived from acmod */ * Derived from acmod */
u16 nfchans; u16 nfchans;
} bsi_t; } bsi_t;
/* more pain */ /* more pain */
typedef struct audblk_s typedef struct audblk_s {
{
/* block switch bit indexed by channel num */ /* block switch bit indexed by channel num */
u16 blksw[5]; u16 blksw[5];
/* dither enable bit indexed by channel num */ /* dither enable bit indexed by channel num */
...@@ -282,7 +296,6 @@ typedef struct audblk_s ...@@ -282,7 +296,6 @@ typedef struct audblk_s
/* FIXME?? figure out exactly how many entries there should be (253-37?) */ /* FIXME?? figure out exactly how many entries there should be (253-37?) */
u16 cpl_bap[256]; u16 cpl_bap[256];
u16 lfe_bap[7]; u16 lfe_bap[7];
} audblk_t; } audblk_t;
/* Everything you wanted to know about band structure */ /* Everything you wanted to know about band structure */
...@@ -304,35 +317,16 @@ typedef struct audblk_s ...@@ -304,35 +317,16 @@ typedef struct audblk_s
* approximate a 1/6 octave scale. * approximate a 1/6 octave scale.
*/ */
typedef struct stream_coeffs_s typedef struct stream_coeffs_s {
{
float fbw[5][256]; float fbw[5][256];
float lfe[256]; float lfe[256];
} stream_coeffs_t; } stream_coeffs_t;
typedef struct stream_samples_s typedef struct stream_samples_s {
{
float channel[6][256]; float channel[6][256];
} stream_samples_t; } stream_samples_t;
#define AC3DEC_FRAME_SIZE (2*256) typedef struct ac3_bit_stream_s {
/*****************************************************************************
* ac3dec_frame_t
*****************************************************************************/
typedef s16 ac3dec_frame_t[ AC3DEC_FRAME_SIZE ];
typedef struct ac3_byte_stream_s
{
u8 * p_byte;
u8 * p_end;
void * info;
} ac3_byte_stream_t;
typedef struct ac3_bit_stream_s
{
u32 buffer; u32 buffer;
int i_available; int i_available;
ac3_byte_stream_t byte_stream; ac3_byte_stream_t byte_stream;
...@@ -340,11 +334,7 @@ typedef struct ac3_bit_stream_s ...@@ -340,11 +334,7 @@ typedef struct ac3_bit_stream_s
unsigned int total_bits_read; /* temporary */ unsigned int total_bits_read; /* temporary */
} ac3_bit_stream_t; } ac3_bit_stream_t;
/***************************************************************************** struct ac3dec_s {
* ac3dec_t : ac3 decoder descriptor
*****************************************************************************/
typedef struct ac3dec_s
{
/* /*
* Input properties * Input properties
*/ */
...@@ -361,9 +351,11 @@ typedef struct ac3dec_s ...@@ -361,9 +351,11 @@ typedef struct ac3dec_s
stream_coeffs_t coeffs; stream_coeffs_t coeffs;
stream_samples_t samples; stream_samples_t samples;
};
} ac3dec_t; /**** ac3 decoder inline functions ****/
int ac3_audio_block (ac3dec_t * p_ac3dec, s16 * buffer);
void ac3_byte_stream_next (ac3_byte_stream_t * p_byte_stream); static ac3_byte_stream_t * ac3_byte_stream (ac3dec_t * p_ac3dec)
{
return &(p_ac3dec->bit_stream.byte_stream);
}
/***************************************************************************** /*****************************************************************************
* ac3_decoder.h : ac3 decoder thread interface * ac3_decoder_thread.h : ac3 decoder thread interface
* (c)1999 VideoLAN * (c)1999 VideoLAN
*****************************************************************************/ *****************************************************************************/
...@@ -21,6 +21,7 @@ typedef struct ac3dec_thread_s ...@@ -21,6 +21,7 @@ typedef struct ac3dec_thread_s
decoder_fifo_t fifo; /* stores the PES stream data */ decoder_fifo_t fifo; /* stores the PES stream data */
input_thread_t * p_input; input_thread_t * p_input;
ts_packet_t * p_ts; ts_packet_t * p_ts;
int sync_ptr; /* sync ptr from ac3 magic header */
/* /*
* Decoder properties * Decoder properties
......
#include "int_types.h" #include "int_types.h"
#include "ac3_decoder.h" #include "ac3_decoder.h"
#include "ac3_bit_allocate.h" #include "ac3_internal.h"
/* /*
static inline s16 logadd(s16 a,s16 b); static inline s16 logadd (s16 a, s16 b);
static s16 calc_lowcomp(s16 a,s16 b0,s16 b1,s16 bin); static s16 calc_lowcomp (s16 a, s16 b0, s16 b1, s16 bin);
static inline u16 min(s16 a,s16 b); static inline u16 min (s16 a, s16 b);
static inline u16 max(s16 a,s16 b); static inline u16 max (s16 a, s16 b);
*/ */
static void ba_compute_psd(s16 start, s16 end, s16 exps[], static void ba_compute_psd (s16 start, s16 end, s16 exps[],
s16 psd[], s16 bndpsd[]); s16 psd[], s16 bndpsd[]);
static void ba_compute_excitation(s16 start, s16 end,s16 fgain, static void ba_compute_excitation (s16 start, s16 end, s16 fgain,
s16 fastleak, s16 slowleak, s16 is_lfe, s16 bndpsd[], s16 fastleak, s16 slowleak, s16 is_lfe,
s16 excite[]); s16 bndpsd[], s16 excite[]);
static void ba_compute_mask(s16 start, s16 end, u16 fscod, static void ba_compute_mask (s16 start, s16 end, u16 fscod,
u16 deltbae, u16 deltnseg, u16 deltoffst[], u16 deltba[], u16 deltbae, u16 deltnseg, u16 deltoffst[],
u16 deltlen[], s16 excite[], s16 mask[]); u16 deltba[], u16 deltlen[], s16 excite[],
static void ba_compute_bap(s16 start, s16 end, s16 snroffset, s16 mask[]);
static void ba_compute_bap (s16 start, s16 end, s16 snroffset,
s16 psd[], s16 mask[], s16 bap[]); s16 psd[], s16 mask[], s16 bap[]);
/* Misc LUTs for bit allocation process */ /* Misc LUTs for bit allocation process */
...@@ -31,7 +32,6 @@ static s16 dbpbtab[] = { 0x000, 0x700, 0x900, 0xb00 }; ...@@ -31,7 +32,6 @@ static s16 dbpbtab[] = { 0x000, 0x700, 0x900, 0xb00 };
static u16 floortab[] = { 0x2f0, 0x2b0, 0x270, 0x230, 0x1f0, 0x170, 0x0f0, 0xf800 }; static u16 floortab[] = { 0x2f0, 0x2b0, 0x270, 0x230, 0x1f0, 0x170, 0x0f0, 0xf800 };
static s16 fastgain[] = { 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400 }; static s16 fastgain[] = { 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400 };
static s16 bndtab[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, static s16 bndtab[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 31, 20, 21, 22, 23, 24, 25, 26, 27, 28, 31,
...@@ -136,53 +136,46 @@ static s16 bndpsd[256]; ...@@ -136,53 +136,46 @@ static s16 bndpsd[256];
static s16 excite[256]; static s16 excite[256];
static s16 mask[256]; static s16 mask[256];
static __inline__ u16 max( s16 a, s16 b ) static __inline__ u16 max (s16 a, s16 b)
{ {
return( a > b ? a : b ); return (a > b ? a : b);
} }
static __inline__ u16 min( s16 a, s16 b ) static __inline__ u16 min (s16 a, s16 b)
{ {
return( a < b ? a : b ); return (a < b ? a : b);
} }
static __inline__ s16 logadd( s16 a, s16 b ) static __inline__ s16 logadd (s16 a, s16 b)
{ {
s16 c; s16 c;
if ( (c = a - b) >= 0 ) if ((c = a - b) >= 0) {
{ return (a + latab[min(((c) >> 1), 255)]);
return( a + latab[min(((c) >> 1), 255)] ); } else {
} return (b + 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 ) static __inline__ s16 calc_lowcomp (s16 a, s16 b0, s16 b1, s16 bin)
{ {
if (bin < 7) if (bin < 7) {
{
if ((b0 + 256) == b1) if ((b0 + 256) == b1)
a = 384; a = 384;
else if (b0 > b1) else if (b0 > b1)
a = max(0, a - 64); a = max(0, a - 64);
} } else if (bin < 20) {
else if (bin < 20)
{
if ((b0 + 256) == b1) if ((b0 + 256) == b1)
a = 320; a = 320;
else if (b0 > b1) else if (b0 > b1)
a = max(0, a - 64) ; a = max(0, a - 64) ;
} } else
else
a = max(0, a - 128); a = max(0, a - 128);
return(a); return a;
} }
void bit_allocate( ac3dec_t * p_ac3dec ) void bit_allocate (ac3dec_t * p_ac3dec)
{ {
u16 i; u16 i;
s16 fgain; s16 fgain;
...@@ -209,19 +202,17 @@ void bit_allocate( ac3dec_t * p_ac3dec ) ...@@ -209,19 +202,17 @@ void bit_allocate( ac3dec_t * p_ac3dec )
floor = floortab[p_ac3dec->audblk.floorcod]; floor = floortab[p_ac3dec->audblk.floorcod];
/* if all the SNR offset constants are zero then the whole block is zero */ /* if all the SNR offset constants are zero then the whole block is zero */
if(!p_ac3dec->audblk.csnroffst && !p_ac3dec->audblk.fsnroffst[0] && if (!p_ac3dec->audblk.csnroffst && !p_ac3dec->audblk.fsnroffst[0] &&
!p_ac3dec->audblk.fsnroffst[1] && !p_ac3dec->audblk.fsnroffst[2] && !p_ac3dec->audblk.fsnroffst[1] && !p_ac3dec->audblk.fsnroffst[2] &&
!p_ac3dec->audblk.fsnroffst[3] && !p_ac3dec->audblk.fsnroffst[4] && !p_ac3dec->audblk.fsnroffst[3] && !p_ac3dec->audblk.fsnroffst[4] &&
!p_ac3dec->audblk.cplfsnroffst && !p_ac3dec->audblk.lfefsnroffst) !p_ac3dec->audblk.cplfsnroffst && !p_ac3dec->audblk.lfefsnroffst) {
{
memset(p_ac3dec->audblk.fbw_bap,0,sizeof(u16) * 256 * 5); 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.cpl_bap,0,sizeof(u16) * 256);
memset(p_ac3dec->audblk.lfe_bap,0,sizeof(u16) * 7); memset(p_ac3dec->audblk.lfe_bap,0,sizeof(u16) * 7);
return; return;
} }
for(i = 0; i < p_ac3dec->bsi.nfchans; i++) for (i = 0; i < p_ac3dec->bsi.nfchans; i++) {
{
start = 0; start = 0;
end = p_ac3dec->audblk.endmant[i] ; end = p_ac3dec->audblk.endmant[i] ;
fgain = fastgain[p_ac3dec->audblk.fgaincod[i]]; fgain = fastgain[p_ac3dec->audblk.fgaincod[i]];
...@@ -229,17 +220,23 @@ void bit_allocate( ac3dec_t * p_ac3dec ) ...@@ -229,17 +220,23 @@ void bit_allocate( ac3dec_t * p_ac3dec )
fastleak = 0; fastleak = 0;
slowleak = 0; slowleak = 0;
ba_compute_psd(start, end, p_ac3dec->audblk.fbw_exp[i], psd, bndpsd); ba_compute_psd (start, end, p_ac3dec->audblk.fbw_exp[i], psd, bndpsd);
ba_compute_excitation(start, end , fgain, fastleak, slowleak, 0, bndpsd, excite); ba_compute_excitation (start, end , fgain, fastleak, slowleak, 0,
bndpsd, excite);
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_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]); ba_compute_bap (start, end, snroffset, psd, mask,
p_ac3dec->audblk.fbw_bap[i]);
} }
if(p_ac3dec->audblk.cplinu) if (p_ac3dec->audblk.cplinu) {
{
start = p_ac3dec->audblk.cplstrtmant; start = p_ac3dec->audblk.cplstrtmant;
end = p_ac3dec->audblk.cplendmant; end = p_ac3dec->audblk.cplendmant;
fgain = fastgain[p_ac3dec->audblk.cplfgaincod]; fgain = fastgain[p_ac3dec->audblk.cplfgaincod];
...@@ -247,17 +244,23 @@ void bit_allocate( ac3dec_t * p_ac3dec ) ...@@ -247,17 +244,23 @@ void bit_allocate( ac3dec_t * p_ac3dec )
fastleak = (p_ac3dec->audblk.cplfleak << 8) + 768; fastleak = (p_ac3dec->audblk.cplfleak << 8) + 768;
slowleak = (p_ac3dec->audblk.cplsleak << 8) + 768; slowleak = (p_ac3dec->audblk.cplsleak << 8) + 768;
ba_compute_psd(start, end, p_ac3dec->audblk.cpl_exp, psd, bndpsd); 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_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_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); ba_compute_bap (start, end, snroffset, psd, mask,
p_ac3dec->audblk.cpl_bap);
} }
if(p_ac3dec->bsi.lfeon) if (p_ac3dec->bsi.lfeon) {
{
start = 0; start = 0;
end = 7; end = 7;
fgain = fastgain[p_ac3dec->audblk.lfefgaincod]; fgain = fastgain[p_ac3dec->audblk.lfefgaincod];
...@@ -265,26 +268,28 @@ void bit_allocate( ac3dec_t * p_ac3dec ) ...@@ -265,26 +268,28 @@ void bit_allocate( ac3dec_t * p_ac3dec )
fastleak = 0; fastleak = 0;
slowleak = 0; slowleak = 0;
ba_compute_psd(start, end, p_ac3dec->audblk.lfe_exp, psd, bndpsd); 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_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_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); ba_compute_bap (start, end, snroffset, psd, mask,
p_ac3dec->audblk.lfe_bap);
} }
} }
static void ba_compute_psd(s16 start, s16 end, s16 exps[], static void ba_compute_psd (s16 start, s16 end, s16 exps[], s16 psd[],
s16 psd[], s16 bndpsd[]) s16 bndpsd[])
{ {
int bin,i,j,k; int bin,i,j,k;
s16 lastbin = 0; s16 lastbin = 0;
/* Map the exponents into dBs */ /* Map the exponents into dBs */
for (bin=start; bin<end; bin++) for (bin=start; bin<end; bin++) {
{
psd[bin] = (3072 - (exps[bin] << 7)); psd[bin] = (3072 - (exps[bin] << 7));
} }
...@@ -292,14 +297,12 @@ static void ba_compute_psd(s16 start, s16 end, s16 exps[], ...@@ -292,14 +297,12 @@ static void ba_compute_psd(s16 start, s16 end, s16 exps[],
j = start; j = start;
k = masktab[start]; k = masktab[start];
do do {
{
lastbin = min(bndtab[k] + bndsz[k], end); lastbin = min(bndtab[k] + bndsz[k], end);
bndpsd[k] = psd[j]; bndpsd[k] = psd[j];
j++; j++;
for (i = j; i < lastbin; i++) for (i = j; i < lastbin; i++) {
{
bndpsd[k] = logadd(bndpsd[k], psd[j]); bndpsd[k] = logadd(bndpsd[k], psd[j]);
j++; j++;
} }
...@@ -308,8 +311,8 @@ static void ba_compute_psd(s16 start, s16 end, s16 exps[], ...@@ -308,8 +311,8 @@ static void ba_compute_psd(s16 start, s16 end, s16 exps[],
} while (end > lastbin); } while (end > lastbin);
} }
static void ba_compute_excitation(s16 start, s16 end,s16 fgain, static void ba_compute_excitation (s16 start, s16 end,s16 fgain, s16 fastleak,
s16 fastleak, s16 slowleak, s16 is_lfe, s16 bndpsd[], s16 slowleak, s16 is_lfe, s16 bndpsd[],
s16 excite[]) s16 excite[])
{ {
int bin; int bin;
...@@ -322,8 +325,7 @@ static void ba_compute_excitation(s16 start, s16 end,s16 fgain, ...@@ -322,8 +325,7 @@ static void ba_compute_excitation(s16 start, s16 end,s16 fgain,
bndstrt = masktab[start]; bndstrt = masktab[start];
bndend = masktab[end - 1] + 1; bndend = masktab[end - 1] + 1;
if (bndstrt == 0) /* For fbw and lfe channels */ if (bndstrt == 0) { /* For fbw and lfe channels */
{
lowcomp = calc_lowcomp(lowcomp, bndpsd[0], bndpsd[1], 0); lowcomp = calc_lowcomp(lowcomp, bndpsd[0], bndpsd[1], 0);
excite[0] = bndpsd[0] - fgain - lowcomp; excite[0] = bndpsd[0] - fgain - lowcomp;
lowcomp = calc_lowcomp(lowcomp, bndpsd[1], bndpsd[2], 1); lowcomp = calc_lowcomp(lowcomp, bndpsd[1], bndpsd[2], 1);
...@@ -331,28 +333,24 @@ static void ba_compute_excitation(s16 start, s16 end,s16 fgain, ...@@ -331,28 +333,24 @@ static void ba_compute_excitation(s16 start, s16 end,s16 fgain,
begin = 7 ; begin = 7 ;
/* Note: Do not call calc_lowcomp() for the last band of the lfe channel, (bin = 6) */ /* Note: Do not call calc_lowcomp() for the last band of the lfe channel, (bin = 6) */
for (bin = 2; bin < 7; bin++) for (bin = 2; bin < 7; bin++) {
{
if (!(is_lfe && (bin == 6))) if (!(is_lfe && (bin == 6)))
lowcomp = calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin+1], bin); lowcomp = calc_lowcomp (lowcomp, bndpsd[bin], bndpsd[bin+1], bin);
fastleak = bndpsd[bin] - fgain; fastleak = bndpsd[bin] - fgain;
slowleak = bndpsd[bin] - sgain; slowleak = bndpsd[bin] - sgain;
excite[bin] = fastleak - lowcomp; excite[bin] = fastleak - lowcomp;
if (!(is_lfe && (bin == 6))) if (!(is_lfe && (bin == 6))) {
{ if (bndpsd[bin] <= bndpsd[bin+1]) {
if (bndpsd[bin] <= bndpsd[bin+1])
{
begin = bin + 1 ; begin = bin + 1 ;
break; break;
} }
} }
} }
for (bin = begin; bin < min(bndend, 22); bin++) for (bin = begin; bin < min(bndend, 22); bin++) {
{
if (!(is_lfe && (bin == 6))) if (!(is_lfe && (bin == 6)))
lowcomp = calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin+1], bin); lowcomp = calc_lowcomp (lowcomp, bndpsd[bin], bndpsd[bin+1], bin);
fastleak -= fdecay ; fastleak -= fdecay ;
fastleak = max(fastleak, bndpsd[bin] - fgain); fastleak = max(fastleak, bndpsd[bin] - fgain);
slowleak -= sdecay ; slowleak -= sdecay ;
...@@ -360,14 +358,11 @@ static void ba_compute_excitation(s16 start, s16 end,s16 fgain, ...@@ -360,14 +358,11 @@ static void ba_compute_excitation(s16 start, s16 end,s16 fgain,
excite[bin] = max(fastleak - lowcomp, slowleak); excite[bin] = max(fastleak - lowcomp, slowleak);
} }
begin = 22; begin = 22;
} } else { /* For coupling channel */
else /* For coupling channel */
{
begin = bndstrt; begin = bndstrt;
} }
for (bin = begin; bin < bndend; bin++) for (bin = begin; bin < bndend; bin++) {
{
fastleak -= fdecay; fastleak -= fdecay;
fastleak = max(fastleak, bndpsd[bin] - fgain); fastleak = max(fastleak, bndpsd[bin] - fgain);
slowleak -= sdecay; slowleak -= sdecay;
...@@ -376,8 +371,8 @@ static void ba_compute_excitation(s16 start, s16 end,s16 fgain, ...@@ -376,8 +371,8 @@ static void ba_compute_excitation(s16 start, s16 end,s16 fgain,
} }
} }
static void ba_compute_mask(s16 start, s16 end, u16 fscod, static void ba_compute_mask (s16 start, s16 end, u16 fscod, u16 deltbae,
u16 deltbae, u16 deltnseg, u16 deltoffst[], u16 deltba[], u16 deltnseg, u16 deltoffst[], u16 deltba[],
u16 deltlen[], s16 excite[], s16 mask[]) u16 deltlen[], s16 excite[], s16 mask[])
{ {
int bin,k; int bin,k;
...@@ -389,34 +384,26 @@ static void ba_compute_mask(s16 start, s16 end, u16 fscod, ...@@ -389,34 +384,26 @@ static void ba_compute_mask(s16 start, s16 end, u16 fscod,
bndend = masktab[end - 1] + 1; bndend = masktab[end - 1] + 1;
/* Compute the masking curve */ /* Compute the masking curve */
for (bin = bndstrt; bin < bndend; bin++) for (bin = bndstrt; bin < bndend; bin++) {
{ if (bndpsd[bin] < dbknee) {
if (bndpsd[bin] < dbknee)
{
excite[bin] += ((dbknee - bndpsd[bin]) >> 2); excite[bin] += ((dbknee - bndpsd[bin]) >> 2);
} }
mask[bin] = max(excite[bin], hth[fscod][bin]); mask[bin] = max(excite[bin], hth[fscod][bin]);
} }
/* Perform delta bit modulation if necessary */ /* Perform delta bit modulation if necessary */
if ((deltbae == DELTA_BIT_REUSE) || (deltbae == DELTA_BIT_NEW)) if ((deltbae == DELTA_BIT_REUSE) || (deltbae == DELTA_BIT_NEW)) {
{
s16 band = 0; s16 band = 0;
s16 seg = 0; s16 seg = 0;
for (seg = 0; seg < deltnseg+1; seg++) for (seg = 0; seg < deltnseg+1; seg++) {
{
band += deltoffst[seg]; band += deltoffst[seg];
if (deltba[seg] >= 4) if (deltba[seg] >= 4) {
{
delta = (deltba[seg] - 3) << 7; delta = (deltba[seg] - 3) << 7;
} } else {
else
{
delta = (deltba[seg] - 4) << 7; delta = (deltba[seg] - 4) << 7;
} }
for (k = 0; k < deltlen[seg]; k++) for (k = 0; k < deltlen[seg]; k++) {
{
mask[band] += delta; mask[band] += delta;
band++; band++;
} }
...@@ -424,8 +411,8 @@ static void ba_compute_mask(s16 start, s16 end, u16 fscod, ...@@ -424,8 +411,8 @@ static void ba_compute_mask(s16 start, s16 end, u16 fscod,
} }
} }
static void ba_compute_bap(s16 start, s16 end, s16 snroffset, static void ba_compute_bap (s16 start, s16 end, s16 snroffset, s16 psd[],
s16 psd[], s16 mask[], s16 bap[]) s16 mask[], s16 bap[])
{ {
int i,j,k; int i,j,k;
s16 lastbin = 0; s16 lastbin = 0;
...@@ -435,8 +422,7 @@ static void ba_compute_bap(s16 start, s16 end, s16 snroffset, ...@@ -435,8 +422,7 @@ static void ba_compute_bap(s16 start, s16 end, s16 snroffset,
i = start; i = start;
j = masktab[start]; j = masktab[start];
do do {
{
lastbin = min(bndtab[j] + bndsz[j], end); lastbin = min(bndtab[j] + bndsz[j], end);
mask[j] -= snroffset; mask[j] -= snroffset;
mask[j] -= floor; mask[j] -= floor;
...@@ -446,8 +432,7 @@ static void ba_compute_bap(s16 start, s16 end, s16 snroffset, ...@@ -446,8 +432,7 @@ static void ba_compute_bap(s16 start, s16 end, s16 snroffset,
mask[j] &= 0x1fe0; mask[j] &= 0x1fe0;
mask[j] += floor; mask[j] += floor;
for (k = i; k < lastbin; k++) for (k = i; k < lastbin; k++) {
{
address = (psd[i] - mask[j]) >> 5; address = (psd[i] - mask[j]) >> 5;
address = min(63, max(0, address)); address = min(63, max(0, address));
bap[i] = baptab[address]; bap[i] = baptab[address];
......
void bit_allocate( ac3dec_t * );
...@@ -9,18 +9,6 @@ static __inline__ u8 GetByte (ac3_byte_stream_t * p_byte_stream) ...@@ -9,18 +9,6 @@ static __inline__ u8 GetByte (ac3_byte_stream_t * p_byte_stream)
return *(p_byte_stream->p_byte++); return *(p_byte_stream->p_byte++);
} }
/*****************************************************************************
* NeedBits : reads i_bits new bits in the bit stream and stores them in the
* bit buffer
*****************************************************************************
* - i_bits must be less or equal 32 !
* - There is something important to notice with that function : if the number
* of bits available in the bit buffer when calling NeedBits() is greater than
* 24 (i_available > 24) but less than the number of needed bits
* (i_available < i_bits), the byte returned by GetByte() will be shifted with
* a negative value and the number of bits available in the bit buffer will be
* set to more than 32 !
*****************************************************************************/
static __inline__ void NeedBits (ac3_bit_stream_t * p_bit_stream, int i_bits) static __inline__ void NeedBits (ac3_bit_stream_t * p_bit_stream, int i_bits)
{ {
while (p_bit_stream->i_available < i_bits) { while (p_bit_stream->i_available < i_bits) {
...@@ -30,12 +18,6 @@ static __inline__ void NeedBits (ac3_bit_stream_t * p_bit_stream, int i_bits) ...@@ -30,12 +18,6 @@ static __inline__ void NeedBits (ac3_bit_stream_t * p_bit_stream, int i_bits)
} }
} }
/*****************************************************************************
* DumpBits : removes i_bits bits from the bit buffer
*****************************************************************************
* - i_bits <= i_available
* - i_bits < 32 (because (u32 << 32) <=> (u32 = u32))
*****************************************************************************/
static __inline__ void DumpBits (ac3_bit_stream_t * p_bit_stream, int i_bits) static __inline__ void DumpBits (ac3_bit_stream_t * p_bit_stream, int i_bits)
{ {
p_bit_stream->buffer <<= i_bits; p_bit_stream->buffer <<= i_bits;
......
#include "int_types.h" #include "int_types.h"
#include "ac3_decoder.h" #include "ac3_decoder.h"
#include "ac3_parse.h" #include "ac3_internal.h"
#include "ac3_exponent.h"
#include "ac3_bit_allocate.h" int ac3_init (ac3dec_t * p_ac3dec)
#include "ac3_mantissa.h" {
#include "ac3_rematrix.h" //p_ac3dec->bit_stream.buffer = 0;
#include "ac3_imdct.h" p_ac3dec->bit_stream.i_available = 0;
#include "ac3_downmix.h"
int ac3_audio_block (ac3dec_t * p_ac3dec, s16 * buffer)
{
parse_audblk( p_ac3dec );
if (exponent_unpack( p_ac3dec ))
return 1;
bit_allocate( p_ac3dec );
mantissa_unpack( p_ac3dec );
if ( p_ac3dec->bsi.acmod == 0x2 )
rematrix( p_ac3dec );
imdct( p_ac3dec );
downmix( p_ac3dec, buffer );
return 0; return 0;
}
int ac3_decode_frame (ac3dec_t * p_ac3dec, s16 * buffer)
{
int i;
parse_bsi (p_ac3dec);
for (i = 0; i < 6; i++) {
parse_audblk (p_ac3dec);
if (exponent_unpack (p_ac3dec))
return 1;
bit_allocate (p_ac3dec);
mantissa_unpack (p_ac3dec);
if (p_ac3dec->bsi.acmod == 0x2)
rematrix (p_ac3dec);
imdct (p_ac3dec);
downmix (p_ac3dec, buffer);
buffer += 2*256;
} }
parse_auxdata (p_ac3dec);
return 0;
}
/***************************************************************************** /*****************************************************************************
* ac3_decoder.c: ac3 decoder thread * ac3_decoder_thread.c: ac3 decoder thread
* (c)1999 VideoLAN * (c)1999 VideoLAN
*****************************************************************************/ *****************************************************************************/
...@@ -42,8 +42,9 @@ ...@@ -42,8 +42,9 @@
#include "ac3_decoder.h" #include "ac3_decoder.h"
#include "ac3_decoder_thread.h" #include "ac3_decoder_thread.h"
#include "ac3_parse.h"
#include "ac3_imdct.h" #define AC3DEC_FRAME_SIZE (2*1536)
typedef s16 ac3dec_frame_t[ AC3DEC_FRAME_SIZE ];
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
...@@ -84,10 +85,12 @@ ac3dec_thread_t * ac3dec_CreateThread( input_thread_t * p_input ) ...@@ -84,10 +85,12 @@ ac3dec_thread_t * ac3dec_CreateThread( input_thread_t * p_input )
vlc_cond_init( &p_ac3dec->fifo.data_wait ); vlc_cond_init( &p_ac3dec->fifo.data_wait );
p_ac3dec->fifo.i_start = 0; p_ac3dec->fifo.i_start = 0;
p_ac3dec->fifo.i_end = 0; p_ac3dec->fifo.i_end = 0;
/* Initialize the ac3 decoder structures */
ac3_init (&p_ac3dec->ac3_decoder);
/* Initialize the bit stream structure */ /* Initialize the bit stream structure */
p_ac3dec->p_input = p_input; p_ac3dec->p_input = p_input;
p_ac3dec->ac3_decoder.bit_stream.buffer = 0;
p_ac3dec->ac3_decoder.bit_stream.i_available = 0;
/* /*
* Initialize the output properties * Initialize the output properties
...@@ -95,8 +98,6 @@ ac3dec_thread_t * ac3dec_CreateThread( input_thread_t * p_input ) ...@@ -95,8 +98,6 @@ ac3dec_thread_t * ac3dec_CreateThread( input_thread_t * p_input )
p_ac3dec->p_aout = p_input->p_aout; p_ac3dec->p_aout = p_input->p_aout;
p_ac3dec->p_aout_fifo = NULL; p_ac3dec->p_aout_fifo = NULL;
imdct_init();
/* Spawn the ac3 decoder thread */ /* Spawn the ac3 decoder thread */
if ( vlc_thread_create(&p_ac3dec->thread_id, "ac3 decoder", (vlc_thread_func_t)RunThread, (void *)p_ac3dec) ) if ( vlc_thread_create(&p_ac3dec->thread_id, "ac3 decoder", (vlc_thread_func_t)RunThread, (void *)p_ac3dec) )
{ {
...@@ -131,25 +132,13 @@ void ac3dec_DestroyThread( ac3dec_thread_t * p_ac3dec ) ...@@ -131,25 +132,13 @@ void ac3dec_DestroyThread( ac3dec_thread_t * p_ac3dec )
/* Following functions are local */ /* Following functions are local */
/*****************************************************************************
* decode_find_sync()
*****************************************************************************/
static __inline__ int decode_find_sync( ac3dec_thread_t * p_ac3dec )
{
while ( (!p_ac3dec->b_die) && (!p_ac3dec->b_error) )
{
if (! (ac3_test_sync (&p_ac3dec->ac3_decoder)))
return 0;
}
return( -1 );
}
/***************************************************************************** /*****************************************************************************
* InitThread : initialize an ac3 decoder thread * InitThread : initialize an ac3 decoder thread
*****************************************************************************/ *****************************************************************************/
static int InitThread( ac3dec_thread_t * p_ac3dec ) static int InitThread( ac3dec_thread_t * p_ac3dec )
{ {
aout_fifo_t aout_fifo; aout_fifo_t aout_fifo;
ac3_byte_stream_t * byte_stream;
intf_DbgMsg( "ac3dec debug: initializing ac3 decoder thread %p\n", p_ac3dec ); intf_DbgMsg( "ac3dec debug: initializing ac3 decoder thread %p\n", p_ac3dec );
...@@ -166,11 +155,12 @@ static int InitThread( ac3dec_thread_t * p_ac3dec ) ...@@ -166,11 +155,12 @@ static int InitThread( ac3dec_thread_t * p_ac3dec )
vlc_cond_wait( &p_ac3dec->fifo.data_wait, &p_ac3dec->fifo.data_lock ); vlc_cond_wait( &p_ac3dec->fifo.data_wait, &p_ac3dec->fifo.data_lock );
} }
p_ac3dec->p_ts = DECODER_FIFO_START( p_ac3dec->fifo )->p_first_ts; p_ac3dec->p_ts = DECODER_FIFO_START( p_ac3dec->fifo )->p_first_ts;
p_ac3dec->ac3_decoder.bit_stream.byte_stream.p_byte = byte_stream = ac3_byte_stream (&p_ac3dec->ac3_decoder);
byte_stream->p_byte =
p_ac3dec->p_ts->buffer + p_ac3dec->p_ts->i_payload_start; p_ac3dec->p_ts->buffer + p_ac3dec->p_ts->i_payload_start;
p_ac3dec->ac3_decoder.bit_stream.byte_stream.p_end = byte_stream->p_end =
p_ac3dec->p_ts->buffer + p_ac3dec->p_ts->i_payload_end; p_ac3dec->p_ts->buffer + p_ac3dec->p_ts->i_payload_end;
p_ac3dec->ac3_decoder.bit_stream.byte_stream.info = p_ac3dec; byte_stream->info = p_ac3dec;
vlc_mutex_unlock( &p_ac3dec->fifo.data_lock ); vlc_mutex_unlock( &p_ac3dec->fifo.data_lock );
aout_fifo.i_type = AOUT_ADEC_STEREO_FIFO; aout_fifo.i_type = AOUT_ADEC_STEREO_FIFO;
...@@ -194,6 +184,8 @@ static int InitThread( ac3dec_thread_t * p_ac3dec ) ...@@ -194,6 +184,8 @@ static int InitThread( ac3dec_thread_t * p_ac3dec )
*****************************************************************************/ *****************************************************************************/
static void RunThread( ac3dec_thread_t * p_ac3dec ) static void RunThread( ac3dec_thread_t * p_ac3dec )
{ {
int sync;
intf_DbgMsg( "ac3dec debug: running ac3 decoder thread (%p) (pid == %i)\n", p_ac3dec, getpid() ); intf_DbgMsg( "ac3dec debug: running ac3 decoder thread (%p) (pid == %i)\n", p_ac3dec, getpid() );
msleep( INPUT_PTS_DELAY ); msleep( INPUT_PTS_DELAY );
...@@ -204,13 +196,44 @@ static void RunThread( ac3dec_thread_t * p_ac3dec ) ...@@ -204,13 +196,44 @@ static void RunThread( ac3dec_thread_t * p_ac3dec )
p_ac3dec->b_error = 1; p_ac3dec->b_error = 1;
} }
sync = 0;
p_ac3dec->sync_ptr = 0;
/* ac3 decoder thread's main loop */ /* ac3 decoder thread's main loop */
/* FIXME : do we have enough room to store the decoded frames ?? */ /* FIXME : do we have enough room to store the decoded frames ?? */
while ( (!p_ac3dec->b_die) && (!p_ac3dec->b_error) ) while ( (!p_ac3dec->b_die) && (!p_ac3dec->b_error) )
{ {
int i; s16 * buffer;
ac3_sync_info_t sync_info;
if (!sync) { /* have to find a synchro point */
int ptr;
ac3_byte_stream_t * p_byte_stream;
p_byte_stream = ac3_byte_stream (&p_ac3dec->ac3_decoder);
decode_find_sync( p_ac3dec ); /* first read till next ac3 magic header */
do {
ac3_byte_stream_next (p_byte_stream);
} while ((!p_ac3dec->sync_ptr) &&
(!p_ac3dec->b_die) &&
(!p_ac3dec->b_error));
/* skip the specified number of bytes */
ptr = p_ac3dec->sync_ptr;
while (--ptr && (!p_ac3dec->b_die) && (!p_ac3dec->b_error)) {
if (p_byte_stream->p_byte >= p_byte_stream->p_end) {
ac3_byte_stream_next (p_byte_stream);
}
p_byte_stream->p_byte++;
}
/* we are in sync now */
sync = 1;
p_ac3dec->sync_ptr = 0;
}
if ( DECODER_FIFO_START(p_ac3dec->fifo)->b_has_pts ) if ( DECODER_FIFO_START(p_ac3dec->fifo)->b_has_pts )
{ {
...@@ -222,46 +245,25 @@ static void RunThread( ac3dec_thread_t * p_ac3dec ) ...@@ -222,46 +245,25 @@ static void RunThread( ac3dec_thread_t * p_ac3dec )
p_ac3dec->p_aout_fifo->date[p_ac3dec->p_aout_fifo->l_end_frame] = LAST_MDATE; p_ac3dec->p_aout_fifo->date[p_ac3dec->p_aout_fifo->l_end_frame] = LAST_MDATE;
} }
parse_syncinfo( &p_ac3dec->ac3_decoder ); if (ac3_sync_frame (&p_ac3dec->ac3_decoder, &sync_info)) {
switch ( p_ac3dec->ac3_decoder.syncinfo.fscod ) sync = 0;
{ goto bad_frame;
case 0:
p_ac3dec->p_aout_fifo->l_rate = 48000;
break;
case 1:
p_ac3dec->p_aout_fifo->l_rate = 44100;
break;
case 2:
p_ac3dec->p_aout_fifo->l_rate = 32000;
break;
default: /* XXX?? */
fprintf( stderr, "ac3dec debug: invalid fscod\n" );
continue;
} }
parse_bsi( &p_ac3dec->ac3_decoder ); p_ac3dec->p_aout_fifo->l_rate = sync_info.sample_rate;
for (i = 0; i < 6; i++)
{
s16 * buffer;
buffer = ((ac3dec_frame_t *)p_ac3dec->p_aout_fifo->buffer)[ p_ac3dec->p_aout_fifo->l_end_frame ]; buffer = ((ac3dec_frame_t *)p_ac3dec->p_aout_fifo->buffer)[ p_ac3dec->p_aout_fifo->l_end_frame ];
if (ac3_audio_block (&p_ac3dec->ac3_decoder, buffer)) if (ac3_decode_frame (&p_ac3dec->ac3_decoder, buffer)) {
sync = 0;
goto bad_frame; goto bad_frame;
}
if (i)
p_ac3dec->p_aout_fifo->date[p_ac3dec->p_aout_fifo->l_end_frame] = LAST_MDATE;
vlc_mutex_lock( &p_ac3dec->p_aout_fifo->data_lock ); vlc_mutex_lock( &p_ac3dec->p_aout_fifo->data_lock );
p_ac3dec->p_aout_fifo->l_end_frame = (p_ac3dec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE; p_ac3dec->p_aout_fifo->l_end_frame = (p_ac3dec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
vlc_cond_signal( &p_ac3dec->p_aout_fifo->data_wait ); vlc_cond_signal( &p_ac3dec->p_aout_fifo->data_wait );
vlc_mutex_unlock( &p_ac3dec->p_aout_fifo->data_lock ); vlc_mutex_unlock( &p_ac3dec->p_aout_fifo->data_lock );
}
parse_auxdata( &p_ac3dec->ac3_decoder );
bad_frame: bad_frame:
} }
...@@ -336,6 +338,8 @@ void ac3_byte_stream_next (ac3_byte_stream_t * p_byte_stream) ...@@ -336,6 +338,8 @@ void ac3_byte_stream_next (ac3_byte_stream_t * p_byte_stream)
/* We were reading the last TS packet of this PES packet... It's /* We were reading the last TS packet of this PES packet... It's
* time to jump to the next PES packet */ * time to jump to the next PES packet */
if (p_ac3dec->p_ts->p_next_ts == NULL) { if (p_ac3dec->p_ts->p_next_ts == NULL) {
int ptr;
/* We are going to read/write the start and end indexes of the /* We are going to read/write the start and end indexes of the
* decoder fifo and to use the fifo's conditional variable, * decoder fifo and to use the fifo's conditional variable,
* that's why we need to take the lock before */ * that's why we need to take the lock before */
...@@ -368,6 +372,13 @@ void ac3_byte_stream_next (ac3_byte_stream_t * p_byte_stream) ...@@ -368,6 +372,13 @@ void ac3_byte_stream_next (ac3_byte_stream_t * p_byte_stream)
/* The next byte could be found in the next PES packet */ /* The next byte could be found in the next PES packet */
p_ac3dec->p_ts = DECODER_FIFO_START (p_ac3dec->fifo)->p_first_ts; p_ac3dec->p_ts = DECODER_FIFO_START (p_ac3dec->fifo)->p_first_ts;
/* parse ac3 magic header */
ptr = p_ac3dec->p_ts->buffer [p_ac3dec->p_ts->i_payload_start+2];
ptr <<= 8;
ptr |= p_ac3dec->p_ts->buffer [p_ac3dec->p_ts->i_payload_start+3];
p_ac3dec->sync_ptr = ptr;
p_ac3dec->p_ts->i_payload_start += 4;
/* We can release the fifo's data lock */ /* We can release the fifo's data lock */
vlc_mutex_unlock (&p_ac3dec->fifo.data_lock); vlc_mutex_unlock (&p_ac3dec->fifo.data_lock);
} }
......
#include "int_types.h" #include "int_types.h"
#include "ac3_decoder.h" #include "ac3_decoder.h"
#include "ac3_downmix.h" #include "ac3_internal.h"
#define NORM 16384 #define NORM 16384
typedef struct prefs_s typedef struct prefs_s {
{
u16 use_dolby_surround; u16 use_dolby_surround;
u16 dual_mono_channel_select; u16 dual_mono_channel_select;
} prefs_t; } prefs_t;
...@@ -20,7 +19,7 @@ static float smixlev_lut[4] = { 0.2928, 0.2071, 0.0 , 0.2071 }; ...@@ -20,7 +19,7 @@ static float smixlev_lut[4] = { 0.2928, 0.2071, 0.0 , 0.2071 };
* to reduce complexity. Realistically, there aren't many machines around * to reduce complexity. Realistically, there aren't many machines around
* with > 2 channel output anyways */ * with > 2 channel output anyways */
void downmix( ac3dec_t * p_ac3dec, s16 * out_buf ) void downmix (ac3dec_t * p_ac3dec, s16 * out_buf)
{ {
int j; int j;
float right_tmp; float right_tmp;
...@@ -29,25 +28,21 @@ void downmix( ac3dec_t * p_ac3dec, s16 * out_buf ) ...@@ -29,25 +28,21 @@ void downmix( ac3dec_t * p_ac3dec, s16 * out_buf )
float *centre = 0, *left = 0, *right = 0, *left_sur = 0, *right_sur = 0; float *centre = 0, *left = 0, *right = 0, *left_sur = 0, *right_sur = 0;
/* /*
if(p_ac3dec->bsi.acmod > 7) if (p_ac3dec->bsi.acmod > 7)
dprintf("(downmix) invalid acmod number\n"); dprintf("(downmix) invalid acmod number\n");
*/ */
/* There are two main cases, with or without Dolby Surround */ /* There are two main cases, with or without Dolby Surround */
if(global_prefs.use_dolby_surround) if (global_prefs.use_dolby_surround) {
{ switch(p_ac3dec->bsi.acmod) {
switch(p_ac3dec->bsi.acmod) case 7: /* 3/2 */
{
/* 3/2 */
case 7:
left = p_ac3dec->samples.channel[0]; left = p_ac3dec->samples.channel[0];
centre = p_ac3dec->samples.channel[1]; centre = p_ac3dec->samples.channel[1];
right = p_ac3dec->samples.channel[2]; right = p_ac3dec->samples.channel[2];
left_sur = p_ac3dec->samples.channel[3]; left_sur = p_ac3dec->samples.channel[3];
right_sur = p_ac3dec->samples.channel[4]; right_sur = p_ac3dec->samples.channel[4];
for ( j = 0; j < 256; j++ ) for (j = 0; j < 256; j++) {
{
right_tmp = 0.2265f * *left_sur++ + 0.2265f * *right_sur++; right_tmp = 0.2265f * *left_sur++ + 0.2265f * *right_sur++;
left_tmp = -1 * right_tmp; left_tmp = -1 * right_tmp;
right_tmp += 0.3204f * *right++ + 0.2265f * *centre; right_tmp += 0.3204f * *right++ + 0.2265f * *centre;
...@@ -55,22 +50,16 @@ void downmix( ac3dec_t * p_ac3dec, s16 * out_buf ) ...@@ -55,22 +50,16 @@ void downmix( ac3dec_t * p_ac3dec, s16 * out_buf )
*(out_buf++) = left_tmp * NORM; *(out_buf++) = left_tmp * NORM;
*(out_buf++) = right_tmp * NORM; *(out_buf++) = right_tmp * NORM;
/*
p_ac3dec->samples.channel[1][j] = right_tmp;
p_ac3dec->samples.channel[0][j] = left_tmp;
*/
} }
break; break;
/* 2/2 */ case 6: /* 2/2 */
case 6:
left = p_ac3dec->samples.channel[0]; left = p_ac3dec->samples.channel[0];
right = p_ac3dec->samples.channel[1]; right = p_ac3dec->samples.channel[1];
left_sur = p_ac3dec->samples.channel[2]; left_sur = p_ac3dec->samples.channel[2];
right_sur = p_ac3dec->samples.channel[3]; right_sur = p_ac3dec->samples.channel[3];
for (j = 0; j < 256; j++) for (j = 0; j < 256; j++) {
{
right_tmp = 0.2265f * *left_sur++ + 0.2265f * *right_sur++; right_tmp = 0.2265f * *left_sur++ + 0.2265f * *right_sur++;
left_tmp = -1 * right_tmp; left_tmp = -1 * right_tmp;
right_tmp += 0.3204f * *right++; right_tmp += 0.3204f * *right++;
...@@ -78,23 +67,17 @@ void downmix( ac3dec_t * p_ac3dec, s16 * out_buf ) ...@@ -78,23 +67,17 @@ void downmix( ac3dec_t * p_ac3dec, s16 * out_buf )
*(out_buf++) = left_tmp * NORM; *(out_buf++) = left_tmp * NORM;
*(out_buf++) = right_tmp * NORM; *(out_buf++) = right_tmp * NORM;
/*
p_ac3dec->samples.channel[1][j] = right_tmp;
p_ac3dec->samples.channel[0][j] = left_tmp;
*/
} }
break; break;
/* 3/1 */ case 5: /* 3/1 */
case 5:
left = p_ac3dec->samples.channel[0]; left = p_ac3dec->samples.channel[0];
centre = p_ac3dec->samples.channel[1]; centre = p_ac3dec->samples.channel[1];
right = p_ac3dec->samples.channel[2]; right = p_ac3dec->samples.channel[2];
/* Mono surround */ /* Mono surround */
right_sur = p_ac3dec->samples.channel[3]; right_sur = p_ac3dec->samples.channel[3];
for (j = 0; j < 256; j++) for (j = 0; j < 256; j++) {
{
right_tmp = 0.2265f * *right_sur++; right_tmp = 0.2265f * *right_sur++;
left_tmp = - right_tmp; left_tmp = - right_tmp;
right_tmp += 0.3204f * *right++ + 0.2265f * *centre; right_tmp += 0.3204f * *right++ + 0.2265f * *centre;
...@@ -102,22 +85,16 @@ void downmix( ac3dec_t * p_ac3dec, s16 * out_buf ) ...@@ -102,22 +85,16 @@ void downmix( ac3dec_t * p_ac3dec, s16 * out_buf )
*(out_buf++) = left_tmp * NORM; *(out_buf++) = left_tmp * NORM;
*(out_buf++) = right_tmp * NORM; *(out_buf++) = right_tmp * NORM;
/*
p_ac3dec->samples.channel[1][j] = right_tmp;
p_ac3dec->samples.channel[0][j] = left_tmp;
*/
} }
break; break;
/* 2/1 */ case 4: /* 2/1 */
case 4:
left = p_ac3dec->samples.channel[0]; left = p_ac3dec->samples.channel[0];
right = p_ac3dec->samples.channel[1]; right = p_ac3dec->samples.channel[1];
/* Mono surround */ /* Mono surround */
right_sur = p_ac3dec->samples.channel[2]; right_sur = p_ac3dec->samples.channel[2];
for (j = 0; j < 256; j++) for (j = 0; j < 256; j++) {
{
right_tmp = 0.2265f * *right_sur++; right_tmp = 0.2265f * *right_sur++;
left_tmp = - right_tmp; left_tmp = - right_tmp;
right_tmp += 0.3204f * *right++; right_tmp += 0.3204f * *right++;
...@@ -125,89 +102,61 @@ void downmix( ac3dec_t * p_ac3dec, s16 * out_buf ) ...@@ -125,89 +102,61 @@ void downmix( ac3dec_t * p_ac3dec, s16 * out_buf )
*(out_buf++) = left_tmp * NORM; *(out_buf++) = left_tmp * NORM;
*(out_buf++) = right_tmp * NORM; *(out_buf++) = right_tmp * NORM;
/*
p_ac3dec->samples.channel[1][j] = right_tmp;
p_ac3dec->samples.channel[0][j] = left_tmp;
*/
} }
break; break;
/* 3/0 */ case 3: /* 3/0 */
case 3:
left = p_ac3dec->samples.channel[0]; left = p_ac3dec->samples.channel[0];
centre = p_ac3dec->samples.channel[1]; centre = p_ac3dec->samples.channel[1];
right = p_ac3dec->samples.channel[2]; right = p_ac3dec->samples.channel[2];
for (j = 0; j < 256; j++) for (j = 0; j < 256; j++) {
{
right_tmp = 0.3204f * *right++ + 0.2265f * *centre; right_tmp = 0.3204f * *right++ + 0.2265f * *centre;
left_tmp = 0.3204f * *left++ + 0.2265f * *centre++; left_tmp = 0.3204f * *left++ + 0.2265f * *centre++;
*(out_buf++) = left_tmp * NORM; *(out_buf++) = left_tmp * NORM;
*(out_buf++) = right_tmp * NORM; *(out_buf++) = right_tmp * NORM;
/*
p_ac3dec->samples.channel[1][j] = right_tmp;
p_ac3dec->samples.channel[0][j] = left_tmp;
*/
} }
break; break;
/* 2/0 */ case 2: /* 2/0 */
case 2:
left = p_ac3dec->samples.channel[0]; left = p_ac3dec->samples.channel[0];
right = p_ac3dec->samples.channel[1]; right = p_ac3dec->samples.channel[1];
for ( j = 0; j < 256; j++ ) for (j = 0; j < 256; j++) {
{
*(out_buf++) = *(left++) * NORM; *(out_buf++) = *(left++) * NORM;
*(out_buf++) = *(right++) * NORM; *(out_buf++) = *(right++) * NORM;
} }
break; break;
/* 1/0 */ case 1: /* 1/0 */
case 1:
/* Mono program! */ /* Mono program! */
right = p_ac3dec->samples.channel[0]; right = p_ac3dec->samples.channel[0];
for (j = 0; j < 256; j++) for (j = 0; j < 256; j++) {
{
right_tmp = 0.7071f * *right++; right_tmp = 0.7071f * *right++;
*(out_buf++) = right_tmp * NORM; *(out_buf++) = right_tmp * NORM;
*(out_buf++) = right_tmp * NORM; *(out_buf++) = right_tmp * NORM;
/*
p_ac3dec->samples.channel[1][j] = right_tmp;
p_ac3dec->samples.channel[0][j] = right_tmp;
*/
} }
break; break;
/* 1+1 */ case 0: /* 1+1 */
case 0:
/* Dual mono, output selected by user */ /* Dual mono, output selected by user */
right = p_ac3dec->samples.channel[global_prefs.dual_mono_channel_select]; right = p_ac3dec->samples.channel[global_prefs.dual_mono_channel_select];
for (j = 0; j < 256; j++) for (j = 0; j < 256; j++) {
{
right_tmp = 0.7071f * *right++; right_tmp = 0.7071f * *right++;
*(out_buf++) = right_tmp * NORM; *(out_buf++) = right_tmp * NORM;
*(out_buf++) = right_tmp * NORM; *(out_buf++) = right_tmp * NORM;
/*
p_ac3dec->samples.channel[1][j] = right_tmp;
p_ac3dec->samples.channel[0][j] = right_tmp;
*/
} }
break; break;
} }
} } else {
else
{
/* Non-Dolby surround downmixes */ /* Non-Dolby surround downmixes */
switch(p_ac3dec->bsi.acmod) switch(p_ac3dec->bsi.acmod) {
{ case 7: /* 3/2 */
/* 3/2 */
case 7:
left = p_ac3dec->samples.channel[0]; left = p_ac3dec->samples.channel[0];
centre = p_ac3dec->samples.channel[1]; centre = p_ac3dec->samples.channel[1];
right = p_ac3dec->samples.channel[2]; right = p_ac3dec->samples.channel[2];
...@@ -217,22 +166,16 @@ void downmix( ac3dec_t * p_ac3dec, s16 * out_buf ) ...@@ -217,22 +166,16 @@ void downmix( ac3dec_t * p_ac3dec, s16 * out_buf )
clev = cmixlev_lut[p_ac3dec->bsi.cmixlev]; clev = cmixlev_lut[p_ac3dec->bsi.cmixlev];
slev = smixlev_lut[p_ac3dec->bsi.surmixlev]; slev = smixlev_lut[p_ac3dec->bsi.surmixlev];
for (j = 0; j < 256; j++) for (j = 0; j < 256; j++) {
{
right_tmp= 0.4142f * *right++ + clev * *centre + slev * *right_sur++; right_tmp= 0.4142f * *right++ + clev * *centre + slev * *right_sur++;
left_tmp = 0.4142f * *left++ + clev * *centre++ + slev * *left_sur++; left_tmp = 0.4142f * *left++ + clev * *centre++ + slev * *left_sur++;
*(out_buf++) = left_tmp * NORM; *(out_buf++) = left_tmp * NORM;
*(out_buf++) = right_tmp * NORM; *(out_buf++) = right_tmp * NORM;
/*
p_ac3dec->samples.channel[1][j] = right_tmp;
p_ac3dec->samples.channel[0][j] = left_tmp;
*/
} }
break; break;
/* 2/2 */ case 6: /* 2/2 */
case 6:
left = p_ac3dec->samples.channel[0]; left = p_ac3dec->samples.channel[0];
right = p_ac3dec->samples.channel[1]; right = p_ac3dec->samples.channel[1];
left_sur = p_ac3dec->samples.channel[2]; left_sur = p_ac3dec->samples.channel[2];
...@@ -240,22 +183,16 @@ void downmix( ac3dec_t * p_ac3dec, s16 * out_buf ) ...@@ -240,22 +183,16 @@ void downmix( ac3dec_t * p_ac3dec, s16 * out_buf )
slev = smixlev_lut[p_ac3dec->bsi.surmixlev]; slev = smixlev_lut[p_ac3dec->bsi.surmixlev];
for (j = 0; j < 256; j++) for (j = 0; j < 256; j++) {
{
right_tmp= 0.4142f * *right++ + slev * *right_sur++; right_tmp= 0.4142f * *right++ + slev * *right_sur++;
left_tmp = 0.4142f * *left++ + slev * *left_sur++; left_tmp = 0.4142f * *left++ + slev * *left_sur++;
*(out_buf++) = left_tmp * NORM; *(out_buf++) = left_tmp * NORM;
*(out_buf++) = right_tmp * NORM; *(out_buf++) = right_tmp * NORM;
/*
p_ac3dec->samples.channel[1][j] = right_tmp;
p_ac3dec->samples.channel[0][j] = left_tmp;
*/
} }
break; break;
/* 3/1 */ case 5: /* 3/1 */
case 5:
left = p_ac3dec->samples.channel[0]; left = p_ac3dec->samples.channel[0];
centre = p_ac3dec->samples.channel[1]; centre = p_ac3dec->samples.channel[1];
right = p_ac3dec->samples.channel[2]; right = p_ac3dec->samples.channel[2];
...@@ -265,22 +202,16 @@ void downmix( ac3dec_t * p_ac3dec, s16 * out_buf ) ...@@ -265,22 +202,16 @@ void downmix( ac3dec_t * p_ac3dec, s16 * out_buf )
clev = cmixlev_lut[p_ac3dec->bsi.cmixlev]; clev = cmixlev_lut[p_ac3dec->bsi.cmixlev];
slev = smixlev_lut[p_ac3dec->bsi.surmixlev]; slev = smixlev_lut[p_ac3dec->bsi.surmixlev];
for (j = 0; j < 256; j++) for (j = 0; j < 256; j++) {
{
right_tmp= 0.4142f * *right++ + clev * *centre + slev * *right_sur; right_tmp= 0.4142f * *right++ + clev * *centre + slev * *right_sur;
left_tmp = 0.4142f * *left++ + clev * *centre++ + slev * *right_sur++; left_tmp = 0.4142f * *left++ + clev * *centre++ + slev * *right_sur++;
*(out_buf++) = left_tmp * NORM; *(out_buf++) = left_tmp * NORM;
*(out_buf++) = right_tmp * NORM; *(out_buf++) = right_tmp * NORM;
/*
p_ac3dec->samples.channel[1][j] = right_tmp;
p_ac3dec->samples.channel[0][j] = left_tmp;
*/
} }
break; break;
/* 2/1 */ case 4: /* 2/1 */
case 4:
left = p_ac3dec->samples.channel[0]; left = p_ac3dec->samples.channel[0];
right = p_ac3dec->samples.channel[1]; right = p_ac3dec->samples.channel[1];
/* Mono surround */ /* Mono surround */
...@@ -288,86 +219,62 @@ void downmix( ac3dec_t * p_ac3dec, s16 * out_buf ) ...@@ -288,86 +219,62 @@ void downmix( ac3dec_t * p_ac3dec, s16 * out_buf )
slev = smixlev_lut[p_ac3dec->bsi.surmixlev]; slev = smixlev_lut[p_ac3dec->bsi.surmixlev];
for (j = 0; j < 256; j++) for (j = 0; j < 256; j++) {
{
right_tmp= 0.4142f * *right++ + slev * *right_sur; right_tmp= 0.4142f * *right++ + slev * *right_sur;
left_tmp = 0.4142f * *left++ + slev * *right_sur++; left_tmp = 0.4142f * *left++ + slev * *right_sur++;
*(out_buf++) = left_tmp * NORM; *(out_buf++) = left_tmp * NORM;
*(out_buf++) = right_tmp * NORM; *(out_buf++) = right_tmp * NORM;
/*
p_ac3dec->samples.channel[1][j] = right_tmp;
p_ac3dec->samples.channel[0][j] = left_tmp;
*/
} }
break; break;
/* 3/0 */ case 3: /* 3/0 */
case 3:
left = p_ac3dec->samples.channel[0]; left = p_ac3dec->samples.channel[0];
centre = p_ac3dec->samples.channel[1]; centre = p_ac3dec->samples.channel[1];
right = p_ac3dec->samples.channel[2]; right = p_ac3dec->samples.channel[2];
clev = cmixlev_lut[p_ac3dec->bsi.cmixlev]; clev = cmixlev_lut[p_ac3dec->bsi.cmixlev];
for (j = 0; j < 256; j++) for (j = 0; j < 256; j++) {
{
right_tmp= 0.4142f * *right++ + clev * *centre; right_tmp= 0.4142f * *right++ + clev * *centre;
left_tmp = 0.4142f * *left++ + clev * *centre++; left_tmp = 0.4142f * *left++ + clev * *centre++;
*(out_buf++) = left_tmp * NORM; *(out_buf++) = left_tmp * NORM;
*(out_buf++) = right_tmp * NORM; *(out_buf++) = right_tmp * NORM;
/*
p_ac3dec->samples.channel[1][j] = right_tmp;
p_ac3dec->samples.channel[0][j] = left_tmp;
*/
} }
break; break;
case 2: case 2: /* 2/0 */
left = p_ac3dec->samples.channel[0]; left = p_ac3dec->samples.channel[0];
right = p_ac3dec->samples.channel[1]; right = p_ac3dec->samples.channel[1];
for ( j = 0; j < 256; j++ ) for (j = 0; j < 256; j++) {
{
*(out_buf++) = *(left++) * NORM; *(out_buf++) = *(left++) * NORM;
*(out_buf++) = *(right++) * NORM; *(out_buf++) = *(right++) * NORM;
} }
break; break;
/* 1/0 */ case 1: /* 1/0 */
case 1:
/* Mono program! */ /* Mono program! */
right = p_ac3dec->samples.channel[0]; right = p_ac3dec->samples.channel[0];
for (j = 0; j < 256; j++) for (j = 0; j < 256; j++) {
{
right_tmp = 0.7071f * *right++; right_tmp = 0.7071f * *right++;
*(out_buf++) = right_tmp * NORM; *(out_buf++) = right_tmp * NORM;
*(out_buf++) = right_tmp * NORM; *(out_buf++) = right_tmp * NORM;
/*
p_ac3dec->samples.channel[1][j] = right_tmp;
p_ac3dec->samples.channel[0][j] = right_tmp;
*/
} }
break; break;
/* 1+1 */ case 0: /* 1+1 */
case 0:
/* Dual mono, output selected by user */ /* Dual mono, output selected by user */
right = p_ac3dec->samples.channel[global_prefs.dual_mono_channel_select]; right = p_ac3dec->samples.channel[global_prefs.dual_mono_channel_select];
for (j = 0; j < 256; j++) for (j = 0; j < 256; j++) {
{
right_tmp = 0.7071f * *right++; right_tmp = 0.7071f * *right++;
*(out_buf++) = right_tmp * NORM; *(out_buf++) = right_tmp * NORM;
*(out_buf++) = right_tmp * NORM; *(out_buf++) = right_tmp * NORM;
/*
p_ac3dec->samples.channel[1][j] = right_tmp;
p_ac3dec->samples.channel[0][j] = right_tmp;
*/
} }
break; break;
} }
......
void downmix( ac3dec_t *, s16 * );
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "int_types.h" #include "int_types.h"
#include "ac3_decoder.h" #include "ac3_decoder.h"
#include "ac3_bit_stream.h" #include "ac3_bit_stream.h"
#include "ac3_exponent.h" #include "ac3_internal.h"
static const s16 exps_1[128] = static const s16 exps_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, { -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,
...@@ -33,13 +33,14 @@ static const s16 exps_3[128] = ...@@ -33,13 +33,14 @@ static const s16 exps_3[128] =
#define UNPACK_CPL 2 #define UNPACK_CPL 2
#define UNPACK_LFE 4 #define UNPACK_LFE 4
static __inline__ int exp_unpack_ch( ac3dec_t * p_ac3dec, u16 type, u16 expstr, u16 ngrps, u16 initial_exp, u16 exps[], u16 * dest ) static __inline__ int exp_unpack_ch (ac3dec_t * p_ac3dec, u16 type,
u16 expstr, u16 ngrps, u16 initial_exp,
u16 exps[], u16 * dest)
{ {
u16 i,j; u16 i,j;
s16 exp_acc; s16 exp_acc;
if ( expstr == EXP_REUSE ) if (expstr == EXP_REUSE) {
{
return 0; return 0;
} }
...@@ -49,20 +50,16 @@ static __inline__ int exp_unpack_ch( ac3dec_t * p_ac3dec, u16 type, u16 expstr, ...@@ -49,20 +50,16 @@ static __inline__ int exp_unpack_ch( ac3dec_t * p_ac3dec, u16 type, u16 expstr,
/* In the case of a fbw channel then the initial absolute values is /* In the case of a fbw channel then the initial absolute values is
* also an exponent */ * also an exponent */
if ( type != UNPACK_CPL ) if (type != UNPACK_CPL) {
{
dest[j++] = exp_acc; dest[j++] = exp_acc;
} }
/* Loop through the groups and fill the dest array appropriately */ /* Loop through the groups and fill the dest array appropriately */
switch ( expstr ) switch (expstr) {
{
case EXP_D15: /* 1 */ case EXP_D15: /* 1 */
for ( i = 0; i < ngrps; i++ ) for (i = 0; i < ngrps; i++) {
{ if (exps[i] > 124) {
if ( exps[i] > 124 ) fprintf (stderr, "ac3dec debug: invalid exponent\n");
{
fprintf( stderr, "ac3dec debug: invalid exponent\n" );
return 1; return 1;
} }
exp_acc += (exps_1[exps[i]] /*- 2*/); exp_acc += (exps_1[exps[i]] /*- 2*/);
...@@ -75,11 +72,9 @@ static __inline__ int exp_unpack_ch( ac3dec_t * p_ac3dec, u16 type, u16 expstr, ...@@ -75,11 +72,9 @@ static __inline__ int exp_unpack_ch( ac3dec_t * p_ac3dec, u16 type, u16 expstr,
break; break;
case EXP_D25: /* 2 */ case EXP_D25: /* 2 */
for ( i = 0; i < ngrps; i++ ) for (i = 0; i < ngrps; i++) {
{ if (exps[i] > 124) {
if ( exps[i] > 124 ) fprintf (stderr, "ac3dec debug: invalid exponent\n");
{
fprintf( stderr, "ac3dec debug: invalid exponent\n" );
return 1; return 1;
} }
exp_acc += (exps_1[exps[i]] /*- 2*/); exp_acc += (exps_1[exps[i]] /*- 2*/);
...@@ -95,11 +90,9 @@ static __inline__ int exp_unpack_ch( ac3dec_t * p_ac3dec, u16 type, u16 expstr, ...@@ -95,11 +90,9 @@ static __inline__ int exp_unpack_ch( ac3dec_t * p_ac3dec, u16 type, u16 expstr,
break; break;
case EXP_D45: /* 3 */ case EXP_D45: /* 3 */
for ( i = 0; i < ngrps; i++ ) for (i = 0; i < ngrps; i++) {
{ if (exps[i] > 124) {
if ( exps[i] > 124 ) fprintf (stderr, "ac3dec debug: invalid exponent\n");
{
fprintf( stderr, "ac3dec debug: invalid exponent\n" );
return 1; return 1;
} }
exp_acc += (exps_1[exps[i]] /*- 2*/); exp_acc += (exps_1[exps[i]] /*- 2*/);
...@@ -124,36 +117,33 @@ static __inline__ int exp_unpack_ch( ac3dec_t * p_ac3dec, u16 type, u16 expstr, ...@@ -124,36 +117,33 @@ static __inline__ int exp_unpack_ch( ac3dec_t * p_ac3dec, u16 type, u16 expstr,
return 0; return 0;
} }
int exponent_unpack( ac3dec_t * p_ac3dec ) int exponent_unpack (ac3dec_t * p_ac3dec)
{ {
u16 i; u16 i;
for ( i = 0; i < p_ac3dec->bsi.nfchans; i++ ) for (i = 0; i < p_ac3dec->bsi.nfchans; i++) {
{ if (exp_unpack_ch (p_ac3dec, UNPACK_FBW, p_ac3dec->audblk.chexpstr[i],
if (exp_unpack_ch( p_ac3dec, UNPACK_FBW, p_ac3dec->audblk.chexpstr[i],
p_ac3dec->audblk.nchgrps[i], p_ac3dec->audblk.nchgrps[i],
p_ac3dec->audblk.exps[i][0], p_ac3dec->audblk.exps[i][0],
&p_ac3dec->audblk.exps[i][1], &p_ac3dec->audblk.exps[i][1],
p_ac3dec->audblk.fbw_exp[i] )) p_ac3dec->audblk.fbw_exp[i]))
return 1; return 1;
} }
if ( p_ac3dec->audblk.cplinu ) if (p_ac3dec->audblk.cplinu) {
{ if (exp_unpack_ch (p_ac3dec, UNPACK_CPL, p_ac3dec->audblk.cplexpstr,
if (exp_unpack_ch( p_ac3dec, UNPACK_CPL, p_ac3dec->audblk.cplexpstr,
p_ac3dec->audblk.ncplgrps, p_ac3dec->audblk.ncplgrps,
p_ac3dec->audblk.cplabsexp << 1, p_ac3dec->audblk.cplabsexp << 1,
p_ac3dec->audblk.cplexps, p_ac3dec->audblk.cplexps,
&p_ac3dec->audblk.cpl_exp[p_ac3dec->audblk.cplstrtmant] )) &p_ac3dec->audblk.cpl_exp[p_ac3dec->audblk.cplstrtmant]))
return 1; return 1;
} }
if ( p_ac3dec->bsi.lfeon ) if (p_ac3dec->bsi.lfeon) {
{ if (exp_unpack_ch (p_ac3dec, UNPACK_LFE, p_ac3dec->audblk.lfeexpstr,
if (exp_unpack_ch( p_ac3dec, UNPACK_LFE, p_ac3dec->audblk.lfeexpstr,
2, p_ac3dec->audblk.lfeexps[0], 2, p_ac3dec->audblk.lfeexps[0],
&p_ac3dec->audblk.lfeexps[1], &p_ac3dec->audblk.lfeexps[1],
p_ac3dec->audblk.lfe_exp )) p_ac3dec->audblk.lfe_exp))
return 1; return 1;
} }
......
int exponent_unpack( ac3dec_t * );
...@@ -2,13 +2,12 @@ ...@@ -2,13 +2,12 @@
#include "int_types.h" #include "int_types.h"
#include "ac3_decoder.h" #include "ac3_decoder.h"
#include "ac3_imdct.h" #include "ac3_internal.h"
void imdct_do_256(float x[],float y[],float delay[]); void imdct_do_256(float x[],float y[],float delay[]);
void imdct_do_512(float x[],float y[],float delay[]); void imdct_do_512(float x[],float y[],float delay[]);
typedef struct complex_s typedef struct complex_s {
{
float real; float real;
float imag; float imag;
} complex_t; } complex_t;
...@@ -119,22 +118,21 @@ static __inline__ complex_t cmplx_mult(complex_t a, complex_t b) ...@@ -119,22 +118,21 @@ static __inline__ complex_t cmplx_mult(complex_t a, complex_t b)
return ret; return ret;
} }
void imdct_init(void) static void imdct_init(void) __attribute__ ((__constructor__));
static void imdct_init(void)
{ {
int i,k; int i,k;
complex_t angle_step; complex_t angle_step;
complex_t current_angle; complex_t current_angle;
/* Twiddle factors to turn IFFT into IMDCT */ /* Twiddle factors to turn IFFT into IMDCT */
for( i=0; i < N/4; i++) for (i=0; i < N/4; i++) {
{
xcos1[i] = -cos(2 * M_PI * (8*i+1)/(8*N)) ; xcos1[i] = -cos(2 * M_PI * (8*i+1)/(8*N)) ;
xsin1[i] = -sin(2 * M_PI * (8*i+1)/(8*N)) ; xsin1[i] = -sin(2 * M_PI * (8*i+1)/(8*N)) ;
} }
/* More twiddle factors to turn IFFT into IMDCT */ /* More twiddle factors to turn IFFT into IMDCT */
for( i=0; i < N/8; i++) for (i=0; i < N/8; i++) {
{
xcos2[i] = -cos(2 * M_PI * (8*i+1)/(4*N)) ; xcos2[i] = -cos(2 * M_PI * (8*i+1)/(4*N)) ;
xsin2[i] = -sin(2 * M_PI * (8*i+1)/(4*N)) ; xsin2[i] = -sin(2 * M_PI * (8*i+1)/(4*N)) ;
} }
...@@ -148,29 +146,26 @@ void imdct_init(void) ...@@ -148,29 +146,26 @@ void imdct_init(void)
w[5] = w_32; w[5] = w_32;
w[6] = w_64; w[6] = w_64;
for( i = 0; i < 7; i++) for (i = 0; i < 7; i++) {
{
angle_step.real = cos(-2.0f * M_PI / (1 << (i+1))); angle_step.real = cos(-2.0f * M_PI / (1 << (i+1)));
angle_step.imag = sin(-2.0f * M_PI / (1 << (i+1))); angle_step.imag = sin(-2.0f * M_PI / (1 << (i+1)));
current_angle.real = 1.0f; current_angle.real = 1.0f;
current_angle.imag = 0.0f; current_angle.imag = 0.0f;
for (k = 0; k < 1 << i; k++) for (k = 0; k < 1 << i; k++) {
{
w[i][k] = current_angle; w[i][k] = current_angle;
current_angle = cmplx_mult(current_angle,angle_step); current_angle = cmplx_mult(current_angle,angle_step);
} }
} }
} }
void imdct( ac3dec_t * p_ac3dec ) void imdct (ac3dec_t * p_ac3dec)
{ {
int i; int i;
for(i=0; i<p_ac3dec->bsi.nfchans;i++) for (i=0; i<p_ac3dec->bsi.nfchans;i++) {
{ if (p_ac3dec->audblk.blksw[i])
if(p_ac3dec->audblk.blksw[i])
imdct_do_256(p_ac3dec->coeffs.fbw[i],p_ac3dec->samples.channel[i],delay[i]); imdct_do_256(p_ac3dec->coeffs.fbw[i],p_ac3dec->samples.channel[i],delay[i]);
else else
imdct_do_512(p_ac3dec->coeffs.fbw[i],p_ac3dec->samples.channel[i],delay[i]); imdct_do_512(p_ac3dec->coeffs.fbw[i],p_ac3dec->samples.channel[i],delay[i]);
...@@ -202,31 +197,26 @@ imdct_do_512(float x[],float y[],float delay[]) ...@@ -202,31 +197,26 @@ imdct_do_512(float x[],float y[],float delay[])
float *window_ptr; float *window_ptr;
/* Pre IFFT complex multiply plus IFFT cmplx conjugate */ /* Pre IFFT complex multiply plus IFFT cmplx conjugate */
for( i=0; i < N/4; i++) for (i=0; i < N/4; i++) {
{
/* z[i] = (X[N/2-2*i-1] + j * X[2*i]) * (xcos1[i] + j * xsin1[i]) ; */ /* z[i] = (X[N/2-2*i-1] + j * X[2*i]) * (xcos1[i] + j * xsin1[i]) ; */
buf[i].real = (x[N/2-2*i-1] * xcos1[i]) - (x[2*i] * xsin1[i]); buf[i].real = (x[N/2-2*i-1] * xcos1[i]) - (x[2*i] * xsin1[i]);
buf[i].imag = -((x[2*i] * xcos1[i]) + (x[N/2-2*i-1] * xsin1[i])); buf[i].imag = -((x[2*i] * xcos1[i]) + (x[N/2-2*i-1] * xsin1[i]));
} }
/* Bit reversed shuffling */ /* Bit reversed shuffling */
for(i=0; i<N/4; i++) for (i=0; i<N/4; i++) {
{
k = bit_reverse_512[i]; k = bit_reverse_512[i];
if (k < i) if (k < i)
swap_cmplx(&buf[i],&buf[k]); swap_cmplx(&buf[i],&buf[k]);
} }
/* FFT Merge */ /* FFT Merge */
for (m=0; m < 7; m++) for (m=0; m < 7; m++) {
{
two_m = (1 << m); two_m = (1 << m);
two_m_plus_one = (1 << (m+1)); two_m_plus_one = (1 << (m+1));
for(k = 0; k < two_m; k++) for (k = 0; k < two_m; k++) {
{ for (i = 0; i < 128; i += two_m_plus_one) {
for(i = 0; i < 128; i += two_m_plus_one)
{
p = k + i; p = k + i;
q = p + two_m; q = p + two_m;
tmp_a_r = buf[p].real; tmp_a_r = buf[p].real;
...@@ -237,14 +227,12 @@ imdct_do_512(float x[],float y[],float delay[]) ...@@ -237,14 +227,12 @@ imdct_do_512(float x[],float y[],float delay[])
buf[p].imag = tmp_a_i + tmp_b_i; buf[p].imag = tmp_a_i + tmp_b_i;
buf[q].real = tmp_a_r - tmp_b_r; buf[q].real = tmp_a_r - tmp_b_r;
buf[q].imag = tmp_a_i - tmp_b_i; buf[q].imag = tmp_a_i - tmp_b_i;
} }
} }
} }
/* Post IFFT complex multiply plus IFFT complex conjugate*/ /* Post IFFT complex multiply plus IFFT complex conjugate*/
for( i=0; i < N/4; i++) for (i=0; i < N/4; i++) {
{
/* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */ /* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */
tmp_a_r = buf[i].real; tmp_a_r = buf[i].real;
tmp_a_i = - buf[i].imag; tmp_a_i = - buf[i].imag;
...@@ -256,29 +244,25 @@ imdct_do_512(float x[],float y[],float delay[]) ...@@ -256,29 +244,25 @@ imdct_do_512(float x[],float y[],float delay[])
delay_ptr = delay; delay_ptr = delay;
window_ptr = window; window_ptr = window;
/* Window and convert to real valued signal */ /* Window and convert to real valued signal */
for(i=0; i<N/8; i++) for (i=0; i<N/8; i++) {
{
*y_ptr++ = 2.0f * (-buf[N/8+i].imag * *window_ptr++ + *delay_ptr++); *y_ptr++ = 2.0f * (-buf[N/8+i].imag * *window_ptr++ + *delay_ptr++);
*y_ptr++ = 2.0f * ( buf[N/8-i-1].real * *window_ptr++ + *delay_ptr++); *y_ptr++ = 2.0f * (buf[N/8-i-1].real * *window_ptr++ + *delay_ptr++);
} }
for(i=0; i<N/8; i++) for (i=0; i<N/8; i++) {
{
*y_ptr++ = 2.0f * (-buf[i].real * *window_ptr++ + *delay_ptr++); *y_ptr++ = 2.0f * (-buf[i].real * *window_ptr++ + *delay_ptr++);
*y_ptr++ = 2.0f * ( buf[N/4-i-1].imag * *window_ptr++ + *delay_ptr++); *y_ptr++ = 2.0f * (buf[N/4-i-1].imag * *window_ptr++ + *delay_ptr++);
} }
/* The trailing edge of the window goes into the delay line */ /* The trailing edge of the window goes into the delay line */
delay_ptr = delay; delay_ptr = delay;
for(i=0; i<N/8; i++) for (i=0; i<N/8; i++) {
{
*delay_ptr++ = -buf[N/8+i].real * *--window_ptr; *delay_ptr++ = -buf[N/8+i].real * *--window_ptr;
*delay_ptr++ = buf[N/8-i-1].imag * *--window_ptr; *delay_ptr++ = buf[N/8-i-1].imag * *--window_ptr;
} }
for(i=0; i<N/8; i++) for (i=0; i<N/8; i++) {
{
*delay_ptr++ = buf[i].imag * *--window_ptr; *delay_ptr++ = buf[i].imag * *--window_ptr;
*delay_ptr++ = -buf[N/4-i-1].real * *--window_ptr; *delay_ptr++ = -buf[N/4-i-1].real * *--window_ptr;
} }
...@@ -304,8 +288,7 @@ imdct_do_256(float x[],float y[],float delay[]) ...@@ -304,8 +288,7 @@ imdct_do_256(float x[],float y[],float delay[])
buf_2 = &buf[64]; buf_2 = &buf[64];
/* Pre IFFT complex multiply plus IFFT cmplx conjugate */ /* Pre IFFT complex multiply plus IFFT cmplx conjugate */
for(k=0; k<N/8; k++) for (k=0; k<N/8; k++) {
{
/* X1[k] = X[2*k] */ /* X1[k] = X[2*k] */
/* X2[k] = X[2*k+1] */ /* X2[k] = X[2*k+1] */
...@@ -321,26 +304,21 @@ imdct_do_256(float x[],float y[],float delay[]) ...@@ -321,26 +304,21 @@ imdct_do_256(float x[],float y[],float delay[])
} }
/* IFFT Bit reversed shuffling */ /* IFFT Bit reversed shuffling */
for(i=0; i<N/8; i++) for (i=0; i<N/8; i++) {
{
k = bit_reverse_256[i]; k = bit_reverse_256[i];
if (k < i) if (k < i) {
{
swap_cmplx(&buf_1[i],&buf_1[k]); swap_cmplx(&buf_1[i],&buf_1[k]);
swap_cmplx(&buf_2[i],&buf_2[k]); swap_cmplx(&buf_2[i],&buf_2[k]);
} }
} }
/* FFT Merge */ /* FFT Merge */
for (m=0; m < 6; m++) for (m=0; m < 6; m++) {
{
two_m = (1 << m); two_m = (1 << m);
two_m_plus_one = (1 << (m+1)); two_m_plus_one = (1 << (m+1));
for(k = 0; k < two_m; k++) for (k = 0; k < two_m; k++) {
{ for (i = 0; i < 64; i += two_m_plus_one) {
for(i = 0; i < 64; i += two_m_plus_one)
{
p = k + i; p = k + i;
q = p + two_m; q = p + two_m;
/* Do block 1 */ /* Do block 1 */
...@@ -362,14 +340,12 @@ imdct_do_256(float x[],float y[],float delay[]) ...@@ -362,14 +340,12 @@ imdct_do_256(float x[],float y[],float delay[])
buf_2[p].imag = tmp_a_i + tmp_b_i; buf_2[p].imag = tmp_a_i + tmp_b_i;
buf_2[q].real = tmp_a_r - tmp_b_r; buf_2[q].real = tmp_a_r - tmp_b_r;
buf_2[q].imag = tmp_a_i - tmp_b_i; buf_2[q].imag = tmp_a_i - tmp_b_i;
} }
} }
} }
/* Post IFFT complex multiply */ /* Post IFFT complex multiply */
for( i=0; i < N/8; i++) for (i=0; i < N/8; i++) {
{
/* y1[n] = z1[n] * (xcos2[n] + j * xs in2[n]) ; */ /* y1[n] = z1[n] * (xcos2[n] + j * xs in2[n]) ; */
tmp_a_r = buf_1[i].real; tmp_a_r = buf_1[i].real;
tmp_a_i = - buf_1[i].imag; tmp_a_i = - buf_1[i].imag;
...@@ -383,8 +359,7 @@ imdct_do_256(float x[],float y[],float delay[]) ...@@ -383,8 +359,7 @@ imdct_do_256(float x[],float y[],float delay[])
} }
/* Window and convert to real valued signal */ /* Window and convert to real valued signal */
for(i=0; i<N/8; i++) for (i=0; i<N/8; i++) {
{
y[2*i] = -buf_1[i].imag * window[2*i]; y[2*i] = -buf_1[i].imag * window[2*i];
y[2*i+1] = buf_1[N/8-i-1].real * window[2*i+1]; y[2*i+1] = buf_1[N/8-i-1].real * window[2*i+1];
y[N/4+2*i] = -buf_1[i].real * window[N/4+2*i]; y[N/4+2*i] = -buf_1[i].real * window[N/4+2*i];
...@@ -396,8 +371,7 @@ imdct_do_256(float x[],float y[],float delay[]) ...@@ -396,8 +371,7 @@ imdct_do_256(float x[],float y[],float delay[])
} }
/* Overlap and add */ /* Overlap and add */
for(i=0; i<N/2; i++) for (i=0; i<N/2; i++) {
{
y[i] = 2 * (y[i] + delay[i]); y[i] = 2 * (y[i] + delay[i]);
delay[i] = y[N/2+i]; delay[i] = y[N/2+i];
} }
......
void imdct( ac3dec_t * p_ac3dec );
void imdct_init( void );
/* 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)
/* ac3_bit_allocate.c */
void bit_allocate (ac3dec_t *);
/* ac3_downmix.c */
void downmix (ac3dec_t *, s16 *);
/* ac3_exponent.c */
int exponent_unpack (ac3dec_t *);
/* ac3_imdct.c */
void imdct (ac3dec_t * p_ac3dec);
/* ac3_mantissa.c */
void mantissa_unpack (ac3dec_t *);
/* ac3_parse.c */
int ac3_test_sync (ac3dec_t *);
void parse_syncinfo (ac3dec_t *);
void parse_bsi (ac3dec_t *);
void parse_audblk (ac3dec_t *);
void parse_auxdata (ac3dec_t *);
/* ac3_rematrix.c */
void rematrix (ac3dec_t *);
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
#include "int_types.h" #include "int_types.h"
#include "ac3_decoder.h" #include "ac3_decoder.h"
#include "ac3_mantissa.h" #include "ac3_internal.h"
#include "ac3_bit_stream.h" #include "ac3_bit_stream.h"
#define Q0 ((-2 << 15) / 3) #define Q0 ((-2 << 15) / 3.0)
#define Q1 (0) #define Q1 (0)
#define Q2 ((2 << 15) / 3) #define Q2 ((2 << 15) / 3.0)
static float q_1_0[ 32 ] = { Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, static float q_1_0[ 32 ] = { 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,
Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2,
...@@ -24,11 +24,11 @@ static float q_1_2[ 32 ] = { Q0, Q1, Q2, Q0, Q1, Q2, Q0, Q1, Q2, ...@@ -24,11 +24,11 @@ static float q_1_2[ 32 ] = { Q0, Q1, Q2, Q0, Q1, Q2, Q0, Q1, Q2,
#undef Q1 #undef Q1
#undef Q2 #undef Q2
#define Q0 ((-4 << 15) / 5) #define Q0 ((-4 << 15) / 5.0)
#define Q1 ((-2 << 15) / 5) #define Q1 ((-2 << 15) / 5.0)
#define Q2 (0) #define Q2 (0)
#define Q3 ((2 << 15) / 5) #define Q3 ((2 << 15) / 5.0)
#define Q4 ((4 << 15) / 5) #define Q4 ((4 << 15) / 5.0)
static float q_2_0[ 128 ] = static float 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, { 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, 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,
...@@ -56,17 +56,17 @@ static float q_2_2[ 128 ] = ...@@ -56,17 +56,17 @@ static float q_2_2[ 128 ] =
#undef Q3 #undef Q3
#undef Q4 #undef Q4
#define Q0 ((-10 << 15) / 11) #define Q0 ((-10 << 15) / 11.0)
#define Q1 ((-8 << 15) / 11) #define Q1 ((-8 << 15) / 11.0)
#define Q2 ((-6 << 15) / 11) #define Q2 ((-6 << 15) / 11.0)
#define Q3 ((-4 << 15) / 11) #define Q3 ((-4 << 15) / 11.0)
#define Q4 ((-2 << 15) / 11) #define Q4 ((-2 << 15) / 11.0)
#define Q5 (0) #define Q5 (0)
#define Q6 ((2 << 15) / 11) #define Q6 ((2 << 15) / 11.0)
#define Q7 ((4 << 15) / 11) #define Q7 ((4 << 15) / 11.0)
#define Q8 ((6 << 15) / 11) #define Q8 ((6 << 15) / 11.0)
#define Q9 ((8 << 15) / 11) #define Q9 ((8 << 15) / 11.0)
#define QA ((10 << 15) / 11) #define QA ((10 << 15) / 11.0)
static float q_4_0[ 128 ] = { Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, static float 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, 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,
...@@ -105,15 +105,16 @@ static float q_4_1[ 128 ] = { Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA, ...@@ -105,15 +105,16 @@ static float q_4_1[ 128 ] = { Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
/* Lookup tables of 0.16 two's complement quantization values */ /* Lookup tables of 0.16 two's complement quantization values */
static float q_3[7] = { (-6 << 15)/7, (-4 << 15)/7, (-2 << 15)/7, static float q_3[8] = { (-6 << 15)/7.0, (-4 << 15)/7.0, (-2 << 15)/7.0,
0 , ( 2 << 15)/7, ( 4 << 15)/7, 0 , (2 << 15)/7.0, (4 << 15)/7.0,
( 6 << 15)/7}; (6 << 15)/7.0, 0 };
static float q_5[15] = { (-14 << 15)/15, (-12 << 15)/15, (-10 << 15)/15, static float q_5[16] = { (-14 << 15)/15.0, (-12 << 15)/15.0, (-10 << 15)/15.0,
( -8 << 15)/15, ( -6 << 15)/15, ( -4 << 15)/15, (-8 << 15)/15.0, (-6 << 15)/15.0, (-4 << 15)/15.0,
( -2 << 15)/15, 0 , ( 2 << 15)/15, (-2 << 15)/15.0, 0 , (2 << 15)/15.0,
( 4 << 15)/15, ( 6 << 15)/15, ( 8 << 15)/15, (4 << 15)/15.0, (6 << 15)/15.0, (8 << 15)/15.0,
( 10 << 15)/15, ( 12 << 15)/15, ( 14 << 15)/15}; (10 << 15)/15.0, (12 << 15)/15.0, (14 << 15)/15.0,
0 };
/* These store the persistent state of the packed mantissas */ /* These store the persistent state of the packed mantissas */
static float q_1[2]; static float q_1[2];
...@@ -157,28 +158,25 @@ static float exp_lut[ 25 ] = ...@@ -157,28 +158,25 @@ static float exp_lut[ 25 ] =
}; };
/* Fetch an unpacked, left justified, and properly biased/dithered mantissa value */ /* Fetch an unpacked, left justified, and properly biased/dithered mantissa value */
static __inline__ float float_get( ac3dec_t * p_ac3dec, u16 bap, u16 exp ) static __inline__ float float_get (ac3dec_t * p_ac3dec, u16 bap, u16 exp)
{ {
u32 group_code; u32 group_code;
/* If the bap is 0-5 then we have special cases to take care of */ /* If the bap is 0-5 then we have special cases to take care of */
switch ( bap ) switch (bap) {
{
case 0: case 0:
return( 0 ); return (0); /* FIXME dither */
case 1: case 1:
if ( q_1_pointer >= 0 ) if (q_1_pointer >= 0) {
{ return (q_1[q_1_pointer--] * exp_lut[exp]);
return( q_1[q_1_pointer--] * exp_lut[exp] );
} }
NeedBits( &(p_ac3dec->bit_stream), 5 );
group_code = p_ac3dec->bit_stream.buffer >> (32 - 5);
DumpBits( &(p_ac3dec->bit_stream), 5 );
if ( group_code > 26 ) NeedBits (&(p_ac3dec->bit_stream), 5);
{ group_code = p_ac3dec->bit_stream.buffer >> (32 - 5);
fprintf( stderr, "ac3dec debug: invalid mantissa\n" ); DumpBits (&(p_ac3dec->bit_stream), 5);
if (group_code >= 27) {
fprintf (stderr, "ac3dec debug: invalid mantissa\n");
} }
q_1[ 1 ] = q_1_1[ group_code ]; q_1[ 1 ] = q_1_1[ group_code ];
...@@ -186,20 +184,18 @@ static __inline__ float float_get( ac3dec_t * p_ac3dec, u16 bap, u16 exp ) ...@@ -186,20 +184,18 @@ static __inline__ float float_get( ac3dec_t * p_ac3dec, u16 bap, u16 exp )
q_1_pointer = 1; q_1_pointer = 1;
return( q_1_0[group_code] * exp_lut[exp] ); return (q_1_0[group_code] * exp_lut[exp]);
case 2: case 2:
if ( q_2_pointer >= 0 ) if (q_2_pointer >= 0) {
{ return (q_2[q_2_pointer--] * exp_lut[exp]);
return( q_2[q_2_pointer--] * exp_lut[exp] );
} }
NeedBits( &(p_ac3dec->bit_stream), 7 ); NeedBits (&(p_ac3dec->bit_stream), 7);
group_code = p_ac3dec->bit_stream.buffer >> (32 - 7); group_code = p_ac3dec->bit_stream.buffer >> (32 - 7);
DumpBits( &(p_ac3dec->bit_stream), 7 ); DumpBits (&(p_ac3dec->bit_stream), 7);
if ( group_code > 124 ) if (group_code >= 125) {
{ fprintf (stderr, "ac3dec debug: invalid mantissa\n");
fprintf( stderr, "ac3dec debug: invalid mantissa\n" );
} }
q_2[ 1 ] = q_2_1[ group_code ]; q_2[ 1 ] = q_2_1[ group_code ];
...@@ -207,62 +203,58 @@ static __inline__ float float_get( ac3dec_t * p_ac3dec, u16 bap, u16 exp ) ...@@ -207,62 +203,58 @@ static __inline__ float float_get( ac3dec_t * p_ac3dec, u16 bap, u16 exp )
q_2_pointer = 1; q_2_pointer = 1;
return( q_2_0[ group_code ] * exp_lut[exp] ); return (q_2_0[ group_code ] * exp_lut[exp]);
case 3: case 3:
NeedBits( &(p_ac3dec->bit_stream), 3 ); NeedBits (&(p_ac3dec->bit_stream), 3);
group_code = p_ac3dec->bit_stream.buffer >> (32 - 3); group_code = p_ac3dec->bit_stream.buffer >> (32 - 3);
DumpBits( &(p_ac3dec->bit_stream), 3 ); DumpBits (&(p_ac3dec->bit_stream), 3);
if ( group_code > 6 ) if (group_code >= 7) {
{ fprintf (stderr, "ac3dec debug: invalid mantissa\n");
fprintf( stderr, "ac3dec debug: invalid mantissa\n" );
} }
return( q_3[group_code] * exp_lut[exp] ); return (q_3[group_code] * exp_lut[exp]);
case 4: case 4:
if ( q_4_pointer >= 0 ) if (q_4_pointer >= 0) {
{ return (q_4[q_4_pointer--] * exp_lut[exp]);
return( q_4[q_4_pointer--] * exp_lut[exp] );
} }
NeedBits( &(p_ac3dec->bit_stream), 7 ); NeedBits (&(p_ac3dec->bit_stream), 7);
group_code = p_ac3dec->bit_stream.buffer >> (32 - 7); group_code = p_ac3dec->bit_stream.buffer >> (32 - 7);
DumpBits( &(p_ac3dec->bit_stream), 7 ); DumpBits (&(p_ac3dec->bit_stream), 7);
if ( group_code > 120 ) if (group_code >= 121) {
{ fprintf (stderr, "ac3dec debug: invalid mantissa\n");
fprintf( stderr, "ac3dec debug: invalid mantissa\n" );
} }
q_4[ 0 ] = q_4_1[ group_code ]; q_4[ 0 ] = q_4_1[ group_code ];
q_4_pointer = 0; q_4_pointer = 0;
return( q_4_0[ group_code ] * exp_lut[exp] ); return (q_4_0[ group_code ] * exp_lut[exp]);
case 5: case 5:
NeedBits( &(p_ac3dec->bit_stream), 4 ); NeedBits (&(p_ac3dec->bit_stream), 4);
group_code = p_ac3dec->bit_stream.buffer >> (32 - 4); group_code = p_ac3dec->bit_stream.buffer >> (32 - 4);
DumpBits( &(p_ac3dec->bit_stream), 4 ); DumpBits (&(p_ac3dec->bit_stream), 4);
if ( group_code > 14 ) if (group_code >= 15) {
{ fprintf (stderr, "ac3dec debug: invalid mantissa\n");
fprintf( stderr, "ac3dec debug: invalid mantissa\n" );
} }
return( q_5[group_code] * exp_lut[exp] ); return (q_5[group_code] * exp_lut[exp]);
default: default:
NeedBits( &(p_ac3dec->bit_stream), qnttztab[bap] ); NeedBits (&(p_ac3dec->bit_stream), qnttztab[bap]);
group_code = (((s32)(p_ac3dec->bit_stream.buffer)) >> (32 - qnttztab[bap])) << (16 - qnttztab[bap]); group_code = (((s32)(p_ac3dec->bit_stream.buffer)) >> (32 - qnttztab[bap])) << (16 - qnttztab[bap]);
DumpBits( &(p_ac3dec->bit_stream), qnttztab[bap] ); DumpBits (&(p_ac3dec->bit_stream), qnttztab[bap]);
return( ((s32)group_code) * exp_lut[exp] ); return (((s32)group_code) * exp_lut[exp]);
} }
} }
static __inline__ void uncouple_channel( ac3dec_t * p_ac3dec, u32 ch ) static __inline__ void uncouple_channel (ac3dec_t * p_ac3dec, u32 ch)
{ {
u32 bnd = 0; u32 bnd = 0;
u32 i,j; u32 i,j;
...@@ -270,12 +262,10 @@ static __inline__ void uncouple_channel( ac3dec_t * p_ac3dec, u32 ch ) ...@@ -270,12 +262,10 @@ static __inline__ void uncouple_channel( ac3dec_t * p_ac3dec, u32 ch )
u32 cpl_exp_tmp; u32 cpl_exp_tmp;
u32 cpl_mant_tmp; u32 cpl_mant_tmp;
for(i=p_ac3dec->audblk.cplstrtmant;i<p_ac3dec->audblk.cplendmant;) for (i = p_ac3dec->audblk.cplstrtmant; i < p_ac3dec->audblk.cplendmant;) {
{ if (!p_ac3dec->audblk.cplbndstrc[bnd]) {
if(!p_ac3dec->audblk.cplbndstrc[bnd])
{
cpl_exp_tmp = p_ac3dec->audblk.cplcoexp[ch][bnd] + 3 * p_ac3dec->audblk.mstrcplco[ch]; cpl_exp_tmp = p_ac3dec->audblk.cplcoexp[ch][bnd] + 3 * p_ac3dec->audblk.mstrcplco[ch];
if(p_ac3dec->audblk.cplcoexp[ch][bnd] == 15) if (p_ac3dec->audblk.cplcoexp[ch][bnd] == 15)
cpl_mant_tmp = (p_ac3dec->audblk.cplcomant[ch][bnd]) << 12; cpl_mant_tmp = (p_ac3dec->audblk.cplcomant[ch][bnd]) << 12;
else else
cpl_mant_tmp = ((0x10) | p_ac3dec->audblk.cplcomant[ch][bnd]) << 11; cpl_mant_tmp = ((0x10) | p_ac3dec->audblk.cplcomant[ch][bnd]) << 11;
...@@ -284,15 +274,14 @@ static __inline__ void uncouple_channel( ac3dec_t * p_ac3dec, u32 ch ) ...@@ -284,15 +274,14 @@ static __inline__ void uncouple_channel( ac3dec_t * p_ac3dec, u32 ch )
} }
bnd++; bnd++;
for(j=0;j < 12; j++) for (j=0;j < 12; j++) {
{
p_ac3dec->coeffs.fbw[ch][i] = cpl_coord * p_ac3dec->audblk.cplfbw[i]; p_ac3dec->coeffs.fbw[ch][i] = cpl_coord * p_ac3dec->audblk.cplfbw[i];
i++; i++;
} }
} }
} }
void mantissa_unpack( ac3dec_t * p_ac3dec ) void mantissa_unpack (ac3dec_t * p_ac3dec)
{ {
int i, j; int i, j;
...@@ -300,58 +289,44 @@ void mantissa_unpack( ac3dec_t * p_ac3dec ) ...@@ -300,58 +289,44 @@ void mantissa_unpack( ac3dec_t * p_ac3dec )
q_2_pointer = -1; q_2_pointer = -1;
q_4_pointer = -1; q_4_pointer = -1;
if ( p_ac3dec->audblk.cplinu ) if (p_ac3dec->audblk.cplinu) {
{
/* 1 */ /* 1 */
for ( i = 0; !p_ac3dec->audblk.chincpl[i]; i++ ) for (i = 0; !p_ac3dec->audblk.chincpl[i]; i++) {
{ for (j = 0; j < p_ac3dec->audblk.endmant[i]; j++) {
for ( j = 0; j < p_ac3dec->audblk.endmant[i]; j++ ) p_ac3dec->coeffs.fbw[i][j] = float_get (p_ac3dec, p_ac3dec->audblk.fbw_bap[i][j], p_ac3dec->audblk.fbw_exp[i][j]);
{
p_ac3dec->coeffs.fbw[i][j] = float_get( p_ac3dec, p_ac3dec->audblk.fbw_bap[i][j], p_ac3dec->audblk.fbw_exp[i][j] );
} }
} }
/* 2 */ /* 2 */
for ( j = 0; j < p_ac3dec->audblk.endmant[i]; j++ ) for (j = 0; j < p_ac3dec->audblk.endmant[i]; j++) {
{ p_ac3dec->coeffs.fbw[i][j] = float_get (p_ac3dec, p_ac3dec->audblk.fbw_bap[i][j], p_ac3dec->audblk.fbw_exp[i][j]);
p_ac3dec->coeffs.fbw[i][j] = float_get( p_ac3dec, p_ac3dec->audblk.fbw_bap[i][j], p_ac3dec->audblk.fbw_exp[i][j] );
} }
for ( j = p_ac3dec->audblk.cplstrtmant; j < p_ac3dec->audblk.cplendmant; j++ ) for (j = p_ac3dec->audblk.cplstrtmant; j < p_ac3dec->audblk.cplendmant; j++) {
{ p_ac3dec->audblk.cplfbw[j] = float_get (p_ac3dec, p_ac3dec->audblk.cpl_bap[j], p_ac3dec->audblk.cpl_exp[j]);
p_ac3dec->audblk.cplfbw[j] = float_get( p_ac3dec, p_ac3dec->audblk.cpl_bap[j], p_ac3dec->audblk.cpl_exp[j] );
} }
uncouple_channel( p_ac3dec, i ); uncouple_channel (p_ac3dec, i);
/* 3 */ /* 3 */
for ( i++; i < p_ac3dec->bsi.nfchans; i++ ) for (i++; i < p_ac3dec->bsi.nfchans; i++) {
{ for (j = 0; j < p_ac3dec->audblk.endmant[i]; j++) {
for ( j = 0; j < p_ac3dec->audblk.endmant[i]; j++ ) p_ac3dec->coeffs.fbw[i][j] = float_get (p_ac3dec, p_ac3dec->audblk.fbw_bap[i][j], p_ac3dec->audblk.fbw_exp[i][j]);
{
p_ac3dec->coeffs.fbw[i][j] = float_get( p_ac3dec, p_ac3dec->audblk.fbw_bap[i][j], p_ac3dec->audblk.fbw_exp[i][j] );
} }
if ( p_ac3dec->audblk.chincpl[i] ) if (p_ac3dec->audblk.chincpl[i]) {
{ uncouple_channel (p_ac3dec, i);
uncouple_channel( p_ac3dec, i );
} }
} }
} } else {
else for (i = 0; i < p_ac3dec->bsi.nfchans; i++) {
{ for (j = 0; j < p_ac3dec->audblk.endmant[i]; j++) {
for ( i = 0; i < p_ac3dec->bsi.nfchans; i++ ) p_ac3dec->coeffs.fbw[i][j] = float_get (p_ac3dec, p_ac3dec->audblk.fbw_bap[i][j], p_ac3dec->audblk.fbw_exp[i][j]);
{
for ( j = 0; j < p_ac3dec->audblk.endmant[i]; j++ )
{
p_ac3dec->coeffs.fbw[i][j] = float_get( p_ac3dec, p_ac3dec->audblk.fbw_bap[i][j], p_ac3dec->audblk.fbw_exp[i][j] );
} }
} }
} }
if ( p_ac3dec->bsi.lfeon ) if (p_ac3dec->bsi.lfeon) {
{
/* There are always 7 mantissas for lfe, no dither for lfe */ /* There are always 7 mantissas for lfe, no dither for lfe */
for ( j = 0; j < 7; j++ ) for (j = 0; j < 7; j++) {
{ p_ac3dec->coeffs.lfe[j] = float_get (p_ac3dec, p_ac3dec->audblk.lfe_bap[j], p_ac3dec->audblk.lfe_exp[j]);
p_ac3dec->coeffs.lfe[j] = float_get( p_ac3dec, p_ac3dec->audblk.lfe_bap[j], p_ac3dec->audblk.lfe_exp[j] );
} }
} }
} }
void mantissa_unpack( ac3dec_t * );
#include "int_types.h" #include "int_types.h"
#include "ac3_decoder.h" #include "ac3_decoder.h"
#include "ac3_parse.h" #include "ac3_internal.h"
#include "ac3_bit_stream.h" #include "ac3_bit_stream.h"
/* Misc LUT */ /* Misc LUT */
static u16 nfchans[] = { 2, 1, 2, 3, 3, 4, 4, 5 }; static u16 nfchans[] = { 2, 1, 2, 3, 3, 4, 4, 5 };
struct frmsize_s struct frmsize_s {
{
u16 bit_rate; u16 bit_rate;
u16 frm_size[3]; u16 frm_size[3];
}; };
...@@ -52,330 +51,309 @@ static struct frmsize_s frmsizecod_tbl[] = { ...@@ -52,330 +51,309 @@ static struct frmsize_s frmsizecod_tbl[] = {
{ 640 ,{1280 ,1393 ,1920 } }, { 640 ,{1280 ,1393 ,1920 } },
{ 640 ,{1280 ,1394 ,1920 } }}; { 640 ,{1280 ,1394 ,1920 } }};
/* Look for a sync word */ static int fscod_tbl[] = {48000, 44100, 32000};
int ac3_test_sync (ac3dec_t * p_ac3dec)
/* Parse a syncinfo structure */
int ac3_sync_frame (ac3dec_t * p_ac3dec, ac3_sync_info_t * p_sync_info)
{ {
NeedBits( &(p_ac3dec->bit_stream), 16 ); int buf;
if ( (p_ac3dec->bit_stream.buffer >> (32 - 16)) == 0x0b77 )
{
p_ac3dec->bit_stream.total_bits_read = 0; p_ac3dec->bit_stream.total_bits_read = 0;
DumpBits( &(p_ac3dec->bit_stream), 16 ); p_ac3dec->bit_stream.i_available = 0;
return 0;
} /* sync word - should be 0x0b77 */
DumpBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 16);
buf = p_ac3dec->bit_stream.buffer >> (32 - 16);
DumpBits (&(p_ac3dec->bit_stream), 16);
if (buf != 0x0b77)
return 1; return 1;
}
/* Parse a syncinfo structure, minus the sync word */
void parse_syncinfo( ac3dec_t * p_ac3dec )
{
/* Get crc1 - we don't actually use this data though */ /* Get crc1 - we don't actually use this data though */
NeedBits( &(p_ac3dec->bit_stream), 16 ); NeedBits (&(p_ac3dec->bit_stream), 16);
DumpBits( &(p_ac3dec->bit_stream), 16 ); DumpBits (&(p_ac3dec->bit_stream), 16);
/* Get the sampling rate */ /* Get the sampling rate */
NeedBits( &(p_ac3dec->bit_stream), 2 ); NeedBits (&(p_ac3dec->bit_stream), 2);
p_ac3dec->syncinfo.fscod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); p_ac3dec->syncinfo.fscod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2));
// fprintf( stderr, "parse debug: fscod == %i\n", p_ac3dec->syncinfo.fscod ); DumpBits (&(p_ac3dec->bit_stream), 2);
DumpBits( &(p_ac3dec->bit_stream), 2 );
/* Get the frame size code */ /* Get the frame size code */
NeedBits( &(p_ac3dec->bit_stream), 6 ); NeedBits (&(p_ac3dec->bit_stream), 6);
p_ac3dec->syncinfo.frmsizecod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 6)); p_ac3dec->syncinfo.frmsizecod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 6));
// fprintf( stderr, "parse debug: frmsizecod == %i\n", p_ac3dec->syncinfo.frmsizecod ); DumpBits (&(p_ac3dec->bit_stream), 6);
DumpBits( &(p_ac3dec->bit_stream), 6 );
p_sync_info->bit_rate = frmsizecod_tbl[p_ac3dec->syncinfo.frmsizecod].bit_rate;
p_ac3dec->syncinfo.bit_rate = frmsizecod_tbl[p_ac3dec->syncinfo.frmsizecod].bit_rate;
// fprintf( stderr, "parse debug: bit_rate == %i\n", p_ac3dec->syncinfo.bit_rate );
p_ac3dec->syncinfo.frame_size = frmsizecod_tbl[p_ac3dec->syncinfo.frmsizecod].frm_size[p_ac3dec->syncinfo.fscod]; p_ac3dec->syncinfo.frame_size = frmsizecod_tbl[p_ac3dec->syncinfo.frmsizecod].frm_size[p_ac3dec->syncinfo.fscod];
// fprintf( stderr, "parse debug: frame_size == %i\n", p_ac3dec->syncinfo.frame_size ); p_sync_info->frame_size = 2 * p_ac3dec->syncinfo.frame_size;
p_sync_info->sample_rate = fscod_tbl[p_ac3dec->syncinfo.fscod];
return 0;
} }
/* /*
* This routine fills a bsi struct from the AC3 stream * This routine fills a bsi struct from the AC3 stream
*/ */
void parse_bsi( ac3dec_t * p_ac3dec ) void parse_bsi (ac3dec_t * p_ac3dec)
{ {
u32 i; u32 i;
/* Check the AC-3 version number */ /* Check the AC-3 version number */
NeedBits( &(p_ac3dec->bit_stream), 5 ); NeedBits (&(p_ac3dec->bit_stream), 5);
p_ac3dec->bsi.bsid = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5)); p_ac3dec->bsi.bsid = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5));
DumpBits( &(p_ac3dec->bit_stream), 5 ); DumpBits (&(p_ac3dec->bit_stream), 5);
/* Get the audio service provided by the steram */ /* Get the audio service provided by the steram */
NeedBits( &(p_ac3dec->bit_stream), 3 ); NeedBits (&(p_ac3dec->bit_stream), 3);
p_ac3dec->bsi.bsmod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3)); p_ac3dec->bsi.bsmod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3));
DumpBits( &(p_ac3dec->bit_stream), 3 ); DumpBits (&(p_ac3dec->bit_stream), 3);
/* Get the audio coding mode (ie how many channels)*/ /* Get the audio coding mode (ie how many channels)*/
NeedBits( &(p_ac3dec->bit_stream), 3 ); NeedBits (&(p_ac3dec->bit_stream), 3);
p_ac3dec->bsi.acmod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3)); p_ac3dec->bsi.acmod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3));
DumpBits( &(p_ac3dec->bit_stream), 3 ); DumpBits (&(p_ac3dec->bit_stream), 3);
/* Predecode the number of full bandwidth channels as we use this /* Predecode the number of full bandwidth channels as we use this
* number a lot */ * number a lot */
p_ac3dec->bsi.nfchans = nfchans[p_ac3dec->bsi.acmod]; p_ac3dec->bsi.nfchans = nfchans[p_ac3dec->bsi.acmod];
/* If it is in use, get the centre channel mix level */ /* If it is in use, get the centre channel mix level */
if ((p_ac3dec->bsi.acmod & 0x1) && (p_ac3dec->bsi.acmod != 0x1)) if ((p_ac3dec->bsi.acmod & 0x1) && (p_ac3dec->bsi.acmod != 0x1)) {
{ NeedBits (&(p_ac3dec->bit_stream), 2);
NeedBits( &(p_ac3dec->bit_stream), 2 );
p_ac3dec->bsi.cmixlev = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); p_ac3dec->bsi.cmixlev = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2));
DumpBits( &(p_ac3dec->bit_stream), 2 ); DumpBits (&(p_ac3dec->bit_stream), 2);
} }
/* If it is in use, get the surround channel mix level */ /* If it is in use, get the surround channel mix level */
if (p_ac3dec->bsi.acmod & 0x4) if (p_ac3dec->bsi.acmod & 0x4) {
{ NeedBits (&(p_ac3dec->bit_stream), 2);
NeedBits( &(p_ac3dec->bit_stream), 2 );
p_ac3dec->bsi.surmixlev = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); p_ac3dec->bsi.surmixlev = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2));
DumpBits( &(p_ac3dec->bit_stream), 2 ); DumpBits (&(p_ac3dec->bit_stream), 2);
} }
/* Get the dolby surround mode if in 2/0 mode */ /* Get the dolby surround mode if in 2/0 mode */
if(p_ac3dec->bsi.acmod == 0x2) if (p_ac3dec->bsi.acmod == 0x2) {
{ NeedBits (&(p_ac3dec->bit_stream), 2);
NeedBits( &(p_ac3dec->bit_stream), 2 );
p_ac3dec->bsi.dsurmod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); p_ac3dec->bsi.dsurmod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2));
DumpBits( &(p_ac3dec->bit_stream), 2 ); DumpBits (&(p_ac3dec->bit_stream), 2);
} }
/* Is the low frequency effects channel on? */ /* Is the low frequency effects channel on? */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->bsi.lfeon = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->bsi.lfeon = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
/* Get the dialogue normalization level */ /* Get the dialogue normalization level */
NeedBits( &(p_ac3dec->bit_stream), 5 ); NeedBits (&(p_ac3dec->bit_stream), 5);
p_ac3dec->bsi.dialnorm = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5)); p_ac3dec->bsi.dialnorm = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5));
DumpBits( &(p_ac3dec->bit_stream), 5 ); DumpBits (&(p_ac3dec->bit_stream), 5);
/* Does compression gain exist? */ /* Does compression gain exist? */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->bsi.compre = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->bsi.compre = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if (p_ac3dec->bsi.compre) if (p_ac3dec->bsi.compre) {
{
/* Get compression gain */ /* Get compression gain */
NeedBits( &(p_ac3dec->bit_stream), 8 ); NeedBits (&(p_ac3dec->bit_stream), 8);
p_ac3dec->bsi.compr = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 8)); p_ac3dec->bsi.compr = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 8));
DumpBits( &(p_ac3dec->bit_stream), 8 ); DumpBits (&(p_ac3dec->bit_stream), 8);
} }
/* Does language code exist? */ /* Does language code exist? */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->bsi.langcode = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->bsi.langcode = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if (p_ac3dec->bsi.langcode) if (p_ac3dec->bsi.langcode) {
{
/* Get langauge code */ /* Get langauge code */
NeedBits( &(p_ac3dec->bit_stream), 8 ); NeedBits (&(p_ac3dec->bit_stream), 8);
p_ac3dec->bsi.langcod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 8)); p_ac3dec->bsi.langcod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 8));
DumpBits( &(p_ac3dec->bit_stream), 8 ); DumpBits (&(p_ac3dec->bit_stream), 8);
} }
/* Does audio production info exist? */ /* Does audio production info exist? */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->bsi.audprodie = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->bsi.audprodie = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if (p_ac3dec->bsi.audprodie) if (p_ac3dec->bsi.audprodie) {
{
/* Get mix level */ /* Get mix level */
NeedBits( &(p_ac3dec->bit_stream), 5 ); NeedBits (&(p_ac3dec->bit_stream), 5);
p_ac3dec->bsi.mixlevel = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5)); p_ac3dec->bsi.mixlevel = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5));
DumpBits( &(p_ac3dec->bit_stream), 5 ); DumpBits (&(p_ac3dec->bit_stream), 5);
/* Get room type */ /* Get room type */
NeedBits( &(p_ac3dec->bit_stream), 2 ); NeedBits (&(p_ac3dec->bit_stream), 2);
p_ac3dec->bsi.roomtyp = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); p_ac3dec->bsi.roomtyp = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2));
DumpBits( &(p_ac3dec->bit_stream), 2 ); DumpBits (&(p_ac3dec->bit_stream), 2);
} }
/* If we're in dual mono mode then get some extra info */ /* If we're in dual mono mode then get some extra info */
if (p_ac3dec->bsi.acmod ==0) if (p_ac3dec->bsi.acmod ==0) {
{
/* Get the dialogue normalization level two */ /* Get the dialogue normalization level two */
NeedBits( &(p_ac3dec->bit_stream), 5 ); NeedBits (&(p_ac3dec->bit_stream), 5);
p_ac3dec->bsi.dialnorm2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5)); p_ac3dec->bsi.dialnorm2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5));
DumpBits( &(p_ac3dec->bit_stream), 5 ); DumpBits (&(p_ac3dec->bit_stream), 5);
/* Does compression gain two exist? */ /* Does compression gain two exist? */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->bsi.compr2e = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->bsi.compr2e = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if (p_ac3dec->bsi.compr2e) if (p_ac3dec->bsi.compr2e) {
{
/* Get compression gain two */ /* Get compression gain two */
NeedBits( &(p_ac3dec->bit_stream), 8 ); NeedBits (&(p_ac3dec->bit_stream), 8);
p_ac3dec->bsi.compr2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 8)); p_ac3dec->bsi.compr2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 8));
DumpBits( &(p_ac3dec->bit_stream), 8 ); DumpBits (&(p_ac3dec->bit_stream), 8);
} }
/* Does language code two exist? */ /* Does language code two exist? */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->bsi.langcod2e = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->bsi.langcod2e = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if (p_ac3dec->bsi.langcod2e) if (p_ac3dec->bsi.langcod2e) {
{
/* Get langauge code two */ /* Get langauge code two */
NeedBits( &(p_ac3dec->bit_stream), 8 ); NeedBits (&(p_ac3dec->bit_stream), 8);
p_ac3dec->bsi.langcod2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 8)); p_ac3dec->bsi.langcod2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 8));
DumpBits( &(p_ac3dec->bit_stream), 8 ); DumpBits (&(p_ac3dec->bit_stream), 8);
} }
/* Does audio production info two exist? */ /* Does audio production info two exist? */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->bsi.audprodi2e = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->bsi.audprodi2e = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if (p_ac3dec->bsi.audprodi2e) if (p_ac3dec->bsi.audprodi2e) {
{
/* Get mix level two */ /* Get mix level two */
NeedBits( &(p_ac3dec->bit_stream), 5 ); NeedBits (&(p_ac3dec->bit_stream), 5);
p_ac3dec->bsi.mixlevel2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5)); p_ac3dec->bsi.mixlevel2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5));
DumpBits( &(p_ac3dec->bit_stream), 5 ); DumpBits (&(p_ac3dec->bit_stream), 5);
/* Get room type two */ /* Get room type two */
NeedBits( &(p_ac3dec->bit_stream), 2 ); NeedBits (&(p_ac3dec->bit_stream), 2);
p_ac3dec->bsi.roomtyp2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); p_ac3dec->bsi.roomtyp2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2));
DumpBits( &(p_ac3dec->bit_stream), 2 ); DumpBits (&(p_ac3dec->bit_stream), 2);
} }
} }
/* Get the copyright bit */ /* Get the copyright bit */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->bsi.copyrightb = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->bsi.copyrightb = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
/* Get the original bit */ /* Get the original bit */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->bsi.origbs = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->bsi.origbs = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
/* Does timecode one exist? */ /* Does timecode one exist? */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->bsi.timecod1e = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->bsi.timecod1e = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if(p_ac3dec->bsi.timecod1e) if (p_ac3dec->bsi.timecod1e) {
{ NeedBits (&(p_ac3dec->bit_stream), 14);
NeedBits( &(p_ac3dec->bit_stream), 14 );
p_ac3dec->bsi.timecod1 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 14)); p_ac3dec->bsi.timecod1 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 14));
DumpBits( &(p_ac3dec->bit_stream), 14 ); DumpBits (&(p_ac3dec->bit_stream), 14);
} }
/* Does timecode two exist? */ /* Does timecode two exist? */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->bsi.timecod2e = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->bsi.timecod2e = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if(p_ac3dec->bsi.timecod2e) if (p_ac3dec->bsi.timecod2e) {
{ NeedBits (&(p_ac3dec->bit_stream), 14);
NeedBits( &(p_ac3dec->bit_stream), 14 );
p_ac3dec->bsi.timecod2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 14)); p_ac3dec->bsi.timecod2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 14));
DumpBits( &(p_ac3dec->bit_stream), 14 ); DumpBits (&(p_ac3dec->bit_stream), 14);
} }
/* Does addition info exist? */ /* Does addition info exist? */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->bsi.addbsie = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->bsi.addbsie = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if(p_ac3dec->bsi.addbsie) if (p_ac3dec->bsi.addbsie) {
{
/* Get how much info is there */ /* Get how much info is there */
NeedBits( &(p_ac3dec->bit_stream), 6 ); NeedBits (&(p_ac3dec->bit_stream), 6);
p_ac3dec->bsi.addbsil = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 6)); p_ac3dec->bsi.addbsil = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 6));
DumpBits( &(p_ac3dec->bit_stream), 6 ); DumpBits (&(p_ac3dec->bit_stream), 6);
/* Get the additional info */ /* Get the additional info */
for(i=0;i<(p_ac3dec->bsi.addbsil + 1);i++) for (i=0;i<(p_ac3dec->bsi.addbsil + 1);i++) {
{ NeedBits (&(p_ac3dec->bit_stream), 8);
NeedBits( &(p_ac3dec->bit_stream), 8 );
p_ac3dec->bsi.addbsi[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 8)); p_ac3dec->bsi.addbsi[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 8));
DumpBits( &(p_ac3dec->bit_stream), 8 ); DumpBits (&(p_ac3dec->bit_stream), 8);
} }
} }
} }
/* More pain inducing parsing */ /* More pain inducing parsing */
void parse_audblk( ac3dec_t * p_ac3dec ) void parse_audblk (ac3dec_t * p_ac3dec)
{ {
int i, j; int i, j;
for (i=0;i < p_ac3dec->bsi.nfchans; i++) for (i=0; i < p_ac3dec->bsi.nfchans; i++) {
{
/* Is this channel an interleaved 256 + 256 block ? */ /* Is this channel an interleaved 256 + 256 block ? */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->audblk.blksw[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.blksw[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
} }
for (i=0;i < p_ac3dec->bsi.nfchans; i++) for (i=0; i < p_ac3dec->bsi.nfchans; i++) {
{
/* Should we dither this channel? */ /* Should we dither this channel? */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->audblk.dithflag[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.dithflag[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
} }
/* Does dynamic range control exist? */ /* Does dynamic range control exist? */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->audblk.dynrnge = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.dynrnge = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if (p_ac3dec->audblk.dynrnge) if (p_ac3dec->audblk.dynrnge) {
{
/* Get dynamic range info */ /* Get dynamic range info */
NeedBits( &(p_ac3dec->bit_stream), 8 ); NeedBits (&(p_ac3dec->bit_stream), 8);
p_ac3dec->audblk.dynrng = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 8)); p_ac3dec->audblk.dynrng = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 8));
DumpBits( &(p_ac3dec->bit_stream), 8 ); DumpBits (&(p_ac3dec->bit_stream), 8);
} }
/* If we're in dual mono mode then get the second channel DR info */ /* If we're in dual mono mode then get the second channel DR info */
if (p_ac3dec->bsi.acmod == 0) if (p_ac3dec->bsi.acmod == 0) {
{
/* Does dynamic range control two exist? */ /* Does dynamic range control two exist? */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->audblk.dynrng2e = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.dynrng2e = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if (p_ac3dec->audblk.dynrng2e) if (p_ac3dec->audblk.dynrng2e) {
{
/* Get dynamic range info */ /* Get dynamic range info */
NeedBits( &(p_ac3dec->bit_stream), 8 ); NeedBits (&(p_ac3dec->bit_stream), 8);
p_ac3dec->audblk.dynrng2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 8)); p_ac3dec->audblk.dynrng2 = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 8));
DumpBits( &(p_ac3dec->bit_stream), 8 ); DumpBits (&(p_ac3dec->bit_stream), 8);
} }
} }
/* Does coupling strategy exist? */ /* Does coupling strategy exist? */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->audblk.cplstre = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.cplstre = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if (p_ac3dec->audblk.cplstre) if (p_ac3dec->audblk.cplstre) {
{
/* Is coupling turned on? */ /* Is coupling turned on? */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->audblk.cplinu = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.cplinu = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if(p_ac3dec->audblk.cplinu) if (p_ac3dec->audblk.cplinu) {
{ for (i=0; i < p_ac3dec->bsi.nfchans; i++) {
for(i=0;i < p_ac3dec->bsi.nfchans; i++) NeedBits (&(p_ac3dec->bit_stream), 1);
{
NeedBits( &(p_ac3dec->bit_stream), 1 );
p_ac3dec->audblk.chincpl[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.chincpl[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
} }
if(p_ac3dec->bsi.acmod == 0x2) if (p_ac3dec->bsi.acmod == 0x2) {
{ NeedBits (&(p_ac3dec->bit_stream), 1);
NeedBits( &(p_ac3dec->bit_stream), 1 );
p_ac3dec->audblk.phsflginu = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.phsflginu = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
} }
NeedBits( &(p_ac3dec->bit_stream), 4 ); NeedBits (&(p_ac3dec->bit_stream), 4);
p_ac3dec->audblk.cplbegf = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4)); p_ac3dec->audblk.cplbegf = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4));
DumpBits( &(p_ac3dec->bit_stream), 4 ); DumpBits (&(p_ac3dec->bit_stream), 4);
NeedBits( &(p_ac3dec->bit_stream), 4 ); NeedBits (&(p_ac3dec->bit_stream), 4);
p_ac3dec->audblk.cplendf = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4)); p_ac3dec->audblk.cplendf = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4));
DumpBits( &(p_ac3dec->bit_stream), 4 ); DumpBits (&(p_ac3dec->bit_stream), 4);
p_ac3dec->audblk.ncplsubnd = (p_ac3dec->audblk.cplendf + 2) - p_ac3dec->audblk.cplbegf + 1; p_ac3dec->audblk.ncplsubnd = (p_ac3dec->audblk.cplendf + 2) - p_ac3dec->audblk.cplbegf + 1;
/* Calculate the start and end bins of the coupling channel */ /* Calculate the start and end bins of the coupling channel */
...@@ -386,114 +364,97 @@ void parse_audblk( ac3dec_t * p_ac3dec ) ...@@ -386,114 +364,97 @@ void parse_audblk( ac3dec_t * p_ac3dec )
* band */ * band */
p_ac3dec->audblk.ncplbnd = p_ac3dec->audblk.ncplsubnd; p_ac3dec->audblk.ncplbnd = p_ac3dec->audblk.ncplsubnd;
for(i=1; i< p_ac3dec->audblk.ncplsubnd; i++) for (i=1; i< p_ac3dec->audblk.ncplsubnd; i++) {
{ NeedBits (&(p_ac3dec->bit_stream), 1);
NeedBits( &(p_ac3dec->bit_stream), 1 );
p_ac3dec->audblk.cplbndstrc[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.cplbndstrc[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->audblk.ncplbnd -= p_ac3dec->audblk.cplbndstrc[i]; p_ac3dec->audblk.ncplbnd -= p_ac3dec->audblk.cplbndstrc[i];
} }
} }
} }
if(p_ac3dec->audblk.cplinu) if (p_ac3dec->audblk.cplinu) {
{
/* Loop through all the channels and get their coupling co-ords */ /* Loop through all the channels and get their coupling co-ords */
for(i=0;i < p_ac3dec->bsi.nfchans;i++) for (i=0; i < p_ac3dec->bsi.nfchans;i++) {
{ if (!p_ac3dec->audblk.chincpl[i])
if(!p_ac3dec->audblk.chincpl[i])
continue; continue;
/* Is there new coupling co-ordinate info? */ /* Is there new coupling co-ordinate info? */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->audblk.cplcoe[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.cplcoe[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if(p_ac3dec->audblk.cplcoe[i]) if (p_ac3dec->audblk.cplcoe[i]) {
{ NeedBits (&(p_ac3dec->bit_stream), 2);
NeedBits( &(p_ac3dec->bit_stream), 2 );
p_ac3dec->audblk.mstrcplco[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); p_ac3dec->audblk.mstrcplco[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2));
DumpBits( &(p_ac3dec->bit_stream), 2 ); DumpBits (&(p_ac3dec->bit_stream), 2);
for(j=0;j < p_ac3dec->audblk.ncplbnd; j++) for (j=0;j < p_ac3dec->audblk.ncplbnd; j++) {
{ NeedBits (&(p_ac3dec->bit_stream), 4);
NeedBits( &(p_ac3dec->bit_stream), 4 );
p_ac3dec->audblk.cplcoexp[i][j] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4)); p_ac3dec->audblk.cplcoexp[i][j] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4));
DumpBits( &(p_ac3dec->bit_stream), 4 ); DumpBits (&(p_ac3dec->bit_stream), 4);
NeedBits( &(p_ac3dec->bit_stream), 4 ); NeedBits (&(p_ac3dec->bit_stream), 4);
p_ac3dec->audblk.cplcomant[i][j] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4)); p_ac3dec->audblk.cplcomant[i][j] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4));
DumpBits( &(p_ac3dec->bit_stream), 4 ); DumpBits (&(p_ac3dec->bit_stream), 4);
} }
} }
} }
/* If we're in dual mono mode, there's going to be some phase info */ /* If we're in dual mono mode, there's going to be some phase info */
if( (p_ac3dec->bsi.acmod == 0x2) && p_ac3dec->audblk.phsflginu && if ((p_ac3dec->bsi.acmod == 0x2) && p_ac3dec->audblk.phsflginu &&
(p_ac3dec->audblk.cplcoe[0] || p_ac3dec->audblk.cplcoe[1])) (p_ac3dec->audblk.cplcoe[0] || p_ac3dec->audblk.cplcoe[1])) {
{ for (j=0; j < p_ac3dec->audblk.ncplbnd; j++) {
for(j=0;j < p_ac3dec->audblk.ncplbnd; j++) NeedBits (&(p_ac3dec->bit_stream), 1);
{
NeedBits( &(p_ac3dec->bit_stream), 1 );
p_ac3dec->audblk.phsflg[j] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.phsflg[j] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
} }
} }
} }
/* If we're in dual mono mode, there may be a rematrix strategy */ /* If we're in dual mono mode, there may be a rematrix strategy */
if(p_ac3dec->bsi.acmod == 0x2) if (p_ac3dec->bsi.acmod == 0x2) {
{ NeedBits (&(p_ac3dec->bit_stream), 1);
NeedBits( &(p_ac3dec->bit_stream), 1 );
p_ac3dec->audblk.rematstr = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.rematstr = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if(p_ac3dec->audblk.rematstr) if (p_ac3dec->audblk.rematstr) {
{ if (p_ac3dec->audblk.cplinu == 0) {
if (p_ac3dec->audblk.cplinu == 0) for (i = 0; i < 4; i++) {
{ NeedBits (&(p_ac3dec->bit_stream), 1);
for(i = 0; i < 4; i++)
{
NeedBits( &(p_ac3dec->bit_stream), 1 );
p_ac3dec->audblk.rematflg[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.rematflg[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
} }
} }
if((p_ac3dec->audblk.cplbegf > 2) && p_ac3dec->audblk.cplinu) if ((p_ac3dec->audblk.cplbegf > 2) && p_ac3dec->audblk.cplinu) {
{ for (i = 0; i < 4; i++) {
for(i = 0; i < 4; i++) NeedBits (&(p_ac3dec->bit_stream), 1);
{
NeedBits( &(p_ac3dec->bit_stream), 1 );
p_ac3dec->audblk.rematflg[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.rematflg[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
} }
} }
if((p_ac3dec->audblk.cplbegf <= 2) && p_ac3dec->audblk.cplinu) if ((p_ac3dec->audblk.cplbegf <= 2) && p_ac3dec->audblk.cplinu) {
{ for (i = 0; i < 3; i++) {
for(i = 0; i < 3; i++) NeedBits (&(p_ac3dec->bit_stream), 1);
{
NeedBits( &(p_ac3dec->bit_stream), 1 );
p_ac3dec->audblk.rematflg[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.rematflg[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
} }
} }
if((p_ac3dec->audblk.cplbegf == 0) && p_ac3dec->audblk.cplinu) if ((p_ac3dec->audblk.cplbegf == 0) && p_ac3dec->audblk.cplinu)
for(i = 0; i < 2; i++) for (i = 0; i < 2; i++) {
{ NeedBits (&(p_ac3dec->bit_stream), 1);
NeedBits( &(p_ac3dec->bit_stream), 1 );
p_ac3dec->audblk.rematflg[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.rematflg[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
} }
} }
} }
if (p_ac3dec->audblk.cplinu) if (p_ac3dec->audblk.cplinu)
{ {
/* Get the coupling channel exponent strategy */ /* Get the coupling channel exponent strategy */
NeedBits( &(p_ac3dec->bit_stream), 2 ); NeedBits (&(p_ac3dec->bit_stream), 2);
p_ac3dec->audblk.cplexpstr = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); p_ac3dec->audblk.cplexpstr = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2));
DumpBits( &(p_ac3dec->bit_stream), 2 ); DumpBits (&(p_ac3dec->bit_stream), 2);
if(p_ac3dec->audblk.cplexpstr==0) if (p_ac3dec->audblk.cplexpstr==0)
p_ac3dec->audblk.ncplgrps = 0; p_ac3dec->audblk.ncplgrps = 0;
else else
p_ac3dec->audblk.ncplgrps = (p_ac3dec->audblk.cplendmant - p_ac3dec->audblk.cplstrtmant) / p_ac3dec->audblk.ncplgrps = (p_ac3dec->audblk.cplendmant - p_ac3dec->audblk.cplstrtmant) /
...@@ -501,37 +462,30 @@ void parse_audblk( ac3dec_t * p_ac3dec ) ...@@ -501,37 +462,30 @@ void parse_audblk( ac3dec_t * p_ac3dec )
} }
for(i = 0; i < p_ac3dec->bsi.nfchans; i++) for (i = 0; i < p_ac3dec->bsi.nfchans; i++) {
{ NeedBits (&(p_ac3dec->bit_stream), 2);
NeedBits( &(p_ac3dec->bit_stream), 2 );
p_ac3dec->audblk.chexpstr[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); p_ac3dec->audblk.chexpstr[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2));
DumpBits( &(p_ac3dec->bit_stream), 2 ); DumpBits (&(p_ac3dec->bit_stream), 2);
} }
/* Get the exponent strategy for lfe channel */ /* Get the exponent strategy for lfe channel */
if(p_ac3dec->bsi.lfeon) if (p_ac3dec->bsi.lfeon) {
{ NeedBits (&(p_ac3dec->bit_stream), 1);
NeedBits( &(p_ac3dec->bit_stream), 1 );
p_ac3dec->audblk.lfeexpstr = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.lfeexpstr = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
} }
/* Determine the bandwidths of all the fbw channels */ /* Determine the bandwidths of all the fbw channels */
for(i = 0; i < p_ac3dec->bsi.nfchans; i++) for (i = 0; i < p_ac3dec->bsi.nfchans; i++) {
{
u16 grp_size; u16 grp_size;
if(p_ac3dec->audblk.chexpstr[i] != EXP_REUSE) if (p_ac3dec->audblk.chexpstr[i] != EXP_REUSE) {
{ if (p_ac3dec->audblk.cplinu && p_ac3dec->audblk.chincpl[i]) {
if (p_ac3dec->audblk.cplinu && p_ac3dec->audblk.chincpl[i])
{
p_ac3dec->audblk.endmant[i] = p_ac3dec->audblk.cplstrtmant; p_ac3dec->audblk.endmant[i] = p_ac3dec->audblk.cplstrtmant;
} } else {
else NeedBits (&(p_ac3dec->bit_stream), 6);
{
NeedBits( &(p_ac3dec->bit_stream), 6 );
p_ac3dec->audblk.chbwcod[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 6)); p_ac3dec->audblk.chbwcod[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 6));
DumpBits( &(p_ac3dec->bit_stream), 6 ); DumpBits (&(p_ac3dec->bit_stream), 6);
p_ac3dec->audblk.endmant[i] = ((p_ac3dec->audblk.chbwcod[i] + 12) * 3) + 37; p_ac3dec->audblk.endmant[i] = ((p_ac3dec->audblk.chbwcod[i] + 12) * 3) + 37;
} }
...@@ -542,244 +496,219 @@ void parse_audblk( ac3dec_t * p_ac3dec ) ...@@ -542,244 +496,219 @@ void parse_audblk( ac3dec_t * p_ac3dec )
} }
/* Get the coupling exponents if they exist */ /* Get the coupling exponents if they exist */
if(p_ac3dec->audblk.cplinu && (p_ac3dec->audblk.cplexpstr != EXP_REUSE)) if (p_ac3dec->audblk.cplinu && (p_ac3dec->audblk.cplexpstr != EXP_REUSE)) {
{ NeedBits (&(p_ac3dec->bit_stream), 4);
NeedBits( &(p_ac3dec->bit_stream), 4 );
p_ac3dec->audblk.cplabsexp = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4)); p_ac3dec->audblk.cplabsexp = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4));
DumpBits( &(p_ac3dec->bit_stream), 4 ); DumpBits (&(p_ac3dec->bit_stream), 4);
for(i=0;i< p_ac3dec->audblk.ncplgrps;i++) for (i=0; i< p_ac3dec->audblk.ncplgrps;i++) {
{ NeedBits (&(p_ac3dec->bit_stream), 7);
NeedBits( &(p_ac3dec->bit_stream), 7 );
p_ac3dec->audblk.cplexps[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 7)); p_ac3dec->audblk.cplexps[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 7));
DumpBits( &(p_ac3dec->bit_stream), 7 ); DumpBits (&(p_ac3dec->bit_stream), 7);
} }
} }
/* Get the fwb channel exponents */ /* Get the fwb channel exponents */
for(i=0;i < p_ac3dec->bsi.nfchans; i++) for (i=0; i < p_ac3dec->bsi.nfchans; i++) {
{ if (p_ac3dec->audblk.chexpstr[i] != EXP_REUSE) {
if(p_ac3dec->audblk.chexpstr[i] != EXP_REUSE) NeedBits (&(p_ac3dec->bit_stream), 4);
{
NeedBits( &(p_ac3dec->bit_stream), 4 );
p_ac3dec->audblk.exps[i][0] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4)); p_ac3dec->audblk.exps[i][0] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4));
DumpBits( &(p_ac3dec->bit_stream), 4 ); DumpBits (&(p_ac3dec->bit_stream), 4);
for(j=1;j<=p_ac3dec->audblk.nchgrps[i];j++) for (j=1; j<=p_ac3dec->audblk.nchgrps[i];j++) {
{ NeedBits (&(p_ac3dec->bit_stream), 7);
NeedBits( &(p_ac3dec->bit_stream), 7 );
p_ac3dec->audblk.exps[i][j] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 7)); p_ac3dec->audblk.exps[i][j] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 7));
DumpBits( &(p_ac3dec->bit_stream), 7 ); DumpBits (&(p_ac3dec->bit_stream), 7);
} }
NeedBits( &(p_ac3dec->bit_stream), 2 ); NeedBits (&(p_ac3dec->bit_stream), 2);
p_ac3dec->audblk.gainrng[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); p_ac3dec->audblk.gainrng[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2));
DumpBits( &(p_ac3dec->bit_stream), 2 ); DumpBits (&(p_ac3dec->bit_stream), 2);
} }
} }
/* Get the lfe channel exponents */ /* Get the lfe channel exponents */
if(p_ac3dec->bsi.lfeon && (p_ac3dec->audblk.lfeexpstr != EXP_REUSE)) if (p_ac3dec->bsi.lfeon && (p_ac3dec->audblk.lfeexpstr != EXP_REUSE)) {
{ NeedBits (&(p_ac3dec->bit_stream), 4);
NeedBits( &(p_ac3dec->bit_stream), 4 );
p_ac3dec->audblk.lfeexps[0] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4)); p_ac3dec->audblk.lfeexps[0] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4));
DumpBits( &(p_ac3dec->bit_stream), 4 ); DumpBits (&(p_ac3dec->bit_stream), 4);
NeedBits( &(p_ac3dec->bit_stream), 7 ); NeedBits (&(p_ac3dec->bit_stream), 7);
p_ac3dec->audblk.lfeexps[1] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 7)); p_ac3dec->audblk.lfeexps[1] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 7));
DumpBits( &(p_ac3dec->bit_stream), 7 ); DumpBits (&(p_ac3dec->bit_stream), 7);
NeedBits( &(p_ac3dec->bit_stream), 7 ); NeedBits (&(p_ac3dec->bit_stream), 7);
p_ac3dec->audblk.lfeexps[2] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 7)); p_ac3dec->audblk.lfeexps[2] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 7));
DumpBits( &(p_ac3dec->bit_stream), 7 ); DumpBits (&(p_ac3dec->bit_stream), 7);
} }
/* Get the parametric bit allocation parameters */ /* Get the parametric bit allocation parameters */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->audblk.baie = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.baie = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if(p_ac3dec->audblk.baie) if (p_ac3dec->audblk.baie) {
{ NeedBits (&(p_ac3dec->bit_stream), 2);
NeedBits( &(p_ac3dec->bit_stream), 2 );
p_ac3dec->audblk.sdcycod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); p_ac3dec->audblk.sdcycod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2));
DumpBits( &(p_ac3dec->bit_stream), 2 ); DumpBits (&(p_ac3dec->bit_stream), 2);
NeedBits( &(p_ac3dec->bit_stream), 2 ); NeedBits (&(p_ac3dec->bit_stream), 2);
p_ac3dec->audblk.fdcycod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); p_ac3dec->audblk.fdcycod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2));
DumpBits( &(p_ac3dec->bit_stream), 2 ); DumpBits (&(p_ac3dec->bit_stream), 2);
NeedBits( &(p_ac3dec->bit_stream), 2 ); NeedBits (&(p_ac3dec->bit_stream), 2);
p_ac3dec->audblk.sgaincod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); p_ac3dec->audblk.sgaincod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2));
DumpBits( &(p_ac3dec->bit_stream), 2 ); DumpBits (&(p_ac3dec->bit_stream), 2);
NeedBits( &(p_ac3dec->bit_stream), 2 ); NeedBits (&(p_ac3dec->bit_stream), 2);
p_ac3dec->audblk.dbpbcod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); p_ac3dec->audblk.dbpbcod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2));
DumpBits( &(p_ac3dec->bit_stream), 2 ); DumpBits (&(p_ac3dec->bit_stream), 2);
NeedBits( &(p_ac3dec->bit_stream), 3 ); NeedBits (&(p_ac3dec->bit_stream), 3);
p_ac3dec->audblk.floorcod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3)); p_ac3dec->audblk.floorcod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3));
DumpBits( &(p_ac3dec->bit_stream), 3 ); DumpBits (&(p_ac3dec->bit_stream), 3);
} }
/* Get the SNR off set info if it exists */ /* Get the SNR off set info if it exists */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->audblk.snroffste = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.snroffste = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if(p_ac3dec->audblk.snroffste) if (p_ac3dec->audblk.snroffste) {
{ NeedBits (&(p_ac3dec->bit_stream), 6);
NeedBits( &(p_ac3dec->bit_stream), 6 );
p_ac3dec->audblk.csnroffst = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 6)); p_ac3dec->audblk.csnroffst = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 6));
DumpBits( &(p_ac3dec->bit_stream), 6 ); DumpBits (&(p_ac3dec->bit_stream), 6);
if(p_ac3dec->audblk.cplinu) if (p_ac3dec->audblk.cplinu) {
{ NeedBits (&(p_ac3dec->bit_stream), 4);
NeedBits( &(p_ac3dec->bit_stream), 4 );
p_ac3dec->audblk.cplfsnroffst = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4)); p_ac3dec->audblk.cplfsnroffst = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4));
DumpBits( &(p_ac3dec->bit_stream), 4 ); DumpBits (&(p_ac3dec->bit_stream), 4);
NeedBits( &(p_ac3dec->bit_stream), 3 ); NeedBits (&(p_ac3dec->bit_stream), 3);
p_ac3dec->audblk.cplfgaincod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3)); p_ac3dec->audblk.cplfgaincod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3));
DumpBits( &(p_ac3dec->bit_stream), 3 ); DumpBits (&(p_ac3dec->bit_stream), 3);
} }
for(i = 0;i < p_ac3dec->bsi.nfchans; i++) for (i = 0;i < p_ac3dec->bsi.nfchans; i++) {
{ NeedBits (&(p_ac3dec->bit_stream), 4);
NeedBits( &(p_ac3dec->bit_stream), 4 );
p_ac3dec->audblk.fsnroffst[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4)); p_ac3dec->audblk.fsnroffst[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4));
DumpBits( &(p_ac3dec->bit_stream), 4 ); DumpBits (&(p_ac3dec->bit_stream), 4);
NeedBits( &(p_ac3dec->bit_stream), 3 ); NeedBits (&(p_ac3dec->bit_stream), 3);
p_ac3dec->audblk.fgaincod[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3)); p_ac3dec->audblk.fgaincod[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3));
DumpBits( &(p_ac3dec->bit_stream), 3 ); DumpBits (&(p_ac3dec->bit_stream), 3);
} }
if(p_ac3dec->bsi.lfeon) if (p_ac3dec->bsi.lfeon) {
{ NeedBits (&(p_ac3dec->bit_stream), 4);
NeedBits( &(p_ac3dec->bit_stream), 4 );
p_ac3dec->audblk.lfefsnroffst = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4)); p_ac3dec->audblk.lfefsnroffst = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4));
DumpBits( &(p_ac3dec->bit_stream), 4 ); DumpBits (&(p_ac3dec->bit_stream), 4);
NeedBits( &(p_ac3dec->bit_stream), 3 ); NeedBits (&(p_ac3dec->bit_stream), 3);
p_ac3dec->audblk.lfefgaincod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3)); p_ac3dec->audblk.lfefgaincod = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3));
DumpBits( &(p_ac3dec->bit_stream), 3 ); DumpBits (&(p_ac3dec->bit_stream), 3);
} }
} }
/* Get coupling leakage info if it exists */ /* Get coupling leakage info if it exists */
if(p_ac3dec->audblk.cplinu) if (p_ac3dec->audblk.cplinu) {
{ NeedBits (&(p_ac3dec->bit_stream), 1);
NeedBits( &(p_ac3dec->bit_stream), 1 );
p_ac3dec->audblk.cplleake = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.cplleake = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if(p_ac3dec->audblk.cplleake) if (p_ac3dec->audblk.cplleake) {
{ NeedBits (&(p_ac3dec->bit_stream), 3);
NeedBits( &(p_ac3dec->bit_stream), 3 );
p_ac3dec->audblk.cplfleak = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3)); p_ac3dec->audblk.cplfleak = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3));
DumpBits( &(p_ac3dec->bit_stream), 3 ); DumpBits (&(p_ac3dec->bit_stream), 3);
NeedBits( &(p_ac3dec->bit_stream), 3 ); NeedBits (&(p_ac3dec->bit_stream), 3);
p_ac3dec->audblk.cplsleak = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3)); p_ac3dec->audblk.cplsleak = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3));
DumpBits( &(p_ac3dec->bit_stream), 3 ); DumpBits (&(p_ac3dec->bit_stream), 3);
} }
} }
/* Get the delta bit alloaction info */ /* Get the delta bit alloaction info */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->audblk.deltbaie = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.deltbaie = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if(p_ac3dec->audblk.deltbaie) if (p_ac3dec->audblk.deltbaie) {
{ if (p_ac3dec->audblk.cplinu) {
if(p_ac3dec->audblk.cplinu) NeedBits (&(p_ac3dec->bit_stream), 2);
{
NeedBits( &(p_ac3dec->bit_stream), 2 );
p_ac3dec->audblk.cpldeltbae = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); p_ac3dec->audblk.cpldeltbae = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2));
DumpBits( &(p_ac3dec->bit_stream), 2 ); DumpBits (&(p_ac3dec->bit_stream), 2);
} }
for(i = 0;i < p_ac3dec->bsi.nfchans; i++) for (i = 0;i < p_ac3dec->bsi.nfchans; i++) {
{ NeedBits (&(p_ac3dec->bit_stream), 2);
NeedBits( &(p_ac3dec->bit_stream), 2 );
p_ac3dec->audblk.deltbae[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2)); p_ac3dec->audblk.deltbae[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 2));
DumpBits( &(p_ac3dec->bit_stream), 2 ); DumpBits (&(p_ac3dec->bit_stream), 2);
} }
if (p_ac3dec->audblk.cplinu && (p_ac3dec->audblk.cpldeltbae == DELTA_BIT_NEW)) if (p_ac3dec->audblk.cplinu && (p_ac3dec->audblk.cpldeltbae == DELTA_BIT_NEW)) {
{ NeedBits (&(p_ac3dec->bit_stream), 3);
NeedBits( &(p_ac3dec->bit_stream), 3 );
p_ac3dec->audblk.cpldeltnseg = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3)); p_ac3dec->audblk.cpldeltnseg = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3));
DumpBits( &(p_ac3dec->bit_stream), 3 ); DumpBits (&(p_ac3dec->bit_stream), 3);
for(i = 0;i < p_ac3dec->audblk.cpldeltnseg + 1; i++) for (i = 0;i < p_ac3dec->audblk.cpldeltnseg + 1; i++) {
{ NeedBits (&(p_ac3dec->bit_stream), 5);
NeedBits( &(p_ac3dec->bit_stream), 5 );
p_ac3dec->audblk.cpldeltoffst[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5)); p_ac3dec->audblk.cpldeltoffst[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5));
DumpBits( &(p_ac3dec->bit_stream), 5 ); DumpBits (&(p_ac3dec->bit_stream), 5);
NeedBits( &(p_ac3dec->bit_stream), 4 ); NeedBits (&(p_ac3dec->bit_stream), 4);
p_ac3dec->audblk.cpldeltlen[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4)); p_ac3dec->audblk.cpldeltlen[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4));
DumpBits( &(p_ac3dec->bit_stream), 4 ); DumpBits (&(p_ac3dec->bit_stream), 4);
NeedBits( &(p_ac3dec->bit_stream), 3 ); NeedBits (&(p_ac3dec->bit_stream), 3);
p_ac3dec->audblk.cpldeltba[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3)); p_ac3dec->audblk.cpldeltba[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3));
DumpBits( &(p_ac3dec->bit_stream), 3 ); DumpBits (&(p_ac3dec->bit_stream), 3);
} }
} }
for(i = 0;i < p_ac3dec->bsi.nfchans; i++) for (i = 0; i < p_ac3dec->bsi.nfchans; i++) {
{ if (p_ac3dec->audblk.deltbae[i] == DELTA_BIT_NEW) {
if (p_ac3dec->audblk.deltbae[i] == DELTA_BIT_NEW) NeedBits (&(p_ac3dec->bit_stream), 3);
{
NeedBits( &(p_ac3dec->bit_stream), 3 );
p_ac3dec->audblk.deltnseg[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3)); p_ac3dec->audblk.deltnseg[i] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3));
DumpBits( &(p_ac3dec->bit_stream), 3 ); DumpBits (&(p_ac3dec->bit_stream), 3);
// if ( p_ac3dec->audblk.deltnseg[i] >= 8 ) // if (p_ac3dec->audblk.deltnseg[i] >= 8)
// fprintf( stderr, "parse debug: p_ac3dec->audblk.deltnseg[%i] == %i\n", i, p_ac3dec->audblk.deltnseg[i] ); // fprintf (stderr, "parse debug: p_ac3dec->audblk.deltnseg[%i] == %i\n", i, p_ac3dec->audblk.deltnseg[i]);
for(j = 0; j < p_ac3dec->audblk.deltnseg[i] + 1; j++) for (j = 0; j < p_ac3dec->audblk.deltnseg[i] + 1; j++) {
{ NeedBits (&(p_ac3dec->bit_stream), 5);
NeedBits( &(p_ac3dec->bit_stream), 5 );
p_ac3dec->audblk.deltoffst[i][j] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5)); p_ac3dec->audblk.deltoffst[i][j] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 5));
DumpBits( &(p_ac3dec->bit_stream), 5 ); DumpBits (&(p_ac3dec->bit_stream), 5);
NeedBits( &(p_ac3dec->bit_stream), 4 ); NeedBits (&(p_ac3dec->bit_stream), 4);
p_ac3dec->audblk.deltlen[i][j] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4)); p_ac3dec->audblk.deltlen[i][j] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 4));
DumpBits( &(p_ac3dec->bit_stream), 4 ); DumpBits (&(p_ac3dec->bit_stream), 4);
NeedBits( &(p_ac3dec->bit_stream), 3 ); NeedBits (&(p_ac3dec->bit_stream), 3);
p_ac3dec->audblk.deltba[i][j] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3)); p_ac3dec->audblk.deltba[i][j] = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 3));
DumpBits( &(p_ac3dec->bit_stream), 3 ); DumpBits (&(p_ac3dec->bit_stream), 3);
} }
} }
} }
} }
/* Check to see if there's any dummy info to get */ /* Check to see if there's any dummy info to get */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
p_ac3dec->audblk.skiple = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1)); p_ac3dec->audblk.skiple = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 1));
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
if ( p_ac3dec->audblk.skiple ) if (p_ac3dec->audblk.skiple) {
{ NeedBits (&(p_ac3dec->bit_stream), 9);
NeedBits( &(p_ac3dec->bit_stream), 9 );
p_ac3dec->audblk.skipl = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 9)); p_ac3dec->audblk.skipl = (u16)(p_ac3dec->bit_stream.buffer >> (32 - 9));
DumpBits( &(p_ac3dec->bit_stream), 9 ); DumpBits (&(p_ac3dec->bit_stream), 9);
for(i = 0; i < p_ac3dec->audblk.skipl ; i++) for (i = 0; i < p_ac3dec->audblk.skipl ; i++) {
{ NeedBits (&(p_ac3dec->bit_stream), 8);
NeedBits( &(p_ac3dec->bit_stream), 8 ); DumpBits (&(p_ac3dec->bit_stream), 8);
DumpBits( &(p_ac3dec->bit_stream), 8 );
} }
} }
} }
void parse_auxdata( ac3dec_t * p_ac3dec ) void parse_auxdata (ac3dec_t * p_ac3dec)
{ {
int i; int i;
int skip_length; int skip_length;
skip_length = (p_ac3dec->syncinfo.frame_size * 16) - p_ac3dec->bit_stream.total_bits_read - 17 - 1; skip_length = (p_ac3dec->syncinfo.frame_size * 16) - p_ac3dec->bit_stream.total_bits_read - 17 - 1;
// fprintf( stderr, "parse debug: skip_length == %i\n", skip_length ); // fprintf (stderr, "parse debug: skip_length == %i\n", skip_length);
for ( i = 0; i < skip_length; i++ ) for (i = 0; i < skip_length; i++) {
{ NeedBits (&(p_ac3dec->bit_stream), 1);
NeedBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
DumpBits( &(p_ac3dec->bit_stream), 1 );
} }
/* get the auxdata exists bit */ /* get the auxdata exists bit */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
/* Skip the CRC reserved bit */ /* Skip the CRC reserved bit */
NeedBits( &(p_ac3dec->bit_stream), 1 ); NeedBits (&(p_ac3dec->bit_stream), 1);
DumpBits( &(p_ac3dec->bit_stream), 1 ); DumpBits (&(p_ac3dec->bit_stream), 1);
/* Get the crc */ /* Get the crc */
NeedBits( &(p_ac3dec->bit_stream), 16 ); NeedBits (&(p_ac3dec->bit_stream), 16);
DumpBits( &(p_ac3dec->bit_stream), 16 ); DumpBits (&(p_ac3dec->bit_stream), 16);
} }
int ac3_test_sync (ac3dec_t *);
void parse_syncinfo( ac3dec_t * );
void parse_bsi( ac3dec_t * );
void parse_audblk( ac3dec_t * );
void parse_auxdata( ac3dec_t * );
#include "int_types.h" #include "int_types.h"
#include "ac3_decoder.h" #include "ac3_decoder.h"
#include "ac3_rematrix.h" #include "ac3_internal.h"
struct rematrix_band_s struct rematrix_band_s {
{
u32 start; u32 start;
u32 end; u32 end;
}; };
static struct rematrix_band_s rematrix_band[] = { {13,24}, {25,36}, {37 ,60}, {61,252}}; static struct rematrix_band_s rematrix_band[] = { {13,24}, {25,36}, {37 ,60}, {61,252}};
static __inline__ u32 min( u32 a, u32 b ) static __inline__ u32 min (u32 a, u32 b)
{ {
return( a < b ? a : b ); return (a < b ? a : b);
} }
/* This routine simply does stereo rematixing for the 2 channel /* This routine simply does stereo rematixing for the 2 channel
* stereo mode */ * stereo mode */
void rematrix( ac3dec_t * p_ac3dec ) void rematrix (ac3dec_t * p_ac3dec)
{ {
u32 num_bands; u32 num_bands;
u32 start; u32 start;
...@@ -25,23 +24,21 @@ void rematrix( ac3dec_t * p_ac3dec ) ...@@ -25,23 +24,21 @@ void rematrix( ac3dec_t * p_ac3dec )
u32 i,j; u32 i,j;
float left,right; float left,right;
if(p_ac3dec->audblk.cplinu || p_ac3dec->audblk.cplbegf > 2) if (p_ac3dec->audblk.cplinu || p_ac3dec->audblk.cplbegf > 2)
num_bands = 4; num_bands = 4;
else if (p_ac3dec->audblk.cplbegf > 0) else if (p_ac3dec->audblk.cplbegf > 0)
num_bands = 3; num_bands = 3;
else else
num_bands = 2; num_bands = 2;
for(i=0;i < num_bands; i++) for (i=0;i < num_bands; i++) {
{ if (!p_ac3dec->audblk.rematflg[i])
if(!p_ac3dec->audblk.rematflg[i])
continue; continue;
start = rematrix_band[i].start; start = rematrix_band[i].start;
end = min(rematrix_band[i].end ,12 * p_ac3dec->audblk.cplbegf + 36); end = min(rematrix_band[i].end ,12 * p_ac3dec->audblk.cplbegf + 36);
for(j=start;j < end; j++) for (j=start;j < end; j++) {
{
left = 0.5f * (p_ac3dec->coeffs.fbw[0][j] + p_ac3dec->coeffs.fbw[1][j]); left = 0.5f * (p_ac3dec->coeffs.fbw[0][j] + p_ac3dec->coeffs.fbw[1][j]);
right = 0.5f * (p_ac3dec->coeffs.fbw[0][j] - p_ac3dec->coeffs.fbw[1][j]); right = 0.5f * (p_ac3dec->coeffs.fbw[0][j] - p_ac3dec->coeffs.fbw[1][j]);
p_ac3dec->coeffs.fbw[0][j] = left; p_ac3dec->coeffs.fbw[0][j] = left;
......
void rematrix( ac3dec_t * );
...@@ -1074,8 +1074,10 @@ static __inline__ void input_DemuxPES( input_thread_t *p_input, ...@@ -1074,8 +1074,10 @@ static __inline__ void input_DemuxPES( input_thread_t *p_input,
break; break;
case AC3_AUDIO_ES: case AC3_AUDIO_ES:
#if 0
/* we skip 4 bytes at the beginning of the AC3 payload */ /* we skip 4 bytes at the beginning of the AC3 payload */
p_ts->i_payload_start += 4; p_ts->i_payload_start += 4;
#endif
p_fifo = &(((ac3dec_thread_t *)(p_es_descriptor->p_dec))->fifo); p_fifo = &(((ac3dec_thread_t *)(p_es_descriptor->p_dec))->fifo);
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment