Peak value of audio into the audio tab.
authorCarl Hetherington <cth@carlh.net>
Thu, 3 Sep 2015 12:52:10 +0000 (13:52 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 14 Sep 2015 09:21:11 +0000 (10:21 +0100)
ChangeLog
src/lib/audio_analysis.cc
src/lib/audio_analysis.h
src/lib/job_manager.cc
src/lib/job_manager.h
src/wx/audio_dialog.cc
src/wx/audio_dialog.h
src/wx/audio_panel.cc
src/wx/audio_panel.h
src/wx/film_editor.cc
src/wx/film_viewer.cc

index 26df71b7b0699511ce1857e52f92e4dd96874626..14dd81da6c354542dbcc79f85cfb99fb4b4b4c13 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2015-09-03  c.hetherington  <cth@carlh.net>
+
+       * Add option to always analyse audio
+       and put the peak value into the audio
+       tab so it's easy to see (#673).
+
 2015-09-14  Carl Hetherington  <cth@carlh.net>
 
        * Version 2.2.0 released.
index 6fcd97c94e654fecdb2c75e9d78e196f1c4dd7c9..10e02232292c30f9dbf17975f49a8c0e88d388d4 100644 (file)
@@ -21,6 +21,8 @@
 #include "cross.h"
 #include "util.h"
 #include "raw_convert.h"
+#include "playlist.h"
+#include "audio_content.h"
 #include <libxml++/libxml++.h>
 #include <boost/filesystem.hpp>
 #include <boost/foreach.hpp>
@@ -38,6 +40,7 @@ using std::cout;
 using std::max;
 using std::list;
 using boost::shared_ptr;
+using boost::dynamic_pointer_cast;
 
 AudioAnalysis::AudioAnalysis (int channels)
 {
@@ -115,3 +118,19 @@ AudioAnalysis::write (boost::filesystem::path filename)
 
        doc->write_to_file_formatted (filename.string ());
 }
+
+float
+AudioAnalysis::gain_correction (shared_ptr<const Playlist> playlist)
+{
+       if (playlist->content().size() == 1 && analysis_gain ()) {
+               /* In this case we know that the analysis was of a single piece of content and
+                  we know that content's gain when the analysis was run.  Hence we can work out
+                  what correction is now needed to make it look `right'.
+               */
+               shared_ptr<const AudioContent> ac = dynamic_pointer_cast<const AudioContent> (playlist->content().front ());
+               DCPOMATIC_ASSERT (ac);
+               return ac->audio_gain() - analysis_gain().get ();
+       }
+
+       return 0.0f;
+}
index 5e71705bf3b2dbb25e1ce2ce038e41a4401b28a5..0d06e5973eca297bcf6d6e4f1240059ab2b68691 100644 (file)
@@ -31,6 +31,8 @@ namespace xmlpp {
        class Element;
 }
 
+class Playlist;
+
 class AudioAnalysis : public boost::noncopyable
 {
 public:
@@ -65,6 +67,8 @@ public:
 
        void write (boost::filesystem::path);
 
+       float gain_correction (boost::shared_ptr<const Playlist> playlist);
+
 private:
        std::vector<std::vector<AudioPoint> > _data;
        boost::optional<float> _peak;
index 3748fa3537b7e972fb5f31b5a65ca026466e78a3..0597983db355ddb7855310fa708ca916683f9608 100644 (file)
@@ -146,8 +146,8 @@ JobManager::scheduler ()
                }
 
                if (active_job != _last_active_job) {
+                       emit (boost::bind (boost::ref (ActiveJobsChanged), _last_active_job, active_job));
                        _last_active_job = active_job;
-                       emit (boost::bind (boost::ref (ActiveJobsChanged), active_job));
                }
 
                dcpomatic_sleep (1);
index 7de7862a18bd2ff7bfc929462d184279d8c8bfb3..560b5ca66c15d8ca9cf8c4840592a1a404bc8cff 100644 (file)
@@ -53,7 +53,7 @@ public:
                );
 
        boost::signals2::signal<void (boost::weak_ptr<Job>)> JobAdded;
-       boost::signals2::signal<void (boost::optional<std::string>)> ActiveJobsChanged;
+       boost::signals2::signal<void (boost::optional<std::string>, boost::optional<std::string>)> ActiveJobsChanged;
 
        static JobManager* instance ();
        static void drop ();
index d4108f89c32aeffadf6136320c1d14693227c999..27b34540611dd76cf94a0af46b1649022e1efe20 100644 (file)
@@ -150,7 +150,7 @@ AudioDialog::try_to_load_analysis ()
         }
 
        _plot->set_analysis (_analysis);
