diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-03-16 21:07:10 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2023-03-16 21:07:10 +0100 |
| commit | 8c5aed0c60927ad3f22ef3b620a4c2e000316a65 (patch) | |
| tree | bee8b41ba5b48cedf7b402367234f4f5eef9d01c /test | |
| parent | c1d296b163ddf88a5b387f98e7e77988a242a996 (diff) | |
Allow writing to sound assets with int32_t as well as float.
Diffstat (limited to 'test')
| -rw-r--r-- | test/sound_asset_writer_test.cc | 126 |
1 files changed, 100 insertions, 26 deletions
diff --git a/test/sound_asset_writer_test.cc b/test/sound_asset_writer_test.cc index 32ab06b5..a413a174 100644 --- a/test/sound_asset_writer_test.cc +++ b/test/sound_asset_writer_test.cc @@ -37,28 +37,23 @@ #include <boost/filesystem.hpp> #include <boost/random.hpp> #include <boost/test/unit_test.hpp> +#include <functional> -BOOST_AUTO_TEST_CASE(sound_asset_writer_no_padding_test) +using std::shared_ptr; + + +static +void +no_padding_test(boost::filesystem::path path, std::function<void (shared_ptr<dcp::SoundAssetWriter>, boost::random::mt19937&, boost::random::uniform_int_distribution<>&)> write) { - auto path = boost::filesystem::path("build/test/sound_asset_writer_no_padding_test.mxf"); dcp::SoundAsset asset({24, 1}, 48000, 6, dcp::LanguageTag{"en-GB"}, dcp::Standard::SMPTE); auto writer = asset.start_write(path); boost::random::mt19937 rng(1); boost::random::uniform_int_distribution<> dist(0, 32767); - std::vector<std::vector<float>> buffers(6); - float* pointers[6]; - for (auto channel = 0; channel < 6; ++channel) { - buffers[channel].resize(2000); - for (int sample = 0; sample < 2000; ++sample) { - buffers[channel][sample] = static_cast<float>(dist(rng)) / (1 << 23); - } - pointers[channel] = buffers[channel].data(); - } - - writer->write(pointers, 6, 2000); + write(writer, rng, dist); writer->finalize(); dcp::SoundAsset check(path); @@ -75,26 +70,61 @@ BOOST_AUTO_TEST_CASE(sound_asset_writer_no_padding_test) } -BOOST_AUTO_TEST_CASE(sound_asset_writer_padding_test) +BOOST_AUTO_TEST_CASE(sound_asset_writer_float_no_padding_test) +{ + auto path = boost::filesystem::path("build/test/sound_asset_writer_float_no_padding_test.mxf"); + + auto write = [](shared_ptr<dcp::SoundAssetWriter> writer, boost::random::mt19937& rng, boost::random::uniform_int_distribution<>& dist) { + std::vector<std::vector<float>> buffers(6); + float* pointers[6]; + for (auto channel = 0; channel < 6; ++channel) { + buffers[channel].resize(2000); + for (int sample = 0; sample < 2000; ++sample) { + buffers[channel][sample] = static_cast<float>(dist(rng)) / (1 << 23); + } + pointers[channel] = buffers[channel].data(); + } + + writer->write(pointers, 6, 2000); + }; + + no_padding_test(path, write); +} + + +BOOST_AUTO_TEST_CASE(sound_asset_writer_int_no_padding_test) +{ + auto path = boost::filesystem::path("build/test/sound_asset_writer_int_no_padding_test.mxf"); + + auto write = [](shared_ptr<dcp::SoundAssetWriter> writer, boost::random::mt19937& rng, boost::random::uniform_int_distribution<>& dist) { + std::vector<std::vector<int32_t>> buffers(6); + int32_t* pointers[6]; + for (auto channel = 0; channel < 6; ++channel) { + buffers[channel].resize(2000); + for (int sample = 0; sample < 2000; ++sample) { + buffers[channel][sample] = dist(rng); + } + pointers[channel] = buffers[channel].data(); + } + + writer->write(pointers, 6, 2000); + }; + + no_padding_test(path, write); +} + + +static +void +padding_test(boost::filesystem::path path, std::function<void (shared_ptr<dcp::SoundAssetWriter>, boost::random::mt19937&, boost::random::uniform_int_distribution<>&)> write) { - auto path = boost::filesystem::path("build/test/sound_asset_writer_padding_test.mxf"); dcp::SoundAsset asset({24, 1}, 48000, 14, dcp::LanguageTag{"en-GB"}, dcp::Standard::SMPTE); auto writer = asset.start_write(path); boost::random::mt19937 rng(1); boost::random::uniform_int_distribution<> dist(0, 32767); - std::vector<std::vector<float>> buffers(6); - float* pointers[6]; - for (auto channel = 0; channel < 6; ++channel) { - buffers[channel].resize(2000); - for (int sample = 0; sample < 2000; ++sample) { - buffers[channel][sample] = static_cast<float>(dist(rng)) / (1 << 23); - } - pointers[channel] = buffers[channel].data(); - } - - writer->write(pointers, 6, 2000); + write(writer, rng, dist); writer->finalize(); dcp::SoundAsset check(path); @@ -115,3 +145,47 @@ BOOST_AUTO_TEST_CASE(sound_asset_writer_padding_test) } } } + + +BOOST_AUTO_TEST_CASE(sound_asset_writer_float_padding_test) +{ + auto path = boost::filesystem::path("build/test/sound_asset_writer_float_padding_test.mxf"); + + auto write = [](shared_ptr<dcp::SoundAssetWriter> writer, boost::random::mt19937& rng, boost::random::uniform_int_distribution<>& dist) { + std::vector<std::vector<float>> buffers(6); + float* pointers[6]; + for (auto channel = 0; channel < 6; ++channel) { + buffers[channel].resize(2000); + for (int sample = 0; sample < 2000; ++sample) { + buffers[channel][sample] = static_cast<float>(dist(rng)) / (1 << 23); + } + pointers[channel] = buffers[channel].data(); + } + + writer->write(pointers, 6, 2000); + }; + + padding_test(path, write); +} + + +BOOST_AUTO_TEST_CASE(sound_asset_writer_int_padding_test) +{ + auto path = boost::filesystem::path("build/test/sound_asset_writer_int_padding_test.mxf"); + + auto write = [](shared_ptr<dcp::SoundAssetWriter> writer, boost::random::mt19937& rng, boost::random::uniform_int_distribution<>& dist) { + std::vector<std::vector<int32_t>> buffers(6); + int32_t* pointers[6]; + for (auto channel = 0; channel < 6; ++channel) { + buffers[channel].resize(2000); + for (int sample = 0; sample < 2000; ++sample) { + buffers[channel][sample] = dist(rng); + } + pointers[channel] = buffers[channel].data(); + } + + writer->write(pointers, 6, 2000); + }; + + padding_test(path, write); +} |
