From da14f67e2c88f55d076274547c327b9e7ef9e953 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Tue, 26 May 2015 10:50:43 +0900 Subject: [PATCH] MP4: Do rounding when calculating the bit rate. --- taglib/mp4/mp4properties.cpp | 6 +++--- tests/test_mp4.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/taglib/mp4/mp4properties.cpp b/taglib/mp4/mp4properties.cpp index e712f5d4..4485dd0e 100644 --- a/taglib/mp4/mp4properties.cpp +++ b/taglib/mp4/mp4properties.cpp @@ -213,16 +213,16 @@ MP4::Properties::read(File *file, Atoms *atoms) pos += 3; } pos += 10; - d->bitrate = (data.toUInt(pos) + 500) / 1000; + d->bitrate = static_cast((data.toUInt(pos) + 500) / 1000.0 + 0.5); } } } else if(data.mid(20, 4) == "alac") { - if (atom->length == 88 && data.mid(56, 4) == "alac") { + if(atom->length == 88 && data.mid(56, 4) == "alac") { d->codec = ALAC; d->bitsPerSample = data.at(69); d->channels = data.at(73); - d->bitrate = data.toUInt(80U) / 1000; + d->bitrate = static_cast(data.toUInt(80U) / 1000.0 + 0.5); d->sampleRate = data.toUInt(84U); } } diff --git a/tests/test_mp4.cpp b/tests/test_mp4.cpp index 77ba6aaa..78e1badf 100644 --- a/tests/test_mp4.cpp +++ b/tests/test_mp4.cpp @@ -55,7 +55,7 @@ public: CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length()); CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds()); CPPUNIT_ASSERT_EQUAL(3705, f.audioProperties()->lengthInMilliseconds()); - CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->bitrate()); + CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->bitrate()); CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels()); CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate()); CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample()); -- 2.40.0