From 9976155aa94be08eb0136399f17bf48108929bd5 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sat, 30 Jan 2016 00:51:28 +0900 Subject: [PATCH] Ignore 'fact' chunk of WAV files if their format is PCM. TagLib reports wrong length of some PCM files with a 'fact' chunk. --- taglib/riff/wav/wavproperties.cpp | 2 +- tests/data/pcm_with_fact_chunk.wav | Bin 0 -> 14756 bytes tests/test_wav.cpp | 17 +++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/data/pcm_with_fact_chunk.wav diff --git a/taglib/riff/wav/wavproperties.cpp b/taglib/riff/wav/wavproperties.cpp index df7cdbae..181e3a6c 100644 --- a/taglib/riff/wav/wavproperties.cpp +++ b/taglib/riff/wav/wavproperties.cpp @@ -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 index 0000000000000000000000000000000000000000..a6dc1d6c58bdbd08730cc16c71a940d581910765 GIT binary patch literal 14756 zcmeIup$)=N07cOUt*0ZfMr8#*X@VjI^be$}xIYep@fd^d!MXaXbD2wdkI8+yot9TS z4oP;|=i4QpL(*r+v$nc!j|dPTK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk q1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009F3EU?r^>olength()); + 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);