HydrogenAudio

Lossy Audio Compression => MP3 => MP3 - Tech => Topic started by: klabautermack on 2007-01-26 16:16:26

Title: Frame Size
Post by: klabautermack on 2007-01-26 16:16:26
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!
Title: Frame Size
Post by: pdq on 2007-01-26 17:03:46
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.
Title: Frame Size
Post by: smack on 2007-01-26 17:11:04
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.

Quote
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.

Quote
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/)
Title: Frame Size
Post by: DualIP on 2007-01-26 19:28:08
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
Title: Frame Size
Post by: Firon on 2007-01-26 19:36:01
Sometimes they might have a VBRI header, but I'm not sure what encoders produce that.
Title: Frame Size
Post by: Mangix on 2007-01-26 21:56:13
there's also ABR...
Title: Frame Size
Post by: Firon on 2007-01-26 23:56:01
ABR is merely restricted VBR, and is treated as VBR. There is no difference to the player.
Title: Frame Size
Post by: klabautermack on 2007-01-28 09:40:08
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)
Title: Frame Size
Post by: robert on 2007-01-28 17:26:04
is framesize +2bytes if bit is 0 ?

No.