]> granicus.if.org Git - taglib/commitdiff
TrueAudio: A bit more accurate calculation of the stream length.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Tue, 26 May 2015 04:35:44 +0000 (13:35 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Sat, 20 Jun 2015 08:36:00 +0000 (17:36 +0900)
taglib/trueaudio/trueaudiofile.cpp
tests/data/tagged.tta [new file with mode: 0644]
tests/test_trueaudio.cpp

index f98d6addcf62bc166b99ae6fb276b5c31c6e7236..ec48aafe471504e9f619d78f2faa20645c1e65a9 100644 (file)
@@ -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 (file)
index 0000000..1677a7e
Binary files /dev/null and b/tests/data/tagged.tta differ
index 49a28af7cb075f79781b9b375366b7275ec10b7f..33cb19041cb68bc96a17d91fed37e2a9897cce0b 100644 (file)
@@ -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);