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 26df71b..14dd81d 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 6fcd97c..10e0223 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 5e71705..0d06e59 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 3748fa3..0597983 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 7de7862..560b5ca 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 d4108f8..27b3454 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 945ff01..c992611 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 4b6167b..adaf826 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 e4ccfaf..00b0644 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 b67c961..6d60772 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 f00cdfe..9241729 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 ();