]> granicus.if.org Git - taglib/commitdiff
Ignore 'fact' chunk of WAV files if their format is PCM.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Fri, 29 Jan 2016 15:51:28 +0000 (00:51 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Fri, 29 Jan 2016 15:51:28 +0000 (00:51 +0900)
TagLib reports wrong length of some PCM files with a 'fact' chunk.

taglib/riff/wav/wavproperties.cpp
tests/data/pcm_with_fact_chunk.wav [new file with mode: 0644]
tests/test_wav.cpp

index df7cdbae467e6b8260bbef7ecbdc74147dcb0656..181e3a6caddce7764a81eb8df3273fa1eac88775 100644 (file)
@@ -192,7 +192,7 @@ void RIFF::WAV::Properties::read(File *file)
   d->sampleRate    = data.toUInt(4, false);
   d->bitsPerSample = data.toShort(14, false);
 
-  if(totalSamples > 0)
+  if(d->format != FORMAT_PCM)
     d->sampleFrames = totalSamples;
   else if(d->channels > 0 && d->bitsPerSample > 0)
     d->sampleFrames = streamLength / (d->channels * ((d->bitsPerSample + 7) / 8));
diff --git a/tests/data/pcm_with_fact_chunk.wav b/tests/data/pcm_with_fact_chunk.wav
new file mode 100644 (file)
index 0000000..a6dc1d6
Binary files /dev/null and b/tests/data/pcm_with_fact_chunk.wav differ
index cdb0ca5826902919e1835d4539ad318a72d0ac20..f3bca4797c4cc1891daf1d4c548ead133919f56d 100644 (file)
@@ -25,6 +25,7 @@ class TestWAV : public CppUnit::TestFixture
   CPPUNIT_TEST(testFuzzedFile1);
   CPPUNIT_TEST(testFuzzedFile2);
   CPPUNIT_TEST(testStripAndProperties);
+  CPPUNIT_TEST(testPCMWithFactChunk);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -247,6 +248,22 @@ public:
     }
   }
 
+  void testPCMWithFactChunk()
+  {
+    RIFF::WAV::File f(TEST_FILE_PATH_C("pcm_with_fact_chunk.wav"));
+    CPPUNIT_ASSERT(f.audioProperties());
+    CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
+    CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
+    CPPUNIT_ASSERT_EQUAL(3675, f.audioProperties()->lengthInMilliseconds());
+    CPPUNIT_ASSERT_EQUAL(32, f.audioProperties()->bitrate());
+    CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
+    CPPUNIT_ASSERT_EQUAL(1000, f.audioProperties()->sampleRate());
+    CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
+    CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->sampleWidth());
+    CPPUNIT_ASSERT_EQUAL(3675U, f.audioProperties()->sampleFrames());
+    CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->format());
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestWAV);