diff --git a/src/MagnumPlugins/WavAudioImporter/Test/CMakeLists.txt b/src/MagnumPlugins/WavAudioImporter/Test/CMakeLists.txt index c82d8b765..120c07dae 100644 --- a/src/MagnumPlugins/WavAudioImporter/Test/CMakeLists.txt +++ b/src/MagnumPlugins/WavAudioImporter/Test/CMakeLists.txt @@ -53,23 +53,26 @@ if(CORRADE_TARGET_EMSCRIPTEN) emscripten_embed_file(WavAudioImporterTest invalidFactChunk.wav "/invalidFactChunk.wav") emscripten_embed_file(WavAudioImporterTest mono8.wav "/mono8.wav") - emscripten_embed_file(WavAudioImporterTest mono8.wav "/mono8junk.wav") - + emscripten_embed_file(WavAudioImporterTest mono8.wav "/mono8.wav") + emscripten_embed_file(WavAudioImporterTest mono8junk.wav "/mono8junk.wav") emscripten_embed_file(WavAudioImporterTest mono8ALaw.wav "/mono8ALaw.wav") emscripten_embed_file(WavAudioImporterTest mono8MuLaw.wav "/mono8MuLaw.wav") emscripten_embed_file(WavAudioImporterTest mono16.wav "/mono16.wav") + emscripten_embed_file(WavAudioImporterTest mono24.wav "/mono24.wav") + emscripten_embed_file(WavAudioImporterTest stereo4.wav "/stereo4.wav") emscripten_embed_file(WavAudioImporterTest stereo8.wav "/stereo8.wav") emscripten_embed_file(WavAudioImporterTest stereo8ALaw.wav "/stereo8ALaw.wav") emscripten_embed_file(WavAudioImporterTest stereo8MuLaw.wav "/stereo8MuLaw.wav") emscripten_embed_file(WavAudioImporterTest stereo12.wav "/stereo12.wav") emscripten_embed_file(WavAudioImporterTest stereo16.wav "/stereo16.wav") emscripten_embed_file(WavAudioImporterTest stereo24.wav "/stereo24.wav") + emscripten_embed_file(WavAudioImporterTest stereo32.wav "/stereo32.wav") emscripten_embed_file(WavAudioImporterTest mono32f.wav "/mono32f.wav") emscripten_embed_file(WavAudioImporterTest stereo32f.wav "/stereo32f.wav") - emscripten_embed_file(WavAudioImporterTest stereo64f.wav "/stereo64f.wav") - emscripten_embed_file(WavAudioImporterTest surround616.wav "/surround616.wav") + emscripten_embed_file(WavAudioImporterTest surround51Channel16.wav "/surround51Channel16.wav") + emscripten_embed_file(WavAudioImporterTest surround71Channel24.wav "/surround71Channel24.wav") endif() diff --git a/src/MagnumPlugins/WavAudioImporter/Test/WavImporterTest.cpp b/src/MagnumPlugins/WavAudioImporter/Test/WavImporterTest.cpp index c230ea135..12fc34f8c 100644 --- a/src/MagnumPlugins/WavAudioImporter/Test/WavImporterTest.cpp +++ b/src/MagnumPlugins/WavAudioImporter/Test/WavImporterTest.cpp @@ -45,29 +45,34 @@ class WavImporterTest: public TestSuite::Tester { void wrongSignature(); void unsupportedFormat(); void unsupportedChannelCount(); + void invalidPadding(); void invalidLength(); void invalidDataChunk(); void invalidFactChunk(); + void mono4(); void mono8(); void mono8junk(); void mono8ALaw(); void mono8MuLaw(); void mono16(); + void stereo4(); void stereo8(); void stereo8ALaw(); void stereo8MuLaw(); void stereo12(); void stereo16(); void stereo24(); + void stereo32(); void mono32f(); void stereo32f(); void stereo64f(); - void surround616(); + void surround51Channel16(); + void surround71Channel24(); void debugAudioFormat(); }; @@ -77,28 +82,34 @@ WavImporterTest::WavImporterTest() { &WavImporterTest::wrongSignature, &WavImporterTest::unsupportedFormat, &WavImporterTest::unsupportedChannelCount, + &WavImporterTest::invalidPadding, &WavImporterTest::invalidLength, &WavImporterTest::invalidDataChunk, &WavImporterTest::invalidFactChunk, + &WavImporterTest::mono4, &WavImporterTest::mono8, &WavImporterTest::mono8junk, &WavImporterTest::mono8ALaw, &WavImporterTest::mono8MuLaw, &WavImporterTest::mono16, + &WavImporterTest::stereo4, &WavImporterTest::stereo8, &WavImporterTest::stereo8ALaw, &WavImporterTest::stereo8MuLaw, &WavImporterTest::stereo12, &WavImporterTest::stereo16, &WavImporterTest::stereo24, + &WavImporterTest::stereo32, &WavImporterTest::mono32f, &WavImporterTest::stereo32f, &WavImporterTest::stereo64f, - &WavImporterTest::surround616, + + &WavImporterTest::surround51Channel16, + &WavImporterTest::surround71Channel24, &WavImporterTest::debugAudioFormat}); } @@ -136,7 +147,7 @@ void WavImporterTest::unsupportedChannelCount() { WavImporter importer; CORRADE_VERIFY(!importer.openFile(Utility::Directory::join(WAVAUDIOIMPORTER_TEST_DIR, "unsupportedChannelCount.wav"))); - CORRADE_COMPARE(out.str(), "Audio::WavImporter::openData(): unsupported channel count 6 with 8 bits per sample\n"); + CORRADE_COMPARE(out.str(), "Audio::WavImporter::openData(): PCM with unsupported channel count 6 with 8 bits per sample\n"); } void WavImporterTest::invalidPadding() { @@ -172,6 +183,19 @@ void WavImporterTest::invalidFactChunk() { CORRADE_COMPARE(importer.format(), Buffer::Format::Mono16); CORRADE_COMPARE(importer.frequency(), 22050); + + CORRADE_COMPARE_AS(importer.data().prefix(8), + Containers::Array::from(-27, -11, -1, -9, 24, -6, 127, -5).prefix(8), + TestSuite::Compare::Container); +} + +void WavImporterTest::mono4() { + std::ostringstream out; + Error redirectError{&out}; + + WavImporter importer; + CORRADE_VERIFY(!importer.openFile(Utility::Directory::join(WAVAUDIOIMPORTER_TEST_DIR, "mono4.wav"))); + CORRADE_COMPARE(out.str(), "Audio::WavImporter::openData(): unsupported format Audio::WavAudioFormat(0x2)\n"); } void WavImporterTest::mono8() { @@ -180,6 +204,10 @@ void WavImporterTest::mono8() { CORRADE_COMPARE(importer.format(), Buffer::Format::Mono8); CORRADE_COMPARE(importer.frequency(), 22050); + + CORRADE_COMPARE_AS(importer.data().prefix(4), + Containers::Array::from(127, 127, 127, 127).prefix(4), + TestSuite::Compare::Container); } void WavImporterTest::mono8junk() { @@ -188,6 +216,10 @@ void WavImporterTest::mono8junk() { CORRADE_COMPARE(importer.format(), Buffer::Format::Mono8); CORRADE_COMPARE(importer.frequency(), 22050); + + CORRADE_COMPARE_AS(importer.data().prefix(4), + Containers::Array::from(127, 127, 127, 127).prefix(4), + TestSuite::Compare::Container); } void WavImporterTest::mono8ALaw() { @@ -196,6 +228,10 @@ void WavImporterTest::mono8ALaw() { CORRADE_COMPARE(importer.format(), Buffer::Format::MonoALaw); CORRADE_COMPARE(importer.frequency(), 8000); + + CORRADE_COMPARE_AS(importer.data().prefix(8), + Containers::Array::from(87, 84, 85, 85, 85, -43, -43, -43).prefix(8), + TestSuite::Compare::Container); } void WavImporterTest::mono8MuLaw() { @@ -204,6 +240,10 @@ void WavImporterTest::mono8MuLaw() { CORRADE_COMPARE(importer.format(), Buffer::Format::MonoMuLaw); CORRADE_COMPARE(importer.frequency(), 8000); + + CORRADE_COMPARE_AS(importer.data().prefix(8), + Containers::Array::from(-5, -3, -1, -2, -1, 127, 127, 126).prefix(8), + TestSuite::Compare::Container); } void WavImporterTest::mono16() { @@ -212,17 +252,28 @@ void WavImporterTest::mono16() { CORRADE_COMPARE(importer.format(), Buffer::Format::Mono16); CORRADE_COMPARE(importer.frequency(), 44000); + CORRADE_COMPARE_AS(importer.data(), Containers::Array::from('\x1d', '\x10', '\x71', '\xc5'), TestSuite::Compare::Container); } +void WavImporterTest::stereo4() { + std::ostringstream out; + Error redirectError{&out}; + + WavImporter importer; + CORRADE_VERIFY(!importer.openFile(Utility::Directory::join(WAVAUDIOIMPORTER_TEST_DIR, "stereo4.wav"))); + CORRADE_COMPARE(out.str(), "Audio::WavImporter::openData(): unsupported format Audio::WavAudioFormat(0x2)\n"); +} + void WavImporterTest::stereo8() { WavImporter importer; CORRADE_VERIFY(importer.openFile(Utility::Directory::join(WAVAUDIOIMPORTER_TEST_DIR, "stereo8.wav"))); CORRADE_COMPARE(importer.format(), Buffer::Format::Stereo8); CORRADE_COMPARE(importer.frequency(), 96000); + CORRADE_COMPARE_AS(importer.data(), Containers::Array::from('\xde', '\xfe', '\xca', '\x7e'), TestSuite::Compare::Container); @@ -234,6 +285,10 @@ void WavImporterTest::stereo8ALaw() { CORRADE_COMPARE(importer.format(), Buffer::Format::StereoALaw); CORRADE_COMPARE(importer.frequency(), 8000); + + CORRADE_COMPARE_AS(importer.data().prefix(8), + Containers::Array::from(-43, -43, -43, -43, -43, -43, 85, -43).prefix(8), + TestSuite::Compare::Container); } void WavImporterTest::stereo8MuLaw() { @@ -242,6 +297,10 @@ void WavImporterTest::stereo8MuLaw() { CORRADE_COMPARE(importer.format(), Buffer::Format::StereoMuLaw); CORRADE_COMPARE(importer.frequency(), 8000); + + CORRADE_COMPARE_AS(importer.data().prefix(8), + Containers::Array::from(-1, -1, -1, -1, -1, -1, 127, -1).prefix(8), + TestSuite::Compare::Container); } void WavImporterTest::stereo12() { @@ -251,7 +310,7 @@ void WavImporterTest::stereo12() { WavImporter importer; CORRADE_VERIFY(!importer.openFile(Utility::Directory::join(WAVAUDIOIMPORTER_TEST_DIR, "stereo12.wav"))); - CORRADE_COMPARE(out.str(), "Audio::WavImporter::openData(): unsupported channel count 2 with 12 bits per sample\n"); + CORRADE_COMPARE(out.str(), "Audio::WavImporter::openData(): PCM with unsupported channel count 2 with 12 bits per sample\n"); } void WavImporterTest::stereo16() { @@ -260,6 +319,10 @@ void WavImporterTest::stereo16() { CORRADE_COMPARE(importer.format(), Buffer::Format::Stereo16); CORRADE_COMPARE(importer.frequency(), 44100); + + CORRADE_COMPARE_AS(importer.data(), + Containers::Array::from(39, 79, 39, 79), + TestSuite::Compare::Container); } void WavImporterTest::stereo24() { @@ -269,7 +332,17 @@ void WavImporterTest::stereo24() { WavImporter importer; CORRADE_VERIFY(!importer.openFile(Utility::Directory::join(WAVAUDIOIMPORTER_TEST_DIR, "stereo24.wav"))); - CORRADE_COMPARE(out.str(), "Audio::WavImporter::openData(): unsupported channel count 2 with 24 bits per sample\n"); + CORRADE_COMPARE(out.str(), "Audio::WavImporter::openData(): PCM with unsupported channel count 2 with 24 bits per sample\n"); +} + +void WavImporterTest::stereo32() { + std::ostringstream out; + Error redirectError{&out}; + + WavImporter importer; + + CORRADE_VERIFY(!importer.openFile(Utility::Directory::join(WAVAUDIOIMPORTER_TEST_DIR, "stereo32.wav"))); + CORRADE_COMPARE(out.str(), "Audio::WavImporter::openData(): PCM with unsupported channel count 2 with 32 bits per sample\n"); } void WavImporterTest::mono32f() { @@ -278,6 +351,10 @@ void WavImporterTest::mono32f() { CORRADE_COMPARE(importer.format(), Buffer::Format::MonoFloat); CORRADE_COMPARE(importer.frequency(), 48000); + + CORRADE_COMPARE_AS(importer.data().prefix(16), + Containers::Array::from(0, 0, 0, 0, 108, 57, -103, 59, 3, 63, 42, 60, -33, -81, -120, 60).prefix(16), + TestSuite::Compare::Container); } void WavImporterTest::stereo32f() { @@ -286,6 +363,10 @@ void WavImporterTest::stereo32f() { CORRADE_COMPARE(importer.format(), Buffer::Format::StereoFloat); CORRADE_COMPARE(importer.frequency(), 44100); + + CORRADE_COMPARE_AS(importer.data().prefix(8), + Containers::Array::from(17, -77, -103, 56, 5, 50, 72, 56).prefix(8), + TestSuite::Compare::Container); } void WavImporterTest::stereo64f() { @@ -294,15 +375,36 @@ void WavImporterTest::stereo64f() { CORRADE_COMPARE(importer.format(), Buffer::Format::StereoDouble); CORRADE_COMPARE(importer.frequency(), 8000); + + CORRADE_COMPARE_AS(importer.data().prefix(64), + Containers::Array::from(0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 63, + 0, 0, 0, 0, 0, 0, 16, 63, + 0, 0, 0, 0, 0, 0, 24, -65, + 0, 0, 0, 0, 0, 0, 0, 0).prefix(64), + TestSuite::Compare::Container); +} + +void WavImporterTest::surround51Channel16() { + std::ostringstream out; + Error redirectError{&out}; + + WavImporter importer; + + CORRADE_VERIFY(!importer.openFile(Utility::Directory::join(WAVAUDIOIMPORTER_TEST_DIR, "surround51Channel16.wav"))); + CORRADE_COMPARE(out.str(), "Audio::WavImporter::openData(): unsupported format Audio::WavAudioFormat::Extensible\n"); } -void WavImporterTest::surround616() { +void WavImporterTest::surround71Channel24() { std::ostringstream out; Error redirectError{&out}; WavImporter importer; - CORRADE_VERIFY(!importer.openFile(Utility::Directory::join(WAVAUDIOIMPORTER_TEST_DIR, "surround616.wav"))); + CORRADE_VERIFY(!importer.openFile(Utility::Directory::join(WAVAUDIOIMPORTER_TEST_DIR, "surround71Channel24.wav"))); CORRADE_COMPARE(out.str(), "Audio::WavImporter::openData(): unsupported format Audio::WavAudioFormat::Extensible\n"); } diff --git a/src/MagnumPlugins/WavAudioImporter/Test/mono24.wav b/src/MagnumPlugins/WavAudioImporter/Test/mono24.wav new file mode 100644 index 000000000..5d733ec46 Binary files /dev/null and b/src/MagnumPlugins/WavAudioImporter/Test/mono24.wav differ diff --git a/src/MagnumPlugins/WavAudioImporter/Test/mono4.wav b/src/MagnumPlugins/WavAudioImporter/Test/mono4.wav new file mode 100644 index 000000000..c7577a9e7 Binary files /dev/null and b/src/MagnumPlugins/WavAudioImporter/Test/mono4.wav differ diff --git a/src/MagnumPlugins/WavAudioImporter/Test/stereo32.wav b/src/MagnumPlugins/WavAudioImporter/Test/stereo32.wav new file mode 100644 index 000000000..009dc66fb Binary files /dev/null and b/src/MagnumPlugins/WavAudioImporter/Test/stereo32.wav differ diff --git a/src/MagnumPlugins/WavAudioImporter/Test/stereo4.wav b/src/MagnumPlugins/WavAudioImporter/Test/stereo4.wav new file mode 100644 index 000000000..a11034614 Binary files /dev/null and b/src/MagnumPlugins/WavAudioImporter/Test/stereo4.wav differ diff --git a/src/MagnumPlugins/WavAudioImporter/Test/surround616.wav b/src/MagnumPlugins/WavAudioImporter/Test/surround51Channel16.wav similarity index 100% rename from src/MagnumPlugins/WavAudioImporter/Test/surround616.wav rename to src/MagnumPlugins/WavAudioImporter/Test/surround51Channel16.wav diff --git a/src/MagnumPlugins/WavAudioImporter/Test/surround71Channel24.wav b/src/MagnumPlugins/WavAudioImporter/Test/surround71Channel24.wav new file mode 100644 index 000000000..a9419a4f3 Binary files /dev/null and b/src/MagnumPlugins/WavAudioImporter/Test/surround71Channel24.wav differ diff --git a/src/MagnumPlugins/WavAudioImporter/WavHeader.h b/src/MagnumPlugins/WavAudioImporter/WavHeader.h index 1f2e527ae..678dbe5cd 100644 --- a/src/MagnumPlugins/WavAudioImporter/WavHeader.h +++ b/src/MagnumPlugins/WavAudioImporter/WavHeader.h @@ -36,7 +36,9 @@ namespace Magnum { namespace Audio { /** @brief WAV audio format */ enum class WavAudioFormat: UnsignedShort { + Unknown = 0x0000, /**< Unknown */ Pcm = 0x0001, /**< PCM */ + Adpcm = 0x0002, /**< Adaptive Differential PCM */ IeeeFloat = 0x0003, /**< IEEE Float */ ALaw = 0x0006, /**< A-Law */ MuLaw = 0x0007, /**< μ-Law */ diff --git a/src/MagnumPlugins/WavAudioImporter/WavImporter.cpp b/src/MagnumPlugins/WavAudioImporter/WavImporter.cpp index da12227c2..17d091702 100644 --- a/src/MagnumPlugins/WavAudioImporter/WavImporter.cpp +++ b/src/MagnumPlugins/WavAudioImporter/WavImporter.cpp @@ -131,7 +131,7 @@ void WavImporter::doOpenData(Containers::ArrayView data) { else if(formatChunk->numChannels == 2 && formatChunk->bitsPerSample == 16) _format = Buffer::Format::Stereo16; else { - Error() << "Audio::WavImporter::openData(): unsupported channel count" + Error() << "Audio::WavImporter::openData(): PCM with unsupported channel count" << formatChunk->numChannels << "with" << formatChunk->bitsPerSample << "bits per sample"; return; @@ -148,7 +148,7 @@ void WavImporter::doOpenData(Containers::ArrayView data) { else if(formatChunk->numChannels == 2 && formatChunk->bitsPerSample == 64) _format = Buffer::Format::StereoDouble; else { - Error() << "Audio::WavImporter::openData(): unsupported channel count" + Error() << "Audio::WavImporter::openData(): IEEE with unsupported channel count" << formatChunk->numChannels << "with" << formatChunk->bitsPerSample << "bits per sample"; return; @@ -161,7 +161,7 @@ void WavImporter::doOpenData(Containers::ArrayView data) { else if(formatChunk->numChannels == 2) _format = Buffer::Format::StereoALaw; else { - Error() << "Audio::WavImporter::openData(): unsupported channel count" + Error() << "Audio::WavImporter::openData(): ALaw with unsupported channel count" << formatChunk->numChannels << "with" << formatChunk->bitsPerSample << "bits per sample"; return; @@ -174,7 +174,7 @@ void WavImporter::doOpenData(Containers::ArrayView data) { else if(formatChunk->numChannels == 2) _format = Buffer::Format::StereoMuLaw; else { - Error() << "Audio::WavImporter::openData(): unsupported channel count" + Error() << "Audio::WavImporter::openData(): ULaw with unsupported channel count" << formatChunk->numChannels << "with" << formatChunk->bitsPerSample << "bits per sample"; return;