Commit 2dabbaa9 authored by Sam Hocevar's avatar Sam Hocevar

. indentation fixes

 . fixed audio syncword detection for mpeg 1 streams (hopefully)
    FIXME: can anyone confirm we can get rid of adec_byte_stream_next
    in audio_decoder_thread.c now that we have the new input ?

 . fixed Layer 2 Mono decoding.
    FIXME: who created freq_table ? what was the rationale for it, and
    where does it come from ?
    FIXME: how can we spare the extra DCT in audio_decoder.c:707 ? I'm too
    tired to think about it.

 . proposal: splitting audio_decoder.c in one file per layer.
parent 9632f78e
...@@ -33,11 +33,14 @@ ...@@ -33,11 +33,14 @@
#include "audio_math.h" /* DCT32(), PCM() */ #include "audio_math.h" /* DCT32(), PCM() */
#include "audio_bit_stream.h" #include "audio_bit_stream.h"
#include <stdio.h>
#define NULL ((void *)0) #define NULL ((void *)0)
/**** wkn ****/ /**** wkn ****/
static float adec_scalefactor_table[64] = { /* 2 ^ (1 - i/3) */ static float adec_scalefactor_table[64] =
{ /* 2 ^ (1 - i/3) */
2.0000000000000000, 1.5874010519681994, 1.2599210498948732, 2.0000000000000000, 1.5874010519681994, 1.2599210498948732,
1.0000000000000000, 0.7937005259840998, 0.6299605249474366, 1.0000000000000000, 0.7937005259840998, 0.6299605249474366,
0.5000000000000000, 0.3968502629920499, 0.3149802624737183, 0.5000000000000000, 0.3968502629920499, 0.3149802624737183,
...@@ -62,7 +65,8 @@ static float adec_scalefactor_table[64] = { /* 2 ^ (1 - i/3) */ ...@@ -62,7 +65,8 @@ static float adec_scalefactor_table[64] = { /* 2 ^ (1 - i/3) */
0.0000009536743164 /* last element is not in the standard... invalid ??? */ 0.0000009536743164 /* last element is not in the standard... invalid ??? */
}; };
static float adec_slope_table[15] = { static float adec_slope_table[15] =
{
0.6666666666666666, 0.2857142857142857, 0.1333333333333333, 0.6666666666666666, 0.2857142857142857, 0.1333333333333333,
0.0645161290322581, 0.0317460317460317, 0.0157480314960630, 0.0645161290322581, 0.0317460317460317, 0.0157480314960630,
0.0078431372549020, 0.0039138943248532, 0.0019550342130987, 0.0078431372549020, 0.0039138943248532, 0.0019550342130987,
...@@ -70,7 +74,8 @@ static float adec_slope_table[15] = { ...@@ -70,7 +74,8 @@ static float adec_slope_table[15] = {
0.0001220777635354, 0.0000610370189520, 0.0000305180437934 0.0001220777635354, 0.0000610370189520, 0.0000305180437934
}; };
static float adec_offset_table[15] = { static float adec_offset_table[15] =
{
-0.6666666666666666, -0.8571428571428571, -0.9333333333333333, -0.6666666666666666, -0.8571428571428571, -0.9333333333333333,
-0.9677419354838710, -0.9841269841269841, -0.9921259842519685, -0.9677419354838710, -0.9841269841269841, -0.9921259842519685,
-0.9960784313725490, -0.9980430528375733, -0.9990224828934506, -0.9960784313725490, -0.9980430528375733, -0.9990224828934506,
...@@ -78,13 +83,14 @@ static float adec_offset_table[15] = { ...@@ -78,13 +83,14 @@ static float adec_offset_table[15] = {
-0.9999389611182323, -0.9999694814905240, -0.9999847409781033 -0.9999389611182323, -0.9999694814905240, -0.9999847409781033
}; };
static u8 adec_layer1_allocation_table[15] = { static u8 adec_layer1_allocation_table[15] =
{
0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
}; };
static int adec_bound_table[4] = {4, 8, 12, 16}; static int adec_bound_table[4] = { 4, 8, 12, 16 };
static int adec_layer1_mono (audiodec_t * p_adec, s16 * buffer) static int adec_layer1_mono( audiodec_t * p_adec, s16 * buffer )
{ {
u8 allocation[32]; u8 allocation[32];
float slope[32]; float slope[32];
...@@ -100,17 +106,25 @@ static int adec_layer1_mono (audiodec_t * p_adec, s16 * buffer) ...@@ -100,17 +106,25 @@ static int adec_layer1_mono (audiodec_t * p_adec, s16 * buffer)
{ {
u8 tmp; u8 tmp;
tmp = GetByte ( &p_adec->bit_stream ); tmp = GetByte ( &p_adec->bit_stream );
if ( (tmp >> 4) > 14 ) if ( (tmp >> 4) > 14 )
{
return 1; return 1;
}
allocation[sb] = adec_layer1_allocation_table [tmp >> 4]; allocation[sb] = adec_layer1_allocation_table [tmp >> 4];
if ((tmp & 15) > 14) if ((tmp & 15) > 14)
{
return 1; return 1;
}
allocation[sb+1] = adec_layer1_allocation_table [tmp & 15]; allocation[sb+1] = adec_layer1_allocation_table [tmp & 15];
} }
/* parse scalefactors */ /* parse scalefactors */
for (sb = 0; sb < 32; sb++) for ( sb = 0; sb < 32; sb++ )
{ {
if ( allocation[sb] ) if ( allocation[sb] )
{ {
...@@ -189,21 +203,30 @@ static int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -189,21 +203,30 @@ static int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer)
u8 tmp; u8 tmp;
tmp = GetByte (&p_adec->bit_stream); tmp = GetByte (&p_adec->bit_stream);
if ((tmp >> 4) > 14) if ((tmp >> 4) > 14)
{
return 1; return 1;
}
allocation_0[sb] = adec_layer1_allocation_table [tmp >> 4]; allocation_0[sb] = adec_layer1_allocation_table [tmp >> 4];
if ((tmp & 15) > 14) if ((tmp & 15) > 14)
{
return 1; return 1;
}
allocation_1[sb] = adec_layer1_allocation_table [tmp & 15]; allocation_1[sb] = adec_layer1_allocation_table [tmp & 15];
} }
for (; sb < 32; sb += 2) for (; sb < 32; sb += 2)
{ {
u8 tmp; u8 tmp;
tmp = GetByte (&p_adec->bit_stream); tmp = GetByte (&p_adec->bit_stream);
if ((tmp >> 4) > 14) if ((tmp >> 4) > 14)
{
return 1; return 1;
}
allocation_0[sb] = allocation_1[sb] = adec_layer1_allocation_table [tmp >> 4]; allocation_0[sb] = allocation_1[sb] = adec_layer1_allocation_table [tmp >> 4];
if ((tmp & 15) > 14) if ((tmp & 15) > 14)
{
return 1; return 1;
}
allocation_0[sb+1] = allocation_1[sb+1] = adec_layer1_allocation_table [tmp & 15]; allocation_0[sb+1] = allocation_1[sb+1] = adec_layer1_allocation_table [tmp & 15];
} }
...@@ -225,6 +248,7 @@ static int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -225,6 +248,7 @@ static int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer)
slope_0[sb] = adec_slope_table[allocation_0[sb]-2] * scalefactor; slope_0[sb] = adec_slope_table[allocation_0[sb]-2] * scalefactor;
offset_0[sb] = adec_offset_table[allocation_0[sb]-2] * scalefactor; offset_0[sb] = adec_offset_table[allocation_0[sb]-2] * scalefactor;
} }
if (allocation_1[sb]) if (allocation_1[sb])
{ {
int index; int index;
...@@ -250,7 +274,9 @@ static int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -250,7 +274,9 @@ static int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer)
for (sb = 0; sb < bound; sb++) for (sb = 0; sb < bound; sb++)
{ {
if (!allocation_0[sb]) if (!allocation_0[sb])
{
sample_0[sb] = 0; sample_0[sb] = 0;
}
else else
{ {
int code; int code;
...@@ -261,8 +287,11 @@ static int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -261,8 +287,11 @@ static int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer)
sample_0[sb] = slope_0[sb] * code + offset_0[sb]; sample_0[sb] = slope_0[sb] * code + offset_0[sb];
} }
if ( !allocation_1[sb] ) if ( !allocation_1[sb] )
{
sample_1[sb] = 0; sample_1[sb] = 0;
}
else else
{ {
int code; int code;
...@@ -274,6 +303,7 @@ static int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -274,6 +303,7 @@ static int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer)
sample_1[sb] = slope_1[sb] * code + offset_1[sb]; sample_1[sb] = slope_1[sb] * code + offset_1[sb];
} }
} }
for (; sb < 32; sb++) for (; sb < 32; sb++)
{ {
if (!allocation_0[sb]) if (!allocation_0[sb])
...@@ -283,14 +313,14 @@ static int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -283,14 +313,14 @@ static int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer)
} }
else else
{ {
int sample; int code;
NeedBits (&p_adec->bit_stream, allocation_0[sb]); NeedBits (&p_adec->bit_stream, allocation_0[sb]);
sample = p_adec->bit_stream.buffer >> (32 - allocation_0[sb]); code = p_adec->bit_stream.buffer >> (32 - allocation_0[sb]);
DumpBits (&p_adec->bit_stream, allocation_0[sb]); DumpBits (&p_adec->bit_stream, allocation_0[sb]);
sample_0[sb] = slope_0[sb] * sample + offset_0[sb]; sample_0[sb] = slope_0[sb] * code + offset_0[sb];
sample_1[sb] = slope_1[sb] * sample + offset_1[sb]; sample_1[sb] = slope_1[sb] * code + offset_1[sb];
} }
} }
...@@ -306,7 +336,8 @@ static int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -306,7 +336,8 @@ static int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer)
return 0; return 0;
} }
typedef struct { typedef struct
{
s8 nbal[32]; s8 nbal[32];
u8 * alloc[32]; u8 * alloc[32];
} alloc_table_t; } alloc_table_t;
...@@ -315,22 +346,27 @@ typedef struct { ...@@ -315,22 +346,27 @@ typedef struct {
#define L5 -2 #define L5 -2
#define L9 -3 #define L9 -3
static void adec_layer2_get_table (u32 header, u8 freq_table[15], static void adec_layer2_get_table( u32 header, u8 freq_table[15],
alloc_table_t ** alloc, int * sblimit) alloc_table_t ** alloc, int * sblimit )
{ {
static s8 table_ab0[16] = { static s8 table_ab0[16] =
{
0, L3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 0, L3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
}; };
static s8 table_ab3[16] = { static s8 table_ab3[16] =
{
0, L3, L5, 3, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16 0, L3, L5, 3, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16
}; };
static s8 table_ab11[8] = { static s8 table_ab11[8] =
{
0, L3, L5, 3, L9, 4, 5, 16 0, L3, L5, 3, L9, 4, 5, 16
}; };
static s8 table_ab23[8] = { static s8 table_ab23[8] =
{
0, L3, L5, 16 0, L3, L5, 16
}; };
static alloc_table_t mpeg1_ab = { static alloc_table_t mpeg1_ab =
{
{4,4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,0,0}, {4,4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,0,0},
{table_ab0, table_ab0, table_ab0, table_ab3, {table_ab0, table_ab0, table_ab0, table_ab3,
table_ab3, table_ab3, table_ab3, table_ab3, table_ab3, table_ab3, table_ab3, table_ab3,
...@@ -342,10 +378,12 @@ static void adec_layer2_get_table (u32 header, u8 freq_table[15], ...@@ -342,10 +378,12 @@ static void adec_layer2_get_table (u32 header, u8 freq_table[15],
table_ab23, table_ab23, NULL, NULL} table_ab23, table_ab23, NULL, NULL}
}; };
static s8 table_cd[16] = { static s8 table_cd[16] =
{
0, L3, L5, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 0, L3, L5, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
}; };
static alloc_table_t mpeg1_cd = { static alloc_table_t mpeg1_cd =
{
{4,4,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {4,4,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{table_cd, table_cd, table_cd, table_cd, {table_cd, table_cd, table_cd, table_cd,
table_cd, table_cd, table_cd, table_cd, table_cd, table_cd, table_cd, table_cd,
...@@ -355,13 +393,16 @@ static void adec_layer2_get_table (u32 header, u8 freq_table[15], ...@@ -355,13 +393,16 @@ static void adec_layer2_get_table (u32 header, u8 freq_table[15],
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL} NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}
}; };
static s8 table_0[16] = { static s8 table_0[16] =
{
0, L3, L5, 3, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 0, L3, L5, 3, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
}; };
static s8 table_4[8] = { static s8 table_4[8] =
{
0, L3, L5, L9, 4, 5, 6, 7 0, L3, L5, L9, 4, 5, 6, 7
}; };
static alloc_table_t mpeg2 = { static alloc_table_t mpeg2 =
{
{4,4,4,4,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0}, {4,4,4,4,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0},
{table_0, table_0, table_0, table_0, {table_0, table_0, table_0, table_0,
table_4, table_4, table_4, table_4, table_4, table_4, table_4, table_4,
...@@ -373,18 +414,23 @@ static void adec_layer2_get_table (u32 header, u8 freq_table[15], ...@@ -373,18 +414,23 @@ static void adec_layer2_get_table (u32 header, u8 freq_table[15],
table_4, table_4, NULL, NULL} table_4, table_4, NULL, NULL}
}; };
static alloc_table_t * alloc_table [4] = { static alloc_table_t * alloc_table [4] =
{
&mpeg2, &mpeg1_cd, &mpeg1_ab, &mpeg1_ab &mpeg2, &mpeg1_cd, &mpeg1_ab, &mpeg1_ab
}; };
static int sblimit_table[12] = { static int sblimit_table[12] =
{
30, 8, 27, 30, 30, 8, 27, 27, 30, 12, 27, 30 30, 8, 27, 30, 30, 8, 27, 27, 30, 12, 27, 30
}; };
int index; int index;
if (!(header & 0x80000)) if (!(header & 0x80000))
{
index = 0; /* mpeg2 */ index = 0; /* mpeg2 */
else { }
else
{
index = (header >> 12) & 15; /* mpeg1, bitrate */ index = (header >> 12) & 15; /* mpeg1, bitrate */
index = freq_table [index]; index = freq_table [index];
} }
...@@ -396,7 +442,7 @@ static void adec_layer2_get_table (u32 header, u8 freq_table[15], ...@@ -396,7 +442,7 @@ static void adec_layer2_get_table (u32 header, u8 freq_table[15],
static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer) static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
{ {
static u8 freq_table[15] = {3, 0, 0, 0, 1, 0, 1, 2, 2, 2, 3, 3, 3, 3, 3}; static u8 freq_table[15] = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
static float L3_table[3] = {-2/3.0, 0, 2/3.0}; static float L3_table[3] = {-2/3.0, 0, 2/3.0};
static float L5_table[5] = {-4/5.0, -2/5.0, 0, 2/5.0, 4/5.0}; static float L5_table[5] = {-4/5.0, -2/5.0, 0, 2/5.0, 4/5.0};
static float L9_table[9] = {-8/9.0, -6/9.0, -4/9.0, -2/9.0, 0, static float L9_table[9] = {-8/9.0, -6/9.0, -4/9.0, -2/9.0, 0,
...@@ -410,23 +456,17 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer) ...@@ -410,23 +456,17 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
alloc_table_t * alloc_table; alloc_table_t * alloc_table;
int sblimit; int sblimit;
int bound;
int sb; int sb;
int gr0, gr1; int gr0, gr1;
int s; int s;
/* get the right allocation table */ /* get the right allocation table */
adec_layer2_get_table (p_adec->header, freq_table, &alloc_table, &sblimit); adec_layer2_get_table (p_adec->header, freq_table, &alloc_table, &sblimit);
/* bound -- not required for mono ! */ /* parse allocation */
//sblimit=27;
bound = sblimit;
/* parse allocation table */
for ( sb=0 ; sb < sblimit ; sb++ ) for (sb = 0; sb < sblimit; sb++)
{ {
int index; int index;
...@@ -439,7 +479,7 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer) ...@@ -439,7 +479,7 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
/* parse scfsi */ /* parse scfsi */
for ( sb = 0 ; sb < sblimit ; sb++ ) for (sb = 0; sb < sblimit; sb++)
{ {
if (allocation[sb]) if (allocation[sb])
{ {
...@@ -449,17 +489,17 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer) ...@@ -449,17 +489,17 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
} }
} }
/* Parse scalefactors */ /* parse scalefactors */
for ( sb = 0 ; sb < sblimit ; sb++ ) for (sb = 0; sb < sblimit; sb++)
{ {
if ( allocation[sb] ) if (allocation[sb])
{ {
int index_0, index_1, index_2; int index_0, index_1, index_2;
float r_slope,r_offset;
switch ( scfsi[sb] ) switch (scfsi[sb])
{ {
case 0 : case 0:
NeedBits (&p_adec->bit_stream, 18); NeedBits (&p_adec->bit_stream, 18);
index_0 = p_adec->bit_stream.buffer >> (32 - 6); index_0 = p_adec->bit_stream.buffer >> (32 - 6);
index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63; index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
...@@ -474,116 +514,126 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer) ...@@ -474,116 +514,126 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
} }
else else
{ {
float scalefactor; float r_scalefactor;
float r_slope, r_offset;
r_slope = adec_slope_table[allocation[sb]-2]; r_slope = adec_slope_table[allocation[sb]-2];
r_offset = adec_offset_table[allocation[sb]-2]; r_offset = adec_offset_table[allocation[sb]-2];
scalefactor = adec_scalefactor_table[index_0]; r_scalefactor = adec_scalefactor_table[index_0];
slope[0][sb] = r_slope * scalefactor; slope[0][sb] = r_slope * r_scalefactor;
offset[0][sb] = r_offset * scalefactor; offset[0][sb] = r_offset * r_scalefactor;
scalefactor = adec_scalefactor_table[index_1]; r_scalefactor = adec_scalefactor_table[index_1];
slope[1][sb] = r_slope * scalefactor; slope[1][sb] = r_slope * r_scalefactor;
offset[1][sb] = r_offset * scalefactor; offset[1][sb] = r_offset * r_scalefactor;
scalefactor = adec_scalefactor_table[index_2]; r_scalefactor = adec_scalefactor_table[index_2];
slope[2][sb] = r_slope * scalefactor; slope[2][sb] = r_slope * r_scalefactor;
offset[2][sb] = r_offset * scalefactor; offset[2][sb] = r_offset * r_scalefactor;
} }
break; break;
case 1 : case 1:
NeedBits ( &p_adec->bit_stream, 12 ); NeedBits (&p_adec->bit_stream, 12);
index_0 = p_adec->bit_stream.buffer >> (32-6); index_0 = p_adec->bit_stream.buffer >> (32 - 6);
index_2 = ( p_adec->bit_stream.buffer >> (32-12) ) & 63; index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
DumpBits (&p_adec->bit_stream, 12);
if ( allocation[sb] < 0 ) if (allocation[sb] < 0)
{ {
slope[0][sb] = slope[1][sb] = slope[0][sb] = slope[1][sb] =
adec_scalefactor_table[index_0]; adec_scalefactor_table[index_0];
slope[2][sb] = adec_scalefactor_table[index_2]; slope[2][sb] = adec_scalefactor_table[index_1];
} }
else else
{ {
float scalefactor; float r_scalefactor;
float r_slope, r_offset;
r_slope = adec_slope_table[allocation[sb]-2]; r_slope = adec_slope_table[allocation[sb]-2];
r_offset = adec_offset_table[allocation[sb]-2]; r_offset = adec_offset_table[allocation[sb]-2];
scalefactor = adec_scalefactor_table[index_0]; r_scalefactor = adec_scalefactor_table[index_0];
slope[0][sb] = slope[1][sb] = r_slope * scalefactor; slope[0][sb] = slope[1][sb] = r_slope * r_scalefactor;
offset[0][sb] = offset[1][sb] = r_offset * scalefactor; offset[0][sb] = offset[1][sb] =
r_offset * r_scalefactor;
scalefactor = adec_scalefactor_table[index_2]; r_scalefactor = adec_scalefactor_table[index_1];
slope[2][sb] = r_slope * scalefactor; slope[2][sb] = r_slope * r_scalefactor;
offset[2][sb] = r_offset * scalefactor; offset[2][sb] = r_offset * r_scalefactor;
} }
break; break;
case 2: case 2:
NeedBits ( &p_adec->bit_stream, 6); NeedBits (&p_adec->bit_stream, 6);
index_0 = p_adec->bit_stream.buffer >> (32 - 6); index_0 = p_adec->bit_stream.buffer >> (32 - 6);
if ( allocation[sb] < 0 ) DumpBits (&p_adec->bit_stream, 6);
if (allocation[sb] < 0)
{ {
slope[0][sb] = slope[1][sb] = slope[2][sb] = slope[0][sb] = slope[1][sb] = slope[2][sb] =
adec_scalefactor_table[index_0]; adec_scalefactor_table[index_0];
} }
else else
{ {
float scalefactor; float r_scalefactor;
float r_slope, r_offset;
r_slope = adec_slope_table[allocation[sb]-2]; r_slope = adec_slope_table[allocation[sb]-2];
r_offset = adec_offset_table[allocation[sb]-2]; r_offset = adec_offset_table[allocation[sb]-2];
scalefactor = adec_scalefactor_table[index_0]; r_scalefactor = adec_scalefactor_table[index_0];
slope[0][sb] = slope[1][sb] = slope[2][sb] = slope[0][sb] = slope[1][sb] = slope[2][sb] =
r_slope * scalefactor; r_slope * r_scalefactor;
offset[0][sb] = offset[1][sb] = offset[2][sb] = offset[0][sb] = offset[1][sb] = offset[2][sb] =
r_offset * scalefactor; r_offset * r_scalefactor;
} }
break; break;
case 3 : case 3:
NeedBits ( &p_adec->bit_stream, 12 ); NeedBits (&p_adec->bit_stream, 12);
index_0 = p_adec->bit_stream.buffer >> (32-6); index_0 = p_adec->bit_stream.buffer >> (32 - 6);
index_2 = ( p_adec->bit_stream.buffer >> (32-12) ) & 63; index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
DumpBits (&p_adec->bit_stream, 12);
if ( allocation[sb] < 0 ) if (allocation[sb] < 0)
{ {
slope[0][sb] = adec_scalefactor_table[index_0]; slope[0][sb] = adec_scalefactor_table[index_0];
slope[2][sb] = slope[1][sb] = slope[1][sb] = slope[2][sb] =
adec_scalefactor_table[index_2]; adec_scalefactor_table[index_1];
} }
else else
{ {
float scalefactor; float r_scalefactor;
float r_slope, r_offset;
r_slope = adec_slope_table[allocation[sb]-2]; r_slope = adec_slope_table[allocation[sb]-2];
r_offset = adec_offset_table[allocation[sb]-2]; r_offset = adec_offset_table[allocation[sb]-2];
scalefactor = adec_scalefactor_table[index_0]; r_scalefactor = adec_scalefactor_table[index_0];
slope[0][sb] = r_slope * scalefactor; slope[0][sb] = r_slope * r_scalefactor;
offset[0][sb] = r_offset * scalefactor; offset[0][sb] = r_offset * r_scalefactor;
scalefactor = adec_scalefactor_table[index_2]; r_scalefactor = adec_scalefactor_table[index_1];
slope[2][sb] = slope[1][sb] = r_slope * scalefactor; slope[1][sb] = slope[2][sb] = r_slope * r_scalefactor;
offset[2][sb] = offset[1][sb] = r_offset * scalefactor; offset[1][sb] = offset[2][sb] =
r_offset * r_scalefactor;
} }
break; break;
} }
} }
} }
/* parse samples */ /* parse samples */
for (gr0 = 0; gr0 < 3; gr0++) for (gr0 = 0; gr0 < 3; gr0++)
{
for (gr1 = 0; gr1 < 4; gr1++) for (gr1 = 0; gr1 < 4; gr1++)
{ {
s16 * XXX_buf; s16 * XXX_buf;
for (sb = 0; sb < bound; sb++) for (sb = 0; sb < sblimit; sb++)
{ {
int code; int code;
...@@ -592,63 +642,7 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer) ...@@ -592,63 +642,7 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
case 0: case 0:
sample[0][sb] = sample[1][sb] = sample[2][sb] = 0; sample[0][sb] = sample[1][sb] = sample[2][sb] = 0;
break; break;
case L3:
NeedBits (&p_adec->bit_stream, 5);
code = p_adec->bit_stream.buffer >> (32 - 5);
DumpBits (&p_adec->bit_stream, 5);
sample[0][sb] = slope[gr0][sb] * L3_table[code % 3];
code /= 3;
sample[1][sb] = slope[gr0][sb] * L3_table[code % 3];
code /= 3;
sample[2][sb] = slope[gr0][sb] * L3_table[code];
break;
case L5:
NeedBits (&p_adec->bit_stream, 7);
code = p_adec->bit_stream.buffer >> (32 - 7);
DumpBits (&p_adec->bit_stream, 7);
sample[0][sb] = slope[gr0][sb] * L5_table[code % 5];
code /= 5;
sample[1][sb] = slope[gr0][sb] * L5_table[code % 5];
code /= 5;
sample[2][sb] = slope[gr0][sb] * L5_table[code];
break;
case L9:
NeedBits (&p_adec->bit_stream, 10);
code = p_adec->bit_stream.buffer >> (32 - 10);
DumpBits (&p_adec->bit_stream, 10);
sample[0][sb] = slope[gr0][sb] * L9_table[code % 9];
code /= 9;
sample[1][sb] = slope[gr0][sb] * L9_table[code % 9];
code /= 9;
sample[2][sb] = slope[gr0][sb] * L9_table[code];
break;
default:
for (s = 0; s < 3; s++) {
NeedBits (&p_adec->bit_stream, allocation[sb]);
code = (p_adec->bit_stream.buffer >>
(32 - allocation[sb]));
DumpBits (&p_adec->bit_stream, allocation[sb]);
sample[s][sb] =
slope[gr0][sb] * code + offset[gr0][sb];
}
}
}
for (; sb < sblimit; sb++) {
int code;
switch (allocation[sb]) {
case 0:
sample[0][sb] = sample[1][sb] = sample[2][sb] = 0;
break;
case L3: case L3:
NeedBits (&p_adec->bit_stream, 5); NeedBits (&p_adec->bit_stream, 5);
code = p_adec->bit_stream.buffer >> (32 - 5); code = p_adec->bit_stream.buffer >> (32 - 5);
...@@ -659,8 +653,8 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer) ...@@ -659,8 +653,8 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
sample[1][sb] = slope[gr0][sb] * L3_table[code % 3]; sample[1][sb] = slope[gr0][sb] * L3_table[code % 3];
code /= 3; code /= 3;
sample[2][sb] = slope[gr0][sb] * L3_table[code]; sample[2][sb] = slope[gr0][sb] * L3_table[code];
break; break;
case L5: case L5:
NeedBits (&p_adec->bit_stream, 7); NeedBits (&p_adec->bit_stream, 7);
code = p_adec->bit_stream.buffer >> (32 - 7); code = p_adec->bit_stream.buffer >> (32 - 7);
...@@ -671,8 +665,8 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer) ...@@ -671,8 +665,8 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
sample[1][sb] = slope[gr0][sb] * L5_table[code % 5]; sample[1][sb] = slope[gr0][sb] * L5_table[code % 5];
code /= 5; code /= 5;
sample[2][sb] = slope[gr0][sb] * L5_table[code]; sample[2][sb] = slope[gr0][sb] * L5_table[code];
break; break;
case L9: case L9:
NeedBits (&p_adec->bit_stream, 10); NeedBits (&p_adec->bit_stream, 10);
code = p_adec->bit_stream.buffer >> (32 - 10); code = p_adec->bit_stream.buffer >> (32 - 10);
...@@ -683,13 +677,14 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer) ...@@ -683,13 +677,14 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
sample[1][sb] = slope[gr0][sb] * L9_table[code % 9]; sample[1][sb] = slope[gr0][sb] * L9_table[code % 9];
code /= 9; code /= 9;
sample[2][sb] = slope[gr0][sb] * L9_table[code]; sample[2][sb] = slope[gr0][sb] * L9_table[code];
break; break;
default: default:
for (s = 0; s < 3; s++) { for (s = 0; s < 3; s++)
{
NeedBits (&p_adec->bit_stream, allocation[sb]); NeedBits (&p_adec->bit_stream, allocation[sb]);
code = (p_adec->bit_stream.buffer >> code = ( p_adec->bit_stream.buffer >>
(32 - allocation[sb])); (32 - allocation[sb]) );
DumpBits (&p_adec->bit_stream, allocation[sb]); DumpBits (&p_adec->bit_stream, allocation[sb]);
sample[s][sb] = sample[s][sb] =
...@@ -697,6 +692,7 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer) ...@@ -697,6 +692,7 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
} }
} }
} }
for (; sb < 32; sb++) for (; sb < 32; sb++)
{ {
sample[0][sb] = sample[1][sb] = sample[2][sb] = 0; sample[0][sb] = sample[1][sb] = sample[2][sb] = 0;
...@@ -706,17 +702,19 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer) ...@@ -706,17 +702,19 @@ static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
{ {
DCT32 (sample[s], &p_adec->bank_0); DCT32 (sample[s], &p_adec->bank_0);
XXX_buf = buffer; XXX_buf = buffer;
PCM (&p_adec->bank_0, &XXX_buf, 1); PCM (&p_adec->bank_0, &XXX_buf, 2);
buffer += 32;
}
/* FIXME: one shouldn't have to do it twice ! */
DCT32 (sample[s], &p_adec->bank_1);
XXX_buf = buffer+1;
PCM (&p_adec->bank_1, &XXX_buf, 2);
buffer += 64;
}
}
} }
return 0;
return 0;
} }
static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
...@@ -741,22 +739,23 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -741,22 +739,23 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
int s; int s;
/* get the right allocation table */ /* get the right allocation table */
adec_layer2_get_table (p_adec->header, freq_table, &alloc_table, &sblimit); adec_layer2_get_table (p_adec->header, freq_table, &alloc_table, &sblimit);
/* calculate bound */ /* calculate bound */
bound = sblimit; bound = sblimit;
if ((p_adec->header & 0xc0) == 0x40) { /* intensity stereo */ if ((p_adec->header & 0xc0) == 0x40) { /* intensity stereo */
int index; int index;
index = (p_adec->header >> 4) & 3; index = (p_adec->header >> 4) & 3;
if (adec_bound_table[index] < sblimit) if (adec_bound_table[index] < sblimit)
{
bound = adec_bound_table[index]; bound = adec_bound_table[index];
} }
}
/* parse allocation */ /* parse allocation */
for (sb = 0; sb < bound; sb++) { for (sb = 0; sb < bound; sb++)
{
int index; int index;
NeedBits (&p_adec->bit_stream, alloc_table->nbal[sb]); NeedBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
...@@ -771,7 +770,9 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -771,7 +770,9 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
allocation_1[sb] = alloc_table->alloc[sb][index]; allocation_1[sb] = alloc_table->alloc[sb][index];
} }
for (; sb < sblimit; sb++) {
for (; sb < sblimit; sb++)
{
int index; int index;
NeedBits (&p_adec->bit_stream, alloc_table->nbal[sb]); NeedBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
...@@ -783,13 +784,17 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -783,13 +784,17 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
/* parse scfsi */ /* parse scfsi */
for (sb = 0; sb < sblimit; sb++) { for (sb = 0; sb < sblimit; sb++)
if (allocation_0[sb]) { {
if (allocation_0[sb])
{
NeedBits (&p_adec->bit_stream, 2); NeedBits (&p_adec->bit_stream, 2);
scfsi_0[sb] = p_adec->bit_stream.buffer >> (32 - 2); scfsi_0[sb] = p_adec->bit_stream.buffer >> (32 - 2);
DumpBits (&p_adec->bit_stream, 2); DumpBits (&p_adec->bit_stream, 2);
} }
if (allocation_1[sb]) {
if (allocation_1[sb])
{
NeedBits (&p_adec->bit_stream, 2); NeedBits (&p_adec->bit_stream, 2);
scfsi_1[sb] = p_adec->bit_stream.buffer >> (32 - 2); scfsi_1[sb] = p_adec->bit_stream.buffer >> (32 - 2);
DumpBits (&p_adec->bit_stream, 2); DumpBits (&p_adec->bit_stream, 2);
...@@ -800,10 +805,12 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -800,10 +805,12 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
for (sb = 0; sb < sblimit; sb++) for (sb = 0; sb < sblimit; sb++)
{ {
if (allocation_0[sb]) { if (allocation_0[sb])
{
int index_0, index_1, index_2; int index_0, index_1, index_2;
switch (scfsi_0[sb]) { switch (scfsi_0[sb])
{
case 0: case 0:
NeedBits (&p_adec->bit_stream, 18); NeedBits (&p_adec->bit_stream, 18);
index_0 = p_adec->bit_stream.buffer >> (32 - 6); index_0 = p_adec->bit_stream.buffer >> (32 - 6);
...@@ -811,11 +818,14 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -811,11 +818,14 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
index_2 = (p_adec->bit_stream.buffer >> (32 - 18)) & 63; index_2 = (p_adec->bit_stream.buffer >> (32 - 18)) & 63;
DumpBits (&p_adec->bit_stream, 18); DumpBits (&p_adec->bit_stream, 18);
if (allocation_0[sb] < 0) { if (allocation_0[sb] < 0)
{
slope_0[0][sb] = adec_scalefactor_table[index_0]; slope_0[0][sb] = adec_scalefactor_table[index_0];
slope_0[1][sb] = adec_scalefactor_table[index_1]; slope_0[1][sb] = adec_scalefactor_table[index_1];
slope_0[2][sb] = adec_scalefactor_table[index_2]; slope_0[2][sb] = adec_scalefactor_table[index_2];
} else { }
else
{
float scalefactor; float scalefactor;
float slope, offset; float slope, offset;
...@@ -835,17 +845,21 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -835,17 +845,21 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
offset_0[2][sb] = offset * scalefactor; offset_0[2][sb] = offset * scalefactor;
} }
break; break;
case 1: case 1:
NeedBits (&p_adec->bit_stream, 12); NeedBits (&p_adec->bit_stream, 12);
index_0 = p_adec->bit_stream.buffer >> (32 - 6); index_0 = p_adec->bit_stream.buffer >> (32 - 6);
index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63; index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
DumpBits (&p_adec->bit_stream, 12); DumpBits (&p_adec->bit_stream, 12);
if (allocation_0[sb] < 0) { if (allocation_0[sb] < 0)
{
slope_0[0][sb] = slope_0[1][sb] = slope_0[0][sb] = slope_0[1][sb] =
adec_scalefactor_table[index_0]; adec_scalefactor_table[index_0];
slope_0[2][sb] = adec_scalefactor_table[index_1]; slope_0[2][sb] = adec_scalefactor_table[index_1];
} else { }
else
{
float scalefactor; float scalefactor;
float slope, offset; float slope, offset;
...@@ -854,22 +868,27 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -854,22 +868,27 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
scalefactor = adec_scalefactor_table[index_0]; scalefactor = adec_scalefactor_table[index_0];
slope_0[0][sb] = slope_0[1][sb] = slope * scalefactor; slope_0[0][sb] = slope_0[1][sb] = slope * scalefactor;
offset_0[0][sb] = offset_0[1][sb] = offset * scalefactor; offset_0[0][sb] = offset_0[1][sb] =
offset * scalefactor;
scalefactor = adec_scalefactor_table[index_1]; scalefactor = adec_scalefactor_table[index_1];
slope_0[2][sb] = slope * scalefactor; slope_0[2][sb] = slope * scalefactor;
offset_0[2][sb] = offset * scalefactor; offset_0[2][sb] = offset * scalefactor;
} }
break; break;
case 2: case 2:
NeedBits (&p_adec->bit_stream, 6); NeedBits (&p_adec->bit_stream, 6);
index_0 = p_adec->bit_stream.buffer >> (32 - 6); index_0 = p_adec->bit_stream.buffer >> (32 - 6);
DumpBits (&p_adec->bit_stream, 6); DumpBits (&p_adec->bit_stream, 6);
if (allocation_0[sb] < 0) { if (allocation_0[sb] < 0)
{
slope_0[0][sb] = slope_0[1][sb] = slope_0[2][sb] = slope_0[0][sb] = slope_0[1][sb] = slope_0[2][sb] =
adec_scalefactor_table[index_0]; adec_scalefactor_table[index_0];
} else { }
else
{
float scalefactor; float scalefactor;
float slope, offset; float slope, offset;
...@@ -883,17 +902,21 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -883,17 +902,21 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
offset * scalefactor; offset * scalefactor;
} }
break; break;
case 3: case 3:
NeedBits (&p_adec->bit_stream, 12); NeedBits (&p_adec->bit_stream, 12);
index_0 = p_adec->bit_stream.buffer >> (32 - 6); index_0 = p_adec->bit_stream.buffer >> (32 - 6);
index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63; index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
DumpBits (&p_adec->bit_stream, 12); DumpBits (&p_adec->bit_stream, 12);
if (allocation_0[sb] < 0) { if (allocation_0[sb] < 0)
{
slope_0[0][sb] = adec_scalefactor_table[index_0]; slope_0[0][sb] = adec_scalefactor_table[index_0];
slope_0[1][sb] = slope_0[2][sb] = slope_0[1][sb] = slope_0[2][sb] =
adec_scalefactor_table[index_1]; adec_scalefactor_table[index_1];
} else { }
else
{
float scalefactor; float scalefactor;
float slope, offset; float slope, offset;
...@@ -906,15 +929,19 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -906,15 +929,19 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
scalefactor = adec_scalefactor_table[index_1]; scalefactor = adec_scalefactor_table[index_1];
slope_0[1][sb] = slope_0[2][sb] = slope * scalefactor; slope_0[1][sb] = slope_0[2][sb] = slope * scalefactor;
offset_0[1][sb] = offset_0[2][sb] = offset * scalefactor; offset_0[1][sb] = offset_0[2][sb] =
offset * scalefactor;
} }
break; break;
} }
} }
if (allocation_1[sb]) {
if (allocation_1[sb])
{
int index_0, index_1, index_2; int index_0, index_1, index_2;
switch (scfsi_1[sb]) { switch (scfsi_1[sb])
{
case 0: case 0:
NeedBits (&p_adec->bit_stream, 18); NeedBits (&p_adec->bit_stream, 18);
index_0 = p_adec->bit_stream.buffer >> (32 - 6); index_0 = p_adec->bit_stream.buffer >> (32 - 6);
...@@ -922,11 +949,14 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -922,11 +949,14 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
index_2 = (p_adec->bit_stream.buffer >> (32 - 18)) & 63; index_2 = (p_adec->bit_stream.buffer >> (32 - 18)) & 63;
DumpBits (&p_adec->bit_stream, 18); DumpBits (&p_adec->bit_stream, 18);
if (allocation_1[sb] < 0) { if (allocation_1[sb] < 0)
{
slope_1[0][sb] = adec_scalefactor_table[index_0]; slope_1[0][sb] = adec_scalefactor_table[index_0];
slope_1[1][sb] = adec_scalefactor_table[index_1]; slope_1[1][sb] = adec_scalefactor_table[index_1];
slope_1[2][sb] = adec_scalefactor_table[index_2]; slope_1[2][sb] = adec_scalefactor_table[index_2];
} else { }
else
{
float scalefactor; float scalefactor;
float slope, offset; float slope, offset;
...@@ -946,17 +976,21 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -946,17 +976,21 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
offset_1[2][sb] = offset * scalefactor; offset_1[2][sb] = offset * scalefactor;
} }
break; break;
case 1: case 1:
NeedBits (&p_adec->bit_stream, 12); NeedBits (&p_adec->bit_stream, 12);
index_0 = p_adec->bit_stream.buffer >> (32 - 6); index_0 = p_adec->bit_stream.buffer >> (32 - 6);
index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63; index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
DumpBits (&p_adec->bit_stream, 12); DumpBits (&p_adec->bit_stream, 12);
if (allocation_1[sb] < 0) { if (allocation_1[sb] < 0)
{
slope_1[0][sb] = slope_1[1][sb] = slope_1[0][sb] = slope_1[1][sb] =
adec_scalefactor_table[index_0]; adec_scalefactor_table[index_0];
slope_1[2][sb] = adec_scalefactor_table[index_1]; slope_1[2][sb] = adec_scalefactor_table[index_1];
} else { }
else
{
float scalefactor; float scalefactor;
float slope, offset; float slope, offset;
...@@ -965,22 +999,27 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -965,22 +999,27 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
scalefactor = adec_scalefactor_table[index_0]; scalefactor = adec_scalefactor_table[index_0];
slope_1[0][sb] = slope_1[1][sb] = slope * scalefactor; slope_1[0][sb] = slope_1[1][sb] = slope * scalefactor;
offset_1[0][sb] = offset_1[1][sb] = offset * scalefactor; offset_1[0][sb] = offset_1[1][sb] =
offset * scalefactor;
scalefactor = adec_scalefactor_table[index_1]; scalefactor = adec_scalefactor_table[index_1];
slope_1[2][sb] = slope * scalefactor; slope_1[2][sb] = slope * scalefactor;
offset_1[2][sb] = offset * scalefactor; offset_1[2][sb] = offset * scalefactor;
} }
break; break;
case 2: case 2:
NeedBits (&p_adec->bit_stream, 6); NeedBits (&p_adec->bit_stream, 6);
index_0 = p_adec->bit_stream.buffer >> (32 - 6); index_0 = p_adec->bit_stream.buffer >> (32 - 6);
DumpBits (&p_adec->bit_stream, 6); DumpBits (&p_adec->bit_stream, 6);
if (allocation_1[sb] < 0) { if (allocation_1[sb] < 0)
{
slope_1[0][sb] = slope_1[1][sb] = slope_1[2][sb] = slope_1[0][sb] = slope_1[1][sb] = slope_1[2][sb] =
adec_scalefactor_table[index_0]; adec_scalefactor_table[index_0];
} else { }
else
{
float scalefactor; float scalefactor;
float slope, offset; float slope, offset;
...@@ -994,17 +1033,21 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -994,17 +1033,21 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
offset * scalefactor; offset * scalefactor;
} }
break; break;
case 3: case 3:
NeedBits (&p_adec->bit_stream, 12); NeedBits (&p_adec->bit_stream, 12);
index_0 = p_adec->bit_stream.buffer >> (32 - 6); index_0 = p_adec->bit_stream.buffer >> (32 - 6);
index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63; index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
DumpBits (&p_adec->bit_stream, 12); DumpBits (&p_adec->bit_stream, 12);
if (allocation_1[sb] < 0) { if (allocation_1[sb] < 0)
{
slope_1[0][sb] = adec_scalefactor_table[index_0]; slope_1[0][sb] = adec_scalefactor_table[index_0];
slope_1[1][sb] = slope_1[2][sb] = slope_1[1][sb] = slope_1[2][sb] =
adec_scalefactor_table[index_1]; adec_scalefactor_table[index_1];
} else { }
else
{
float scalefactor; float scalefactor;
float slope, offset; float slope, offset;
...@@ -1017,7 +1060,8 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -1017,7 +1060,8 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
scalefactor = adec_scalefactor_table[index_1]; scalefactor = adec_scalefactor_table[index_1];
slope_1[1][sb] = slope_1[2][sb] = slope * scalefactor; slope_1[1][sb] = slope_1[2][sb] = slope * scalefactor;
offset_1[1][sb] = offset_1[2][sb] = offset * scalefactor; offset_1[1][sb] = offset_1[2][sb] =
offset * scalefactor;
} }
break; break;
} }
...@@ -1027,16 +1071,21 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -1027,16 +1071,21 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
/* parse samples */ /* parse samples */
for (gr0 = 0; gr0 < 3; gr0++) for (gr0 = 0; gr0 < 3; gr0++)
for (gr1 = 0; gr1 < 4; gr1++) { {
for (gr1 = 0; gr1 < 4; gr1++)
{
s16 * XXX_buf; s16 * XXX_buf;
for (sb = 0; sb < bound; sb++) { for (sb = 0; sb < bound; sb++)
{
int code; int code;
switch (allocation_0[sb]) { switch (allocation_0[sb])
{
case 0: case 0:
sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0; sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
break; break;
case L3: case L3:
NeedBits (&p_adec->bit_stream, 5); NeedBits (&p_adec->bit_stream, 5);
code = p_adec->bit_stream.buffer >> (32 - 5); code = p_adec->bit_stream.buffer >> (32 - 5);
...@@ -1047,8 +1096,8 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -1047,8 +1096,8 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
sample_0[1][sb] = slope_0[gr0][sb] * L3_table[code % 3]; sample_0[1][sb] = slope_0[gr0][sb] * L3_table[code % 3];
code /= 3; code /= 3;
sample_0[2][sb] = slope_0[gr0][sb] * L3_table[code]; sample_0[2][sb] = slope_0[gr0][sb] * L3_table[code];
break; break;
case L5: case L5:
NeedBits (&p_adec->bit_stream, 7); NeedBits (&p_adec->bit_stream, 7);
code = p_adec->bit_stream.buffer >> (32 - 7); code = p_adec->bit_stream.buffer >> (32 - 7);
...@@ -1059,8 +1108,8 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -1059,8 +1108,8 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
sample_0[1][sb] = slope_0[gr0][sb] * L5_table[code % 5]; sample_0[1][sb] = slope_0[gr0][sb] * L5_table[code % 5];
code /= 5; code /= 5;
sample_0[2][sb] = slope_0[gr0][sb] * L5_table[code]; sample_0[2][sb] = slope_0[gr0][sb] * L5_table[code];
break; break;
case L9: case L9:
NeedBits (&p_adec->bit_stream, 10); NeedBits (&p_adec->bit_stream, 10);
code = p_adec->bit_stream.buffer >> (32 - 10); code = p_adec->bit_stream.buffer >> (32 - 10);
...@@ -1071,23 +1120,27 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -1071,23 +1120,27 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
sample_0[1][sb] = slope_0[gr0][sb] * L9_table[code % 9]; sample_0[1][sb] = slope_0[gr0][sb] * L9_table[code % 9];
code /= 9; code /= 9;
sample_0[2][sb] = slope_0[gr0][sb] * L9_table[code]; sample_0[2][sb] = slope_0[gr0][sb] * L9_table[code];
break; break;
default: default:
for (s = 0; s < 3; s++) { for (s = 0; s < 3; s++)
{
NeedBits (&p_adec->bit_stream, allocation_0[sb]); NeedBits (&p_adec->bit_stream, allocation_0[sb]);
code = (p_adec->bit_stream.buffer >> code = ( p_adec->bit_stream.buffer >>
(32 - allocation_0[sb])); (32 - allocation_0[sb]) );
DumpBits (&p_adec->bit_stream, allocation_0[sb]); DumpBits (&p_adec->bit_stream, allocation_0[sb]);
sample_0[s][sb] = sample_0[s][sb] =
slope_0[gr0][sb] * code + offset_0[gr0][sb]; slope_0[gr0][sb] * code + offset_0[gr0][sb];
} }
} }
switch (allocation_1[sb]) {
switch (allocation_1[sb])
{
case 0: case 0:
sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0; sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
break; break;
case L3: case L3:
NeedBits (&p_adec->bit_stream, 5); NeedBits (&p_adec->bit_stream, 5);
code = p_adec->bit_stream.buffer >> (32 - 5); code = p_adec->bit_stream.buffer >> (32 - 5);
...@@ -1098,8 +1151,8 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -1098,8 +1151,8 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
sample_1[1][sb] = slope_1[gr0][sb] * L3_table[code % 3]; sample_1[1][sb] = slope_1[gr0][sb] * L3_table[code % 3];
code /= 3; code /= 3;
sample_1[2][sb] = slope_1[gr0][sb] * L3_table[code]; sample_1[2][sb] = slope_1[gr0][sb] * L3_table[code];
break; break;
case L5: case L5:
NeedBits (&p_adec->bit_stream, 7); NeedBits (&p_adec->bit_stream, 7);
code = p_adec->bit_stream.buffer >> (32 - 7); code = p_adec->bit_stream.buffer >> (32 - 7);
...@@ -1110,8 +1163,8 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -1110,8 +1163,8 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
sample_1[1][sb] = slope_1[gr0][sb] * L5_table[code % 5]; sample_1[1][sb] = slope_1[gr0][sb] * L5_table[code % 5];
code /= 5; code /= 5;
sample_1[2][sb] = slope_1[gr0][sb] * L5_table[code]; sample_1[2][sb] = slope_1[gr0][sb] * L5_table[code];
break; break;
case L9: case L9:
NeedBits (&p_adec->bit_stream, 10); NeedBits (&p_adec->bit_stream, 10);
code = p_adec->bit_stream.buffer >> (32 - 10); code = p_adec->bit_stream.buffer >> (32 - 10);
...@@ -1122,13 +1175,14 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -1122,13 +1175,14 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
sample_1[1][sb] = slope_1[gr0][sb] * L9_table[code % 9]; sample_1[1][sb] = slope_1[gr0][sb] * L9_table[code % 9];
code /= 9; code /= 9;
sample_1[2][sb] = slope_1[gr0][sb] * L9_table[code]; sample_1[2][sb] = slope_1[gr0][sb] * L9_table[code];
break; break;
default: default:
for (s = 0; s < 3; s++) { for (s = 0; s < 3; s++)
{
NeedBits (&p_adec->bit_stream, allocation_1[sb]); NeedBits (&p_adec->bit_stream, allocation_1[sb]);
code = (p_adec->bit_stream.buffer >> code = ( p_adec->bit_stream.buffer >>
(32 - allocation_1[sb])); (32 - allocation_1[sb]) );
DumpBits (&p_adec->bit_stream, allocation_1[sb]); DumpBits (&p_adec->bit_stream, allocation_1[sb]);
sample_1[s][sb] = sample_1[s][sb] =
...@@ -1136,14 +1190,18 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -1136,14 +1190,18 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
} }
} }
} }
for (; sb < sblimit; sb++) {
for (; sb < sblimit; sb++)
{
int code; int code;
switch (allocation_0[sb]) { switch (allocation_0[sb])
{
case 0: case 0:
sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0; sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0; sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
break; break;
case L3: case L3:
NeedBits (&p_adec->bit_stream, 5); NeedBits (&p_adec->bit_stream, 5);
code = p_adec->bit_stream.buffer >> (32 - 5); code = p_adec->bit_stream.buffer >> (32 - 5);
...@@ -1157,8 +1215,8 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -1157,8 +1215,8 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
code /= 3; code /= 3;
sample_0[2][sb] = slope_0[gr0][sb] * L3_table[code]; sample_0[2][sb] = slope_0[gr0][sb] * L3_table[code];
sample_1[2][sb] = slope_1[gr0][sb] * L3_table[code]; sample_1[2][sb] = slope_1[gr0][sb] * L3_table[code];
break; break;
case L5: case L5:
NeedBits (&p_adec->bit_stream, 7); NeedBits (&p_adec->bit_stream, 7);
code = p_adec->bit_stream.buffer >> (32 - 7); code = p_adec->bit_stream.buffer >> (32 - 7);
...@@ -1172,8 +1230,8 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -1172,8 +1230,8 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
code /= 5; code /= 5;
sample_0[2][sb] = slope_0[gr0][sb] * L5_table[code]; sample_0[2][sb] = slope_0[gr0][sb] * L5_table[code];
sample_1[2][sb] = slope_1[gr0][sb] * L5_table[code]; sample_1[2][sb] = slope_1[gr0][sb] * L5_table[code];
break; break;
case L9: case L9:
NeedBits (&p_adec->bit_stream, 10); NeedBits (&p_adec->bit_stream, 10);
code = p_adec->bit_stream.buffer >> (32 - 10); code = p_adec->bit_stream.buffer >> (32 - 10);
...@@ -1187,13 +1245,14 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -1187,13 +1245,14 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
code /= 9; code /= 9;
sample_0[2][sb] = slope_0[gr0][sb] * L9_table[code]; sample_0[2][sb] = slope_0[gr0][sb] * L9_table[code];
sample_1[2][sb] = slope_1[gr0][sb] * L9_table[code]; sample_1[2][sb] = slope_1[gr0][sb] * L9_table[code];
break; break;
default: default:
for (s = 0; s < 3; s++) { for (s = 0; s < 3; s++)
{
NeedBits (&p_adec->bit_stream, allocation_0[sb]); NeedBits (&p_adec->bit_stream, allocation_0[sb]);
code = (p_adec->bit_stream.buffer >> code = ( p_adec->bit_stream.buffer >>
(32 - allocation_0[sb])); (32 - allocation_0[sb]) );
DumpBits (&p_adec->bit_stream, allocation_0[sb]); DumpBits (&p_adec->bit_stream, allocation_0[sb]);
sample_0[s][sb] = sample_0[s][sb] =
...@@ -1203,20 +1262,27 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -1203,20 +1262,27 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
} }
} }
} }
for (; sb < 32; sb++) {
for (; sb < 32; sb++)
{
sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0; sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0; sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
} }
for (s = 0; s < 3; s++) {
for (s = 0; s < 3; s++)
{
DCT32 (sample_0[s], &p_adec->bank_0); DCT32 (sample_0[s], &p_adec->bank_0);
XXX_buf = buffer; XXX_buf = buffer;
PCM (&p_adec->bank_0, &XXX_buf, 2); PCM (&p_adec->bank_0, &XXX_buf, 2);
DCT32 (sample_1[s], &p_adec->bank_1); DCT32 (sample_1[s], &p_adec->bank_1);
XXX_buf = buffer+1; XXX_buf = buffer+1;
PCM (&p_adec->bank_1, &XXX_buf, 2); PCM (&p_adec->bank_1, &XXX_buf, 2);
buffer += 64; buffer += 64;
} }
} }
}
return 0; return 0;
} }
...@@ -1233,19 +1299,24 @@ int adec_init (audiodec_t * p_adec) ...@@ -1233,19 +1299,24 @@ int adec_init (audiodec_t * p_adec)
int adec_sync_frame (audiodec_t * p_adec, adec_sync_info_t * p_sync_info) int adec_sync_frame (audiodec_t * p_adec, adec_sync_info_t * p_sync_info)
{ {
static int mpeg1_sample_rate[3] = {44100, 48000, 32000}; static int mpeg1_sample_rate[3] = {44100, 48000, 32000};
static int mpeg1_layer1_bit_rate[15] = { static int mpeg1_layer1_bit_rate[15] =
{
0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448
}; };
static int mpeg1_layer2_bit_rate[15] = { static int mpeg1_layer2_bit_rate[15] =
{
0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384
}; };
static int mpeg2_layer1_bit_rate[15] = { static int mpeg2_layer1_bit_rate[15] =
{
0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256
}; };
static int mpeg2_layer2_bit_rate[15] = { static int mpeg2_layer2_bit_rate[15] =
{
0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160
}; };
static int * bit_rate_table[8] = { static int * bit_rate_table[8] =
{
NULL, NULL, mpeg2_layer2_bit_rate, mpeg2_layer1_bit_rate, NULL, NULL, mpeg2_layer2_bit_rate, mpeg2_layer1_bit_rate,
NULL, NULL, mpeg1_layer2_bit_rate, mpeg1_layer1_bit_rate NULL, NULL, mpeg1_layer2_bit_rate, mpeg1_layer1_bit_rate
}; };
...@@ -1267,52 +1338,77 @@ int adec_sync_frame (audiodec_t * p_adec, adec_sync_info_t * p_sync_info) ...@@ -1267,52 +1338,77 @@ int adec_sync_frame (audiodec_t * p_adec, adec_sync_info_t * p_sync_info)
/* basic header check : sync word, no emphasis */ /* basic header check : sync word, no emphasis */
if ((header & 0xfff00003) != 0xfff00000) if ((header & 0xfff00003) != 0xfff00000)
{
return 1; return 1;
}
/* calculate bit rate */ /* calculate bit rate */
index = (header >> 17) & 7; /* mpeg ID + layer */ index = (header >> 17) & 7; /* mpeg ID + layer */
bit_rates = bit_rate_table[index]; bit_rates = bit_rate_table[index];
if (bit_rate_table == NULL) if (bit_rate_table == NULL)
{
return 1; /* invalid layer */ return 1; /* invalid layer */
}
index = (header >> 12) & 15; /* bit rate index */ index = (header >> 12) & 15; /* bit rate index */
if (index > 14) if (index > 14)
{
return 1; return 1;
}
bit_rate = bit_rates[index]; bit_rate = bit_rates[index];
/* mpeg 1 layer 2 : check that bitrate per channel is valid */ /* mpeg 1 layer 2 : check that bitrate per channel is valid */
if (bit_rates == mpeg1_layer2_bit_rate) { if (bit_rates == mpeg1_layer2_bit_rate)
if ((header & 0xc0) == 0xc0) { /* mono */ {
if ((header & 0xc0) == 0xc0)
{ /* mono */
if (index > 10) if (index > 10)
{
return 1; /* invalid bitrate per channel */ return 1; /* invalid bitrate per channel */
} else { /* stereo */ }
}
else
{ /* stereo */
if ((1 << index) & 0x2e) if ((1 << index) & 0x2e)
{
return 1; /* invalid bitrate per channel */ return 1; /* invalid bitrate per channel */
} }
} }
}
/* calculate sample rate */ /* calculate sample rate */
index = (header >> 10) & 3; /* sample rate index */ index = (header >> 10) & 3; /* sample rate index */
if (index > 2) if (index > 2)
{
return 1; return 1;
}
sample_rate = mpeg1_sample_rate[index]; sample_rate = mpeg1_sample_rate[index];
if (!(header & 0x80000)) if (!(header & 0x80000))
{
sample_rate >>= 1; /* half sample rate for mpeg2 */ sample_rate >>= 1; /* half sample rate for mpeg2 */
}
/* calculate frame length */ /* calculate frame length */
if ((header & 0x60000) == 0x60000) { /* layer 1 */ if ((header & 0x60000) == 0x60000)
{ /* layer 1 */
frame_size = 48000 * bit_rate / sample_rate; frame_size = 48000 * bit_rate / sample_rate;
if (header & 0x200) /* padding */ if (header & 0x200) /* padding */
{
frame_size += 4; frame_size += 4;
} else { /* layer >1 */ }
}
else
{ /* layer >1 */
frame_size = 144000 * bit_rate / sample_rate; frame_size = 144000 * bit_rate / sample_rate;
if (header & 0x200) /* padding */ if (header & 0x200) /* padding */
{
frame_size ++; frame_size ++;
} }
}
p_sync_info->sample_rate = sample_rate; p_sync_info->sample_rate = sample_rate;
p_sync_info->bit_rate = bit_rate; p_sync_info->bit_rate = bit_rate;
...@@ -1324,7 +1420,8 @@ int adec_sync_frame (audiodec_t * p_adec, adec_sync_info_t * p_sync_info) ...@@ -1324,7 +1420,8 @@ int adec_sync_frame (audiodec_t * p_adec, adec_sync_info_t * p_sync_info)
int adec_decode_frame (audiodec_t * p_adec, s16 * buffer) int adec_decode_frame (audiodec_t * p_adec, s16 * buffer)
{ {
if (!(p_adec->header & 0x10000)) { /* error check, skip it */ if (!(p_adec->header & 0x10000))
{ /* error check, skip it */
GetByte (&p_adec->bit_stream); GetByte (&p_adec->bit_stream);
GetByte (&p_adec->bit_stream); GetByte (&p_adec->bit_stream);
} }
...@@ -1333,31 +1430,49 @@ int adec_decode_frame (audiodec_t * p_adec, s16 * buffer) ...@@ -1333,31 +1430,49 @@ int adec_decode_frame (audiodec_t * p_adec, s16 * buffer)
p_adec->bit_stream.i_available = 0; p_adec->bit_stream.i_available = 0;
switch ((p_adec->header >> 17) & 3) { switch ((p_adec->header >> 17) & 3)
{
case 2: /* layer 2 */ case 2: /* layer 2 */
if ((p_adec->header & 0xc0) == 0xc0) { if ((p_adec->header & 0xc0) == 0xc0)
{
if (adec_layer2_mono (p_adec, buffer)) if (adec_layer2_mono (p_adec, buffer))
{
return 1; return 1;
} else { }
}
else
{
if (adec_layer2_stereo (p_adec, buffer)) if (adec_layer2_stereo (p_adec, buffer))
{
return 1; return 1;
} }
}
break; break;
case 3: /* layer 1 */ case 3: /* layer 1 */
if ((p_adec->header & 0xc0) == 0xc0) { if ((p_adec->header & 0xc0) == 0xc0)
{
if (adec_layer1_mono (p_adec, buffer)) if (adec_layer1_mono (p_adec, buffer))
{
return 1; return 1;
} else { }
}
else
{
if (adec_layer1_stereo (p_adec, buffer)) if (adec_layer1_stereo (p_adec, buffer))
{
return 1; return 1;
} }
}
break; break;
} }
/* skip ancillary data */ /* skip ancillary data */
if ((p_adec->header & 0xf000) == 0) /* free bitrate format */ if ((p_adec->header & 0xf000) == 0) /* free bitrate format */
{
return 0; return 0;
}
/* XXX rewrite the byte counting system to reduce overhead */ /* XXX rewrite the byte counting system to reduce overhead */
...@@ -1367,10 +1482,15 @@ int adec_decode_frame (audiodec_t * p_adec, s16 * buffer) ...@@ -1367,10 +1482,15 @@ int adec_decode_frame (audiodec_t * p_adec, s16 * buffer)
#endif #endif
if (p_adec->bit_stream.total_bytes_read > p_adec->frame_size) if (p_adec->bit_stream.total_bytes_read > p_adec->frame_size)
{
return 1; /* overrun */ return 1; /* overrun */
}
while (p_adec->bit_stream.total_bytes_read < p_adec->frame_size) while (p_adec->bit_stream.total_bytes_read < p_adec->frame_size)
{
GetByte (&p_adec->bit_stream); /* skip ancillary data */ GetByte (&p_adec->bit_stream); /* skip ancillary data */
}
return 0; return 0;
} }
...@@ -205,14 +205,15 @@ static void RunThread (adec_thread_t * p_adec) ...@@ -205,14 +205,15 @@ static void RunThread (adec_thread_t * p_adec)
p_byte_stream = adec_byte_stream ( &p_adec->audio_decoder ); p_byte_stream = adec_byte_stream ( &p_adec->audio_decoder );
/* FIXME: the check will be done later, am I right ? */ /* FIXME: the check will be done later, am I right ? */
adec_byte_stream_next ( p_byte_stream );
/* FIXME: is this really needed ?
adec_byte_stream_next ( p_byte_stream ); */
if( p_adec->b_die || p_adec->b_error ) if( p_adec->b_die || p_adec->b_error )
{ {
goto bad_frame; goto bad_frame;
} }
sync = 1;
} }
if( DECODER_FIFO_START( *p_adec->p_fifo)->b_has_pts ) if( DECODER_FIFO_START( *p_adec->p_fifo)->b_has_pts )
...@@ -229,10 +230,11 @@ static void RunThread (adec_thread_t * p_adec) ...@@ -229,10 +230,11 @@ static void RunThread (adec_thread_t * p_adec)
if( adec_sync_frame (&p_adec->audio_decoder, &sync_info) ) if( adec_sync_frame (&p_adec->audio_decoder, &sync_info) )
{ {
sync = 0;
goto bad_frame; goto bad_frame;
} }
sync = 1;
p_adec->p_aout_fifo->l_rate = sync_info.sample_rate; p_adec->p_aout_fifo->l_rate = sync_info.sample_rate;
buffer = ((s16 *)p_adec->p_aout_fifo->buffer) buffer = ((s16 *)p_adec->p_aout_fifo->buffer)
......
...@@ -315,7 +315,8 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump) ...@@ -315,7 +315,8 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
#define F -32768 #define F -32768
/* These values are not in the same order as in Annex 3-B.3 of the ISO/IEC /* These values are not in the same order as in Annex 3-B.3 of the ISO/IEC
DIS 11172-3 */ DIS 11172-3 */
static const float c[512] = { static const float c[512] =
{
0.000000000 * F, -0.000442505 * F, 0.003250122 * F, -0.007003784 * F, 0.000000000 * F, -0.000442505 * F, 0.003250122 * F, -0.007003784 * F,
0.031082153 * F, -0.078628540 * F, 0.100311279 * F, -0.572036743 * F, 0.031082153 * F, -0.078628540 * F, 0.100311279 * F, -0.572036743 * F,
1.144989014 * F, 0.572036743 * F, 0.100311279 * F, 0.078628540 * F, 1.144989014 * F, 0.572036743 * F, 0.100311279 * F, 0.078628540 * F,
...@@ -452,10 +453,12 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump) ...@@ -452,10 +453,12 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
f = c; f = c;
switch(b->pos) { switch(b->pos)
{
case 0: case 0:
v = b->actual; v = b->actual;
for (i=0; i<32; i++) { for (i=0; i<32; i++)
{
tmp = *f++ * *v; tmp = *f++ * *v;
v += 15; v += 15;
tmp += *f++ * *v--; tmp += *f++ * *v--;
...@@ -473,21 +476,27 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump) ...@@ -473,21 +476,27 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767) if ((tmp += *f++ * *v) > 32767)
{
/* ceiling saturation */ /* ceiling saturation */
**pcm = 0x7FFF; **pcm = 0x7FFF;
else }
if (tmp < -32768) else if (tmp < -32768)
{
/* floor saturation */ /* floor saturation */
**pcm = 0x8000; **pcm = 0x8000;
}
else else
{
**pcm = (s16)tmp; **pcm = (s16)tmp;
}
*pcm += jump; *pcm += jump;
v += 15; v += 15;
} }
break; break;
case 1: case 1:
v = b->actual + 1; v = b->actual + 1;
for (i=0; i<32; i++) { for (i=0; i<32; i++)
{
tmp = *f++ * *v--; tmp = *f++ * *v--;
tmp += *f++ * *v; tmp += *f++ * *v;
v += 15; v += 15;
...@@ -505,19 +514,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump) ...@@ -505,19 +514,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767) if ((tmp += *f++ * *v) > 32767)
{
**pcm = 0x7FFF; **pcm = 0x7FFF;
else }
if (tmp < -32768) else if (tmp < -32768)
{
**pcm = 0x8000; **pcm = 0x8000;
}
else else
{
**pcm = (s16)tmp; **pcm = (s16)tmp;
}
*pcm += jump; *pcm += jump;
v += 15; v += 15;
} }
break; break;
case 2: case 2:
v = b->actual + 2; v = b->actual + 2;
for (i=0; i<32; i++) { for (i=0; i<32; i++)
{
tmp = *f++ * *v--; tmp = *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v; tmp += *f++ * *v;
...@@ -535,19 +550,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump) ...@@ -535,19 +550,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767) if ((tmp += *f++ * *v) > 32767)
{
**pcm = 0x7FFF; **pcm = 0x7FFF;
else }
if (tmp < -32768) else if (tmp < -32768)
{
**pcm = 0x8000; **pcm = 0x8000;
}
else else
{
**pcm = (s16)tmp; **pcm = (s16)tmp;
}
*pcm += jump; *pcm += jump;
v += 15; v += 15;
} }
break; break;
case 3: case 3:
v = b->actual + 3; v = b->actual + 3;
for (i=0; i<32; i++) { for (i=0; i<32; i++)
{
tmp = *f++ * *v--; tmp = *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
...@@ -565,19 +586,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump) ...@@ -565,19 +586,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767) if ((tmp += *f++ * *v) > 32767)
{
**pcm = 0x7FFF; **pcm = 0x7FFF;
else }
if (tmp < -32768) else if (tmp < -32768)
{
**pcm = 0x8000; **pcm = 0x8000;
}
else else
{
**pcm = (s16)tmp; **pcm = (s16)tmp;
}
*pcm += jump; *pcm += jump;
v += 15; v += 15;
} }
break; break;
case 4: case 4:
v = b->actual + 4; v = b->actual + 4;
for (i=0; i<32; i++) { for (i=0; i<32; i++)
{
tmp = *f++ * *v--; tmp = *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
...@@ -595,19 +622,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump) ...@@ -595,19 +622,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767) if ((tmp += *f++ * *v) > 32767)
{
**pcm = 0x7FFF; **pcm = 0x7FFF;
else }
if (tmp < -32768) else if (tmp < -32768)
{
**pcm = 0x8000; **pcm = 0x8000;
}
else else
{
**pcm = (s16)tmp; **pcm = (s16)tmp;
}
*pcm += jump; *pcm += jump;
v += 15; v += 15;
} }
break; break;
case 5: case 5:
v = b->actual + 5; v = b->actual + 5;
for (i=0; i<32; i++) { for (i=0; i<32; i++)
{
tmp = *f++ * *v--; tmp = *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
...@@ -625,19 +658,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump) ...@@ -625,19 +658,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767) if ((tmp += *f++ * *v) > 32767)
{
**pcm = 0x7FFF; **pcm = 0x7FFF;
else }
if (tmp < -32768) else if (tmp < -32768)
{
**pcm = 0x8000; **pcm = 0x8000;
}
else else
{
**pcm = (s16)tmp; **pcm = (s16)tmp;
}
*pcm += jump; *pcm += jump;
v += 15; v += 15;
} }
break; break;
case 6: case 6:
v = b->actual + 6; v = b->actual + 6;
for (i=0; i<32; i++) { for (i=0; i<32; i++)
{
tmp = *f++ * *v--; tmp = *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
...@@ -655,19 +694,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump) ...@@ -655,19 +694,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767) if ((tmp += *f++ * *v) > 32767)
{
**pcm = 0x7FFF; **pcm = 0x7FFF;
else }
if (tmp < -32768) else if (tmp < -32768)
{
**pcm = 0x8000; **pcm = 0x8000;
}
else else
{
**pcm = (s16)tmp; **pcm = (s16)tmp;
}
*pcm += jump; *pcm += jump;
v += 15; v += 15;
} }
break; break;
case 7: case 7:
v = b->actual + 7; v = b->actual + 7;
for (i=0; i<32; i++) { for (i=0; i<32; i++)
{
tmp = *f++ * *v--; tmp = *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
...@@ -685,19 +730,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump) ...@@ -685,19 +730,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767) if ((tmp += *f++ * *v) > 32767)
{
**pcm = 0x7FFF; **pcm = 0x7FFF;
else }
if (tmp < -32768) else if (tmp < -32768)
{
**pcm = 0x8000; **pcm = 0x8000;
}
else else
{
**pcm = (s16)tmp; **pcm = (s16)tmp;
}
*pcm += jump; *pcm += jump;
v += 15; v += 15;
} }
break; break;
case 8: case 8:
v = b->actual + 8; v = b->actual + 8;
for (i=0; i<32; i++) { for (i=0; i<32; i++)
{
tmp = *f++ * *v--; tmp = *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
...@@ -715,19 +766,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump) ...@@ -715,19 +766,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767) if ((tmp += *f++ * *v) > 32767)
{
**pcm = 0x7FFF; **pcm = 0x7FFF;
else }
if (tmp < -32768) else if (tmp < -32768)
{
**pcm = 0x8000; **pcm = 0x8000;
}
else else
{
**pcm = (s16)tmp; **pcm = (s16)tmp;
}
*pcm += jump; *pcm += jump;
v += 15; v += 15;
} }
break; break;
case 9: case 9:
v = b->actual + 9; v = b->actual + 9;
for (i=0; i<32; i++) { for (i=0; i<32; i++)
{
tmp = *f++ * *v--; tmp = *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
...@@ -745,19 +802,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump) ...@@ -745,19 +802,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767) if ((tmp += *f++ * *v) > 32767)
{
**pcm = 0x7FFF; **pcm = 0x7FFF;
else }
if (tmp < -32768) else if (tmp < -32768)
{
**pcm = 0x8000; **pcm = 0x8000;
}
else else
{
**pcm = (s16)tmp; **pcm = (s16)tmp;
}
*pcm += jump; *pcm += jump;
v += 15; v += 15;
} }
break; break;
case 10: case 10:
v = b->actual + 10; v = b->actual + 10;
for (i=0; i<32; i++) { for (i=0; i<32; i++)
{
tmp = *f++ * *v--; tmp = *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
...@@ -775,19 +838,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump) ...@@ -775,19 +838,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767) if ((tmp += *f++ * *v) > 32767)
{
**pcm = 0x7FFF; **pcm = 0x7FFF;
else }
if (tmp < -32768) else if (tmp < -32768)
{
**pcm = 0x8000; **pcm = 0x8000;
}
else else
{
**pcm = (s16)tmp; **pcm = (s16)tmp;
}
*pcm += jump; *pcm += jump;
v += 15; v += 15;
} }
break; break;
case 11: case 11:
v = b->actual + 11; v = b->actual + 11;
for (i=0; i<32; i++) { for (i=0; i<32; i++)
{
tmp = *f++ * *v--; tmp = *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
...@@ -805,19 +874,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump) ...@@ -805,19 +874,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767) if ((tmp += *f++ * *v) > 32767)
{
**pcm = 0x7FFF; **pcm = 0x7FFF;
else }
if (tmp < -32768) else if (tmp < -32768)
{
**pcm = 0x8000; **pcm = 0x8000;
}
else else
{
**pcm = (s16)tmp; **pcm = (s16)tmp;
}
*pcm += jump; *pcm += jump;
v += 15; v += 15;
} }
break; break;
case 12: case 12:
v = b->actual + 12; v = b->actual + 12;
for (i=0; i<32; i++) { for (i=0; i<32; i++)
{
tmp = *f++ * *v--; tmp = *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
...@@ -835,19 +910,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump) ...@@ -835,19 +910,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767) if ((tmp += *f++ * *v) > 32767)
{
**pcm = 0x7FFF; **pcm = 0x7FFF;
else }
if (tmp < -32768) else if (tmp < -32768)
{
**pcm = 0x8000; **pcm = 0x8000;
}
else else
{
**pcm = (s16)tmp; **pcm = (s16)tmp;
}
*pcm += jump; *pcm += jump;
v += 15; v += 15;
} }
break; break;
case 13: case 13:
v = b->actual + 13; v = b->actual + 13;
for (i=0; i<32; i++) { for (i=0; i<32; i++)
{
tmp = *f++ * *v--; tmp = *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
...@@ -865,19 +946,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump) ...@@ -865,19 +946,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
v += 15; v += 15;
tmp += *f++ * *v--; tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767) if ((tmp += *f++ * *v) > 32767)
{
**pcm = 0x7FFF; **pcm = 0x7FFF;
else }
if (tmp < -32768) else if (tmp < -32768)
{
**pcm = 0x8000; **pcm = 0x8000;
}
else else
{
**pcm = (s16)tmp; **pcm = (s16)tmp;
}
*pcm += jump; *pcm += jump;
v += 15; v += 15;
} }
break; break;
case 14: case 14:
v = b->actual + 14; v = b->actual + 14;
for (i=0; i<32; i++) { for (i=0; i<32; i++)
{
tmp = *f++ * *v--; tmp = *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
...@@ -895,19 +982,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump) ...@@ -895,19 +982,25 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
tmp += *f++ * *v; tmp += *f++ * *v;
v += 15; v += 15;
if ((tmp += *f++ * *v) > 32767) if ((tmp += *f++ * *v) > 32767)
{
**pcm = 0x7FFF; **pcm = 0x7FFF;
else }
if (tmp < -32768) else if (tmp < -32768)
{
**pcm = 0x8000; **pcm = 0x8000;
}
else else
{
**pcm = (s16)tmp; **pcm = (s16)tmp;
}
*pcm += jump; *pcm += jump;
v += 15; v += 15;
} }
break; break;
case 15: case 15:
v = b->actual + 15; v = b->actual + 15;
for (i=0; i<32; i++) { for (i=0; i<32; i++)
{
tmp = *f++ * *v--; tmp = *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
...@@ -924,12 +1017,17 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump) ...@@ -924,12 +1017,17 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
tmp += *f++ * *v--; tmp += *f++ * *v--;
tmp += *f++ * *v--; tmp += *f++ * *v--;
if ((tmp += *f++ * *v) > 32767) if ((tmp += *f++ * *v) > 32767)
{
**pcm = 0x7FFF; **pcm = 0x7FFF;
else }
if (tmp < -32768) else if (tmp < -32768)
{
**pcm = 0x8000; **pcm = 0x8000;
}
else else
{
**pcm = (s16)tmp; **pcm = (s16)tmp;
}
*pcm += jump; *pcm += jump;
v += 31; v += 31;
} }
......
...@@ -70,7 +70,7 @@ int main (void) ...@@ -70,7 +70,7 @@ int main (void)
#if 1 #if 1
for (i = 0; i < (2*1152); i++) for (i = 0; i < (2*1152); i++)
intf_DbgMsg ( "%04X\n",(u16)buffer[i] ); fprintf ( stderr, "%04X\n",(u16)buffer[i] );
#endif #endif
} }
......
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