* adec_layer2.c: MPEG Layer II audio decoder
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
+ * $Id: adec_layer2.c,v 1.5 2001/04/12 01:52:45 sam Exp $
*
- * Authors:
+ * Authors: Michel Kaempf <maxx@via.ecp.fr>
+ * Michel Lespinasse <walken@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
*/
-#include "int_types.h"
+#include "defs.h"
+
+#include <stdlib.h> /* NULL */
+#include <string.h> /* memcpy(), memset() */
+
+#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)
/**** wkn ****/
*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_1];
- slope_1[2][sb] = slope * scalefactor;
- offset_1[2][sb] = offset * scalefactor;
- }
+ 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;
+ }
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;
}