2 Copyright (C) 2012-2016 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/audio_analysis_test.cc
22 * @brief Check audio analysis code.
25 #include <boost/test/unit_test.hpp>
26 #include "lib/audio_analysis.h"
27 #include "lib/analyse_audio_job.h"
29 #include "lib/ffmpeg_content.h"
30 #include "lib/dcp_content_type.h"
31 #include "lib/ffmpeg_content.h"
32 #include "lib/ratio.h"
33 #include "lib/job_manager.h"
34 #include "lib/audio_content.h"
37 using boost::shared_ptr;
42 return (float (rand ()) / RAND_MAX) * 2 - 1;
45 BOOST_AUTO_TEST_CASE (audio_analysis_serialisation_test)
47 int const channels = 3;
48 int const points = 4096;
53 for (int i = 0; i < channels; ++i) {
54 for (int j = 0; j < points; ++j) {
56 p[AudioPoint::PEAK] = random_float ();
57 p[AudioPoint::RMS] = random_float ();
62 float const peak = random_float ();
63 DCPTime const peak_time = DCPTime (rand ());
64 a.set_sample_peak (peak, peak_time);
66 a.write ("build/test/audio_analysis_serialisation_test");
70 AudioAnalysis b ("build/test/audio_analysis_serialisation_test");
71 for (int i = 0; i < channels; ++i) {
72 BOOST_CHECK_EQUAL (b.points(i), points);
73 for (int j = 0; j < points; ++j) {
74 AudioPoint p = b.get_point (i, j);
75 BOOST_CHECK_CLOSE (p[AudioPoint::PEAK], random_float (), 1);
76 BOOST_CHECK_CLOSE (p[AudioPoint::RMS], random_float (), 1);
80 BOOST_CHECK (b.sample_peak ());
81 BOOST_CHECK_CLOSE (b.sample_peak().get(), peak, 1);
82 BOOST_CHECK (b.sample_peak_time ());
83 BOOST_CHECK_EQUAL (b.sample_peak_time().get(), peak_time);
92 BOOST_AUTO_TEST_CASE (audio_analysis_test)
94 shared_ptr<Film> film = new_test_film ("audio_analysis_test");
95 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
96 film->set_container (Ratio::from_id ("185"));
97 film->set_name ("audio_analysis_test");
98 boost::filesystem::path p = private_data / "betty_L.wav";
100 shared_ptr<FFmpegContent> c (new FFmpegContent (film, p));
101 film->examine_and_add_content (c);
104 shared_ptr<AnalyseAudioJob> job (new AnalyseAudioJob (film, film->playlist ()));
105 job->Finished.connect (boost::bind (&finished));
106 JobManager::instance()->add (job);
110 /** Check that audio analysis works (i.e. runs without error) with a -ve delay */
111 BOOST_AUTO_TEST_CASE (audio_analysis_negative_delay_test)
113 shared_ptr<Film> film = new_test_film ("audio_analysis_negative_delay_test");
114 film->set_name ("audio_analysis_negative_delay_test");
115 shared_ptr<FFmpegContent> c (new FFmpegContent (film, private_data / "boon_telly.mkv"));
116 film->examine_and_add_content (c);
119 c->audio->set_delay (-250);
121 shared_ptr<AnalyseAudioJob> job (new AnalyseAudioJob (film, film->playlist ()));
122 job->Finished.connect (boost::bind (&finished));
123 JobManager::instance()->add (job);
127 /** Check audio analysis that is incorrect in 2e98263 */
128 BOOST_AUTO_TEST_CASE (audio_analysis_test2)
130 shared_ptr<Film> film = new_test_film ("audio_analysis_test2");
131 film->set_name ("audio_analysis_test2");
132 shared_ptr<FFmpegContent> c (new FFmpegContent (film, private_data / "3d_thx_broadway_2010_lossless.m2ts"));
133 film->examine_and_add_content (c);
136 shared_ptr<AnalyseAudioJob> job (new AnalyseAudioJob (film, film->playlist ()));
137 job->Finished.connect (boost::bind (&finished));
138 JobManager::instance()->add (job);
143 static bool done = false;
151 /* Test a case which was reported to throw an exception; analysing
152 * a 12-channel DCP's audio.
154 BOOST_AUTO_TEST_CASE (audio_analysis_test3)
156 shared_ptr<Film> film = new_test_film ("analyse_audio_test");
157 film->set_container (Ratio::from_id ("185"));
158 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
159 film->set_name ("frobozz");
161 shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/white.wav"));
162 film->examine_and_add_content (content);
165 film->set_audio_channels (12);
166 boost::signals2::connection connection;
167 JobManager::instance()->analyse_audio (film, film->playlist(), connection, boost::bind (&analysis_finished));