]> granicus.if.org Git - taglib/commitdiff
WavPack: A bit more accurate calculation of the stream length.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Tue, 26 May 2015 05:54:20 +0000 (14:54 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Thu, 18 Jun 2015 09:00:03 +0000 (18:00 +0900)
taglib/wavpack/wavpackfile.cpp
tests/data/tagged.wv [new file with mode: 0644]
tests/test_wavpack.cpp

index 8d7463d363814d20087ee30151e166ce494060f7..1a5b417dcdc2714ab7cc49044d20dfb1d5a85b0c 100644 (file)
@@ -272,8 +272,19 @@ void WavPack::File::read(bool readProperties, Properties::ReadStyle /* propertie
 
   // Look for WavPack audio properties
 
-  if(readProperties)
-    d->properties = new Properties(this, length() - d->APESize);
+  if(readProperties) {
+
+    long streamLength;
+
+    if(d->hasAPE)
+      streamLength = d->APELocation;
+    else if(d->hasID3v1)
+      streamLength = d->ID3v1Location;
+    else
+      streamLength = length();
+
+    d->properties = new Properties(this, streamLength);
+  }
 }
 
 long WavPack::File::findAPE()
diff --git a/tests/data/tagged.wv b/tests/data/tagged.wv
new file mode 100644 (file)
index 0000000..333f868
Binary files /dev/null and b/tests/data/tagged.wv differ
index 357d4aafef7167979b26ffe4f7fadd1d5d451f73..656d39a2ac2f816c32b0ccdf401b758276b9938c 100644 (file)
@@ -14,6 +14,7 @@ class TestWavPack : public CppUnit::TestFixture
   CPPUNIT_TEST_SUITE(TestWavPack);
   CPPUNIT_TEST(testNoLengthProperties);
   CPPUNIT_TEST(testMultiChannelProperties);
+  CPPUNIT_TEST(testTaggedProperties);
   CPPUNIT_TEST(testFuzzedFile);
   CPPUNIT_TEST_SUITE_END();
 
@@ -51,6 +52,22 @@ public:
     CPPUNIT_ASSERT_EQUAL(1031, f.audioProperties()->version());
   }
 
+  void testTaggedProperties()
+  {
+    WavPack::File f(TEST_FILE_PATH_C("tagged.wv"));
+    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(172, f.audioProperties()->bitrate());
+    CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
+    CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
+    CPPUNIT_ASSERT_EQUAL(false, f.audioProperties()->isLossless());
+    CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
+    CPPUNIT_ASSERT_EQUAL(156556U, f.audioProperties()->sampleFrames());
+    CPPUNIT_ASSERT_EQUAL(1031, f.audioProperties()->version());
+  }
+
   void testFuzzedFile()
   {
     WavPack::File f(TEST_FILE_PATH_C("infloop.wv"));