Don't feed channels to leqm that we don't have a correction factor for (#2647).
authorCarl Hetherington <cth@carlh.net>
Tue, 7 Nov 2023 23:18:22 +0000 (00:18 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 20 Nov 2023 06:34:23 +0000 (07:34 +0100)
src/lib/audio_analyser.cc
src/lib/audio_analyser.h
test/audio_analysis_test.cc

index 687da9cef1741d8b26648264d067a5362cae5d60..8cbc3145b40d8e5dbc4bf4f0ce9c64324aa56392 100644 (file)
@@ -86,14 +86,14 @@ AudioAnalyser::AudioAnalyser (shared_ptr<const Film> film, shared_ptr<const Play
                }
        };
 
-       int leqm_channels = film->audio_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<double> channel_corrections(leqm_channels, 1);
+       vector<double> 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<const Film> film, shared_ptr<const Play
        add_if_required (channel_corrections, 15, -144); // Unused
 
        _leqm.reset(new leqm_nrt::Calculator(
-               leqm_channels,
+               _leqm_channels,
                film->audio_frame_rate(),
                24,
                channel_corrections,
@@ -150,15 +150,14 @@ AudioAnalyser::analyse (shared_ptr<AudioBuffers> b, DCPTime time)
 #endif
 
        int const frames = b->frames ();
-       int const channels = b->channels ();
-       vector<double> interleaved(frames * channels);
+       vector<double> 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) {
index 01eec36b1d52b5d2bee65f4746d66ae2a4902bf9..3568d853d20a42aca559428822693f5a5a4a7945 100644 (file)
@@ -71,6 +71,7 @@ private:
        Frame _samples_per_point = 1;
 
        boost::scoped_ptr<leqm_nrt::Calculator> _leqm;
+       int _leqm_channels = 0;
        Frame _done = 0;
        std::vector<float> _sample_peak;
        std::vector<Frame> _sample_peak_frame;
index 39abe7e48197325048f9afd3a6211594f3eaf0e2..9ad37ec2e77673a0f2a22eccc69c57403896f26d 100644 (file)
@@ -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<DCPContent>(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>();
+               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.
  */