The audio header consists of a number of audio frames. Because we are not trying to play the audio but only extract some information regarding the audio we only need to read the first audio frames to ensure that we have correctly identified them as audio frames and extracted the metadata we reuire.
Start of Audio id 0xFF (11111111) and then second byte anded with 0xE0(11100000). For example 2nd byte doesnt have to be 0xE0 is just has to have the top 3 signicant bits set. For example 0xFB (11111011) is a common occurence of the second match. The 2nd byte defines flags to indicate various mp3 values.
Having found these two values we then read the header which comprises these two bytes plus a further two to ensure this really is a MP3Header, sometimes the first frame is actually a dummy frame with summary information held within about the whole file, typically using a Xing Header or LAme Header. This is most useful when the file is variable bit rate, if the file is variable bit rate but does not use a summary header it will not be correctly identified as a VBR frame and the track length will be incorrectly calculated. Strictly speaking MP3 means Layer III file but MP2 Layer II), MP1 Layer I) and MPEG-2 files are sometimes used and named with the .mp3 suffix so this library attempts to supports all these formats.
|
|