2 Copyright (C) 2023 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libdcp is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libdcp. If not, see <http://www.gnu.org/licenses/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
35 #include "sound_asset.h"
36 #include "sound_asset_writer.h"
37 #include <boost/filesystem.hpp>
38 #include <boost/random.hpp>
39 #include <boost/test/unit_test.hpp>
42 BOOST_AUTO_TEST_CASE(sound_asset_writer_no_padding_test)
44 auto path = boost::filesystem::path("build/test/sound_asset_writer_no_padding_test.mxf");
45 dcp::SoundAsset asset({24, 1}, 48000, 6, dcp::LanguageTag{"en-GB"}, dcp::Standard::SMPTE);
46 auto writer = asset.start_write(path);
48 boost::random::mt19937 rng(1);
49 boost::random::uniform_int_distribution<> dist(0, 32767);
51 std::vector<std::vector<float>> buffers(6);
53 for (auto channel = 0; channel < 6; ++channel) {
54 buffers[channel].resize(2000);
55 for (int sample = 0; sample < 2000; ++sample) {
56 buffers[channel][sample] = static_cast<float>(dist(rng)) / (1 << 23);
58 pointers[channel] = buffers[channel].data();
61 writer->write(pointers, 6, 2000);
64 dcp::SoundAsset check(path);
65 auto reader = check.start_read();
66 auto frame = reader->get_frame(0);
70 for (auto channel = 0; channel < 6; ++channel) {
71 for (auto sample = 0; sample < 2000; ++sample) {
72 BOOST_REQUIRE_EQUAL(frame->get(channel, sample), dist(rng));
78 BOOST_AUTO_TEST_CASE(sound_asset_writer_padding_test)
80 auto path = boost::filesystem::path("build/test/sound_asset_writer_padding_test.mxf");
81 dcp::SoundAsset asset({24, 1}, 48000, 14, dcp::LanguageTag{"en-GB"}, dcp::Standard::SMPTE);
82 auto writer = asset.start_write(path);
84 boost::random::mt19937 rng(1);
85 boost::random::uniform_int_distribution<> dist(0, 32767);
87 std::vector<std::vector<float>> buffers(6);
89 for (auto channel = 0; channel < 6; ++channel) {
90 buffers[channel].resize(2000);
91 for (int sample = 0; sample < 2000; ++sample) {
92 buffers[channel][sample] = static_cast<float>(dist(rng)) / (1 << 23);
94 pointers[channel] = buffers[channel].data();
97 writer->write(pointers, 6, 2000);
100 dcp::SoundAsset check(path);
101 auto reader = check.start_read();
102 auto frame = reader->get_frame(0);
106 for (auto channel = 0; channel < 6; ++channel) {
107 for (auto sample = 0; sample < 2000; ++sample) {
108 BOOST_REQUIRE_EQUAL(frame->get(channel, sample), dist(rng));
112 for (auto channel = 7; channel < 14; ++channel) {
113 for (auto sample = 0; sample < 2000; ++sample) {
114 BOOST_REQUIRE_EQUAL(frame->get(channel, sample), 0);