Fix failure to examine non-flat-ratio VFs (#2775).
[dcpomatic.git] / test / audio_analysis_test.cc
index 9ad37ec2e77673a0f2a22eccc69c57403896f26d..8ded9eda9296d28a67f17a0fc7520e07e5a96415 100644 (file)
@@ -41,6 +41,7 @@
 #include "lib/ratio.h"
 #include "test.h"
 #include <boost/test/unit_test.hpp>
+#include <numeric>
 
 
 using std::make_shared;
@@ -263,3 +264,47 @@ BOOST_AUTO_TEST_CASE(analyse_audio_with_strange_channel_count)
        BOOST_CHECK(!wait_for_jobs());
 }
 
+
+BOOST_AUTO_TEST_CASE(analyse_audio_with_more_channels_than_film)
+{
+       auto picture = content_factory("test/data/flat_red.png");
+       auto film_16ch = new_test_film2("analyse_audio_with_more_channels_than_film_16ch", picture);
+       film_16ch->set_audio_channels(16);
+       make_and_verify_dcp(film_16ch);
+
+       auto pcm_16ch = find_file(film_16ch->dir(film_16ch->dcp_name()), "pcm_");
+       auto sound = content_factory(pcm_16ch)[0];
+
+       auto film_6ch = new_test_film2("analyse_audio_with_more_channels_than_film_6ch", { sound });
+
+       auto playlist = make_shared<Playlist>();
+       playlist->add(film_6ch, sound);
+       boost::signals2::connection c;
+       JobManager::instance()->analyse_audio(film_6ch, playlist, false, c, [](Job::Result) {});
+       BOOST_CHECK(!wait_for_jobs());
+}
+
+
+BOOST_AUTO_TEST_CASE(analyse_audio_uses_processor_when_analysing_whole_film)
+{
+       auto sound = content_factory(TestPaths::private_data() / "betty_stereo.wav")[0];
+       auto film = new_test_film2("analyse_audio_uses_processor_when_analysing_whole_film", { sound });
+
+       auto job = make_shared<AnalyseAudioJob>(film, film->playlist(), true);
+       JobManager::instance()->add(job);
+       BOOST_REQUIRE(!wait_for_jobs());
+
+       AudioAnalysis analysis(job->path());
+
+       BOOST_REQUIRE(analysis.channels() > 2);
+       bool centre_non_zero = false;
+       /* Make sure there's something from the mid-side decoder on the centre channel */
+       for (auto point = 0; point < analysis.points(2); ++point) {
+               if (std::abs(analysis.get_point(2, point)[AudioPoint::Type::PEAK]) > 0) {
+                       centre_non_zero = true;
+               }
+       }
+
+       BOOST_CHECK(centre_non_zero);
+}
+