]> git.sesse.net Git - vlc/commitdiff
. moved the MPEG audio decoder to the new bitstream
authorSam Hocevar <sam@videolan.org>
Thu, 11 Jan 2001 17:44:48 +0000 (17:44 +0000)
committerSam Hocevar <sam@videolan.org>
Thu, 11 Jan 2001 17:44:48 +0000 (17:44 +0000)
    I wasn't sure whether the bits counting method was effective to
  skip ancillary data at the end of a frame, but I kept it for
  safety. There is still a lot to optimize in the bit counting, like
  unrolling the first iteration of some loops, but I don't know if
  it would be worth it. The other solution would have been to look for
  a startcode after eache frame, without caring about the ancillary bits.

  . cleaning in the SPU decoder.

14 files changed:
include/audio_output.h
src/audio_decoder/adec_bit_stream.h [deleted file]
src/audio_decoder/adec_generic.c
src/audio_decoder/adec_generic.h
src/audio_decoder/adec_layer1.c
src/audio_decoder/adec_layer1.h
src/audio_decoder/adec_layer2.c
src/audio_decoder/adec_layer2.h
src/audio_decoder/adec_math.c
src/audio_decoder/adec_test.c
src/audio_decoder/audio_decoder.c
src/audio_decoder/audio_decoder.h
src/spu_decoder/spu_decoder.c
src/spu_decoder/spu_decoder.h

index 9b09537eee0298a0a80e4a39dc72ee326af6f47b..07e1ec7ed213a5a14d80c99ed90f8c6dd1df56e0 100644 (file)
@@ -49,7 +49,7 @@
  * order to avoid rounding problems and heavy computations, as the function
  * that handles this structure only uses additions.
  *****************************************************************************/
-typedef struct
+typedef struct aout_increment_s
 {
     /* The remainder is used to keep track of the fractional part of the
      * index. */
@@ -73,7 +73,7 @@ typedef struct
 /*****************************************************************************
  * aout_fifo_t
  *****************************************************************************/
-typedef struct
+typedef struct aout_fifo_s
 {
     /* See the fifo types below */
     int                 i_type;
diff --git a/src/audio_decoder/adec_bit_stream.h b/src/audio_decoder/adec_bit_stream.h
deleted file mode 100644 (file)
index 05cf32b..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*****************************************************************************
- * audio_bit_stream.h: getbits functions for the audio decoder
- *****************************************************************************
- * Copyright (C) 2000 VideoLAN
- *
- * Authors:
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
- *****************************************************************************/
-
-static __inline__ u8 GetByte (adec_bit_stream_t * p_bit_stream)
-{
-    /* Are there some bytes left in the current buffer ? */
-    if (p_bit_stream->byte_stream.p_byte >= p_bit_stream->byte_stream.p_end) {
-        /* no, switch to next buffer */
-        adec_byte_stream_next (&p_bit_stream->byte_stream);
-    }
-
-    p_bit_stream->total_bytes_read++;
-
-    return *(p_bit_stream->byte_stream.p_byte++);
-}
-
-static __inline__ void NeedBits (adec_bit_stream_t * p_bit_stream, int i_bits)
-{
-    while (p_bit_stream->i_available < i_bits) {
-        p_bit_stream->buffer |=
-            ((u32)GetByte (p_bit_stream)) << (24 - p_bit_stream->i_available);
-        p_bit_stream->i_available += 8;
-    }
-}
-
-static __inline__ void DumpBits (adec_bit_stream_t * p_bit_stream, int i_bits)
-{
-    p_bit_stream->buffer <<= i_bits;
-    p_bit_stream->i_available -= i_bits;
-}
index 7d4df6eb4cd3e90b92a40ac94db59432177af648..9429a02b68cc26bd90f9fd2f8689c908b663838f 100644 (file)
  * 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;
@@ -39,7 +44,7 @@ int adec_init (audiodec_t * p_adec)
     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] =
@@ -71,49 +76,47 @@ int adec_sync_frame (audiodec_t * p_adec, adec_sync_info_t * p_sync_info)
     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 */
             }
@@ -122,37 +125,48 @@ int adec_sync_frame (audiodec_t * p_adec, adec_sync_info_t * p_sync_info)
 
     /* 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;
@@ -161,77 +175,76 @@ int adec_sync_frame (audiodec_t * p_adec, adec_sync_info_t * p_sync_info)
     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;
index aa70543d569562440c301742cac6b0bcb9f42fc2..49e999d0c2fc976cc3d4ecca39e589c4dca7ec71 100644 (file)
@@ -31,61 +31,12 @@ typedef struct adec_sync_info_s {
     int bit_rate;       /* nominal bit rate in kbps */
 } adec_sync_info_t;
 
-typedef struct adec_byte_stream_s {
-    u8 * p_byte;
-    u8 * p_end;
-    void * info;
-} adec_byte_stream_t;
-
-/**** audio decoder API - functions publically provided by the audio dec. ****/
-
-int adec_init (audiodec_t * p_adec);
-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);
-static adec_byte_stream_t * adec_byte_stream (audiodec_t * p_adec);
-
-/**** audio decoder API - user functions to be provided to the audio dec. ****/
-
-void adec_byte_stream_next (adec_byte_stream_t * p_byte_stream);
-
-/**** EVERYTHING AFTER THIS POINT IS PRIVATE ! DO NOT USE DIRECTLY ****/
-
-/**** audio decoder internal structures ****/
-
-typedef struct adec_bank_s {
+typedef struct adec_bank_s
+{
     float               v1[512];
     float               v2[512];
     float *             actual;
     int                 pos;
+    
 } adec_bank_t;
 
-typedef struct adec_bit_stream_s {
-    u32 buffer;
-    int i_available;
-    adec_byte_stream_t byte_stream;
-    int total_bytes_read;
-} adec_bit_stream_t;
-
-struct audiodec_s {
-    /*
-     * Input properties
-     */
-
-    /* The bit stream structure handles the PES stream at the bit level */
-    adec_bit_stream_t   bit_stream;
-
-    /*
-     * Decoder properties
-     */
-    u32                 header;
-    int                 frame_size;
-    adec_bank_t         bank_0;
-    adec_bank_t         bank_1;
-};
-
-/**** audio decoder inline functions ****/
-
-static adec_byte_stream_t * adec_byte_stream (audiodec_t * p_adec)
-{
-    return &(p_adec->bit_stream.byte_stream);
-}
index 1490c6e2baace19362f36604e1b7d6117a44bb30..dd45c6b665d37477c50b6ea96b1879103446e2c9 100644 (file)
  *
  */
 
-#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)
 
@@ -88,79 +95,90 @@ static u8 adec_layer1_allocation_table[15] =
 
 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];
             }
         }
 
@@ -170,10 +188,12 @@ int adec_layer1_mono( audiodec_t * p_adec, s16 * buffer )
         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];
@@ -181,85 +201,97 @@ int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer)
     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;
         }
     }
 
@@ -269,56 +301,53 @@ int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer)
     {
         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];
             }
         }
 
@@ -331,6 +360,8 @@ int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer)
         buffer += 64;
     }
 
+    p_adec->i_read_bits += i_read_bits;
+
     return 0;
 }
 
index ba54237cb09a280edf9a66df8f2a3077e7c57a54..c558b94328d216b8e9be555980bc79e22b90231b 100644 (file)
@@ -20,6 +20,6 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
-int adec_layer1_mono( audiodec_t * p_adec, s16 * buffer );
-int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer);
+int adec_layer1_mono( adec_thread_t * p_adec, s16 * buffer );
+int adec_layer1_stereo (adec_thread_t * p_adec, s16 * buffer);
 
index 9e9913ce83d6a5ae0bae019f57bd915d637e8438..f8da423cbb6d966f29fcb1bc8331d9a9eaa8be21 100644 (file)
  *
  */
 
-#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)
 
@@ -187,7 +194,7 @@ static void adec_layer2_get_table( u32 header, u8 freq_table[15],
     *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};
@@ -206,6 +213,7 @@ int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
     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);
@@ -217,9 +225,8 @@ int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
     {
         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];
     }
@@ -230,9 +237,8 @@ int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
     {
         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;
         }
     }
 
@@ -246,127 +252,123 @@ int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
 
             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;
             }
         }
@@ -391,9 +393,8 @@ int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
                         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;
@@ -403,9 +404,8 @@ int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
                     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;
@@ -415,9 +415,8 @@ int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
                     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;
@@ -429,10 +428,9 @@ int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
                     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];
