Basic and slightly inaccurate support for <Space> in subtitles (#2103).
[dcpomatic.git] / src / lib / audio_analyser.cc
index 3868e05b7196e4724e243d17acdfe78b11a476d9..53d764a9b58dfbe55083719760e17f4a5db96334 100644 (file)
@@ -60,8 +60,8 @@ AudioAnalyser::AudioAnalyser (shared_ptr<const Film> film, shared_ptr<const Play
 #ifdef DCPOMATIC_HAVE_EBUR128_PATCHED_FFMPEG
        , _ebur128 (new AudioFilterGraph(film->audio_frame_rate(), film->audio_channels()))
 #endif
-       , _sample_peak (new float[film->audio_channels()])
-       , _sample_peak_frame (new Frame[film->audio_channels()])
+       , _sample_peak (film->audio_channels())
+       , _sample_peak_frame (film->audio_channels())
        , _analysis (film->audio_channels())
 {
 
@@ -70,7 +70,7 @@ AudioAnalyser::AudioAnalyser (shared_ptr<const Film> film, shared_ptr<const Play
        _ebur128->setup (_filters);
 #endif
 
-       _current = new AudioPoint[_film->audio_channels()];
+       _current = std::vector<AudioPoint>(_film->audio_channels());
 
        if (!from_zero) {
                _start = _playlist->start().get_value_or(DCPTime());
@@ -87,8 +87,14 @@ 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();
+       }
+
        /* XXX: is this right?  Especially for more than 5.1? */
-       vector<double> channel_corrections(film->audio_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
@@ -103,7 +109,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(
-               film->audio_channels(),
+               leqm_channels,
                film->audio_frame_rate(),
                24,
                channel_corrections,
@@ -121,12 +127,9 @@ AudioAnalyser::AudioAnalyser (shared_ptr<const Film> film, shared_ptr<const Play
 
 AudioAnalyser::~AudioAnalyser ()
 {
-       delete[] _current;
        for (auto i: _filters) {
                delete const_cast<Filter*> (i);
        }
-       delete[] _sample_peak;
-       delete[] _sample_peak_frame;
 }