MPEG Audio Layer I/II/III frame header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Within an MPEG audio file, there is no main header, as an MPEG audio file is just built up from a succession of smaller parts called frames. Each frame is a datablock with its own header and audio information. In the case of Layer I or Layer II, frames are totally independent from each other, so you can cut any part of an MPEG audio file and play it correctly. The player will then play the music starting from the first full valid frame it will find. However, in the case of Layer III, frames are not always independant. Due to the possible use of the "byte reservoir", wich is a kind of internal buffer, frames are often dependent of each other. In the worst case, 9 input frames may be needed before beeing able to decode one single frame.If you need to retrieve information about an MPEG audio file, you might simply locate the first frame, and retrieve information from its header. Information within other frames should be consistent with the first one, except for the bitrate, as you might be retrieving information from a variable bitrate (VBR) file. In a VBR file, the bitrate can be changed in each frame. It can be used, as an exemple, to keep a constant sound quality during the whole file, by using more bits when the music is more complex and thus requires more bits to be encoded with a similar quality. The frame header itself is 32 bits (4 bytes) length. The first twelve bits (or first eleven bits in the case of the MPEG 2.5 extension) of a frame header are always set to 1 and are called "frame sync". Frames may also feature an optional CRC checksum. It is 16 bits long and, if it exists, immediately follows the frame header. After the CRC comes the audio data. By re-calculating the CRC and comparing its value to the sored one, you can check if the frame has been altered during transmission of the bitstream. Here are the details of what is within a frame header: AAAAAAAA AAABBCCD EEEEFFGH IIJJKLMM
Note: MPEG Version 2.5 was added lately to the MPEG 2 standard.
It is an extension used for very low bitrate files, allowing
the use of lower sampling frequencies. If your decoder does
not support this extension, it is recommended for you to use
12 bits for synchronization instead of 11 bits.
NOTES: All values are in kbps MPEG files may feature variable bitrate (VBR). Each frame
may then be created with a different bitrate. It may be used
in all layers. Layer III decoders must support this method.
Layer I & II decoders may support it.
For Layer II there are some combinations of bitrate and mode
which are not allowed. Here is a list of allowed combinations.
Mode extension is used to join informations that are of no
use for stereo effect, thus reducing needed bits. These bits
are dynamically determined by an encoder in Joint stereo mode,
and Joint Stereo can be changed from one frame to another,
or even switched on or off.
Complete frequency range of MPEG file is divided in subbands
There are 32 subbands. For Layer I & II these two bits determine
frequency range (bands) where intensity stereo is applied.
For Layer III these two bits determine which type of joint
stereo is used (intensity stereo or m/s stereo). Frequency
range is determined within decompression algorithm.
Some material used within this page originally came from
http://www.datavoyage.com/mpgscript/mpeghdr.htm by Predrag Supurovic
|