]> granicus.if.org Git - taglib/commitdiff
MP4: Do rounding when calculating the bit rate.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Tue, 26 May 2015 01:50:43 +0000 (10:50 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Thu, 18 Jun 2015 08:00:10 +0000 (17:00 +0900)
taglib/mp4/mp4properties.cpp
tests/test_mp4.cpp

index e712f5d48d4e0e1d7fbce0e8bb209b5ce416074f..4485dd0e4f0b00b5bf1e3e3ad31e69ef4d414fd6 100644 (file)
@@ -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<int>((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<int>(data.toUInt(80U) / 1000.0 + 0.5);
       d->sampleRate    = data.toUInt(84U);
     }
   }
index 77ba6aaaf79be4d47146ef1078bac13f7a626701..78e1badf35e62d76b5cb32d1ea510299919d8baa 100644 (file)
@@ -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());