* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
-#include "int_types.h"
+#include "defs.h"
+
+#include "config.h"
+#include "common.h"
+#include "threads.h"
+#include "mtime.h"
+#include "stream_control.h"
+#include "input_ext-dec.h"
#include "adec_generic.h"
+#include "audio_decoder.h"
#include "adec_math.h" /* DCT32(), PCM() */
-#include "adec_bit_stream.h"
#include "adec_layer1.h"
#include "adec_layer2.h"
-#define NULL ((void *)0)
-
-int adec_init (audiodec_t * p_adec)
+int adec_Init( adec_thread_t * p_adec )
{
p_adec->bank_0.actual = p_adec->bank_0.v1;
p_adec->bank_0.pos = 0;
return 0;
}
-int adec_sync_frame (audiodec_t * p_adec, adec_sync_info_t * p_sync_info)
+int adec_SyncFrame( adec_thread_t * p_adec, adec_sync_info_t * p_sync_info )
{
static int mpeg1_sample_rate[3] = {44100, 48000, 32000};
static int mpeg1_layer1_bit_rate[15] =
int bit_rate;
int frame_size;
- p_adec->bit_stream.total_bytes_read = 0;
+ /* We read the whole header, but only really take 8 bits */
+ header = GetBits( &p_adec->bit_stream, 8 ) << 24;
+ header |= ShowBits( &p_adec->bit_stream, 24 );
- header = GetByte (&p_adec->bit_stream) << 24;
- header |= GetByte (&p_adec->bit_stream) << 16;
- header |= GetByte (&p_adec->bit_stream) << 8;
- header |= GetByte (&p_adec->bit_stream);
p_adec->header = header;
/* basic header check : sync word, no emphasis */
- if ((header & 0xfff00003) != 0xfff00000)
+ if( (header & 0xfff00003) != 0xfff00000 )
{
return 1;
}
/* calculate bit rate */
- index = (header >> 17) & 7; /* mpeg ID + layer */
- bit_rates = bit_rate_table[index];
- if (bit_rate_table == NULL)
+ index = ( header >> 17 ) & 7; /* mpeg ID + layer */
+ bit_rates = bit_rate_table[ index ];
+ if( bit_rate_table == NULL )
{
return 1; /* invalid layer */
}
- index = (header >> 12) & 15; /* bit rate index */
+ index = ( header >> 12 ) & 15; /* bit rate index */
if (index > 14)
{
return 1;
}
- bit_rate = bit_rates[index];
+ bit_rate = bit_rates[ index ];
/* 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)
+ if( (header & 0xc0) == 0xc0 )
{ /* mono */
- if (index > 10)
+ if( index > 10 )
{
return 1; /* invalid bitrate per channel */
}
}
else
{ /* stereo */
- if ((1 << index) & 0x2e)
+ if( (1 << index) & 0x2e )
{
return 1; /* invalid bitrate per channel */
}
/* calculate sample rate */
- index = (header >> 10) & 3; /* sample rate index */
- if (index > 2)
+ index = ( header >> 10 ) & 3; /* sample rate index */
+ if( index > 2 )
{
return 1;
}
- sample_rate = mpeg1_sample_rate[index];
- if (!(header & 0x80000))
+ sample_rate = mpeg1_sample_rate[ index ];
+
+ if( ! (header & 0x80000) )
{
sample_rate >>= 1; /* half sample rate for mpeg2 */
}
/* calculate frame length */
- if ((header & 0x60000) == 0x60000)
- { /* layer 1 */
+ if( (header & 0x60000) == 0x60000 )
+ {
+ /* layer 1 */
frame_size = 48000 * bit_rate / sample_rate;
- if (header & 0x200) /* padding */
+
+ /* padding */
+ if( header & 0x200 )
{
frame_size += 4;
}
}
else
- { /* layer >1 */
+ {
+ /* layer >1 */
frame_size = 144000 * bit_rate / sample_rate;
- if (header & 0x200) /* padding */
+
+ /* padding */
+ if( header & 0x200 )
{
frame_size ++;
}
}
+ /* Now we are sure we want this header, read it */
+ RemoveBits( &p_adec->bit_stream, 24 );
+ p_adec->i_read_bits = 32;
+
p_sync_info->sample_rate = sample_rate;
p_sync_info->bit_rate = bit_rate;
p_sync_info->frame_size = frame_size;
return 0;
}
-int adec_decode_frame (audiodec_t * p_adec, s16 * buffer)
+int adec_DecodeFrame( adec_thread_t * p_adec, s16 * buffer )
{
- if (!(p_adec->header & 0x10000))
- { /* error check, skip it */
- GetByte (&p_adec->bit_stream);
- GetByte (&p_adec->bit_stream);
+ int i_total_bytes_read;
+
+ if( ! (p_adec->header & 0x10000) )
+ {
+ /* Error check, skip it */
+ RemoveBits( &p_adec->bit_stream, 16 );
+ p_adec->i_read_bits += 16;
}
/* parse audio data */
- p_adec->bit_stream.i_available = 0;
-
- switch ((p_adec->header >> 17) & 3)
+ switch( (p_adec->header >> 17) & 3 )
{
- case 2: /* layer 2 */
- if ((p_adec->header & 0xc0) == 0xc0)
+ case 2:
+ /* layer 2 */
+ 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;
- case 3: /* layer 1 */
- if ((p_adec->header & 0xc0) == 0xc0)
+ case 3:
+ /* layer 1 */
+ 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;
}
- /* 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;
}
- /* XXX rewrite the byte counting system to reduce overhead */
-
-#if 0
- intf_DbgMsg ( "skip %d",
- p_adec->frame_size - p_adec->bit_stream.total_bytes_read );
-#endif
+ RealignBits( &p_adec->bit_stream );
+ i_total_bytes_read = ( p_adec->i_read_bits + 7 ) / 8;
- if (p_adec->bit_stream.total_bytes_read > p_adec->frame_size)
+ if( i_total_bytes_read > p_adec->frame_size )
{
return 1; /* overrun */
}
- while (p_adec->bit_stream.total_bytes_read < p_adec->frame_size)
+ while( i_total_bytes_read++ < p_adec->frame_size )
{
- GetByte (&p_adec->bit_stream); /* skip ancillary data */
+ RemoveBits( &p_adec->bit_stream, 8 ); /* skip ancillary data */
}
return 0;
*
*/
-#include "int_types.h"
+#include "defs.h"
+
+#include "config.h"
+#include "common.h"
+#include "threads.h"
+#include "mtime.h"
+#include "stream_control.h"
+#include "input_ext-dec.h"
#include "adec_generic.h"
+#include "audio_decoder.h"
#include "adec_math.h" /* DCT32(), PCM() */
-#include "adec_bit_stream.h"
#define NULL ((void *)0)
static int adec_bound_table[4] = { 4, 8, 12, 16 };
-int adec_layer1_mono( audiodec_t * p_adec, s16 * buffer )
+int adec_layer1_mono( adec_thread_t * p_adec, s16 * buffer )
{
u8 allocation[32];
float slope[32];
float offset[32];
float sample[32];
- int sb;
+ int i_sb;
int s;
+ int i_read_bits = 0;
- /* parse allocation */
+ /*
+ * Parse the allocation tables
+ */
- for (sb = 0; sb < 32; sb += 2)
+ for (i_sb = 0; i_sb < 32; i_sb += 2)
{
u8 tmp;
- tmp = GetByte ( &p_adec->bit_stream );
+
+ /* i_read_bits will be updated at the end of the loop */
+ tmp = GetBits ( &p_adec->bit_stream, 8 );
if ( (tmp >> 4) > 14 )
{
return 1;
}
- allocation[sb] = adec_layer1_allocation_table [tmp >> 4];
+ allocation[i_sb] = adec_layer1_allocation_table [tmp >> 4];
if ((tmp & 15) > 14)
{
return 1;
}
- allocation[sb+1] = adec_layer1_allocation_table [tmp & 15];
+ allocation[i_sb+1] = adec_layer1_allocation_table [tmp & 15];
}
- /* parse scalefactors */
+ i_read_bits += 8 * 16; /* we did 16 iterations */
+
+ /*
+ * Parse scalefactors
+ */
- for ( sb = 0; sb < 32; sb++ )
+ for ( i_sb = 0; i_sb < 32; i_sb++ )
{
- if ( allocation[sb] )
+ if ( allocation[i_sb] )
{
int index;
float scalefactor;
- NeedBits ( &p_adec->bit_stream, 6 );
- index = p_adec->bit_stream.buffer >> (32 - 6);
- DumpBits ( &p_adec->bit_stream, 6 );
+ index = GetBits( &p_adec->bit_stream, 6);
+
+ /* We also add the bits we'll take later in the sample parsing */
+ i_read_bits += 6 + 12 * allocation[i_sb];
scalefactor = adec_scalefactor_table[index];
- slope[sb] = adec_slope_table[allocation[sb]-2] * scalefactor;
- offset[sb] = adec_offset_table[allocation[sb]-2] * scalefactor;
+ slope[i_sb] = adec_slope_table[allocation[i_sb]-2] * scalefactor;
+ offset[i_sb] = adec_offset_table[allocation[i_sb]-2] * scalefactor;
}
}
- /* parse samples */
+ /*
+ * Parse samples
+ */
- for (s = 0; s < 12; s++)
+ for ( s = 0 ; s < 12; s++)
{
s16 * XXX_buf;
- for (sb = 0; sb < 32; sb++)
+ for (i_sb = 0; i_sb < 32; i_sb++)
{
- if (!allocation[sb])
+ if (!allocation[i_sb])
{
- sample[sb] = 0;
+ sample[i_sb] = 0;
}
else
{
int code;
- NeedBits (&p_adec->bit_stream, allocation[sb]);
- code = p_adec->bit_stream.buffer >> (32 - allocation[sb]);
- DumpBits (&p_adec->bit_stream, allocation[sb]);
+ /* The bits were already counted in the scalefactors parsing */
+ code = GetBits( &p_adec->bit_stream, allocation[i_sb] );
- sample[sb] = slope[sb] * code + offset[sb];
+ sample[i_sb] = slope[i_sb] * code + offset[i_sb];
}
}
buffer += 32;
}
+ p_adec->i_read_bits += i_read_bits;
+
return 0;
}
-int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer)
+int adec_layer1_stereo( adec_thread_t * p_adec, s16 * buffer )
{
u8 allocation_0[32], allocation_1[32];
float slope_0[32], slope_1[32];
float sample_0[32], sample_1[32];
int bound;
- int sb;
+ int i_sb;
int s;
+ int i_read_bits = 0;
- /* calculate bound */
+ /*
+ * Calculate bound
+ */
bound = 32;
if ( (p_adec->header & 0xc0) == 0x40)
- { /* intensity stereo */
+ {
+ /* intensity stereo */
int index;
index = (p_adec->header >> 4) & 3;
bound = adec_bound_table[index];
}
- /* parse allocation */
+ /*
+ * Parse allocation
+ */
- for (sb = 0; sb < bound; sb++)
+ for (i_sb = 0; i_sb < bound; i_sb++)
{
u8 tmp;
- tmp = GetByte (&p_adec->bit_stream);
+ tmp = GetBits( &p_adec->bit_stream, 8 );
if ((tmp >> 4) > 14)
{
return 1;
}
- allocation_0[sb] = adec_layer1_allocation_table [tmp >> 4];
+ allocation_0[i_sb] = adec_layer1_allocation_table [tmp >> 4];
if ((tmp & 15) > 14)
{
return 1;
}
- allocation_1[sb] = adec_layer1_allocation_table [tmp & 15];
+ allocation_1[i_sb] = adec_layer1_allocation_table [tmp & 15];
}
- for (; sb < 32; sb += 2)
+ for (; i_sb < 32; i_sb += 2)
{
u8 tmp;
- tmp = GetByte (&p_adec->bit_stream);
+ tmp = GetBits( &p_adec->bit_stream, 8 );
+
if ((tmp >> 4) > 14)
{
return 1;
}
- allocation_0[sb] = allocation_1[sb] = adec_layer1_allocation_table [tmp >> 4];
+ allocation_0[i_sb] = allocation_1[i_sb]
+ = adec_layer1_allocation_table [tmp >> 4];
+
if ((tmp & 15) > 14)
{
return 1;
}
- allocation_0[sb+1] = allocation_1[sb+1] = adec_layer1_allocation_table [tmp & 15];
+ allocation_0[i_sb+1] = allocation_1[i_sb+1]
+ = adec_layer1_allocation_table [tmp & 15];
}
- /* parse scalefactors */
+ i_read_bits += 4 * ( 32 + bound ); /* we read 8*bound and 4*(32-bound) */
+
+ /*
+ * Parse scalefactors
+ */
- for ( sb = 0; sb < 32; sb++ )
+ for ( i_sb = 0; i_sb < 32; i_sb++ )
{
- if ( allocation_0[sb] )
+ if ( allocation_0[i_sb] )
{
int index;
float scalefactor;
- NeedBits (&p_adec->bit_stream, 6);
- index = p_adec->bit_stream.buffer >> (32 - 6);
- DumpBits (&p_adec->bit_stream, 6);
+ index = GetBits( &p_adec->bit_stream, 6 );
+ i_read_bits += 6;
scalefactor = adec_scalefactor_table[index];
- slope_0[sb] = adec_slope_table[allocation_0[sb]-2] * scalefactor;
- offset_0[sb] = adec_offset_table[allocation_0[sb]-2] * scalefactor;
+ slope_0[i_sb] = adec_slope_table[allocation_0[i_sb]-2] * scalefactor;
+ offset_0[i_sb] = adec_offset_table[allocation_0[i_sb]-2] * scalefactor;
}
- if (allocation_1[sb])
+ if (allocation_1[i_sb])
{
int index;
float scalefactor;
- NeedBits (&p_adec->bit_stream, 6);
- index = p_adec->bit_stream.buffer >> (32 - 6);
- DumpBits (&p_adec->bit_stream, 6);
+ index = GetBits( &p_adec->bit_stream, 6 );
+ i_read_bits += 6;
scalefactor = adec_scalefactor_table[index];
- slope_1[sb] = adec_slope_table[allocation_1[sb]-2] * scalefactor;
- offset_1[sb] = adec_offset_table[allocation_1[sb]-2] * scalefactor;
+ slope_1[i_sb] = adec_slope_table[allocation_1[i_sb]-2] * scalefactor;
+ offset_1[i_sb] = adec_offset_table[allocation_1[i_sb]-2] * scalefactor;
}
}
{
s16 * XXX_buf;
- for (sb = 0; sb < bound; sb++)
+ for (i_sb = 0; i_sb < bound; i_sb++)
{
- if (!allocation_0[sb])
+ if (!allocation_0[i_sb])
{
- sample_0[sb] = 0;
+ sample_0[i_sb] = 0;
}
else
{
int code;
- NeedBits (&p_adec->bit_stream, allocation_0[sb]);
- code = p_adec->bit_stream.buffer >> (32 - allocation_0[sb]);
- DumpBits (&p_adec->bit_stream, allocation_0[sb]);
+ code = GetBits( &p_adec->bit_stream, allocation_0[i_sb] );
+ i_read_bits += allocation_0[i_sb];
- sample_0[sb] = slope_0[sb] * code + offset_0[sb];
+ sample_0[i_sb] = slope_0[i_sb] * code + offset_0[i_sb];
}
- if ( !allocation_1[sb] )
+ if ( !allocation_1[i_sb] )
{
- sample_1[sb] = 0;
+ sample_1[i_sb] = 0;
}
else
{
int code;
- NeedBits (&p_adec->bit_stream, allocation_1[sb]);
- code = p_adec->bit_stream.buffer >> (32 - allocation_1[sb]);
- DumpBits (&p_adec->bit_stream, allocation_1[sb]);
+ code = GetBits( &p_adec->bit_stream, allocation_1[i_sb] );
+ i_read_bits += allocation_1[i_sb];
- sample_1[sb] = slope_1[sb] * code + offset_1[sb];
+ sample_1[i_sb] = slope_1[i_sb] * code + offset_1[i_sb];
}
}
- for (; sb < 32; sb++)
+ for (; i_sb < 32; i_sb++)
{
- if (!allocation_0[sb])
+ if (!allocation_0[i_sb])
{
- sample_0[sb] = 0;
- sample_1[sb] = 0;
+ sample_0[i_sb] = 0;
+ sample_1[i_sb] = 0;
}
else
{
int code;
- NeedBits (&p_adec->bit_stream, allocation_0[sb]);
- code = p_adec->bit_stream.buffer >> (32 - allocation_0[sb]);
- DumpBits (&p_adec->bit_stream, allocation_0[sb]);
+ code = GetBits( &p_adec->bit_stream, allocation_0[i_sb] );
+ i_read_bits += allocation_0[i_sb];
- sample_0[sb] = slope_0[sb] * code + offset_0[sb];
- sample_1[sb] = slope_1[sb] * code + offset_1[sb];
+ sample_0[i_sb] = slope_0[i_sb] * code + offset_0[i_sb];
+ sample_1[i_sb] = slope_1[i_sb] * code + offset_1[i_sb];
}
}
buffer += 64;
}
+ p_adec->i_read_bits += i_read_bits;
+
return 0;
}
*
*/
-#include "int_types.h"
+#include "defs.h"
+
+#include "config.h"
+#include "common.h"
+#include "threads.h"
+#include "mtime.h"
+#include "stream_control.h"
+#include "input_ext-dec.h"
#include "adec_generic.h"
+#include "audio_decoder.h"
#include "adec_math.h" /* DCT32(), PCM() */
-#include "adec_bit_stream.h"
#define NULL ((void *)0)
*sblimit = sblimit_table[index];
}
-int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
+int adec_layer2_mono( adec_thread_t * p_adec, s16 * buffer )
{
static u8 freq_table[15] = {2, 1, 1, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2};
static float L3_table[3] = {-2/3.0, 0, 2/3.0};
int sb;
int gr0, gr1;
int s;
+ int i_read_bits = 0;
/* get the right allocation table */
adec_layer2_get_table (p_adec->header, freq_table, &alloc_table, &sblimit);
{
int index;
- NeedBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
- index = p_adec->bit_stream.buffer >> (32 - alloc_table->nbal[sb]);
- DumpBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
+ index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
+ i_read_bits += alloc_table->nbal[sb];
allocation[sb] = alloc_table->alloc[sb][index];
}
{
if (allocation[sb])
{
- NeedBits (&p_adec->bit_stream, 2);
- scfsi[sb] = p_adec->bit_stream.buffer >> (32 - 2);
- DumpBits (&p_adec->bit_stream, 2);
+ scfsi[sb] = GetBits (&p_adec->bit_stream, 2);
+ i_read_bits += 2;
}
}
switch (scfsi[sb])
{
- case 0:
- NeedBits (&p_adec->bit_stream, 18);
- index_0 = p_adec->bit_stream.buffer >> (32 - 6);
- index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
- index_2 = (p_adec->bit_stream.buffer >> (32 - 18)) & 63;
- DumpBits (&p_adec->bit_stream, 18);
-
- if (allocation[sb] < 0)
- {
- slope[0][sb] = adec_scalefactor_table[index_0];
- slope[1][sb] = adec_scalefactor_table[index_1];
- slope[2][sb] = adec_scalefactor_table[index_2];
- }
- else
- {
- float r_scalefactor;
- float r_slope, r_offset;
-
- r_slope = adec_slope_table[allocation[sb]-2];
- r_offset = adec_offset_table[allocation[sb]-2];
-
- r_scalefactor = adec_scalefactor_table[index_0];
- slope[0][sb] = r_slope * r_scalefactor;
- offset[0][sb] = r_offset * r_scalefactor;
-
- r_scalefactor = adec_scalefactor_table[index_1];
- slope[1][sb] = r_slope * r_scalefactor;
- offset[1][sb] = r_offset * r_scalefactor;
-
- r_scalefactor = adec_scalefactor_table[index_2];
- slope[2][sb] = r_slope * r_scalefactor;
- offset[2][sb] = r_offset * r_scalefactor;
- }
+ case 0:
+ index_0 = GetBits(&p_adec->bit_stream,6);
+ index_1 = GetBits(&p_adec->bit_stream,6);
+ index_2 = GetBits(&p_adec->bit_stream,6);
+ i_read_bits += 18;
+
+ if (allocation[sb] < 0)
+ {
+ slope[0][sb] = adec_scalefactor_table[index_0];
+ slope[1][sb] = adec_scalefactor_table[index_1];
+ slope[2][sb] = adec_scalefactor_table[index_2];
+ }
+ else
+ {
+ float r_scalefactor;
+ float r_slope, r_offset;
+
+ r_slope = adec_slope_table[allocation[sb]-2];
+ r_offset = adec_offset_table[allocation[sb]-2];
+
+ r_scalefactor = adec_scalefactor_table[index_0];
+ slope[0][sb] = r_slope * r_scalefactor;
+ offset[0][sb] = r_offset * r_scalefactor;
+
+ r_scalefactor = adec_scalefactor_table[index_1];
+ slope[1][sb] = r_slope * r_scalefactor;
+ offset[1][sb] = r_offset * r_scalefactor;
+
+ r_scalefactor = adec_scalefactor_table[index_2];
+ slope[2][sb] = r_slope * r_scalefactor;
+ offset[2][sb] = r_offset * r_scalefactor;
+ }
break;
- case 1:
- NeedBits (&p_adec->bit_stream, 12);
- index_0 = p_adec->bit_stream.buffer >> (32 - 6);
- index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
- DumpBits (&p_adec->bit_stream, 12);
-
- if (allocation[sb] < 0)
- {
- slope[0][sb] = slope[1][sb] =
- adec_scalefactor_table[index_0];
- slope[2][sb] = adec_scalefactor_table[index_1];
- }
- else
- {
- float r_scalefactor;
- float r_slope, r_offset;
-
- r_slope = adec_slope_table[allocation[sb]-2];
- r_offset = adec_offset_table[allocation[sb]-2];
-
- r_scalefactor = adec_scalefactor_table[index_0];
- slope[0][sb] = slope[1][sb] = r_slope * r_scalefactor;
- offset[0][sb] = offset[1][sb] =
- r_offset * r_scalefactor;
-
- r_scalefactor = adec_scalefactor_table[index_1];
- slope[2][sb] = r_slope * r_scalefactor;
- offset[2][sb] = r_offset * r_scalefactor;
- }
+ case 1:
+ index_0 = GetBits(&p_adec->bit_stream,6);
+ index_1 = GetBits(&p_adec->bit_stream,6);
+ i_read_bits += 12;
+
+ if (allocation[sb] < 0)
+ {
+ slope[0][sb] = slope[1][sb] =
+ adec_scalefactor_table[index_0];
+ slope[2][sb] = adec_scalefactor_table[index_1];
+ }
+ else
+ {
+ float r_scalefactor;
+ float r_slope, r_offset;
+
+ r_slope = adec_slope_table[allocation[sb]-2];
+ r_offset = adec_offset_table[allocation[sb]-2];
+
+ r_scalefactor = adec_scalefactor_table[index_0];
+ slope[0][sb] = slope[1][sb] = r_slope * r_scalefactor;
+ offset[0][sb] = offset[1][sb] =
+ r_offset * r_scalefactor;
+
+ r_scalefactor = adec_scalefactor_table[index_1];
+ slope[2][sb] = r_slope * r_scalefactor;
+ offset[2][sb] = r_offset * r_scalefactor;
+ }
break;
- case 2:
- NeedBits (&p_adec->bit_stream, 6);
- index_0 = p_adec->bit_stream.buffer >> (32 - 6);
- DumpBits (&p_adec->bit_stream, 6);
-
- if (allocation[sb] < 0)
- {
- slope[0][sb] = slope[1][sb] = slope[2][sb] =
- adec_scalefactor_table[index_0];
- }
- else
- {
- float r_scalefactor;
- float r_slope, r_offset;
-
- r_slope = adec_slope_table[allocation[sb]-2];
- r_offset = adec_offset_table[allocation[sb]-2];
-
- r_scalefactor = adec_scalefactor_table[index_0];
- slope[0][sb] = slope[1][sb] = slope[2][sb] =
- r_slope * r_scalefactor;
- offset[0][sb] = offset[1][sb] = offset[2][sb] =
- r_offset * r_scalefactor;
- }
+ case 2:
+ index_0 = GetBits( &p_adec->bit_stream, 6 );
+ i_read_bits += 6;
+
+ if (allocation[sb] < 0)
+ {
+ slope[0][sb] = slope[1][sb] = slope[2][sb] =
+ adec_scalefactor_table[index_0];
+ }
+ else
+ {
+ float r_scalefactor;
+ float r_slope, r_offset;
+
+ r_slope = adec_slope_table[allocation[sb]-2];
+ r_offset = adec_offset_table[allocation[sb]-2];
+
+ r_scalefactor = adec_scalefactor_table[index_0];
+ slope[0][sb] = slope[1][sb] = slope[2][sb] =
+ r_slope * r_scalefactor;
+ offset[0][sb] = offset[1][sb] = offset[2][sb] =
+ r_offset * r_scalefactor;
+ }
break;
- case 3:
- NeedBits (&p_adec->bit_stream, 12);
- index_0 = p_adec->bit_stream.buffer >> (32 - 6);
- index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
- DumpBits (&p_adec->bit_stream, 12);
-
- if (allocation[sb] < 0)
- {
- slope[0][sb] = adec_scalefactor_table[index_0];
- slope[1][sb] = slope[2][sb] =
- adec_scalefactor_table[index_1];
- }
- else
- {
- float r_scalefactor;
- float r_slope, r_offset;
-
- r_slope = adec_slope_table[allocation[sb]-2];
- r_offset = adec_offset_table[allocation[sb]-2];
-
- r_scalefactor = adec_scalefactor_table[index_0];
- slope[0][sb] = r_slope * r_scalefactor;
- offset[0][sb] = r_offset * r_scalefactor;
-
- r_scalefactor = adec_scalefactor_table[index_1];
- slope[1][sb] = slope[2][sb] = r_slope * r_scalefactor;
- offset[1][sb] = offset[2][sb] =
- r_offset * r_scalefactor;
- }
+ case 3:
+ index_0 = GetBits(&p_adec->bit_stream,6);
+ index_1 = GetBits(&p_adec->bit_stream,6);
+ i_read_bits += 12;
+
+ if (allocation[sb] < 0)
+ {
+ slope[0][sb] = adec_scalefactor_table[index_0];
+ slope[1][sb] = slope[2][sb] =
+ adec_scalefactor_table[index_1];
+ }
+ else
+ {
+ float r_scalefactor;
+ float r_slope, r_offset;
+
+ r_slope = adec_slope_table[allocation[sb]-2];
+ r_offset = adec_offset_table[allocation[sb]-2];
+
+ r_scalefactor = adec_scalefactor_table[index_0];
+ slope[0][sb] = r_slope * r_scalefactor;
+ offset[0][sb] = r_offset * r_scalefactor;
+
+ r_scalefactor = adec_scalefactor_table[index_1];
+ slope[1][sb] = slope[2][sb] = r_slope * r_scalefactor;
+ offset[1][sb] = offset[2][sb] =
+ r_offset * r_scalefactor;
+ }
break;
}
}
break;
case L3:
- NeedBits (&p_adec->bit_stream, 5);
- code = p_adec->bit_stream.buffer >> (32 - 5);
- DumpBits (&p_adec->bit_stream, 5);
+ code = GetBits( &p_adec->bit_stream, 5 );
+ i_read_bits += 5;
sample[0][sb] = slope[gr0][sb] * L3_table[code % 3];
code /= 3;
break;
case L5:
- NeedBits (&p_adec->bit_stream, 7);
- code = p_adec->bit_stream.buffer >> (32 - 7);
- DumpBits (&p_adec->bit_stream, 7);
+ code = GetBits( &p_adec->bit_stream, 7 );
+ i_read_bits += 7;
sample[0][sb] = slope[gr0][sb] * L5_table[code % 5];
code /= 5;
break;
case L9:
- NeedBits (&p_adec->bit_stream, 10);
- code = p_adec->bit_stream.buffer >> (32 - 10);
- DumpBits (&p_adec->bit_stream, 10);
+ code = GetBits( &p_adec->bit_stream, 10 );
+ i_read_bits += 10;
sample[0][sb] = slope[gr0][sb] * L9_table[code % 9];
code /= 9;
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]);
+ code = GetBits( &p_adec->bit_stream,
+ allocation[sb] );
+ i_read_bits += allocation[sb];
sample[s][sb] =
slope[gr0][sb] * code + offset[gr0][sb];
}
}
+ p_adec->i_read_bits += i_read_bits;
+
return 0;
}
-int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
+int adec_layer2_stereo( adec_thread_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 float L3_table[3] = {-2/3.0, 0, 2/3.0};
int sb;
int gr0, gr1;
int s;
+ int i_read_bits = 0;
/* get the right allocation table */
adec_layer2_get_table (p_adec->header, freq_table, &alloc_table, &sblimit);
{
int index;
- NeedBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
- index = p_adec->bit_stream.buffer >> (32 - alloc_table->nbal[sb]);
- DumpBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
-
+ index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
allocation_0[sb] = alloc_table->alloc[sb][index];
- NeedBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
- index = p_adec->bit_stream.buffer >> (32 - alloc_table->nbal[sb]);
- DumpBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
-
+ index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
allocation_1[sb] = alloc_table->alloc[sb][index];
+
+ i_read_bits += alloc_table->nbal[sb] * 2;
}
for (; sb < sblimit; sb++)
{
int index;
- NeedBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
- index = p_adec->bit_stream.buffer >> (32 - alloc_table->nbal[sb]);
- DumpBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
-
+ index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
allocation_0[sb] = allocation_1[sb] = alloc_table->alloc[sb][index];
+ i_read_bits += alloc_table->nbal[sb];
}
/* parse scfsi */
{
if (allocation_0[sb])
{
- NeedBits (&p_adec->bit_stream, 2);
- scfsi_0[sb] = p_adec->bit_stream.buffer >> (32 - 2);
- DumpBits (&p_adec->bit_stream, 2);
+ scfsi_0[sb] = GetBits (&p_adec->bit_stream, 2);
+ i_read_bits += 2;
}
if (allocation_1[sb])
{
- NeedBits (&p_adec->bit_stream, 2);
- scfsi_1[sb] = p_adec->bit_stream.buffer >> (32 - 2);
- DumpBits (&p_adec->bit_stream, 2);
+ scfsi_1[sb] = GetBits (&p_adec->bit_stream, 2);
+ i_read_bits += 2;
}
}
switch (scfsi_0[sb])
{
- case 0:
- NeedBits (&p_adec->bit_stream, 18);
- index_0 = p_adec->bit_stream.buffer >> (32 - 6);
- index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
- index_2 = (p_adec->bit_stream.buffer >> (32 - 18)) & 63;
- DumpBits (&p_adec->bit_stream, 18);
-
- if (allocation_0[sb] < 0)
- {
- slope_0[0][sb] = adec_scalefactor_table[index_0];
- slope_0[1][sb] = adec_scalefactor_table[index_1];
- slope_0[2][sb] = adec_scalefactor_table[index_2];
- }
- else
- {
- float scalefactor;
- float slope, offset;
-
- slope = adec_slope_table[allocation_0[sb]-2];
- offset = adec_offset_table[allocation_0[sb]-2];
-
- scalefactor = adec_scalefactor_table[index_0];
- slope_0[0][sb] = slope * scalefactor;
- offset_0[0][sb] = offset * scalefactor;
-
- scalefactor = adec_scalefactor_table[index_1];
- slope_0[1][sb] = slope * scalefactor;
- offset_0[1][sb] = offset * scalefactor;
-
- scalefactor = adec_scalefactor_table[index_2];
- slope_0[2][sb] = slope * scalefactor;
- offset_0[2][sb] = offset * scalefactor;
- }
+ case 0:
+ index_0 = GetBits(&p_adec->bit_stream,6);
+ index_1 = GetBits(&p_adec->bit_stream,6);
+ index_2 = GetBits(&p_adec->bit_stream,6);
+ i_read_bits += 18;
+
+ if (allocation_0[sb] < 0)
+ {
+ slope_0[0][sb] = adec_scalefactor_table[index_0];
+ slope_0[1][sb] = adec_scalefactor_table[index_1];
+ slope_0[2][sb] = adec_scalefactor_table[index_2];
+ }
+ else
+ {
+ float scalefactor;
+ float slope, offset;
+
+ slope = adec_slope_table[allocation_0[sb]-2];
+ offset = adec_offset_table[allocation_0[sb]-2];
+
+ scalefactor = adec_scalefactor_table[index_0];
+ slope_0[0][sb] = slope * scalefactor;
+ offset_0[0][sb] = offset * scalefactor;
+
+ scalefactor = adec_scalefactor_table[index_1];
+ slope_0[1][sb] = slope * scalefactor;
+ offset_0[1][sb] = offset * scalefactor;
+
+ scalefactor = adec_scalefactor_table[index_2];
+ slope_0[2][sb] = slope * scalefactor;
+ offset_0[2][sb] = offset * scalefactor;
+ }
break;
- case 1:
- NeedBits (&p_adec->bit_stream, 12);
- index_0 = p_adec->bit_stream.buffer >> (32 - 6);
- index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
- DumpBits (&p_adec->bit_stream, 12);
-
- if (allocation_0[sb] < 0)
- {
- slope_0[0][sb] = slope_0[1][sb] =
- adec_scalefactor_table[index_0];
- slope_0[2][sb] = adec_scalefactor_table[index_1];
- }
- else
- {
- float scalefactor;
- float slope, offset;
-
- slope = adec_slope_table[allocation_0[sb]-2];
- offset = adec_offset_table[allocation_0[sb]-2];
-
- scalefactor = adec_scalefactor_table[index_0];
- slope_0[0][sb] = slope_0[1][sb] = slope * scalefactor;
- offset_0[0][sb] = offset_0[1][sb] =
+ case 1:
+ index_0 = GetBits(&p_adec->bit_stream,6);
+ index_1 = GetBits(&p_adec->bit_stream,6);
+ i_read_bits += 12;
+
+ if (allocation_0[sb] < 0)
+ {
+ slope_0[0][sb] = slope_0[1][sb] =
+ adec_scalefactor_table[index_0];
+ slope_0[2][sb] = adec_scalefactor_table[index_1];
+ }
+ else
+ {
+ float scalefactor;
+ float slope, offset;
+
+ slope = adec_slope_table[allocation_0[sb]-2];
+ offset = adec_offset_table[allocation_0[sb]-2];
+
+ scalefactor = adec_scalefactor_table[index_0];
+ slope_0[0][sb] = slope_0[1][sb] = slope * scalefactor;
+ offset_0[0][sb] = offset_0[1][sb] =
offset * scalefactor;
- scalefactor = adec_scalefactor_table[index_1];
- slope_0[2][sb] = slope * scalefactor;
- offset_0[2][sb] = offset * scalefactor;
- }
+ scalefactor = adec_scalefactor_table[index_1];
+ slope_0[2][sb] = slope * scalefactor;
+ offset_0[2][sb] = offset * scalefactor;
+ }
break;
- case 2:
- NeedBits (&p_adec->bit_stream, 6);
- index_0 = p_adec->bit_stream.buffer >> (32 - 6);
- DumpBits (&p_adec->bit_stream, 6);
-
- if (allocation_0[sb] < 0)
- {
- slope_0[0][sb] = slope_0[1][sb] = slope_0[2][sb] =
- adec_scalefactor_table[index_0];
- }
- else
- {
- float scalefactor;
- float slope, offset;
-
- slope = adec_slope_table[allocation_0[sb]-2];
- offset = adec_offset_table[allocation_0[sb]-2];
-
- scalefactor = adec_scalefactor_table[index_0];
- slope_0[0][sb] = slope_0[1][sb] = slope_0[2][sb] =
- slope * scalefactor;
- offset_0[0][sb] = offset_0[1][sb] = offset_0[2][sb] =
- offset * scalefactor;
- }
+ case 2:
+ index_0 = GetBits( &p_adec->bit_stream, 6 );
+ i_read_bits += 6;
+
+ if (allocation_0[sb] < 0)
+ {
+ slope_0[0][sb] = slope_0[1][sb] = slope_0[2][sb] =
+ adec_scalefactor_table[index_0];
+ }
+ else
+ {
+ float scalefactor;
+ float slope, offset;
+
+ slope = adec_slope_table[allocation_0[sb]-2];
+ offset = adec_offset_table[allocation_0[sb]-2];
+
+ scalefactor = adec_scalefactor_table[index_0];
+ slope_0[0][sb] = slope_0[1][sb] = slope_0[2][sb] =
+ slope * scalefactor;
+ offset_0[0][sb] = offset_0[1][sb] = offset_0[2][sb] =
+ offset * scalefactor;
+ }
break;
- case 3:
- NeedBits (&p_adec->bit_stream, 12);
- index_0 = p_adec->bit_stream.buffer >> (32 - 6);
- index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
- DumpBits (&p_adec->bit_stream, 12);
-
- if (allocation_0[sb] < 0)
- {
- slope_0[0][sb] = adec_scalefactor_table[index_0];
- slope_0[1][sb] = slope_0[2][sb] =
- adec_scalefactor_table[index_1];
- }
- else
- {
- float scalefactor;
- float slope, offset;
-
- slope = adec_slope_table[allocation_0[sb]-2];
- offset = adec_offset_table[allocation_0[sb]-2];
-
- scalefactor = adec_scalefactor_table[index_0];
- slope_0[0][sb] = slope * scalefactor;
- offset_0[0][sb] = offset * scalefactor;
-
- scalefactor = adec_scalefactor_table[index_1];
- slope_0[1][sb] = slope_0[2][sb] = slope * scalefactor;
- offset_0[1][sb] = offset_0[2][sb] =
- offset * scalefactor;
- }
+ case 3:
+ index_0 = GetBits(&p_adec->bit_stream,6);
+ index_1 = GetBits(&p_adec->bit_stream,6);
+ i_read_bits += 12;
+
+ if (allocation_0[sb] < 0)
+ {
+ slope_0[0][sb] = adec_scalefactor_table[index_0];
+ slope_0[1][sb] = slope_0[2][sb] =
+ adec_scalefactor_table[index_1];
+ }
+ else
+ {
+ float scalefactor;
+ float slope, offset;
+
+ slope = adec_slope_table[allocation_0[sb]-2];
+ offset = adec_offset_table[allocation_0[sb]-2];
+
+ scalefactor = adec_scalefactor_table[index_0];
+ slope_0[0][sb] = slope * scalefactor;
+ offset_0[0][sb] = offset * scalefactor;
+
+ scalefactor = adec_scalefactor_table[index_1];
+ slope_0[1][sb] = slope_0[2][sb] = slope * scalefactor;
+ offset_0[1][sb] = offset_0[2][sb] =
+ offset * scalefactor;
+ }
break;
}
}
switch (scfsi_1[sb])
{
- case 0:
- NeedBits (&p_adec->bit_stream, 18);
- index_0 = p_adec->bit_stream.buffer >> (32 - 6);
- index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
- index_2 = (p_adec->bit_stream.buffer >> (32 - 18)) & 63;
- DumpBits (&p_adec->bit_stream, 18);
-
- if (allocation_1[sb] < 0)
- {
- slope_1[0][sb] = adec_scalefactor_table[index_0];
- slope_1[1][sb] = adec_scalefactor_table[index_1];
- slope_1[2][sb] = adec_scalefactor_table[index_2];
- }
- else
- {
- float scalefactor;
- float slope, offset;
-
- slope = adec_slope_table[allocation_1[sb]-2];
- offset = adec_offset_table[allocation_1[sb]-2];
-
- scalefactor = adec_scalefactor_table[index_0];
- slope_1[0][sb] = slope * scalefactor;
- offset_1[0][sb] = offset * scalefactor;
-
- scalefactor = adec_scalefactor_table[index_1];
- slope_1[1][sb] = slope * scalefactor;
- offset_1[1][sb] = offset * scalefactor;
-
- scalefactor = adec_scalefactor_table[index_2];
- slope_1[2][sb] = slope * scalefactor;
- offset_1[2][sb] = offset * scalefactor;
- }
+ case 0:
+ index_0 = GetBits(&p_adec->bit_stream,6);
+ index_1 = GetBits(&p_adec->bit_stream,6);
+ index_2 = GetBits(&p_adec->bit_stream,6);
+ i_read_bits += 18;
+
+ if (allocation_1[sb] < 0)
+ {
+ slope_1[0][sb] = adec_scalefactor_table[index_0];
+ slope_1[1][sb] = adec_scalefactor_table[index_1];
+ slope_1[2][sb] = adec_scalefactor_table[index_2];
+ }
+ else
+ {
+ float scalefactor;
+ float slope, offset;
+
+ slope = adec_slope_table[allocation_1[sb]-2];
+ offset = adec_offset_table[allocation_1[sb]-2];
+
+ scalefactor = adec_scalefactor_table[index_0];
+ slope_1[0][sb] = slope * scalefactor;
+ offset_1[0][sb] = offset * scalefactor;
+
+ scalefactor = adec_scalefactor_table[index_1];
+ slope_1[1][sb] = slope * scalefactor;
+ offset_1[1][sb] = offset * scalefactor;
+
+ scalefactor = adec_scalefactor_table[index_2];
+ slope_1[2][sb] = slope * scalefactor;
+ offset_1[2][sb] = offset * scalefactor;
+ }
break;
- case 1:
- NeedBits (&p_adec->bit_stream, 12);
- index_0 = p_adec->bit_stream.buffer >> (32 - 6);
- index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
- DumpBits (&p_adec->bit_stream, 12);
-
- if (allocation_1[sb] < 0)
- {
- slope_1[0][sb] = slope_1[1][sb] =
- adec_scalefactor_table[index_0];
- slope_1[2][sb] = adec_scalefactor_table[index_1];
- }
- else
- {
- float scalefactor;
- float slope, offset;
-
- slope = adec_slope_table[allocation_1[sb]-2];
- offset = adec_offset_table[allocation_1[sb]-2];
-
- scalefactor = adec_scalefactor_table[index_0];
- slope_1[0][sb] = slope_1[1][sb] = slope * scalefactor;
- offset_1[0][sb] = offset_1[1][sb] =
- offset * scalefactor;
+ case 1:
+ index_0 = GetBits(&p_adec->bit_stream,6);
+ index_1 = GetBits(&p_adec->bit_stream,6);
+ i_read_bits += 12;
+
+ if (allocation_1[sb] < 0)
+ {
+ slope_1[0][sb] = slope_1[1][sb] =
+ adec_scalefactor_table[index_0];
+ slope_1[2][sb] = adec_scalefactor_table[index_1];
+ }
+ else
+ {
+ float scalefactor;
+ float slope, offset;
+
+ slope = adec_slope_table[allocation_1[sb]-2];
+ offset = adec_offset_table[allocation_1[sb]-2];
+
+ scalefactor = adec_scalefactor_table[index_0];
+ slope_1[0][sb] = slope_1[1][sb] = slope * scalefactor;
+ offset_1[0][sb] = offset_1[1][sb] =
+ offset * scalefactor;
- scalefactor = adec_scalefactor_table[index_1];
- slope_1[2][sb] = slope * scalefactor;
- offset_1[2][sb] = offset * scalefactor;
- }
+ scalefactor = adec_scalefactor_table[index_1];
+ slope_1[2][sb] = slope * scalefactor;
+ offset_1[2][sb] = offset * scalefactor;
+ }
break;
- case 2:
- NeedBits (&p_adec->bit_stream, 6);
- index_0 = p_adec->bit_stream.buffer >> (32 - 6);
- DumpBits (&p_adec->bit_stream, 6);
-
- if (allocation_1[sb] < 0)
- {
- slope_1[0][sb] = slope_1[1][sb] = slope_1[2][sb] =
- adec_scalefactor_table[index_0];
- }
- else
- {
- float scalefactor;
- float slope, offset;
-
- slope = adec_slope_table[allocation_1[sb]-2];
- offset = adec_offset_table[allocation_1[sb]-2];
-
- scalefactor = adec_scalefactor_table[index_0];
- slope_1[0][sb] = slope_1[1][sb] = slope_1[2][sb] =
- slope * scalefactor;
- offset_1[0][sb] = offset_1[1][sb] = offset_1[2][sb] =
- offset * scalefactor;
- }
+ case 2:
+ index_0 = GetBits( &p_adec->bit_stream, 6 );
+ i_read_bits += 6;
+
+ if (allocation_1[sb] < 0)
+ {
+ slope_1[0][sb] = slope_1[1][sb] = slope_1[2][sb] =
+ adec_scalefactor_table[index_0];
+ }
+ else
+ {
+ float scalefactor;
+ float slope, offset;
+
+ slope = adec_slope_table[allocation_1[sb]-2];
+ offset = adec_offset_table[allocation_1[sb]-2];
+
+ scalefactor = adec_scalefactor_table[index_0];
+ slope_1[0][sb] = slope_1[1][sb] = slope_1[2][sb] =
+ slope * scalefactor;
+ offset_1[0][sb] = offset_1[1][sb] = offset_1[2][sb] =
+ offset * scalefactor;
+ }
break;
- case 3:
- NeedBits (&p_adec->bit_stream, 12);
- index_0 = p_adec->bit_stream.buffer >> (32 - 6);
- index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
- DumpBits (&p_adec->bit_stream, 12);
-
- if (allocation_1[sb] < 0)
- {
- slope_1[0][sb] = adec_scalefactor_table[index_0];
- slope_1[1][sb] = slope_1[2][sb] =
- adec_scalefactor_table[index_1];
- }
- else
- {
- float scalefactor;
- float slope, offset;
-
- slope = adec_slope_table[allocation_1[sb]-2];
- offset = adec_offset_table[allocation_1[sb]-2];
-
- scalefactor = adec_scalefactor_table[index_0];
- slope_1[0][sb] = slope * scalefactor;
- offset_1[0][sb] = offset * scalefactor;
-
- scalefactor = adec_scalefactor_table[index_1];
- slope_1[1][sb] = slope_1[2][sb] = slope * scalefactor;
- offset_1[1][sb] = offset_1[2][sb] =
- offset * scalefactor;
- }
+ case 3:
+ index_0 = GetBits(&p_adec->bit_stream,6);
+ index_1 = GetBits(&p_adec->bit_stream,6);
+ i_read_bits += 12;
+
+ if (allocation_1[sb] < 0)
+ {
+ slope_1[0][sb] = adec_scalefactor_table[index_0];
+ slope_1[1][sb] = slope_1[2][sb] =
+ adec_scalefactor_table[index_1];
+ }
+ else
+ {
+ float scalefactor;
+ float slope, offset;
+
+ slope = adec_slope_table[allocation_1[sb]-2];
+ offset = adec_offset_table[allocation_1[sb]-2];
+
+ scalefactor = adec_scalefactor_table[index_0];
+ slope_1[0][sb] = slope * scalefactor;
+ offset_1[0][sb] = offset * scalefactor;
+
+ scalefactor = adec_scalefactor_table[index_1];
+ slope_1[1][sb] = slope_1[2][sb] = slope * scalefactor;
+ offset_1[1][sb] = offset_1[2][sb] =
+ offset * scalefactor;
+ }
break;
}
}
break;
case L3:
- NeedBits (&p_adec->bit_stream, 5);
- code = p_adec->bit_stream.buffer >> (32 - 5);
- DumpBits (&p_adec->bit_stream, 5);
+ code = GetBits( &p_adec->bit_stream, 5 );
+ i_read_bits += 5;
sample_0[0][sb] = slope_0[gr0][sb] * L3_table[code % 3];
code /= 3;
break;
case L5:
- NeedBits (&p_adec->bit_stream, 7);
- code = p_adec->bit_stream.buffer >> (32 - 7);
- DumpBits (&p_adec->bit_stream, 7);
+ code = GetBits( &p_adec->bit_stream, 7 );
+ i_read_bits += 7;
sample_0[0][sb] = slope_0[gr0][sb] * L5_table[code % 5];
code /= 5;
break;
case L9:
- NeedBits (&p_adec->bit_stream, 10);
- code = p_adec->bit_stream.buffer >> (32 - 10);
- DumpBits (&p_adec->bit_stream, 10);
+ code = GetBits( &p_adec->bit_stream, 10 );
+ i_read_bits += 10;
sample_0[0][sb] = slope_0[gr0][sb] * L9_table[code % 9];
code /= 9;
default:
for (s = 0; s < 3; s++)
{
- NeedBits (&p_adec->bit_stream, allocation_0[sb]);
- code = ( p_adec->bit_stream.buffer >>
- (32 - allocation_0[sb]) );
- DumpBits (&p_adec->bit_stream, allocation_0[sb]);
+ code = GetBits( &p_adec->bit_stream,
+ allocation_0[sb] );
+ i_read_bits += allocation_0[sb];
sample_0[s][sb] =
slope_0[gr0][sb] * code + offset_0[gr0][sb];
break;
case L3:
- NeedBits (&p_adec->bit_stream, 5);
- code = p_adec->bit_stream.buffer >> (32 - 5);
- DumpBits (&p_adec->bit_stream, 5);
+ code = GetBits( &p_adec->bit_stream, 5 );
+ i_read_bits += 5;
sample_1[0][sb] = slope_1[gr0][sb] * L3_table[code % 3];
code /= 3;
break;
case L5:
- NeedBits (&p_adec->bit_stream, 7);
- code = p_adec->bit_stream.buffer >> (32 - 7);
- DumpBits (&p_adec->bit_stream, 7);
+ code = GetBits( &p_adec->bit_stream, 7 );
+ i_read_bits += 7;
sample_1[0][sb] = slope_1[gr0][sb] * L5_table[code % 5];
code /= 5;
break;
case L9:
- NeedBits (&p_adec->bit_stream, 10);
- code = p_adec->bit_stream.buffer >> (32 - 10);
- DumpBits (&p_adec->bit_stream, 10);
+ code = GetBits( &p_adec->bit_stream, 10 );
+ i_read_bits += 10;
sample_1[0][sb] = slope_1[gr0][sb] * L9_table[code % 9];
code /= 9;
default:
for (s = 0; s < 3; s++)
{
- NeedBits (&p_adec->bit_stream, allocation_1[sb]);
- code = ( p_adec->bit_stream.buffer >>
- (32 - allocation_1[sb]) );
- DumpBits (&p_adec->bit_stream, allocation_1[sb]);
+ code = GetBits( &p_adec->bit_stream,
+ allocation_1[sb] );
+ i_read_bits += allocation_1[sb];
sample_1[s][sb] =
slope_1[gr0][sb] * code + offset_1[gr0][sb];
break;
case L3:
- NeedBits (&p_adec->bit_stream, 5);
- code = p_adec->bit_stream.buffer >> (32 - 5);
- DumpBits (&p_adec->bit_stream, 5);
+ code = GetBits( &p_adec->bit_stream, 5 );
+ i_read_bits += 5;
sample_0[0][sb] = slope_0[gr0][sb] * L3_table[code % 3];
sample_1[0][sb] = slope_1[gr0][sb] * L3_table[code % 3];
break;
case L5:
- NeedBits (&p_adec->bit_stream, 7);
- code = p_adec->bit_stream.buffer >> (32 - 7);
- DumpBits (&p_adec->bit_stream, 7);
+ code = GetBits( &p_adec->bit_stream, 7 );
+ i_read_bits += 7;
sample_0[0][sb] = slope_0[gr0][sb] * L5_table[code % 5];
sample_1[0][sb] = slope_1[gr0][sb] * L5_table[code % 5];
break;
case L9:
- NeedBits (&p_adec->bit_stream, 10);
- code = p_adec->bit_stream.buffer >> (32 - 10);
- DumpBits (&p_adec->bit_stream, 10);
+ code = GetBits( &p_adec->bit_stream, 10 );
+ i_read_bits += 10;
sample_0[0][sb] = slope_0[gr0][sb] * L9_table[code % 9];
sample_1[0][sb] = slope_1[gr0][sb] * L9_table[code % 9];
default:
for (s = 0; s < 3; s++)
{
- NeedBits (&p_adec->bit_stream, allocation_0[sb]);
- code = ( p_adec->bit_stream.buffer >>
- (32 - allocation_0[sb]) );
- DumpBits (&p_adec->bit_stream, allocation_0[sb]);
+ code = GetBits( &p_adec->bit_stream,
+ allocation_0[sb] );
+ i_read_bits += allocation_0[sb];
sample_0[s][sb] =
slope_0[gr0][sb] * code + offset_0[gr0][sb];
}
}
+ p_adec->i_read_bits += i_read_bits;
+
return 0;
}
* audio_decoder.c: MPEG audio decoder thread
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
- * $Id: audio_decoder.c,v 1.45 2001/01/05 18:46:44 massiot Exp $
+ * $Id: audio_decoder.c,v 1.46 2001/01/11 17:44:48 sam Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Michel Lespinasse <walken@via.ecp.fr>
/* Allocate the memory needed to store the thread's structure */
if ( (p_adec = (adec_thread_t *)malloc (sizeof(adec_thread_t))) == NULL )
{
- intf_ErrMsg ( "adec error: not enough memory for adec_CreateThread() to create the new thread" );
+ intf_ErrMsg ( "adec error: not enough memory for"
+ " adec_CreateThread() to create the new thread" );
return 0;
}
p_adec->p_config = p_config;
p_adec->p_fifo = p_config->decoder_config.p_decoder_fifo;
-
/*
* Initialize the decoder properties
*/
- adec_init ( &p_adec->audio_decoder );
+ adec_Init ( p_adec );
/*
* Initialize the output properties
p_adec->p_aout_fifo = NULL;
/* Spawn the audio decoder thread */
- if ( vlc_thread_create(&p_adec->thread_id, "audio decoder", (vlc_thread_func_t)RunThread, (void *)p_adec) )
+ if ( vlc_thread_create(&p_adec->thread_id, "audio decoder",
+ (vlc_thread_func_t)RunThread, (void *)p_adec) )
{
intf_ErrMsg ("adec error: can't spawn audio decoder thread");
free (p_adec);
return p_adec->thread_id;
}
+/* following functions are local */
+
/*****************************************************************************
* InitThread : initialize an audio decoder thread
*****************************************************************************
static int InitThread (adec_thread_t * p_adec)
{
aout_fifo_t aout_fifo;
- adec_byte_stream_t * byte_stream;
intf_DbgMsg ("adec debug: initializing audio decoder thread %p", p_adec);
- /* Our first job is to initialize the bit stream structure with the
- * beginning of the input stream */
- vlc_mutex_lock ( &p_adec->p_fifo->data_lock );
- while ( DECODER_FIFO_ISEMPTY(*p_adec->p_fifo) )
- {
- if (p_adec->p_fifo->b_die)
- {
- vlc_mutex_unlock ( &p_adec->p_fifo->data_lock );
- return -1;
- }
- vlc_cond_wait ( &p_adec->p_fifo->data_wait, &p_adec->p_fifo->data_lock );
- }
- p_adec->p_data = DECODER_FIFO_START ( *p_adec->p_fifo )->p_first;
- byte_stream = adec_byte_stream ( &p_adec->audio_decoder );
- byte_stream->p_byte = p_adec->p_data->p_payload_start;
- byte_stream->p_end = p_adec->p_data->p_payload_end;
- byte_stream->info = p_adec;
- vlc_mutex_unlock ( &p_adec->p_fifo->data_lock );
+ p_adec->p_config->decoder_config.pf_init_bit_stream( &p_adec->bit_stream,
+ p_adec->p_config->decoder_config.p_decoder_fifo );
aout_fifo.i_type = AOUT_ADEC_STEREO_FIFO;
aout_fifo.i_channels = 2;
aout_fifo.l_frame_size = ADEC_FRAME_SIZE;
/* Creating the audio output fifo */
- if ( (p_adec->p_aout_fifo = aout_CreateFifo(p_adec->p_aout, &aout_fifo)) == NULL )
+ if ( (p_adec->p_aout_fifo =
+ aout_CreateFifo(p_adec->p_aout, &aout_fifo)) == NULL )
{
return -1;
}
{
int sync;
- intf_DbgMsg ( "adec debug: running audio decoder thread (%p) (pid == %i)", p_adec, getpid() );
+ intf_DbgMsg ( "adec debug: running audio decoder thread (%p) (pid == %i)",
+ p_adec, getpid() );
/* You really suck */
//msleep ( INPUT_PTS_DELAY );
/* Initializing the audio decoder thread */
- if( InitThread (p_adec) )
- {
- p_adec->p_fifo->b_error = 1;
- }
+ p_adec->p_fifo->b_error = InitThread (p_adec);
sync = 0;
s16 * buffer;
adec_sync_info_t sync_info;
- if ( !sync )
- {
- /* have to find a synchro point */
- adec_byte_stream_t * p_byte_stream;
-
- intf_DbgMsg ( "adec: sync" );
-
- p_byte_stream = adec_byte_stream ( &p_adec->audio_decoder );
- /* FIXME: the check will be done later, am I right ? */
-
- /* FIXME: is this really needed ?
- adec_byte_stream_next ( p_byte_stream ); */
-
- if( p_adec->p_fifo->b_die || p_adec->p_fifo->b_error )
- {
- goto bad_frame;
- }
-
- }
-
if( DECODER_FIFO_START( *p_adec->p_fifo)->i_pts )
{
p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] =
LAST_MDATE;
}
- if( adec_sync_frame (&p_adec->audio_decoder, &sync_info) )
+ if( ! adec_SyncFrame (p_adec, &sync_info) )
{
- goto bad_frame;
- }
-
- sync = 1;
+ 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)
- + (p_adec->p_aout_fifo->l_end_frame * ADEC_FRAME_SIZE);
+ buffer = ((s16 *)p_adec->p_aout_fifo->buffer)
+ + (p_adec->p_aout_fifo->l_end_frame * ADEC_FRAME_SIZE);
- if( adec_decode_frame (&p_adec->audio_decoder, buffer) )
- {
- sync = 0;
- goto bad_frame;
+ if( adec_DecodeFrame (p_adec, buffer) )
+ {
+ /* Ouch, failed decoding... We'll have to resync */
+ sync = 0;
+ }
+ else
+ {
+ vlc_mutex_lock (&p_adec->p_aout_fifo->data_lock);
+
+ p_adec->p_aout_fifo->l_end_frame =
+ (p_adec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
+ vlc_cond_signal (&p_adec->p_aout_fifo->data_wait);
+ vlc_mutex_unlock (&p_adec->p_aout_fifo->data_lock);
+ }
}
-
- vlc_mutex_lock (&p_adec->p_aout_fifo->data_lock);
-
- p_adec->p_aout_fifo->l_end_frame =
- (p_adec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
- vlc_cond_signal (&p_adec->p_aout_fifo->data_wait);
- vlc_mutex_unlock (&p_adec->p_aout_fifo->data_lock);
-
- bad_frame:
}
/* If b_error is set, the audio decoder thread enters the error loop */
intf_DbgMsg ("adec debug: audio decoder thread %p destroyed", p_adec);
}
-void adec_byte_stream_next ( adec_byte_stream_t * p_byte_stream )
-{
- adec_thread_t * p_adec = p_byte_stream->info;
-
- /* We are looking for the next TS packet that contains real data,
- * and not just a PES header */
- do
- {
- /* We were reading the last TS packet of this PES packet... It's
- * time to jump to the next PES packet */
- if (p_adec->p_data->p_next == NULL)
- {
- /* We are going to read/write the start and end indexes of the
- * decoder fifo and to use the fifo's conditional variable,
- * that's why we need to take the lock before */
- vlc_mutex_lock (&p_adec->p_fifo->data_lock);
-
- /* Is the input thread dying ? */
- if (p_adec->p_fifo->b_die)
- {
- vlc_mutex_unlock (&(p_adec->p_fifo->data_lock));
- return;
- }
-
- /* We should increase the start index of the decoder fifo, but
- * if we do this now, the input thread could overwrite the
- * pointer to the current PES packet, and we weren't able to
- * give it back to the netlist. That's why we free the PES
- * packet first. */
- p_adec->p_fifo->pf_delete_pes (p_adec->p_fifo->p_packets_mgt,
- DECODER_FIFO_START(*p_adec->p_fifo));
- DECODER_FIFO_INCSTART (*p_adec->p_fifo);
-
- while (DECODER_FIFO_ISEMPTY(*p_adec->p_fifo))
- {
- vlc_cond_wait (&p_adec->p_fifo->data_wait, &p_adec->p_fifo->data_lock);
- if (p_adec->p_fifo->b_die)
- {
- vlc_mutex_unlock (&(p_adec->p_fifo->data_lock));
- return;
- }
- }
-
- /* The next byte could be found in the next PES packet */
- p_adec->p_data = DECODER_FIFO_START (*p_adec->p_fifo)->p_first;
-
- /* We can release the fifo's data lock */
- vlc_mutex_unlock (&p_adec->p_fifo->data_lock);
- }
- /* Perhaps the next TS packet of the current PES packet contains
- * real data (ie its payload's size is greater than 0) */
- else
- {
- p_adec->p_data = p_adec->p_data->p_next;
- }
- } while (p_adec->p_data->p_payload_start == p_adec->p_data->p_payload_end);
-
- /* We've found a TS packet which contains interesting data... */
- p_byte_stream->p_byte = p_adec->p_data->p_payload_start;
- p_byte_stream->p_end = p_adec->p_data->p_payload_end;
-}