@@ -461,10 +459,12 @@ int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
         }
     }
 
+    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};
@@ -484,6 +484,7 @@ int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
     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);
@@ -505,28 +506,22 @@ int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
     {
         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 */
@@ -535,16 +530,14 @@ int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
     {
         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;
         }
     }
 
@@ -558,127 +551,123 @@ int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
 
             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;
             }
         }
@@ -689,127 +678,123 @@ int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
 
             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;
             }
         }
@@ -834,9 +819,8 @@ int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
                         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;
@@ -846,9 +830,8 @@ int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
                     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;
@@ -858,9 +841,8 @@ int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
                     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;
@@ -872,10 +854,9 @@ int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
                     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];
@@ -889,9 +870,8 @@ int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
                     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;
@@ -901,9 +881,8 @@ int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
                     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;
@@ -913,9 +892,8 @@ int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
                     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;
@@ -927,10 +905,9 @@ int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
                     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];
@@ -950,9 +927,8 @@ int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
                     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];
@@ -965,9 +941,8 @@ int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
                     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];
@@ -980,9 +955,8 @@ int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
                     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];
@@ -997,10 +971,9 @@ int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
                     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];
@@ -1031,6 +1004,8 @@ int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
         }
     }
 
+    p_adec->i_read_bits += i_read_bits;
+
     return 0;
 }
 
index ba90bbe8bfd9ec8da55f584b60728ae7412531ec..272c902aa58ce669e9c46f47bcbd7c508bfbdddd 100644 (file)
@@ -20,6 +20,6 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
-int adec_layer2_mono( audiodec_t * p_adec, s16 * buffer );
-int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer);
+int adec_layer2_mono   ( adec_thread_t * p_adec, s16 * buffer );
+int adec_layer2_stereo ( adec_thread_t * p_adec, s16 * buffer );
 
index ca65159c6433d4255f0f04f5b39b4d93f7d0a58b..dc66df9dd746bdce71db116bd2af924f229f63ed 100644 (file)
@@ -21,7 +21,7 @@
  *****************************************************************************/
 
 #include "int_types.h"
-#include "adec_generic.h"                                     /* adec_bank_t */
+#include "adec_generic.h"
 
 /*****************************************************************************
  * DCT32: Fast 32 points Discrete Cosine Transform
index b96896e74dfdb884abb1bde1b3dd805ada1bd9c1..4bd1a2e9d3c60368809e4fe3d196b4ae588e359f 100644 (file)
@@ -37,6 +37,7 @@
 
 #include "int_types.h"
 #include "adec_generic.h"
+#include "audio_decoder.h"
 
 #define ADEC_FRAME_SIZE (2*1152)
 
index 4a8bfec7026f50dd0387afbdb2c0102117c1e8f0..00fdb08870d69d038bebc127c479ee0a77360fcc 100644 (file)
@@ -2,7 +2,7 @@
  * 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>
@@ -83,7 +83,8 @@ vlc_thread_t adec_CreateThread ( adec_config_t * p_config )
     /* 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;
     }
 
@@ -93,11 +94,10 @@ vlc_thread_t adec_CreateThread ( adec_config_t * p_config )
     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
@@ -106,7 +106,8 @@ vlc_thread_t adec_CreateThread ( adec_config_t * p_config )
     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);
@@ -117,6 +118,8 @@ vlc_thread_t adec_CreateThread ( adec_config_t * p_config )
     return p_adec->thread_id;
 }
 
+/* following functions are local */
+
 /*****************************************************************************
  * InitThread : initialize an audio decoder thread
  *****************************************************************************
@@ -126,28 +129,11 @@ vlc_thread_t adec_CreateThread ( adec_config_t * p_config )
 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;
@@ -155,7 +141,8 @@ static int InitThread (adec_thread_t * p_adec)
     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;
     }
@@ -174,16 +161,14 @@ static void RunThread (adec_thread_t * p_adec)
 {
     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;
 
@@ -193,26 +178,6 @@ static void RunThread (adec_thread_t * p_adec)
         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] =
@@ -225,32 +190,30 @@ static void RunThread (adec_thread_t * p_adec)
                 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 */
@@ -322,64 +285,3 @@ static void EndThread ( adec_thread_t *p_adec )
     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;
