Error in time calculation
Jahshan Bhatti
jabhatti91 at gmail.com
Fri Mar 16 21:15:52 CET 2007
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). Actually, mplayer doesn't calculate the
time correctly either which changes with different MP3 audio codecs. Only
xine and realplayer give the right time. I don't know if there is something
wrong with my MP3 files or LAME or taglib or my system setup, but I invite
you to try it yourself (the resampling) and see what you get for the time.
And if this has been reported already, sorry for the repetition.
Sincerely,
Jahshan
More information about the taglib-devel
mailing list