-       _plot->set_gain_correction (gain_correction ());
+       _plot->set_gain_correction (_analysis->gain_correction (_playlist));
        setup_peak_time ();
 
        /* Set up some defaults if no check boxes are checked */
@@ -220,7 +220,7 @@ AudioDialog::content_changed (int p)
                        /* We can use a short-cut to render the effect of this
                           change, rather than recalculating everything.
                        */
-                       _plot->set_gain_correction (gain_correction ());
+                       _plot->set_gain_correction (_analysis->gain_correction (_playlist));
                        setup_peak_time ();
                } else {
                        try_to_load_analysis ();
@@ -259,7 +259,7 @@ AudioDialog::setup_peak_time ()
                return;
        }
 
-       float const peak_dB = 20 * log10 (_analysis->peak().get()) + gain_correction ();
+       float const peak_dB = 20 * log10 (_analysis->peak().get()) + _analysis->gain_correction (_playlist);
 
        _peak_time->SetLabel (
                wxString::Format (
@@ -283,22 +283,3 @@ AudioDialog::Show (bool show)
        try_to_load_analysis ();
        return r;
 }
-
-/** @return gain correction in dB required to be added to raw gain values to render
- *  the dialog correctly.
- */
-float
-AudioDialog::gain_correction ()
-{
-       if (_playlist->content().size() == 1 && _analysis->analysis_gain ()) {
-               /* In this case we know that the analysis was of a single piece of content and
-                  we know that content's gain when the analysis was run.  Hence we can work out
-                  what correction is now needed to make it look `right'.
-               */
-               shared_ptr<const AudioContent> ac = dynamic_pointer_cast<const AudioContent> (_playlist->content().front ());
-               DCPOMATIC_ASSERT (ac);
-               return ac->audio_gain() - _analysis->analysis_gain().get ();
-       }
-
-       return 0.0f;
-}
index 945ff013b8c847f64c781e7b9657a4e56ef698c9..c99261150dda24da1bfbc670d2b67e0f78e0c4e2 100644 (file)
@@ -42,7 +42,6 @@ private:
        void try_to_load_analysis ();
        void analysis_finished ();
        void setup_peak_time ();
-       float gain_correction ();
 
        boost::shared_ptr<AudioAnalysis> _analysis;
        boost::weak_ptr<Film> _film;
index 4b6167bf7fba781f5bdc40f42df9d755c5cd1c32..adaf826f453af12a69de3c815e4ddcee43fb1e86 100644 (file)
 
 */
 
-#include "lib/config.h"
-#include "lib/ffmpeg_content.h"
-#include "lib/cinema_sound_processor.h"
 #include "audio_panel.h"
 #include "audio_mapping_view.h"
 #include "wx_util.h"
 #include "gain_calculator_dialog.h"
 #include "content_panel.h"
 #include "audio_dialog.h"
+#include "lib/config.h"
+#include "lib/ffmpeg_content.h"
+#include "lib/cinema_sound_processor.h"
+#include "lib/job_manager.h"
 #include <wx/spinctrl.h>
 #include <boost/lexical_cast.hpp>
 #include <boost/foreach.hpp>
@@ -38,6 +39,7 @@ using std::pair;
 using boost::dynamic_pointer_cast;
 using boost::lexical_cast;
 using boost::shared_ptr;
+using boost::optional;
 
 AudioPanel::AudioPanel (ContentPanel* p)
        : ContentSubPanel (p, _("Audio"))
@@ -48,9 +50,15 @@ AudioPanel::AudioPanel (ContentPanel* p)
 
        int r = 0;
 
-       _show = new wxButton (this, wxID_ANY, _("Show graph of audio levels..."));
-       grid->Add (_show, wxGBPosition (r, 0), wxGBSpan (1, 2));
-       ++r;
+       {
+               wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
+               _show = new wxButton (this, wxID_ANY, _("Show graph of audio levels..."));
+               s->Add (_show);
+               _peak = new wxStaticText (this, wxID_ANY, wxT (""));
+               s->Add (_peak, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
+               grid->Add (s, wxGBPosition (r, 0), wxGBSpan (1, 2));
+               ++r;
+       }
 
        add_label_to_grid_bag_sizer (grid, this, _("Gain"), true, wxGBPosition (r, 0));
        _gain = new ContentSpinCtrlDouble<AudioContent> (
@@ -102,6 +110,8 @@ AudioPanel::AudioPanel (ContentPanel* p)
        _gain_calculate_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&AudioPanel::gain_calculate_button_clicked, this));
 
        _mapping_connection = _mapping->Changed.connect (boost::bind (&AudioPanel::mapping_changed, this, _1));
+
+       JobManager::instance()->ActiveJobsChanged.connect (boost::bind (&AudioPanel::active_jobs_changed, this, _1));
 }
 
 AudioPanel::~AudioPanel ()
