mirror of
https://github.com/taglib/taglib.git
synced 2025-07-18 21:14:23 -04:00
Merge pull request #560 from TsudaKageyu/audioprop-mpeg
(wishlist) MPEG: AudioProperties improvements
This commit is contained in:
BIN
tests/data/bladeenc.mp3
Normal file
BIN
tests/data/bladeenc.mp3
Normal file
Binary file not shown.
BIN
tests/data/lame_cbr.mp3
Normal file
BIN
tests/data/lame_cbr.mp3
Normal file
Binary file not shown.
BIN
tests/data/lame_vbr.mp3
Normal file
BIN
tests/data/lame_vbr.mp3
Normal file
Binary file not shown.
BIN
tests/data/vbri.mp3
Normal file
BIN
tests/data/vbri.mp3
Normal file
Binary file not shown.
@ -3,6 +3,9 @@
|
||||
#include <tstring.h>
|
||||
#include <mpegfile.h>
|
||||
#include <id3v2tag.h>
|
||||
#include <mpegproperties.h>
|
||||
#include <xingheader.h>
|
||||
#include <mpegheader.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include "utils.h"
|
||||
|
||||
@ -12,6 +15,10 @@ using namespace TagLib;
|
||||
class TestMPEG : public CppUnit::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(TestMPEG);
|
||||
CPPUNIT_TEST(testAudioPropertiesXingHeaderCBR);
|
||||
CPPUNIT_TEST(testAudioPropertiesXingHeaderVBR);
|
||||
CPPUNIT_TEST(testAudioPropertiesVBRIHeader);
|
||||
CPPUNIT_TEST(testAudioPropertiesNoVBRHeaders);
|
||||
CPPUNIT_TEST(testVersion2DurationWithXingHeader);
|
||||
CPPUNIT_TEST(testSaveID3v24);
|
||||
CPPUNIT_TEST(testSaveID3v24WrongParam);
|
||||
@ -23,10 +30,81 @@ class TestMPEG : public CppUnit::TestFixture
|
||||
|
||||
public:
|
||||
|
||||
void testAudioPropertiesXingHeaderCBR()
|
||||
{
|
||||
MPEG::File f(TEST_FILE_PATH_C("lame_cbr.mp3"));
|
||||
CPPUNIT_ASSERT(f.audioProperties());
|
||||
CPPUNIT_ASSERT_EQUAL(1887, f.audioProperties()->length());
|
||||
CPPUNIT_ASSERT_EQUAL(1887, f.audioProperties()->lengthInSeconds());
|
||||
CPPUNIT_ASSERT_EQUAL(1887164, f.audioProperties()->lengthInMilliseconds());
|
||||
CPPUNIT_ASSERT_EQUAL(64, f.audioProperties()->bitrate());
|
||||
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->channels());
|
||||
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
|
||||
CPPUNIT_ASSERT_EQUAL(MPEG::XingHeader::Xing, f.audioProperties()->xingHeader()->type());
|
||||
}
|
||||
|
||||
void testAudioPropertiesXingHeaderVBR()
|
||||
{
|
||||
MPEG::File f(TEST_FILE_PATH_C("lame_vbr.mp3"));
|
||||
CPPUNIT_ASSERT(f.audioProperties());
|
||||
CPPUNIT_ASSERT_EQUAL(1887, f.audioProperties()->length());
|
||||
CPPUNIT_ASSERT_EQUAL(1887, f.audioProperties()->lengthInSeconds());
|
||||
CPPUNIT_ASSERT_EQUAL(1887164, f.audioProperties()->lengthInMilliseconds());
|
||||
CPPUNIT_ASSERT_EQUAL(70, f.audioProperties()->bitrate());
|
||||
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->channels());
|
||||
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
|
||||
CPPUNIT_ASSERT_EQUAL(MPEG::XingHeader::Xing, f.audioProperties()->xingHeader()->type());
|
||||
}
|
||||
|
||||
void testAudioPropertiesVBRIHeader()
|
||||
{
|
||||
MPEG::File f(TEST_FILE_PATH_C("vbri.mp3"));
|
||||
CPPUNIT_ASSERT(f.audioProperties());
|
||||
CPPUNIT_ASSERT_EQUAL(222, f.audioProperties()->length());
|
||||
CPPUNIT_ASSERT_EQUAL(222, f.audioProperties()->lengthInSeconds());
|
||||
CPPUNIT_ASSERT_EQUAL(222198, f.audioProperties()->lengthInMilliseconds());
|
||||
CPPUNIT_ASSERT_EQUAL(233, f.audioProperties()->bitrate());
|
||||
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
|
||||
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
|
||||
CPPUNIT_ASSERT_EQUAL(MPEG::XingHeader::VBRI, f.audioProperties()->xingHeader()->type());
|
||||
}
|
||||
|
||||
void testAudioPropertiesNoVBRHeaders()
|
||||
{
|
||||
MPEG::File f(TEST_FILE_PATH_C("bladeenc.mp3"));
|
||||
CPPUNIT_ASSERT(f.audioProperties());
|
||||
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
|
||||
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
|
||||
CPPUNIT_ASSERT_EQUAL(3553, f.audioProperties()->lengthInMilliseconds());
|
||||
CPPUNIT_ASSERT_EQUAL(64, f.audioProperties()->bitrate());
|
||||
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->channels());
|
||||
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
|
||||
CPPUNIT_ASSERT(!f.audioProperties()->xingHeader());
|
||||
|
||||
long last = f.lastFrameOffset();
|
||||
|
||||
f.seek(last);
|
||||
MPEG::Header lastHeader(f.readBlock(4));
|
||||
|
||||
while (!lastHeader.isValid()) {
|
||||
|
||||
last = f.previousFrameOffset(last);
|
||||
|
||||
f.seek(last);
|
||||
lastHeader = MPEG::Header(f.readBlock(4));
|
||||
}
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(28213L, last);
|
||||
CPPUNIT_ASSERT_EQUAL(209, lastHeader.frameLength());
|
||||
}
|
||||
|
||||
void testVersion2DurationWithXingHeader()
|
||||
{
|
||||
MPEG::File f(TEST_FILE_PATH_C("mpeg2.mp3"));
|
||||
CPPUNIT_ASSERT(f.audioProperties());
|
||||
CPPUNIT_ASSERT_EQUAL(5387, f.audioProperties()->length());
|
||||
CPPUNIT_ASSERT_EQUAL(5387, f.audioProperties()->lengthInSeconds());
|
||||
CPPUNIT_ASSERT_EQUAL(5387285, f.audioProperties()->lengthInMilliseconds());
|
||||
}
|
||||
|
||||
void testSaveID3v24()
|
||||
|
Reference in New Issue
Block a user