Updated cs_CZ translation from Tomáš Begeni.
[dcpomatic.git] / src / lib / audio_analyser.cc
index 687da9cef1741d8b26648264d067a5362cae5d60..6e7b9fa86971152e88755fe049c9ba68c3a9f9f2 100644 (file)
@@ -52,12 +52,12 @@ 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)
 #ifdef DCPOMATIC_HAVE_EBUR128_PATCHED_FFMPEG
-       , _ebur128 (new AudioFilterGraph(film->audio_frame_rate(), film->audio_channels()))
+       , _ebur128(film->audio_frame_rate(), film->audio_channels())
 #endif
        , _sample_peak (film->audio_channels())
        , _sample_peak_frame (film->audio_channels())
@@ -65,13 +65,13 @@ AudioAnalyser::AudioAnalyser (shared_ptr<const Film> film, shared_ptr<const Play
 {
 
 #ifdef DCPOMATIC_HAVE_EBUR128_PATCHED_FFMPEG
-       _filters.push_back (new Filter("ebur128", "ebur128", "audio", "ebur128=peak=true"));
-       _ebur128->setup (_filters);
+       _filters.push_back({"ebur128", "ebur128", "audio", "ebur128=peak=true"});
+       _ebur128.setup(_filters);
 #endif
 
        _current = std::vector<AudioPoint>(_film->audio_channels());
 
-       if (!from_zero) {
+       if (!whole_film) {
                _start = _playlist->start().get_value_or(DCPTime());
        }
 
@@ -86,14 +86,22 @@ AudioAnalyser::AudioAnalyser (shared_ptr<const Film> film, shared_ptr<const Play
                }
        };
 
-       int 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? */
-       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 +116,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,
@@ -124,14 +132,6 @@ AudioAnalyser::AudioAnalyser (shared_ptr<const Film> film, shared_ptr<const Play
 }
 
 
-AudioAnalyser::~AudioAnalyser ()
-{
-       for (auto i: _filters) {
-               delete const_cast<Filter*> (i);
-       }
-}
-
-
 void
 AudioAnalyser::analyse (shared_ptr<AudioBuffers> b, DCPTime time)
 {
@@ -145,20 +145,19 @@ AudioAnalyser::analyse (shared_ptr<AudioBuffers> b, DCPTime time)
 
 #ifdef DCPOMATIC_HAVE_EBUR128_PATCHED_FFMPEG
        if (Config::instance()->analyse_ebur128 ()) {
-               _ebur128->process (b);
+               _ebur128.process(b);
        }
 #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) {
@@ -205,7 +204,7 @@ AudioAnalyser::finish ()
 
 #ifdef DCPOMATIC_HAVE_EBUR128_PATCHED_FFMPEG
        if (Config::instance()->analyse_ebur128 ()) {
-               void* eb = _ebur128->get("Parsed_ebur128_0")->priv;
+               void* eb = _ebur128.get("Parsed_ebur128_0")->priv;
                vector<float> true_peak;
                for (int i = 0; i < _film->audio_channels(); ++i) {
                        true_peak.push_back (av_ebur128_get_true_peaks(eb)[i]);