The private life of MP3 frames 

 
How is MP3 built?

Warning: http://www.mp3-tech.org/programmer/frame_header.html is more correct and up to date.

Most people with a little knowledge in MP3 files know that the sound is divided into smaller parts and compressed with a psycoacoustic model. This smaller pieces of the audio is then put into something called 'frames', which is a little datablock with a header. I'll focus on that header in this text.

The header is 4 bytes, 32 bits, big and begins with something called sync. This sync is, at least according to the MPEG standard, 12 set bits in a row. Some add-on standards made later uses 11 set bits and one cleared bit. The sync is directly followed by a ID bit, indicating if the file is a MPEG-1 och MPEG-2 file. 0=MPEG-2 and 1=MPEG-1

The layer is defined with the two layers bits. They are oddly defined as

0 0Not defined
0 1Layer III
1 0Layer II
1 1Layer I

With this information and the information in the bitrate field we can determine the bitrate of the audio (in kbit/s) according to this table.

Bitrate
value
MPEG-1,
layer I
MPEG-1,
layer II
MPEG-1,
layer III
MPEG-2,
layer I
MPEG-2,
layer II
MPEG-2,
layer III
0 0 0 0
0 0 0 132323232328
0 0 1 0644840644816
0 0 1 1965648965624
0 1 0 012864561286432
0 1 0 116080641608064
0 1 1 019296801929680
0 1 1 12241129622411256
1 0 0 025612811225612864
1 0 0 1288160128288160128
1 0 1 0320192160320192160
1 0 1 1352224192352224112
1 1 0 0384256224384256128
1 1 0 1416320256416320256
1 1 1 0448384320448384320
1 1 1 1

The sample rate is described in the frequency field. These values is dependent of which MPEG standard is used according to the following table.

Frequency
value
MPEG-1MPEG-2
0 044100 Hz22050 Hz
0 148000 Hz24000 Hz
1 032000 Hz16000 Hz
1 1

Three bits is not needed in the decoding process at all. These are the copyright bit, original home bit and the private bit. The copyright has the same meaning as the copyright bit on CDs and DAT tapes, i.e. telling that it is illegal to copy the contents if the bit is set. The original home bit indicates, if set, that the frame is located on its original media. No one seems to know what the privat bit is good for.

If the protection bit is NOT set then the frame header is followed by a 16 bit checksum, inserted before the audio data. If the padding bit is set then the frame is padded with an extra byte. Knowing this the size of the complete frame can be calculated with the following formula

FrameSize = 144 * BitRate / SampleRate
when the padding bit is cleared and

FrameSize = (144 * BitRate / SampleRate) + 1
when the padding bit is set.

The frameSize is of course an integer. If for an example BitRate=128000, SampleRate=44100 and the padding bit is cleared, then the FrameSize = 144 * 128000 / 44100 = 417

The mode field is used to tell which sort of stereo/mono encoding that has been used. The purpose of the mode extension field is different for different layers, but I really don't know exactly what it's for.

Mode valuemode
0 0Stereo
0 1Joint stereo
1 0Dual channel
1 1Mono

The last field is the emphasis field. It is used to sort of 're-equalize' the sound after a Dolby-like noise supression. This is not very used and will probably never be. The following noise supression model is used

Emphasis valueEmphasis method
0 0none
0 150/15ms
1 0
1 1CCITT j.17
Frame header.
Frame header.