-}
index 769de359fdd9386cb03012e18aa25df68c154d4f..e3ba63b49d20c99b0adb947acc78191b7c46537d 100644 (file)
@@ -2,7 +2,7 @@
  * audio_decoder.h : audio decoder thread interface
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: audio_decoder.h,v 1.4 2001/01/05 14:45:47 sam Exp $
+ * $Id: audio_decoder.h,v 1.5 2001/01/11 17:44:48 sam Exp $
  *
  * Authors:
  * Michel Kaempf <maxx@via.ecp.fr>
@@ -36,24 +36,33 @@ typedef struct adec_thread_s
      * Input properties
      */
     decoder_fifo_t *    p_fifo;                /* stores the PES stream data */
-    data_packet_t *     p_data;
+    /* The bit stream structure handles the PES stream at the bit level */
+    bit_stream_t        bit_stream;
+    int                 i_read_bits;
     adec_config_t *     p_config;
 
-
     /*
      * Decoder properties
      */
-    audiodec_t          audio_decoder;
+    u32                 header;
+    int                 frame_size;
+    adec_bank_t         bank_0;
+    adec_bank_t         bank_1;
 
     /*
      * Output properties
      */
-    aout_fifo_t *       p_aout_fifo; /* stores the decompressed audio frames */
-    aout_thread_t *     p_aout;           /* needed to create the audio fifo */
+    struct aout_fifo_s *    p_aout_fifo;   /* stores the decompressed frames */
+    struct aout_thread_s *  p_aout;       /* needed to create the audio fifo */
 
 } adec_thread_t;
 
 /*****************************************************************************
  * Prototypes
  *****************************************************************************/
-vlc_thread_t adec_CreateThread       ( adec_config_t * p_config );
+vlc_thread_t adec_CreateThread   ( adec_config_t * p_config );
+int          adec_Init           ( adec_thread_t * p_adec );
+int          adec_SyncFrame      ( adec_thread_t * p_adec,
+                                   adec_sync_info_t * p_sync_info );
+int          adec_DecodeFrame    ( adec_thread_t * p_adec, s16 * buffer );
+
index 46e61b0d1591ddc0680335cf2df5ecd3703cf3b2..309a7fa9ae42e92353564f7d9bb66c4691dea92d 100644 (file)
@@ -63,17 +63,18 @@ vlc_thread_t spudec_CreateThread( vdec_config_t * p_config )
     intf_DbgMsg("spudec debug: creating spu decoder thread");
 
     /* Allocate the memory needed to store the thread's structure */
-    if ( (p_spudec = (spudec_thread_t *)malloc( sizeof(spudec_thread_t) )) == NULL )
+    p_spudec = (spudec_thread_t *)malloc( sizeof(spudec_thread_t) );
+
+    if ( p_spudec == NULL )
     {
-        intf_ErrMsg("spudec error: not enough memory for spudec_CreateThread() to create the new thread");
+        intf_ErrMsg( "spudec error: not enough memory "
+                     "for spudec_CreateThread() to create the new thread" );
         return( 0 );
     }
 
     /*
      * Initialize the thread properties
      */
-    p_spudec->p_fifo->b_die = 0;
-    p_spudec->p_fifo->b_error = 0;
     p_spudec->p_config = p_config;
     p_spudec->p_fifo = p_config->decoder_config.p_decoder_fifo;
 
@@ -106,7 +107,8 @@ static int InitThread( spudec_thread_t *p_spudec )
 {
     intf_DbgMsg("spudec debug: initializing spu decoder thread %p", p_spudec);
 
-    p_spudec->p_config->decoder_config.pf_init_bit_stream( &p_spudec->bit_stream,
+    p_spudec->p_config->decoder_config.pf_init_bit_stream(
+            &p_spudec->bit_stream,
             p_spudec->p_config->decoder_config.p_decoder_fifo );
 
     /* Mark thread as running and return */
index 030cb2e22ccbef239dc21081d96c4be4bda7bf61..6f56fd22075c53d2d01c93683b6ce21fa814bf74 100644 (file)
@@ -39,10 +39,8 @@ typedef struct spudec_thread_s
     vdec_config_t *     p_config;
 
     /*
-     * Decoder properties
+     * Output properties
      */
-    unsigned int        total_bits_read;
-    /* ... */
     vout_thread_t *     p_vout;          /* needed to create the spu objects */
 
 } spudec_thread_t;