From 4ae0193c125cc70176eb1660919d507fbf5378e4 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 8 Nov 2023 00:18:22 +0100 Subject: [PATCH] Don't feed channels to leqm that we don't have a correction factor for (#2647). --- src/lib/audio_analyser.cc | 15 +++++++-------- src/lib/audio_analyser.h | 1 + test/audio_analysis_test.cc | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/lib/audio_analyser.cc b/src/lib/audio_analyser.cc index 687da9cef..8cbc3145b 100644 --- a/src/lib/audio_analyser.cc +++ b/src/lib/audio_analyser.cc @@ -86,14 +86,14 @@ AudioAnalyser::AudioAnalyser (shared_ptr film, shared_ptraudio_channels(); + _leqm_channels = film->audio_channels(); auto content = _playlist->content(); if (content.size() == 1 && content[0]->audio) { - leqm_channels = content[0]->audio->mapping().mapped_output_channels().size(); + _leqm_channels = content[0]->audio->mapping().mapped_output_channels().size(); } /* XXX: is this right? Especially for more than 5.1? */ - vector channel_corrections(leqm_channels, 1); + vector channel_corrections(_leqm_channels, 1); add_if_required (channel_corrections, 4, -3); // Ls add_if_required (channel_corrections, 5, -3); // Rs add_if_required (channel_corrections, 6, -144); // HI @@ -108,7 +108,7 @@ AudioAnalyser::AudioAnalyser (shared_ptr film, shared_ptraudio_frame_rate(), 24, channel_corrections, @@ -150,15 +150,14 @@ AudioAnalyser::analyse (shared_ptr b, DCPTime time) #endif int const frames = b->frames (); - int const channels = b->channels (); - vector interleaved(frames * channels); + vector interleaved(frames * _leqm_channels); - for (int j = 0; j < channels; ++j) { + for (int j = 0; j < _leqm_channels; ++j) { float const* data = b->data(j); for (int i = 0; i < frames; ++i) { float s = data[i]; - interleaved[i * channels + j] = s; + interleaved[i * _leqm_channels + j] = s; float as = fabsf (s); if (as < 10e-7) { diff --git a/src/lib/audio_analyser.h b/src/lib/audio_analyser.h index 01eec36b1..3568d853d 100644 --- a/src/lib/audio_analyser.h +++ b/src/lib/audio_analyser.h @@ -71,6 +71,7 @@ private: Frame _samples_per_point = 1; boost::scoped_ptr _leqm; + int _leqm_channels = 0; Frame _done = 0; std::vector _sample_peak; std::vector _sample_peak_frame; diff --git a/test/audio_analysis_test.cc b/test/audio_analysis_test.cc index 39abe7e48..9ad37ec2e 100644 --- a/test/audio_analysis_test.cc +++ b/test/audio_analysis_test.cc @@ -31,6 +31,7 @@ #include "lib/audio_analysis.h" #include "lib/audio_content.h" #include "lib/content_factory.h" +#include "lib/dcp_content.h" #include "lib/dcp_content_type.h" #include "lib/ffmpeg_content.h" #include "lib/ffmpeg_content.h" @@ -211,6 +212,29 @@ BOOST_AUTO_TEST_CASE (analyse_audio_leqm_test) } +BOOST_AUTO_TEST_CASE(analyse_audio_leqm_same_with_empty_channels) +{ + auto dcp = make_shared(TestPaths::private_data() / "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV"); + auto film = new_test_film2("analyse_audio_leqm_test2", { dcp }); + film->set_audio_channels(8); + + auto analyse = [film, dcp](int channels) { + film->set_audio_channels(channels); + auto playlist = make_shared(); + playlist->add(film, dcp); + boost::signals2::connection c; + JobManager::instance()->analyse_audio(film, playlist, false, c, [](Job::Result) {}); + BOOST_CHECK(!wait_for_jobs()); + AudioAnalysis analysis(film->audio_analysis_path(playlist)); + return analysis.leqm().get_value_or(0); + }; + + BOOST_CHECK_CLOSE(analyse( 6), 84.51411, 0.001); + BOOST_CHECK_CLOSE(analyse( 8), 84.51411, 0.001); + BOOST_CHECK_CLOSE(analyse(16), 84.51411, 0.001); +} + + /** Bug #2364; a file with a lot of silent video at the end (about 50s worth) * crashed the audio analysis with an OOM on Windows. */ -- 2.30.2