[PATCH] Fix calculation of number of samples per frame
Xavier Duret
xaviour.maillists at gmail.com
Wed Jan 24 13:57:54 CET 2007
This fixes KDE Bug 130185 as reported by the user that is to say for
episode 18 of season 3 of LUG radio. Contrarily to what some people
have been writing before even looking at the file itself, there is a
Xing header in this file. Robert Hegemann of the LAME project actually
found what the problem in taglib is (comment 20 of the bug report). As
always this patches has been tested against my test database and did
not introduce any regression. Also as always, the patch has to be
applied after my other patches.
diff -ruN taglib.old/taglib/mpeg/mpegheader.h taglib/taglib/mpeg/mpegheader.h
--- taglib.old/taglib/mpeg/mpegheader.h 2007-01-24 12:09:15.000000000 +0100
+++ taglib/taglib/mpeg/mpegheader.h 2007-01-24 12:09:31.000000000 +0100
@@ -139,6 +139,11 @@
int frameLength() const;
/*!
+ * Returns the number of samples per frame.
+ */
+ int samplesPerFrame() const;
+
+ /*!
* Makes a shallow copy of the header.
*/
Header &operator=(const Header &h);
diff -ruN taglib.old/taglib/mpeg/mpegheader.cpp
taglib/taglib/mpeg/mpegheader.cpp
--- taglib.old/taglib/mpeg/mpegheader.cpp 2007-01-24
12:09:12.000000000 +0100
+++ taglib/taglib/mpeg/mpegheader.cpp 2007-01-24
12:09:32.000000000 +0100
@@ -38,6 +38,7 @@
layer(0),
protectionEnabled(false),
sampleRate(0),
+ samplesPerFrame(0),
isPadded(false),
channelMode(Stereo),
isCopyrighted(false),
@@ -50,6 +51,7 @@
bool protectionEnabled;
int bitrate;
int sampleRate;
+ int samplesPerFrame;
bool isPadded;
ChannelMode channelMode;
bool isCopyrighted;
@@ -133,6 +135,11 @@
return d->frameLength;
}
+int MPEG::Header::samplesPerFrame() const
+{
+ return d->samplesPerFrame;
+}
+
MPEG::Header &MPEG::Header::operator=(const Header &h)
{
if(&h == this)
@@ -235,6 +242,15 @@
d->channelMode = ChannelMode((uchar(data[3]) & 0xC0) >> 6);
+ // Calculate the number of samples per frame
+
+ static const int samplesPerFrames[2][3] = {
+ { 384, 1152, 1152 }, // Version 1
+ { 384, 1152, 576 } // Version 2 and 2.5
+ };
+
+ d->samplesPerFrame = samplesPerFrames[versionIndex][layerIndex];
+
// TODO: Add mode extension for completeness
d->isOriginal = flags[2];
diff -ruN taglib.old/taglib/mpeg/mpegproperties.cpp
taglib/taglib/mpeg/mpegproperties.cpp
--- taglib.old/taglib/mpeg/mpegproperties.cpp 2007-01-24
12:24:44.000000000 +0100
+++ taglib/taglib/mpeg/mpegproperties.cpp 2007-01-24
12:25:08.000000000 +0100
@@ -211,9 +211,7 @@
firstHeader.sampleRate() > 0 &&
d->xingHeader->totalFrames() > 0)
{
- static const int blockSize[] = { 0, 384, 1152, 1152 };
-
- d->length = (blockSize[firstHeader.layer()] *
d->xingHeader->totalFrames()) / firstHeader.sampleRate();
+ d->length = (firstHeader.samplesPerFrame() *
d->xingHeader->totalFrames()) / firstHeader.sampleRate();
d->bitrate = d->length > 0 ? d->xingHeader->totalSize() * 8 /
d->length / 1000 : 0;
}
else {
More information about the taglib-devel
mailing list