Fix apparently ineffective processors when analysing audio (#2671).
[dcpomatic.git] / src / lib / audio_analyser.cc
index 45097c5b619cdcab5d296da3c963aaf7632763c0..6e7b9fa86971152e88755fe049c9ba68c3a9f9f2 100644 (file)
@@ -52,7 +52,7 @@ using namespace dcpomatic;
 static auto constexpr num_points = 1024;
 
 
-AudioAnalyser::AudioAnalyser (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist, bool from_zero, std::function<void (float)> set_progress)
+AudioAnalyser::AudioAnalyser(shared_ptr<const Film> film, shared_ptr<const Playlist> playlist, bool whole_film, std::function<void (float)> set_progress)
        : _film (film)
        , _playlist (playlist)
        , _set_progress (set_progress)
@@ -71,7 +71,7 @@ AudioAnalyser::AudioAnalyser (shared_ptr<const Film> film, shared_ptr<const Play
 
        _current = std::vector<AudioPoint>(_film->audio_channels());
 
-       if (!from_zero) {
+       if (!whole_film) {
                _start = _playlist->start().get_value_or(DCPTime());
        }
 
@@ -86,10 +86,18 @@ AudioAnalyser::AudioAnalyser (shared_ptr<const Film> film, shared_ptr<const Play
                }
        };
 
-       _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();
+       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
+                        * calculate LEQ(m) for L, R and C.  I'm not sure if this is
+                        * right or not.
+                        */
+                       _leqm_channels = std::min(film->audio_channels(), channel + 1);
+               }
        }
 
        /* XXX: is this right?  Especially for more than 5.1? */