DelfMPEG's MPEG1 Layer III frame decoder



Overview


Read_Side_Info()
 /* fetch side information from bitstream, fill si[gr][ch] structures */

for(gr=0; gr<2; gr++)
 /* decode two granules */
{

    for(ch=0; ch<channels; ch++)
     /* read+scale one or two channels (mono or stereo) */
    {
        Read_Scalefactors( si[gr][ch], scalefac[ch] )
         /* fetch scalefactors from bitstream */

        Read_Huffman( si[gr][ch], xr[ch] )
         /* fetch samples from bitstream (Huffman decoding) */
         /* perform reordering and y=x^(4/3) scaling */
         /* uses tables: htab[], ro[], pow43tab[] */
         /* output: xr[ch] (integer values!) */

        Scale_Samples( si[gr][ch], xr[ch], scalefac[ch] )
         /* descale samples */
         /* uses table: quantab[] - y=2^((x-210)/4) */
         /* input (integer) / output (fraction): xr[ch] */
    }

    Joint_Stereo( si[gr][1], xr, scalefac[1] )
     /* joint-stereo processing (intensity and/or mid/side stereo) */
     /* INTENSITY STEREO DECODING IS NOT IMPLEMENTED YET */

    for(ch=0; ch<channels; ch++)
     /* filter+synthesize one or two channels (mono or stereo) */
    {
        Hybrid_Filter( si[gr][ch], xr[ch], prev[ch] )
         /* perform anti-aliasing, IMDCT and frequency inversion */
         /* input/output: xr[ch] */

        Synthesis( xr[ch], outbuf[gr][ch] )
         /* polyphase filter */
         /* input: xr[ch]  output: outbuf[gr][ch] */
    }
}



Notes about the implementation


the bitstream processing routines (side info, scalefactors, Huffman decoding)
are based on amp11 (C++ code, by Niklas Beisert). I've spent quite a lot of
time optimizing them, especially Huffman decoding.

for the sample scaling routines I've used ideas from amp11 and FalcAMP (DSP56K
code, by Denis Huguet and David Carrere).
hi David, my brand new "Double Precision Multiply" routine seems to be the
solution for the accuracy problems. hope you'll like it. ;)

the hybrid filter routines (anti-aliasing, IMDCT) are adapted from FalcAMP.

the synthesis routine (polyphase filter) is adapted from the mp2 player for
Atari Falcon (DSP56K code, by Fredrik Noring and Tomas Berndtsson).

