Speed up content selection when we have audio analysis files (#2247).
authorCarl Hetherington <cth@carlh.net>
Sun, 8 May 2022 21:24:51 +0000 (23:24 +0200)
committerCarl Hetherington <cth@carlh.net>
Sun, 8 May 2022 21:25:42 +0000 (23:25 +0200)
src/wx/audio_panel.cc
src/wx/audio_panel.h

index f25af27f740f231fbbf36a961f05f422b5a198f8..7efdeb8ac88de1acd7c63cda135f8d0f87db6b01 100644 (file)
@@ -57,6 +57,9 @@ using namespace boost::placeholders;
 using namespace dcpomatic;
 
 
+std::map<boost::filesystem::path, float> AudioPanel::_peak_cache;
+
+
 AudioPanel::AudioPanel (ContentPanel* p)
        : ContentSubPanel (p, _("Audio"))
 {
@@ -445,8 +448,18 @@ AudioPanel::peak () const
                auto playlist = make_shared<Playlist>();
                playlist->add (_parent->film(), sel.front());
                try {
-                       auto analysis = make_shared<AudioAnalysis>(_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<AudioAnalysis>(path);
+                               peak_dB = linear_to_db(analysis->overall_sample_peak().first.peak) + analysis->gain_correction(playlist);
+                               _peak_cache[path] = *peak_dB;
+                       }
                } catch (...) {
 
                }
index 213ad4cb7db23384ef100d880492a219255b34a0..e3a29495512b740312094237c977b478b5329f32 100644 (file)
@@ -83,4 +83,6 @@ private:
 
        boost::signals2::scoped_connection _mapping_connection;
        boost::signals2::scoped_connection _active_jobs_connection;
+
+       static std::map<boost::filesystem::path, float> _peak_cache;
 };