Fix silent stereo mixdown exports when the project audio channel count is > 6.
[dcpomatic.git] / test / cpl_metadata_test.cc
1 /*
2     Copyright (C) 2023 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21
22 #include "lib/audio_content.h"
23 #include "lib/content.h"
24 #include "lib/content_factory.h"
25 #include "lib/film.h"
26 #include "test.h"
27 #include <dcp/cpl.h>
28 #include <dcp/dcp.h>
29 #include <boost/test/unit_test.hpp>
30
31
32 using std::shared_ptr;
33
34
35 BOOST_AUTO_TEST_CASE(main_sound_configuration_test_51_vi)
36 {
37         auto picture = content_factory("test/data/flat_red.png")[0];
38         auto L = content_factory("test/data/L.wav")[0];
39         auto R = content_factory("test/data/R.wav")[0];
40         auto C = content_factory("test/data/C.wav")[0];
41         auto Lfe = content_factory("test/data/Lfe.wav")[0];
42         auto Ls = content_factory("test/data/Ls.wav")[0];
43         auto Rs = content_factory("test/data/Rs.wav")[0];
44         auto VI = content_factory("test/data/sine_440.wav")[0];
45
46         auto film = new_test_film2("main_sound_configuration_test_51_vi", { picture, L, R, C, Lfe, Ls, Rs, VI });
47         film->set_audio_channels(8);
48
49         auto set_map = [](shared_ptr<Content> content, dcp::Channel channel) {
50                 auto map = content->audio->mapping();
51                 map.set(0, channel, 1.0f);
52                 content->audio->set_mapping(map);
53         };
54
55         set_map(L, dcp::Channel::LEFT);
56         set_map(R, dcp::Channel::RIGHT);
57         set_map(C, dcp::Channel::CENTRE);
58         set_map(Lfe, dcp::Channel::LFE);
59         set_map(Ls, dcp::Channel::LS);
60         set_map(Rs, dcp::Channel::RS);
61         set_map(VI, dcp::Channel::VI);
62
63         make_and_verify_dcp(film);
64
65         dcp::DCP dcp(film->dir(film->dcp_name()));
66         dcp.read();
67         BOOST_REQUIRE_EQUAL(dcp.cpls().size(), 1U);
68         auto cpl = dcp.cpls()[0];
69
70         auto msc = cpl->main_sound_configuration();
71         BOOST_REQUIRE(msc);
72
73         /* We think this should say 51 not 71 at the start (#2580) */
74         BOOST_CHECK_EQUAL(msc->to_string(), "51/L,R,C,LFE,Ls,Rs,-,VIN");
75 }
76
77
78 BOOST_AUTO_TEST_CASE(main_sound_configuration_test_71)
79 {
80         auto picture = content_factory("test/data/flat_red.png")[0];
81         auto L = content_factory("test/data/L.wav")[0];
82         auto R = content_factory("test/data/R.wav")[0];
83         auto C = content_factory("test/data/C.wav")[0];
84         auto Lfe = content_factory("test/data/Lfe.wav")[0];
85         auto Ls = content_factory("test/data/Ls.wav")[0];
86         auto Rs = content_factory("test/data/Rs.wav")[0];
87         auto BsL = content_factory("test/data/Ls.wav")[0];
88         auto BsR = content_factory("test/data/Rs.wav")[0];
89         auto VI = content_factory("test/data/sine_440.wav")[0];
90
91         auto film = new_test_film2("main_sound_configuration_test_51_vi", { picture, L, R, C, Lfe, Ls, Rs, BsL, BsR, VI });
92         film->set_audio_channels(12);
93
94         auto set_map = [](shared_ptr<Content> content, dcp::Channel channel) {
95                 auto map = content->audio->mapping();
96                 map.set(0, channel, 1.0f);
97                 content->audio->set_mapping(map);
98         };
99
100         set_map(L, dcp::Channel::LEFT);
101         set_map(R, dcp::Channel::RIGHT);
102         set_map(C, dcp::Channel::CENTRE);
103         set_map(Lfe, dcp::Channel::LFE);
104         set_map(Ls, dcp::Channel::LS);
105         set_map(Rs, dcp::Channel::RS);
106         set_map(BsL, dcp::Channel::BSL);
107         set_map(BsR, dcp::Channel::BSR);
108         set_map(VI, dcp::Channel::VI);
109
110         make_and_verify_dcp(film);
111
112         dcp::DCP dcp(film->dir(film->dcp_name()));
113         dcp.read();
114         BOOST_REQUIRE_EQUAL(dcp.cpls().size(), 1U);
115         auto cpl = dcp.cpls()[0];
116
117         auto msc = cpl->main_sound_configuration();
118         BOOST_REQUIRE(msc);
119
120         BOOST_CHECK_EQUAL(msc->to_string(), "71/L,R,C,LFE,Lss,Rss,-,VIN,-,-,Lrs,Rrs");
121 }