Hi all (1st post;) )
My application needs to calculate
song lenght
vbr or cbr?
bitrate
samplerate
what i do is:
open mp3 and jump to first frame header
read bitrate, sampelrate, padding
calc framesize
frameCount++
jump to next frameheader
1)
i found the following formula: FrameSize = 144 * BitRate / (SampleRate + Padding)
i dont really unterstand the /( ...+padding)
it means with padding flag, the frame size is lower. i think with padding flag set, there are 8bits more!?
isnt it like:
FrameSize = (int) ((144 * BitRate / SampleRate) + Padding)
so, for 128kb/s 44khz mp3 its 417byts without padding, and 418 with padding.
2)
what exactly means "VBR" or "CBR" ?how many frames have to differ from others bitrate, to be VBR? in my test mp3s never all the frames have the same bitrate.
3)
how can i calculate the framsize in case bitrate bits = 0%0000 (free?) ?
thx4help!
1) The padding byte is added occasionally so that the bit rate, which can result in a non-integer number of bytes per frame, can come out even.
2) The only way a file can be CBR is if ALL of the frames have exactly the same bit rate.
1)
isnt it like:
FrameSize = (int) ((144 * BitRate / SampleRate) + Padding)
so, for 128kb/s 44khz mp3 its 417byts without padding, and 418 with padding.
Yes, that's correct for MPEG-1, where each frame contains 1152 samples.
For MPEG-2 LSF (with 576 samples per frame) the factor is 72 instead of 144.
2)
what exactly means "VBR" or "CBR" ?how many frames have to differ from others bitrate, to be VBR? in my test mp3s never all the frames have the same bitrate.
The "V" is for "variable" and the "C" is for "constant". If it's not constant, then it's variable.
Therefore, an mp3 file is VBR if not all frames have the same bitrate. Or in other words, it is VBR if at least one frame has a bitrate that differs from the others.
3)
how can i calculate the framsize in case bitrate bits = 0%0000 (free?) ?
You can't.
When you have found the first frame header which indicates "free bitrate", you have to search the file for the second frame header and use the "distance" between these two frame headers (i.e. the framesize) to calculate the bitrate.
I'd suggest you also have a look at the source code of some existing decoders to learn more about such details, for example MAD MPEG Audio Decoder (http://www.underbit.com/products/mad/)
For VBR files, check if the first frame has a"xing" vbr header.
From the data it contains, you can get stuff like playtime without reading the entire file
Sometimes they might have a VBRI header, but I'm not sure what encoders produce that.
there's also ABR...
ABR is merely restricted VBR, and is treated as VBR. There is no difference to the player.
hey thx:)
1)
isnt it like:
FrameSize = (int) ((144 * BitRate / SampleRate) + Padding)
so, for 128kb/s 44khz mp3 its 417byts without padding, and 418 with padding.
Yes, that's correct for MPEG-1, where each frame contains 1152 samples.
For MPEG-2 LSF (with 576 samples per frame) the factor is 72 instead of 144.
ok, i think i keep the formula, and only change the bitrate. i can use 144, if i take the same sample rate values.
what about the protection bit?
Protection bit
0 - Protected by CRC (16bit CRC follows header)
1 - Not protected
is framesize +2bytes if bit is 0 ?
whats that:??
(http://img201.imageshack.us/img201/6666/clipboard01ln0.jpg)
ipod converter (http://www.poddox.com)
is framesize +2bytes if bit is 0 ?
No.