2 Copyright (C) 2017 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/>.
21 /** @file test/torture_test.cc
22 * @brief Entire projects that are programmatically created and checked.
25 #include "lib/audio_content.h"
27 #include "lib/dcp_content_type.h"
28 #include "lib/ratio.h"
29 #include "lib/content_factory.h"
33 #include <dcp/reel_sound_asset.h>
34 #include <dcp/sound_asset.h>
35 #include <boost/test/unit_test.hpp>
38 using boost::shared_ptr;
40 /** Test a fairly complex arrangement of content */
41 BOOST_AUTO_TEST_CASE (torture_test1)
43 shared_ptr<Film> film = new_test_film ("torture_test");
44 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
45 film->set_name ("torture_test");
46 film->set_container (Ratio::from_id ("185"));
47 film->set_sequence (false);
49 /* Staircase at an offset of 2000 samples, trimmed both start and end, with a gain of 6dB */
50 shared_ptr<Content> staircase = content_factory(film, "test/data/staircase.wav").front ();
51 film->examine_and_add_content (staircase);
53 staircase->set_position (DCPTime::from_frames (2000, film->audio_frame_rate()));
54 staircase->set_trim_start (ContentTime::from_frames (12, 48000));
55 staircase->set_trim_end (ContentTime::from_frames (35, 48000));
56 staircase->audio->set_gain (20 * log10(2));
58 /* And again at an offset of 50000 samples, trimmed both start and end, with a gain of 6dB */
59 staircase = content_factory(film, "test/data/staircase.wav").front ();
60 film->examine_and_add_content (staircase);
62 staircase->set_position (DCPTime::from_frames (50000, film->audio_frame_rate()));
63 staircase->set_trim_start (ContentTime::from_frames (12, 48000));
64 staircase->set_trim_end (ContentTime::from_frames (35, 48000));
65 staircase->audio->set_gain (20 * log10(2));
67 film->set_video_frame_rate (24);
68 film->write_metadata ();
72 dcp::DCP dcp ("build/test/torture_test/" + film->dcp_name(false));
75 list<shared_ptr<dcp::CPL> > cpls = dcp.cpls ();
76 BOOST_REQUIRE_EQUAL (cpls.size(), 1);
77 list<shared_ptr<dcp::Reel> > reels = cpls.front()->reels ();
78 BOOST_REQUIRE_EQUAL (reels.size(), 1);
80 shared_ptr<dcp::ReelSoundAsset> reel_sound = reels.front()->main_sound();
81 BOOST_REQUIRE (reel_sound);
82 shared_ptr<dcp::SoundAsset> sound = reel_sound->asset();
83 BOOST_REQUIRE (sound);
85 shared_ptr<dcp::SoundAssetReader> sound_reader = sound->start_read ();
87 /* First frame silent */
88 shared_ptr<const dcp::SoundFrame> fr = sound_reader->get_frame (0);
89 for (int i = 0; i < fr->samples(); ++i) {
90 for (int j = 0; j < 6; ++j) {
91 BOOST_CHECK_EQUAL (fr->get(j, i), 0);
95 /* The first staircase is 4800 - 12 - 35 = 4753 samples. One frame is 2000 samples, so we span 3 frames */
97 BOOST_REQUIRE_EQUAL (fr->samples(), 2000);
101 fr = sound_reader->get_frame (1);
102 for (int i = 0; i < fr->samples(); ++i) {
103 for (int j = 0; j < 6; ++j) {
105 BOOST_CHECK_EQUAL ((fr->get(j, i) + 128) >> 8, stair * 2);
108 BOOST_CHECK_EQUAL (fr->get(j, i), 0);
113 fr = sound_reader->get_frame (2);
114 for (int i = 0; i < fr->samples(); ++i) {
115 for (int j = 0; j < 6; ++j) {
117 BOOST_CHECK_EQUAL ((fr->get(j, i) + 128) >> 8, stair * 2);
120 BOOST_CHECK_EQUAL (fr->get(j, i), 0);
125 fr = sound_reader->get_frame (3);
126 for (int i = 0; i < fr->samples(); ++i) {
127 for (int j = 0; j < 6; ++j) {
128 if (j == 2 && i < (4753 - (2000 * 2))) {
129 BOOST_CHECK_EQUAL ((fr->get(j, i) + 128) >> 8, stair * 2);
132 BOOST_CHECK_EQUAL (fr->get(j, i), 0);
137 /* Then some silence */
139 for (int i = 4; i < 24; ++i) {
140 fr = sound_reader->get_frame (i);
141 for (int j = 0; j < fr->samples(); ++j) {
142 for (int k = 0; k < 6; ++k) {
143 BOOST_CHECK_EQUAL (fr->get(k, j), 0);
148 /* Then the same thing again */
151 fr = sound_reader->get_frame (25);
152 for (int i = 0; i < fr->samples(); ++i) {
153 for (int j = 0; j < 6; ++j) {
155 BOOST_CHECK_EQUAL ((fr->get(j, i) + 128) >> 8, stair * 2);
158 BOOST_CHECK_EQUAL (fr->get(j, i), 0);
163 fr = sound_reader->get_frame (26);
164 for (int i = 0; i < fr->samples(); ++i) {
165 for (int j = 0; j < 6; ++j) {
167 BOOST_CHECK_EQUAL ((fr->get(j, i) + 128) >> 8, stair * 2);
170 BOOST_CHECK_EQUAL (fr->get(j, i), 0);
175 fr = sound_reader->get_frame (27);
176 for (int i = 0; i < fr->samples(); ++i) {
177 for (int j = 0; j < 6; ++j) {
178 if (j == 2 && i < (4753 - (2000 * 2))) {
179 BOOST_CHECK_EQUAL ((fr->get(j, i) + 128) >> 8, stair * 2);
182 BOOST_CHECK_EQUAL (fr->get(j, i), 0);