Stage II: Sidedata parsing

The next step is to parse the sidedata. The sidedata has the parameters that are needed to decode the main data that is to follow. Since I don’t have the ISO doc, this is where things get dicey. I have the source of a couple open source mp3 decoders and some random docs on mp3s, but I can’t really vouch for the correctness.

If the protection bit was set in the header, there is a 16 bit CRC word before the start of the sidedata.

pseudo code of sidedata format (primarily based fraunhofer ref source):

main_data_begin = getbits(9)

if  mono
    private_bits = getbits(5)
else
    private_bits = getbits(3)

for ch from 0 upto num_channels
    for i from 0 upto 4
        scfsi[ch][i] = getbits(1)

for gr from 0 upto 2
     for ch from upto num_channels
          part2_3_length[ch][gr] = getbits(12)
          big_values[ch][gr] = getbits(9)
          global_gain[ch][gr] = getbits(8)
          scalefac_compress[ch][gr] = getbits(4)
          window_switching_flag[ch][gr] = getbits(1)
          if window_switching_flag[ch][gr]
              block_type[ch][gr] = getbits(2)
              mixed_block_flag[ch][gr] = getbits(1)
              for i from 0 upto 2
                   table_select[ch][gr][i] = getbits(5)
              for i from 0 upto 3
                   subblock_gain[ch][gr][i] = getbits(3)
              if block_type[ch][gr] == 2 and mixed_block_flag[ch][gr] == 0
                  region0_count[ch][gr] = 8
              else
                  region0_count[ch][gr] = 7
              region1_count[ch][gr] = 20 - region0_count[ch][gr]
          else
               for i from 0 upto 3
                   table_select[ch][gr][i] = getbits(5)
               region0_count[ch][gr] = getbits(4)
               region1_count[ch][gr] = getbits(3)
               block_type[ch][gr] = 0
          preflag[ch][gr] = getbits(1)
          scalefac_scale[ch][gr] = getbits(1)
          count1table_select[ch][gr] = getbits(1)

gr = granule. Each frame has 2 granules each with 18*32 subband samples
main_data_end = negative offset in bytes from next frames header to the end of main data
private_bits = standard has no meaning for these.
scfsi= scale factor selection info. ‘0’ means there are scalefactors for each granule, ‘1’ means one set of scalefactors
part2_3_length=number of bits used for scalefactors and huffman data
big_values= size of big value section
global_gain=quantize step size.
scalefac_compress = used to lookup number of bits in scalefactors
window_switching_flag = true means a block other than normal(0) is used
block_type = used to select window type (len and style)
mixed_block_flag= true if different windows for high and low freq bands
table_select = which huffman table to use.
subblock_gain=offset from global gain for each short block
region0_count = number of scalefactors in region 0 minus one
region1_count = number of scalefactors in region 1 minus one
preflag = if set, a table of values are added to the scalefactors
scalefac_scale = chooses step size of scalefactor quantizer
count1table_select =huffman table selection for “ones” region

Later today I’m going to post python code that decodes the sidedata and also descriptions of each of the values parsed.

Advertisements
This entry was posted in pyMP3. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s