Some tidying up, add channel selector to Audio dialog.
authorCarl Hetherington <cth@carlh.net>
Mon, 25 Feb 2013 00:11:49 +0000 (00:11 +0000)
committerCarl Hetherington <cth@carlh.net>
Mon, 25 Feb 2013 00:11:49 +0000 (00:11 +0000)
src/lib/analyse_audio_job.cc
src/lib/analyse_audio_job.h
src/lib/ffmpeg_decoder.cc
src/lib/util.cc
src/lib/util.h
src/wx/audio_dialog.cc
src/wx/audio_dialog.h
src/wx/audio_plot.cc
src/wx/audio_plot.h
src/wx/film_editor.cc
src/wx/film_editor.h

index 190d2a5d96ace73ae7b34dccdbab876cd3333859..fb5f2868f33e9f82a79c595afdca736a33cc23f9 100644 (file)
 
 using std::string;
 using std::max;
+using std::cout;
 using boost::shared_ptr;
 
-int const AnalyseAudioJob::_num_points = 1024;
+int const AnalyseAudioJob::_num_points = 128;
 
 AnalyseAudioJob::AnalyseAudioJob (shared_ptr<Film> f)
        : Job (f)
-       , _done_for_this_point (0)
        , _done (0)
        , _samples_per_point (1)
 {
@@ -94,20 +94,16 @@ AnalyseAudioJob::audio (shared_ptr<AudioBuffers> b)
                        _current[j][AudioPoint::RMS] += pow (s, 2);
                        _current[j][AudioPoint::PEAK] = max (_current[j][AudioPoint::PEAK], fabsf (s));
 
-                       if (_done_for_this_point == _samples_per_point) {
+                       if ((_done % _samples_per_point) == 0) {
                                _current[j][AudioPoint::RMS] = 20 * log10 (sqrt (_current[j][AudioPoint::RMS] / _samples_per_point));
                                _current[j][AudioPoint::PEAK] = 20 * log10 (_current[j][AudioPoint::PEAK]);
-                               
                                _analysis->add_point (j, _current[j]);
                                
-                               _done_for_this_point = 0;
                                _current[j] = AudioPoint ();
                        }
                }
-               
-               ++_done_for_this_point;
-       }
 
-       _done += b->frames ();
+               ++_done;
+       }
 }
 
index 1e7229ce61dc6f67de38e49ee40966e8c2e23b99..dc1e073ee15a031552dc3975572ad2c8d9f97b2b 100644 (file)
@@ -33,7 +33,6 @@ public:
 private:
        void audio (boost::shared_ptr<AudioBuffers>);
 
-       int64_t _done_for_this_point;
        int64_t _done;
        int64_t _samples_per_point;
        std::vector<AudioPoint> _current;
