]> granicus.if.org Git - taglib/commitdiff
APE: Use the audio stream length in calculating the bit rate.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Tue, 26 May 2015 01:12:29 +0000 (10:12 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Thu, 18 Jun 2015 05:41:37 +0000 (14:41 +0900)
taglib/ape/apeproperties.cpp
tests/data/mac-399-tagged.ape [new file with mode: 0644]
tests/test_ape.cpp

index 89a11be392c928baa52a9f4432e7536c267e9a9a..233399ef1aa711dfb5ba53b629d880441fb8c5c5 100644 (file)
@@ -33,6 +33,8 @@
 #include "id3v2tag.h"
 #include "apeproperties.h"
 #include "apefile.h"
+#include "apetag.h"
+#include "apefooter.h"
 
 using namespace TagLib;
 
@@ -149,10 +151,18 @@ void APE::Properties::read(File *file)
   else
     analyzeOld(file);
 
+  long streamLength = file->length() - offset;
+
+  if(file->hasID3v1Tag())
+    streamLength -= 128;
+
+  if(file->hasAPETag())
+    streamLength -= file->APETag()->footer()->completeTagSize();
+
   if(d->sampleFrames > 0 && d->sampleRate > 0) {
     const double length = d->sampleFrames * 1000.0 / d->sampleRate;
     d->length  = static_cast<int>(length + 0.5);
-    d->bitrate = static_cast<int>(file->length() * 8.0 / length + 0.5);
+    d->bitrate = static_cast<int>(streamLength * 8.0 / length + 0.5);
   }
 }
 
diff --git a/tests/data/mac-399-tagged.ape b/tests/data/mac-399-tagged.ape
new file mode 100644 (file)
index 0000000..3f5a656
Binary files /dev/null and b/tests/data/mac-399-tagged.ape differ
index c2b0d3dc93063f99ebdc6d9967d15d21495498cd..1ac732555a2125a1c30abb70c60d7c3bdf9e3864 100644 (file)
@@ -14,6 +14,7 @@ class TestAPE : public CppUnit::TestFixture
 {
   CPPUNIT_TEST_SUITE(TestAPE);
   CPPUNIT_TEST(testProperties399);
+  CPPUNIT_TEST(testProperties399Tagged);
   CPPUNIT_TEST(testProperties396);
   CPPUNIT_TEST(testProperties390);
   CPPUNIT_TEST(testFuzzedFile1);
@@ -37,6 +38,21 @@ public:
     CPPUNIT_ASSERT_EQUAL(3990, f.audioProperties()->version());
   }
 
+  void testProperties399Tagged()
+  {
+    APE::File f(TEST_FILE_PATH_C("mac-399-tagged.ape"));
+    CPPUNIT_ASSERT(f.audioProperties());
+    CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
+    CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
+    CPPUNIT_ASSERT_EQUAL(3550, f.audioProperties()->lengthInMilliseconds());
+    CPPUNIT_ASSERT_EQUAL(192, f.audioProperties()->bitrate());
+    CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
+    CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
+    CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
+    CPPUNIT_ASSERT_EQUAL(156556U, f.audioProperties()->sampleFrames());
+    CPPUNIT_ASSERT_EQUAL(3990, f.audioProperties()->version());
+  }
+
   void testProperties396()
   {
     APE::File f(TEST_FILE_PATH_C("mac-396.ape"));