From 527093fa643049d370f4daee8206349981edbf95 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 11 Feb 2024 13:10:48 +0100 Subject: [PATCH] Fix apparently ineffective processors when analysing audio (#2671). A whole film ("DCP side") analysis would behave the same as a single piece of content analysis if the film only had one piece of content. Here we also clarify that audio analysis of the whole film is different to that for a single piece of content; for the whole film we use processors, and for single pieces of content we do not. --- src/lib/analyse_audio_job.cc | 13 ++++++++++--- src/lib/analyse_audio_job.h | 3 ++- src/lib/audio_analyser.cc | 10 +++++----- src/lib/audio_analyser.h | 2 +- test/audio_analysis_test.cc | 25 +++++++++++++++++++++++++ 5 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/lib/analyse_audio_job.cc b/src/lib/analyse_audio_job.cc index ca0f49f57..a6ce5dcc8 100644 --- a/src/lib/analyse_audio_job.cc +++ b/src/lib/analyse_audio_job.cc @@ -47,12 +47,16 @@ using namespace boost::placeholders; #endif -/** @param from_zero true to analyse audio from time 0 in the playlist, otherwise begin at Playlist::start */ -AnalyseAudioJob::AnalyseAudioJob (shared_ptr film, shared_ptr playlist, bool from_zero) +/** @param whole_film true to analyse the whole film' audio (i.e. start from time 0 and use processors), false + * to analyse just the single piece of content in the playlist (i.e. start from Playlist::start() and do not + * use processors. + */ +AnalyseAudioJob::AnalyseAudioJob (shared_ptr film, shared_ptr playlist, bool whole_film) : Job (film) - , _analyser (film, playlist, from_zero, boost::bind(&Job::set_progress, this, _1, false)) + , _analyser(film, playlist, whole_film, boost::bind(&Job::set_progress, this, _1, false)) , _playlist (playlist) , _path (film->audio_analysis_path(playlist)) + , _whole_film(whole_film) { LOG_DEBUG_AUDIO_ANALYSIS_NC("AnalyseAudioJob::AnalyseAudioJob"); } @@ -89,6 +93,9 @@ AnalyseAudioJob::run () player->set_fast (); player->set_play_referenced (); player->Audio.connect (bind(&AudioAnalyser::analyse, &_analyser, _1, _2)); + if (!_whole_film) { + player->set_disable_audio_processor(); + } bool has_any_audio = false; for (auto c: _playlist->content()) { diff --git a/src/lib/analyse_audio_job.h b/src/lib/analyse_audio_job.h index 2b749da6b..afd52c304 100644 --- a/src/lib/analyse_audio_job.h +++ b/src/lib/analyse_audio_job.h @@ -50,7 +50,7 @@ class Filter; class AnalyseAudioJob : public Job { public: - AnalyseAudioJob (std::shared_ptr, std::shared_ptr, bool from_zero); + AnalyseAudioJob(std::shared_ptr, std::shared_ptr, bool whole_film); ~AnalyseAudioJob (); std::string name () const override; @@ -70,6 +70,7 @@ private: std::shared_ptr _playlist; /** playlist's audio analysis path when the job was created */ boost::filesystem::path _path; + bool _whole_film; static const int _num_points; }; diff --git a/src/lib/audio_analyser.cc b/src/lib/audio_analyser.cc index df76932de..6e7b9fa86 100644 --- a/src/lib/audio_analyser.cc +++ b/src/lib/audio_analyser.cc @@ -52,7 +52,7 @@ using namespace dcpomatic; static auto constexpr num_points = 1024; -AudioAnalyser::AudioAnalyser (shared_ptr film, shared_ptr playlist, bool from_zero, std::function set_progress) +AudioAnalyser::AudioAnalyser(shared_ptr film, shared_ptr playlist, bool whole_film, std::function set_progress) : _film (film) , _playlist (playlist) , _set_progress (set_progress) @@ -71,7 +71,7 @@ AudioAnalyser::AudioAnalyser (shared_ptr film, shared_ptr(_film->audio_channels()); - if (!from_zero) { + if (!whole_film) { _start = _playlist->start().get_value_or(DCPTime()); } @@ -87,7 +87,9 @@ AudioAnalyser::AudioAnalyser (shared_ptr film, shared_ptrcontent(); - if (content.size() == 1 && content[0]->audio) { + if (whole_film) { + _leqm_channels = film->audio_channels(); + } else { _leqm_channels = 0; for (auto channel: content[0]->audio->mapping().mapped_output_channels()) { /* This means that if, for example, a file only maps C we will @@ -96,8 +98,6 @@ AudioAnalyser::AudioAnalyser (shared_ptr film, shared_ptraudio_channels(), channel + 1); } - } else { - _leqm_channels = film->audio_channels(); } /* XXX: is this right? Especially for more than 5.1? */ diff --git a/src/lib/audio_analyser.h b/src/lib/audio_analyser.h index 4708f517a..3d40f8026 100644 --- a/src/lib/audio_analyser.h +++ b/src/lib/audio_analyser.h @@ -39,7 +39,7 @@ class Playlist; class AudioAnalyser { public: - AudioAnalyser (std::shared_ptr film, std::shared_ptr playlist, bool from_zero, std::function set_progress); + AudioAnalyser(std::shared_ptr film, std::shared_ptr playlist, bool whole_film, std::function set_progress); AudioAnalyser (AudioAnalyser const&) = delete; AudioAnalyser& operator= (AudioAnalyser const&) = delete; diff --git a/test/audio_analysis_test.cc b/test/audio_analysis_test.cc index 8bdca4c32..8ded9eda9 100644 --- a/test/audio_analysis_test.cc +++ b/test/audio_analysis_test.cc @@ -41,6 +41,7 @@ #include "lib/ratio.h" #include "test.h" #include +#include using std::make_shared; @@ -283,3 +284,27 @@ BOOST_AUTO_TEST_CASE(analyse_audio_with_more_channels_than_film) 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(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); +} + -- 2.30.2