| Summary: | timePerFrame incorrectly calculated in mpegproperties.cpp | ||
|---|---|---|---|
| Product: | [Unmaintained] taglib | Reporter: | Stephen F. Booth <me> |
| Component: | general | Assignee: | Scott Wheeler <wheeler> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | ||
| Priority: | NOR | ||
| Version First Reported In: | unspecified | ||
| Target Milestone: | --- | ||
| Platform: | Compiled Sources | ||
| OS: | Other | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
SVN commit 689510 by wheeler:
Promote the int to a float so that the calcualtion works properly. Patch from Stephen Booth.
BUG:143938
M +1 -1 mpegproperties.cpp
--- trunk/kdesupport/taglib/taglib/mpeg/mpegproperties.cpp #689509:689510
@@ -213,7 +213,7 @@
{
static const int blockSize[] = { 0, 384, 1152, 1152 };
- double timePerFrame = blockSize[firstHeader.layer()] / firstHeader.sampleRate();
+ double timePerFrame = double(blockSize[firstHeader.layer()]) / firstHeader.sampleRate();
d->length = int(timePerFrame * d->xingHeader->totalFrames());
d->bitrate = d->length > 0 ? d->xingHeader->totalSize() * 8 / d->length / 1000 : 0;
}
|
Version: svn (using KDE Devel) Installed from: Compiled sources Compiler: gcc version 4.0.1 (Apple Computer, Inc. build 5367) OS: OS X The calculation of timePerFrame in mepegproperties.cpp almost always results in zero because the result of integer division is being cast to a double. This leads to the length() method of MPEGFile return 0. It is necessary to promote one of the ints before dividing to get an accurate result. Here is a patch with one way to fix the problem: svn diff mpegproperties.cpp Index: mpegproperties.cpp =================================================================== --- mpegproperties.cpp (revision 651409) +++ mpegproperties.cpp (working copy) @@ -213,7 +213,7 @@ { static const int blockSize[] = { 0, 384, 1152, 1152 }; - double timePerFrame = blockSize[firstHeader.layer()] / firstHeader.sampleRate(); + double timePerFrame = (double)blockSize[firstHeader.layer()] / firstHeader.sampleRate(); d->length = int(timePerFrame * d->xingHeader->totalFrames()); d->bitrate = d->length > 0 ? d->xingHeader->totalSize() * 8 / d->length / 1000 : 0; }