FLAC: AudioProperties improvements

Add lengthInSeconds(), lengthInMilliseconds() properties. (#503)
Add bitsPerSample() property besides sampleWidth(). (#360)
Remove some data members which are not needed to carry.
Add some tests for audio properties.
Add some supplementary comments.
This commit is contained in:
Tsuda Kageyu
2015-05-21 12:15:11 +09:00
parent 88947e7a48
commit 21412e2ba2
4 changed files with 109 additions and 38 deletions

BIN
tests/data/sinewave.flac Normal file

Binary file not shown.

View File

@ -25,6 +25,7 @@ class TestFLAC : public CppUnit::TestFixture
CPPUNIT_TEST(testSaveMultipleValues);
CPPUNIT_TEST(testDict);
CPPUNIT_TEST(testInvalid);
CPPUNIT_TEST(testAudioProperties);
CPPUNIT_TEST(testZeroSizedPadding);
CPPUNIT_TEST_SUITE_END();
@ -256,6 +257,24 @@ public:
CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f.properties().size());
}
void testAudioProperties()
{
FLAC::File f(TEST_FILE_PATH_C("sinewave.flac"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(3550, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(145, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->sampleWidth());
CPPUNIT_ASSERT_EQUAL(156556ULL, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(
ByteVector("\xcf\xe3\xd9\xda\xba\xde\xab\x2c\xbf\x2c\xa2\x35\x27\x4b\x7f\x76"),
f.audioProperties()->signature());
}
void testZeroSizedPadding()
{
ScopedFileCopy copy("zero-sized-padding", ".flac");