2 Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic 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 DCP-o-matic 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 /** @file test/audio_mapping_test.cc
23 * @brief Test AudioMapping class.
24 * @ingroup selfcontained
28 #include <boost/test/unit_test.hpp>
29 #include "lib/audio_mapping.h"
30 #include "lib/constants.h"
31 #include "lib/compose.hpp"
36 using boost::optional;
39 BOOST_AUTO_TEST_CASE (audio_mapping_test)
42 BOOST_CHECK_EQUAL (none.input_channels(), 0);
44 AudioMapping four (4, MAX_DCP_AUDIO_CHANNELS);
45 BOOST_CHECK_EQUAL (four.input_channels(), 4);
49 for (int i = 0; i < 4; ++i) {
50 for (int j = 0; j < MAX_DCP_AUDIO_CHANNELS; ++j) {
51 BOOST_CHECK_EQUAL (four.get(i, j), (i == 0 && j == 1) ? 1 : 0);
55 auto mapped = four.mapped_output_channels ();
56 BOOST_CHECK_EQUAL (mapped.size(), 1U);
57 BOOST_CHECK_EQUAL (mapped.front(), 1);
61 for (int i = 0; i < 4; ++i) {
62 for (int j = 0; j < MAX_DCP_AUDIO_CHANNELS; ++j) {
63 BOOST_CHECK_EQUAL (four.get (i, j), 0);
70 guess_check (boost::filesystem::path filename, int output_channel)
72 AudioMapping m (1, 8);
73 m.make_default (0, filename);
74 for (int i = 0; i < 8; ++i) {
75 BOOST_TEST_INFO (String::compose("%1 channel %2", filename, i));
76 BOOST_CHECK_CLOSE (m.get(0, i), i == output_channel ? 1 : 0, 0.01);
81 BOOST_AUTO_TEST_CASE (audio_mapping_guess_test)
83 guess_check ("stuff_L_nonsense.wav", 0);
84 guess_check ("stuff_nonsense.wav", 2);
85 guess_check ("fred_R.wav", 1);
86 guess_check ("jim_C_sheila.aiff", 2);
87 guess_check ("things_Lfe_and.wav", 3);
88 guess_check ("weeee_Ls.aiff", 4);
89 guess_check ("try_Rs-it.wav", 5);
92 guess_check ("things_LFE.wav", 3);
93 guess_check ("ptish_Lsr_abc.wav", 6);
94 guess_check ("ptish_Rsr_abc.wav", 7);
95 guess_check ("more_Lss_s.wav", 4);
96 guess_check ("other_Rss.aiff", 5);
98 /* Only the filename should be taken into account */
99 guess_check ("-Lfe-/foo_L.wav", 0);
102 guess_check ("jake-Lrs-good.wav", 6);
103 guess_check ("elwood-Rrs-good.wav", 7);
107 BOOST_AUTO_TEST_CASE(audio_mapping_take_from_larger)
109 AudioMapping A(4, 9);
110 AudioMapping B(2, 3);
121 BOOST_CHECK_CLOSE(B.get(0, 0), 4, 0.01);
122 BOOST_CHECK_CLOSE(B.get(1, 0), 8, 0.01);
123 BOOST_CHECK_CLOSE(B.get(0, 1), 3, 0.01);
124 BOOST_CHECK_CLOSE(B.get(1, 1), 6, 0.01);
125 BOOST_CHECK_CLOSE(B.get(0, 2), 1, 0.01);
126 BOOST_CHECK_CLOSE(B.get(1, 2), 9, 0.01);
130 BOOST_AUTO_TEST_CASE(audio_mapping_take_from_smaller)
132 AudioMapping A(4, 9);
133 AudioMapping B(2, 3);
144 BOOST_CHECK_CLOSE(A.get(0, 0), 4, 0.01);
145 BOOST_CHECK_CLOSE(A.get(1, 0), 8, 0.01);
146 BOOST_CHECK_CLOSE(A.get(0, 1), 3, 0.01);
147 BOOST_CHECK_CLOSE(A.get(1, 1), 6, 0.01);
148 BOOST_CHECK_CLOSE(A.get(0, 2), 1, 0.01);
149 BOOST_CHECK_CLOSE(A.get(1, 2), 9, 0.01);