MPEG AUDIO LAYER I / II / III Frame HEADER
An MPEG audio file is built up from smaller parts called frames. Generally, frames are independent items. Each frame has its own header and audio informations. As there is no file header, you can cut any part of MPEG file and play it correctly ( this should be done on frame boundaries but most applications will handle incorrect headers). However, for Layer III, this is not 100% correct. Due to internal data organization in MPEG Layer III files, frames are often dependent of each other and they can not BE CUT OFF JUST LIKE THAT.
???? When you want to read info about an MPEG file, it is usually enough to find the first frame, read its header and assume that the other frames are the same. But this may not be always the case. Variable bitrate MPEG files may use so called bitrate switching, which means that bitrate changes according to the content of each frame. This way lower bitrates may be used in frames where it will not reduce sound quality. This allows making better compression while keeping high quality of sound.
???? The frame header is constituted by the very first four bytes (32bits) in a frame. The first eleven bits (or first twelve bits, see below about frame sync) of a frame header are always set and they are called " frame sync ". Therefore, you can search through the file for the first occurence of frame sync (meaning that you have to find a byte with a value of 255, and followed by a byte its three (or four) most significant bits set with ). Then you read the whole header and check if the values are correct. you will see in the following table the exact meaning of each bit in the header. Each value that is specified as reserved, invalid, bad, or not allowed should indicate An Invalid Header.????frames May Have a CRC Check. The CRC IS 16 BITS Long and IT EXISTS, IT FOLLOWS The Frame HEADER. AFTER THE CRC Comes The Audio Data. You Calculate The CRC of The Frame, And Compare It with the one you read from the file. This is actially a very good method to check the mpeg frame value.
???? here is a presentation of the header content. CHARACTERS from a to m all used to indeicate difflow, you can see details about the content of each field.
Aaaaaaa Aaabbccd eeeeffgh iijjklmm
SignLength (BITS) POSITION (BITS) DescriptionA11 (31-21) Frame Sync (All Bits Set) B2 (20,19) MPEG Audio Version ID00 - MPEG VERSION 2.5 (Unofficial) 01 - Reserved10 - MPEG Version 2 (ISO / IEC 13818 -3) 11 - MPEG VERSION 1 (ISO / IEC 11172-3) NOTE: MPEG VERSION 2.5 IS Not Official Standard. It is an extension of the standard buy for very low bitrate files. If you decoder does not support this extension, IT is recommended for you to use 12 bits for synchronization instead of 11 bits.C2 (18,17) Layer description00 - reserved01 - Layer III10 - Layer II11 - Layer ID1 (16) Protection bit0 - Protected by CRC (16bit crc follows header) 1 - Not protectede4 (15,12) Bitrate Index
bitsV1, L1V1, L2V1, L3V2, L1V2, L2 & L30000freefreefreefreefree000132323232800106448404816001196564856240100128645664320101160806480400110192968096480111224112961125610002561281121286410012881601281448010103201921601609610113522241921761121100384256224192128110141632025622414411104483843202561601111badbadbadbadbad NOTES: All values are in kbpsV1 - MPEG Version 1V2 - MPEG Version 2 and Version 2.5L1 - Layer IL2 - Layer IIL3 - Layer III "free" means free format If the. correct fixed bitrate (such files can not use variable bitrate) is different than those presented in upper table it must be determined by the application. This may be implemented only for internal purposes since third party applications have no means to findout correct bitrate. Howewer, this is not impossible to do but demands lots of efforts. "bad" means that this is not an allowed value MPEG files may have variable bitrate (VBR). Each frame may be created with 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 is some of the book {baseowed. here is a list of allowed combinations.bitrate
Single Channel
Stereo
INTENSITY STEREO
Dual Channel
Free
YES
YES
YES
YES
32
YES
NO
NO
NO
48
YES
NO
NO
NO
56
YES
NO
NO
NO
64
YES
YES
YES
YES
80
YES
NO
NO
NO
96
YES
YES
YES
YES
112
YES
YES
YES
YES
128
YES
YES
YES
YES
160
YES
YES
YES
YES
192
YES
YES
YES
YES
224
NO
YES
YES
YES
256
NO
YES
YES
YES
320
NO
YES
YES
YES
384
NO
YES
YES
YES
F2 (11,10) Sampling Rate Frequency Index (Values Are IN Hz)