Merge pull request #986 from ufleisch/ufleisch/wav-extensible-subformat

WAV: Support subformat in WAVE_FORMAT_EXTENSIBLE (#850)
This commit is contained in:
Urs Fleisch 2021-01-01 11:48:06 +01:00
commit 1a2e1d08ac
3 changed files with 23 additions and 0 deletions

View File

@ -184,6 +184,14 @@ void RIFF::WAV::Properties::read(File *file)
}
d->format = data.toShort(0, false);
if((d->format & 0xffff) == 0xfffe) {
// if extensible then read the format from the subformat
if(data.size() != 40) {
debug("RIFF::WAV::Properties::read() - extensible size incorrect");
return;
}
d->format = data.toShort(24, false);
}
if(d->format != FORMAT_PCM && d->format != FORMAT_IEEE_FLOAT && totalSamples == 0) {
debug("RIFF::WAV::Properties::read() - Non-PCM format, but 'fact' chunk not found.");
return;

BIN
tests/data/uint8we.wav Normal file

Binary file not shown.

View File

@ -57,6 +57,7 @@ class TestWAV : public CppUnit::TestFixture
CPPUNIT_TEST(testFileWithGarbageAppended);
CPPUNIT_TEST(testStripAndProperties);
CPPUNIT_TEST(testPCMWithFactChunk);
CPPUNIT_TEST(testWaveFormatExtensible);
CPPUNIT_TEST_SUITE_END();
public:
@ -369,6 +370,20 @@ public:
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->format());
}
void testWaveFormatExtensible()
{
RIFF::WAV::File f(TEST_FILE_PATH_C("uint8we.wav"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(2937, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(128, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(8000, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(8, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(23493U, f.audioProperties()->sampleFrames());
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->format());
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestWAV);