Stage I: Sync bits and Headers

Time to get roll’n. First a standard disclaimer. The code is meant to be readable and written quickly. I’ll go back later and optimize. Also I make mistakes, but once discovered I’ll correct them as fast as possible. whew…

MP3s are composed of a series of frames. And each frame starts with a sync word. The sync word is 12 1’s (0xFFF). If reading an MP3 stream, one would wait for the sync word and then try to decode the rest of the header and maybe wait for the next frame to make sure that the syncword that was found was real and not just a random occurrence.

Bit start bit pos bit length Description
0 12 Frame sync word 0xFFF
12 1 MPEG version, 0=v2 1=v1
13 2 Layer, 00=reserved 01=layer III 10=layer II 11=layer I
15 1 Protection bit, 0=has 16bit CRC after header 1=no protection
16 4 Bitrate index

bits bitrate
0000 free
0001 32
0010 40
0011 48
0100 56
0101 64
0110 80
0111 96
1000 112
1001 128
1010 160
1011 192
1100 224
1101 256
1110 320
1111 bad
20 2 Sampling rate 00=44100 01=48000 10=32000 11=reserved
22 1 Padding bit 0=no pad 1=padded
23 1 Private bit
24 2 Channel mode 00=stereo 01=joint stereo 10=dual channel 11= single
26 2 Mode extention (joint stereo)
28 1 Copyrighted? 1=true
29 1 Original? 1=true
30 2 Emphasis 00=none 01=50/15ms 10=reserved 11=CCIT J.17

I whipped up some code to find the sync and parse the header from a standard MP3 and created a new bitbucket repo.

Bitbucket home of pyMP3

This entry was posted in pyMP3. Bookmark the permalink.

One Response to Stage I: Sync bits and Headers

  1. “Mode extention (joint stereo)”


Leave a Reply

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

You are commenting using your 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