index 58c7317ac49700c1f792a52f97ddbe409e0e9606..148764162c20fe70bfdd9d4be2e7ed96faaf8d57 100644 (file)
@@ -197,7 +197,7 @@ FFmpegDecoder::setup_audio ()
 void
 FFmpegDecoder::setup_subtitle ()
 {
-       if (!_subtitle_stream) {
+       if (!_subtitle_stream || _subtitle_stream->id() >= _format_context->nb_streams) {
                return;
        }
 
index 4ee304600f0d368cbba0acd367b7cc0eaa03c60b..f807bf32936a04b5100ff906d85b1c79973c92d3 100644 (file)
@@ -898,3 +898,23 @@ cpu_info ()
 
        return info;
 }
+
+string
+audio_channel_name (int c)
+{
+       assert (MAX_AUDIO_CHANNELS == 6);
+
+       /* TRANSLATORS: these are the names of audio channels; Lfe (sub) is the low-frequency
+          enhancement channel (sub-woofer)./
+       */
+       string const channels[] = {
+               "Left",
+               "Right",
+               "Centre",
+               "Lfe (sub)",
+               "Left surround",
+               "Right surround",
+       };
+
+       return channels[c];
+}
index 87735ea8e82b8bc27e77b17515da26eedc8155ee..b76aead41fcc127305a2ba8bf9a7f3a8bda20d13 100644 (file)
@@ -57,6 +57,7 @@ extern std::vector<std::string> split_at_spaces_considering_quotes (std::string)
 extern std::string md5_digest (std::string);
 extern std::string md5_digest (void const *, int);
 extern void ensure_ui_thread ();
+extern std::string audio_channel_name (int);
 
 typedef int SourceFrame;
 
index 7f87ee5fd4ee6b19b60940589c13b5051e22ae73..11efc153c69c13e8c5a38c2d7f1395c4b2f17458 100644 (file)
@@ -1,27 +1,79 @@
+/*
+    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
 #include "audio_dialog.h"
 #include "audio_plot.h"
 #include "audio_analysis.h"
 #include "film.h"
+#include "wx_util.h"
 
 using boost::shared_ptr;
 
 AudioDialog::AudioDialog (wxWindow* parent, boost::shared_ptr<Film> film)
        : wxDialog (parent, wxID_ANY, _("Audio"), wxDefaultPosition, wxSize (640, 512), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
+       , _plot (0)
 {
-       wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
+       wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
+
+       _plot = new AudioPlot (this);
+       sizer->Add (_plot, 1);
+
+       wxFlexGridSizer* table = new wxFlexGridSizer (2, 6, 6);
+
+       add_label_to_sizer (table, this, _("Channel"));
+       _channel = new wxChoice (this, wxID_ANY);
+       table->Add (_channel, 1, wxEXPAND | wxALL, 6);
+
+       sizer->Add (table);
+
+       set_film (film);
+
+       SetSizer (sizer);
+       sizer->Layout ();
+       sizer->SetSizeHints (this);
+
+       _channel->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (AudioDialog::channel_changed), 0, this);
+}
 
+void
+AudioDialog::set_film (boost::shared_ptr<Film> f)
+{
        shared_ptr<AudioAnalysis> a;
-       
+
        try {
-               a.reset (new AudioAnalysis (film->audio_analysis_path ()));
-               _plot = new AudioPlot (this, a, 0);
-               sizer->Add (_plot, 1);
+               a.reset (new AudioAnalysis (f->audio_analysis_path ()));
        } catch (...) {
+
+       }
                
+       _plot->set_analysis (a);
+
+       _channel->Clear ();
+       for (int i = 0; i < f->audio_stream()->channels(); ++i) {
+               _channel->Append (audio_channel_name (i));
        }
 
-       SetSizer (sizer);
-       sizer->Layout ();
-       sizer->SetSizeHints (this);
+       _channel->SetSelection (0);
 }
 
+void
+AudioDialog::channel_changed (wxCommandEvent &)
+{
+       _plot->set_channel (_channel->GetSelection ());
+}
index 324a1ec9955f473b9d13eaa41e3834e794e29bb2..1e4563972f095fd0d16da554cfaf5b9aac560fd3 100644 (file)
@@ -1,3 +1,22 @@
+/*
+    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
 #include <boost/shared_ptr.hpp>
 #include <wx/wx.h>
 
@@ -9,6 +28,11 @@ class AudioDialog : public wxDialog
 public:
        AudioDialog (wxWindow *, boost::shared_ptr<Film>);
 
+       void set_film (boost::shared_ptr<Film>);
+
 private:
+       void channel_changed (wxCommandEvent &);
+       
        AudioPlot* _plot;
+       wxChoice* _channel;
 };
index 4fda3227d336c0c975a9c7e5a9d716e283c76f30..cc2d8f6b428785f513ec9be74a478b2105608ef6 100644 (file)
@@ -1,3 +1,22 @@
+/*
+    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
 #include <iostream>
 #include <boost/bind.hpp>
 #include <wx/graphics.h>
@@ -14,20 +33,39 @@ using std::min;
 using boost::bind;
 using boost::shared_ptr;
 
-AudioPlot::AudioPlot (wxWindow* parent, shared_ptr<AudioAnalysis> a, int c)
+AudioPlot::AudioPlot (wxWindow* parent)
        : wxPanel (parent)
-       , _analysis (a)
-       , _channel (c)
+       , _channel (0)
 {
        Connect (wxID_ANY, wxEVT_PAINT, wxPaintEventHandler (AudioPlot::paint), 0, this);
 
        SetMinSize (wxSize (640, 512));
 }
 
+void
+AudioPlot::set_analysis (shared_ptr<AudioAnalysis> a)
+{
+       _analysis = a;
+       _channel = 0;
+       Refresh ();
+}
+
+void
+AudioPlot::set_channel (int c)
+{
+       _channel = c;
+       Refresh ();
+}
+
 void
 AudioPlot::paint (wxPaintEvent &)
 {
        wxPaintDC dc (this);
+
+       if (!_analysis) {
+               return;
+       }
+       
        wxGraphicsContext* gc = wxGraphicsContext::Create (dc);
        if (!gc) {
                return;
index 565997f7e3490ec9736af183f38647bb350c560b..03bd793233bfb80409347331de46dbe6aca2d471 100644 (file)
@@ -26,7 +26,10 @@ class AudioAnalysis;
 class AudioPlot : public wxPanel
 {
 public:
-       AudioPlot (wxWindow *, boost::shared_ptr<AudioAnalysis>, int);
+       AudioPlot (wxWindow *);
+
+       void set_analysis (boost::shared_ptr<AudioAnalysis>);
+       void set_channel (int c);
 
 private:
        void paint (wxPaintEvent &);
index 0a9b6d87c0ff0b6c7133dca7102aa69cfe961770..725f2d1b3c517f2dd4178fee92a20cc380798514 100644 (file)
@@ -63,6 +63,7 @@ FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
        : wxPanel (parent)
        , _film (f)
        , _generally_sensitive (true)
+       , _audio_dialog (0)
 {
        wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
        SetSizer (s);
@@ -346,22 +347,8 @@ FilmEditor::make_audio_panel ()
        grid->Add (_use_external_audio);
        grid->AddSpacer (0);
 
-       assert (MAX_AUDIO_CHANNELS == 6);
-
-       /* TRANSLATORS: these are the names of audio channels; Lfe (sub) is the low-frequency
-          enhancement channel (sub-woofer)./
-       */
-       wxString const channels[] = {
-               _("Left"),
-               _("Right"),
-               _("Centre"),
-               _("Lfe (sub)"),
-               _("Left surround"),
-               _("Right surround"),
-       };
-
        for (int i = 0; i < MAX_AUDIO_CHANNELS; ++i) {
-               add_label_to_sizer (grid, _audio_panel, channels[i]);
+               add_label_to_sizer (grid, _audio_panel, audio_channel_name (i));
                _external_audio[i] = new wxFilePickerCtrl (_audio_panel, wxID_ANY, wxT (""), _("Select Audio File"), wxT ("*.wav"));
                grid->Add (_external_audio[i], 1, wxEXPAND);
        }
@@ -762,6 +749,10 @@ FilmEditor::set_film (shared_ptr<Film> f)
        } else {
                FileChanged ("");
        }
