Error in time calculation

Jahshan Bhatti jabhatti91 at gmail.com
Fri Mar 16 22:44:19 CET 2007


On Friday 16 March 2007, Jahshan Bhatti wrote:
> Hi all,
> I had downloaded some MP3s (MPEG 2.5 Layer III 11025 kHz VBR) and when I
> played it with Amarok, the total time listed in the playlist was double the
> actual time which led to all sorts of problems. I finally traced the source
> of the problem to taglib. I looked at the source (mpeg/mpegproperties.cpp)
> and calculated using its method and got the same doubled result:
>
> 	static const int blockSize[] = { 0, 384, 1152, 1152 };
>
> 	double timePerFrame = blockSize[firstHeader.layer()];
> 	timePerFrame = firstHeader.sampleRate() > 0 ? timePerFrame /
> firstHeader.sampleRate() : 0;
> 	d->length = int(timePerFrame * xingHeader.totalFrames());
>
> After lots of experimenting, I've come to the conclusion that the
> calculations don't work for resampled music (try using LAME and a 44100 kHz
> wav file and resampling to 11025 or 22050 kHz).

I did a bit more research and came up with this page: http://www.codeproject.com/audio/MPEGAudioInfo.asp

Under section 2.1.4, it has a table with blockSizes and it changes for Layer III MPEG 2/2.5 to 576 instead of 1152. So I guess you can either recreate the blockSize array into table like in the webpage:

	static const int blockSize[3][4] = {
    { 0, 384, 1152, 1152 }, // Version 1
    { 0, 384, 1152, 576, // Version 2
    { 0, 384, 1152, 576 }  // Version 2.5
  };
	double timePerFrame = blockSize[firstHeader.version()][firstHeader.layer()];

or:

	double timePerFrame = blockSize[firstHeader.layer()];
	timePerFrame = firstHeader.version()>1&&firstHeader.layer()==3 ? 576 : timePerFrame;

or whatever... I don't really know what is more efficient... I'm just a first year CS student ;)

I hope this helps,
Jahshan Bhatti
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.kde.org/pipermail/taglib-devel/attachments/20070316/670da909/attachment.html 


More information about the taglib-devel mailing list