@@ -119,6 +129,7 @@ AudioPanel::film_changed (Film::Property property)
        case Film::AUDIO_CHANNELS:
        case Film::AUDIO_PROCESSOR:
                _mapping->set_output_channels (_parent->film()->audio_output_names ());
+               setup_peak ();
                break;
        case Film::VIDEO_FRAME_RATE:
                setup_description ();
@@ -140,7 +151,10 @@ AudioPanel::film_content_changed (int property)
                        _mapping->set (AudioMapping ());
                }
                setup_description ();
+               setup_peak ();
                _sizer->Layout ();
+       } else if (property == AudioContentProperty::AUDIO_GAIN) {
+               setup_peak ();
        }
 }
 
@@ -221,3 +235,47 @@ AudioPanel::show_clicked ()
        _audio_dialog = new AudioDialog (this, _parent->film (), ac.front ());
        _audio_dialog->Show ();
 }
+
+void
+AudioPanel::setup_peak ()
+{
+       AudioContentList sel = _parent->selected_audio ();
+       bool alert = false;
+
+       if (sel.size() != 1) {
+               _peak->SetLabel (wxT (""));
+       } else {
+               shared_ptr<Playlist> playlist (new Playlist);
+               playlist->add (sel.front ());
+               try {
+                       shared_ptr<AudioAnalysis> analysis (new AudioAnalysis (_parent->film()->audio_analysis_path (playlist)));
+                       if (analysis->peak ()) {
+                               float const peak_dB = 20 * log10 (analysis->peak().get()) + analysis->gain_correction (playlist);
+                               if (peak_dB > -3) {
+                                       alert = true;
+                               }
+                               _peak->SetLabel (wxString::Format (_("Peak: %.2fdB"), peak_dB));
+                       } else {
+                               _peak->SetLabel (_("Peak: unknown"));
+                       }
+               } catch (...) {
+                       _peak->SetLabel (_("Peak: unknown"));
+               }
+       }
+
+       static wxColour normal = _peak->GetForegroundColour ();
+
+       if (alert) {
+               _peak->SetForegroundColour (wxColour (255, 0, 0));
+       } else {
+               _peak->SetForegroundColour (normal);
+       }
+}
+
+void
+AudioPanel::active_jobs_changed (optional<string> j)
+{
+       if (j && *j == "analyse_audio") {
+               setup_peak ();
+       }
+}
index e4ccfaf3d7143fe881d3019879d58f35a4fffbc1..00b06442e75dc7a56ee9aeda498257f7ec75eb21 100644 (file)
@@ -43,10 +43,13 @@ private:
        void gain_calculate_button_clicked ();
        void mapping_changed (AudioMapping);
        void setup_description ();
+       void setup_peak ();
+       void active_jobs_changed (boost::optional<std::string>);
 
        wxButton* _show;
        ContentSpinCtrlDouble<AudioContent>* _gain;
        wxButton* _gain_calculate_button;
+       wxStaticText* _peak;
        ContentSpinCtrl<AudioContent>* _delay;
        AudioMappingView* _mapping;
        wxStaticText* _description;
index b67c9612dbb765e4eeaa67070f1e0693712e89d3..6d60772be0f2dc805ff88ca565a3114f3f90f602 100644 (file)
@@ -53,7 +53,7 @@ FilmEditor::FilmEditor (wxWindow* parent, FilmViewer* viewer)
        _main_notebook->AddPage (_dcp_panel->panel (), _("DCP"), false);
 
        JobManager::instance()->ActiveJobsChanged.connect (
-               bind (&FilmEditor::active_jobs_changed, this, _1)
+               bind (&FilmEditor::active_jobs_changed, this, _2)
                );
 
        set_film (shared_ptr<Film> ());
index f00cdfe28ae8ee910940c8d185f541a8cf146792..9241729708a2cee57c6149a88b78c23071c2cf00 100644 (file)
@@ -114,7 +114,7 @@ FilmViewer::FilmViewer (wxWindow* p)
        set_film (shared_ptr<Film> ());
 
        JobManager::instance()->ActiveJobsChanged.connect (
-               bind (&FilmViewer::active_jobs_changed, this, _1)
+               bind (&FilmViewer::active_jobs_changed, this, _2)
                );
 
        setup_sensitivity ();