<html><head><meta name="qrichtext" content="1" /></head><body style="font-size:10pt;font-family:Bitstream Vera Sans">
<p>On Friday 16 March 2007, Jahshan Bhatti wrote:</p>
<p><span style="color:#008000">> Hi all,</span></p>
<p><span style="color:#008000">> I had downloaded some MP3s (MPEG 2.5 Layer III 11025 kHz VBR) and when I</span></p>
<p><span style="color:#008000">> played it with Amarok, the total time listed in the playlist was double the</span></p>
<p><span style="color:#008000">> actual time which led to all sorts of problems. I finally traced the source</span></p>
<p><span style="color:#008000">> of the problem to taglib. I looked at the source (mpeg/mpegproperties.cpp)</span></p>
<p><span style="color:#008000">> and calculated using its method and got the same doubled result:</span></p>
<p><span style="color:#008000">></span></p>
<p><span style="color:#008000">>         static const int blockSize[] = { 0, 384, 1152, 1152 };</span></p>
<p><span style="color:#008000">></span></p>
<p><span style="color:#008000">>         double timePerFrame = blockSize[firstHeader.layer()];</span></p>
<p><span style="color:#008000">>         timePerFrame = firstHeader.sampleRate() > 0 ? timePerFrame /</span></p>
<p><span style="color:#008000">> firstHeader.sampleRate() : 0;</span></p>
<p><span style="color:#008000">>         d->length = int(timePerFrame * xingHeader.totalFrames());</span></p>
<p><span style="color:#008000">></span></p>
<p><span style="color:#008000">> After lots of experimenting, I've come to the conclusion that the</span></p>
<p><span style="color:#008000">> calculations don't work for resampled music (try using LAME and a 44100 kHz</span></p>
<p><span style="color:#008000">> wav file and resampling to 11025 or 22050 kHz).</span></p>
<p></p>
<p>I did a bit more research and came up with this page: http://www.codeproject.com/audio/MPEGAudioInfo.asp</p>
<p></p>
<p>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:</p>
<p></p>
<p>        static const int blockSize[3][4] = {</p>
<p> { 0, 384, 1152, 1152 }, // Version 1</p>
<p> { 0, 384, 1152, 576, // Version 2</p>
<p> { 0, 384, 1152, 576 } // Version 2.5</p>
<p> };</p>
<p>        double timePerFrame = blockSize[firstHeader.version()][firstHeader.layer()];</p>
<p></p>
<p>or:</p>
<p></p>
<p>        double timePerFrame = blockSize[firstHeader.layer()];</p>
<p>        timePerFrame = firstHeader.version()>1&&firstHeader.layer()==3 ? 576 : timePerFrame;</p>
<p></p>
<p>or whatever... I don't really know what is more efficient... I'm just a first year CS student ;)</p>
<p></p>
<p>I hope this helps,</p>
<p>Jahshan Bhatti</p>
</body></html>