+
+       if (_audio_dialog) {
+               _audio_dialog->set_film (_film);
+       }
        
        film_changed (Film::NAME);
        film_changed (Film::USE_DCI_NAME);
@@ -823,6 +814,7 @@ FilmEditor::set_things_sensitive (bool s)
        _j2k_bandwidth->Enable (s);
        _audio_gain->Enable (s);
        _audio_gain_calculate_button->Enable (s);
+       _show_audio->Enable (s);
        _audio_delay->Enable (s);
        _still_duration->Enable (s);
 
@@ -1185,7 +1177,11 @@ FilmEditor::setup_dcp_name ()
 void
 FilmEditor::show_audio_clicked (wxCommandEvent &)
 {
-       AudioDialog* d = new AudioDialog (this, _film);
-       d->ShowModal ();
-       d->Destroy ();
+       if (_audio_dialog) {
+               _audio_dialog->Destroy ();
+               _audio_dialog = 0;
+       }
+       
+       _audio_dialog = new AudioDialog (this, _film);
+       _audio_dialog->Show ();
 }
index bd0300aed6c5e9efd7fde7a35729b2008039ab58..2af747bb0447f35e2d4e666626f5f8c4b37173f1 100644 (file)
@@ -29,8 +29,8 @@
 #include "lib/film.h"
 
 class wxNotebook;
-
 class Film;
+class AudioDialog;
 
 /** @class FilmEditor
  *  @brief A wx widget to edit a film's metadata, and perform various functions.
@@ -179,4 +179,5 @@ private:
        std::vector<Format const *> _formats;
 
        bool _generally_sensitive;
+       AudioDialog* _audio_dialog;
 };