From 1c9a65e90d05f02e1fd4914268435a9c2274459e Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 8 May 2022 23:24:51 +0200 Subject: [PATCH] Speed up content selection when we have audio analysis files (#2247). --- src/wx/audio_panel.cc | 17 +++++++++++++++-- src/wx/audio_panel.h | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/wx/audio_panel.cc b/src/wx/audio_panel.cc index f25af27f7..7efdeb8ac 100644 --- a/src/wx/audio_panel.cc +++ b/src/wx/audio_panel.cc @@ -57,6 +57,9 @@ using namespace boost::placeholders; using namespace dcpomatic; +std::map AudioPanel::_peak_cache; + + AudioPanel::AudioPanel (ContentPanel* p) : ContentSubPanel (p, _("Audio")) { @@ -445,8 +448,18 @@ AudioPanel::peak () const auto playlist = make_shared(); playlist->add (_parent->film(), sel.front()); try { - auto analysis = make_shared(_parent->film()->audio_analysis_path(playlist)); - peak_dB = linear_to_db(analysis->overall_sample_peak().first.peak) + analysis->gain_correction(playlist); + /* Loading the audio analysis file is slow, and this ::peak() is called a few times when + * the content selection is changed, so cache it. + */ + auto const path = _parent->film()->audio_analysis_path(playlist); + auto cached = _peak_cache.find(path); + if (cached != _peak_cache.end()) { + peak_dB = cached->second; + } else { + auto analysis = make_shared(path); + peak_dB = linear_to_db(analysis->overall_sample_peak().first.peak) + analysis->gain_correction(playlist); + _peak_cache[path] = *peak_dB; + } } catch (...) { } diff --git a/src/wx/audio_panel.h b/src/wx/audio_panel.h index 213ad4cb7..e3a294955 100644 --- a/src/wx/audio_panel.h +++ b/src/wx/audio_panel.h @@ -83,4 +83,6 @@ private: boost::signals2::scoped_connection _mapping_connection; boost::signals2::scoped_connection _active_jobs_connection; + + static std::map _peak_cache; }; -- 2.30.2