aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTsuda Kageyu <tsuda.kageyu@gmail.com>2015-05-26 13:35:44 +0900
committerTsuda Kageyu <tsuda.kageyu@gmail.com>2015-06-20 17:36:00 +0900
commit2155b4fd50f035269733555951eb7a0cbe1b5a54 (patch)
tree298c1d95adfa289d9d4a947208a205219b089af5
parenteb73612a2b7ae8a9ce32bf42f3fbe55060d7b3de (diff)
TrueAudio: A bit more accurate calculation of the stream length.
-rw-r--r--taglib/trueaudio/trueaudiofile.cpp18
-rw-r--r--tests/data/tagged.ttabin0 -> 81819 bytes
-rw-r--r--tests/test_trueaudio.cpp16
3 files changed, 28 insertions, 6 deletions
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
--- /dev/null
+++ b/tests/data/tagged.tta
Binary files 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);