From: Tsuda Kageyu Date: Tue, 26 May 2015 04:35:44 +0000 (+0900) Subject: TrueAudio: A bit more accurate calculation of the stream length. X-Git-Tag: v1.10beta~37^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2155b4fd50f035269733555951eb7a0cbe1b5a54;p=taglib TrueAudio: A bit more accurate calculation of the stream length. --- diff --git a/taglib/trueaudio/trueaudiofile.cpp b/taglib/trueaudio/trueaudiofile.cpp index f98d6add..ec48aafe 100644 --- a/taglib/trueaudio/trueaudiofile.cpp +++ b/taglib/trueaudio/trueaudiofile.cpp @@ -246,7 +246,6 @@ bool TrueAudio::File::hasID3v2Tag() const return d->hasID3v2; } - //////////////////////////////////////////////////////////////////////////////// // private members //////////////////////////////////////////////////////////////////////////////// @@ -284,16 +283,23 @@ void TrueAudio::File::read(bool readProperties, Properties::ReadStyle /* propert // Look for TrueAudio metadata if(readProperties) { - if(d->ID3v2Location >= 0) { + + long streamLength; + + if(d->hasID3v1) + streamLength = d->ID3v1Location; + else + streamLength = length(); + + if(d->hasID3v2) { seek(d->ID3v2Location + d->ID3v2OriginalSize); - d->properties = new Properties(readBlock(TrueAudio::HeaderSize), - length() - d->ID3v2OriginalSize); + streamLength -= (d->ID3v2Location + d->ID3v2OriginalSize); } else { seek(0); - d->properties = new Properties(readBlock(TrueAudio::HeaderSize), - length()); } + + d->properties = new Properties(readBlock(TrueAudio::HeaderSize), streamLength); } } diff --git a/tests/data/tagged.tta b/tests/data/tagged.tta new file mode 100644 index 00000000..1677a7ed Binary files /dev/null and b/tests/data/tagged.tta differ diff --git a/tests/test_trueaudio.cpp b/tests/test_trueaudio.cpp index 49a28af7..33cb1904 100644 --- a/tests/test_trueaudio.cpp +++ b/tests/test_trueaudio.cpp @@ -11,6 +11,7 @@ class TestTrueAudio : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(TestTrueAudio); CPPUNIT_TEST(testReadPropertiesWithoutID3v2); + CPPUNIT_TEST(testReadPropertiesWithTags); CPPUNIT_TEST_SUITE_END(); public: @@ -30,6 +31,21 @@ public: CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->ttaVersion()); } + void testReadPropertiesWithTags() + { + TrueAudio::File f(TEST_FILE_PATH_C("tagged.tta")); + CPPUNIT_ASSERT(f.audioProperties()); + CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length()); + CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds()); + CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds()); + CPPUNIT_ASSERT_EQUAL(173, 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(162496U, f.audioProperties()->sampleFrames()); + CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->ttaVersion()); + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestTrueAudio);