diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-02-25 00:11:49 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-02-25 00:11:49 +0000 |
| commit | 040a227d300033f8a103dc6eb67847286131d9b7 (patch) | |
| tree | 54093eaad6186817d1ee744d3f299f93ea49b475 /src | |
| parent | dcd968d6d64d645816af0efbcd2f928128c95b9f (diff) | |
Some tidying up, add channel selector to Audio dialog.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/analyse_audio_job.cc | 14 | ||||
| -rw-r--r-- | src/lib/analyse_audio_job.h | 1 | ||||
| -rw-r--r-- | src/lib/ffmpeg_decoder.cc | 2 | ||||
| -rw-r--r-- | src/lib/util.cc | 20 | ||||
| -rw-r--r-- | src/lib/util.h | 1 | ||||
| -rw-r--r-- | src/wx/audio_dialog.cc | 68 | ||||
| -rw-r--r-- | src/wx/audio_dialog.h | 24 | ||||
| -rw-r--r-- | src/wx/audio_plot.cc | 44 | ||||
| -rw-r--r-- | src/wx/audio_plot.h | 5 | ||||
| -rw-r--r-- | src/wx/film_editor.cc | 32 | ||||
| -rw-r--r-- | src/wx/film_editor.h | 3 |
11 files changed, 172 insertions, 42 deletions
diff --git a/src/lib/analyse_audio_job.cc b/src/lib/analyse_audio_job.cc index 190d2a5d9..fb5f2868f 100644 --- a/src/lib/analyse_audio_job.cc +++ b/src/lib/analyse_audio_job.cc @@ -27,13 +27,13 @@ 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; + } } diff --git a/src/lib/analyse_audio_job.h b/src/lib/analyse_audio_job.h index 1e7229ce6..dc1e073ee 100644 --- a/src/lib/analyse_audio_job.h +++ b/src/lib/analyse_audio_job.h @@ -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; diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 58c7317ac..148764162 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -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; } diff --git a/src/lib/util.cc b/src/lib/util.cc index 4ee304600..f807bf329 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -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]; +} diff --git a/src/lib/util.h b/src/lib/util.h index 87735ea8e..b76aead41 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -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; diff --git a/src/wx/audio_dialog.cc b/src/wx/audio_dialog.cc index 7f87ee5fd..11efc153c 100644 --- a/src/wx/audio_dialog.cc +++ b/src/wx/audio_dialog.cc @@ -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 ()); +} diff --git a/src/wx/audio_dialog.h b/src/wx/audio_dialog.h index 324a1ec99..1e4563972 100644 --- a/src/wx/audio_dialog.h +++ b/src/wx/audio_dialog.h @@ -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; }; diff --git a/src/wx/audio_plot.cc b/src/wx/audio_plot.cc index 4fda3227d..cc2d8f6b4 100644 --- a/src/wx/audio_plot.cc +++ b/src/wx/audio_plot.cc @@ -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,10 +33,9 @@ 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); @@ -25,9 +43,29 @@ AudioPlot::AudioPlot (wxWindow* parent, shared_ptr<AudioAnalysis> a, int c) } 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; diff --git a/src/wx/audio_plot.h b/src/wx/audio_plot.h index 565997f7e..03bd79323 100644 --- a/src/wx/audio_plot.h +++ b/src/wx/audio_plot.h @@ -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 &); diff --git a/src/wx/film_editor.cc b/src/wx/film_editor.cc index 0a9b6d87c..725f2d1b3 100644 --- a/src/wx/film_editor.cc +++ b/src/wx/film_editor.cc @@ -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 (); } diff --git a/src/wx/film_editor.h b/src/wx/film_editor.h index bd0300aed..2af747bb0 100644 --- a/src/wx/film_editor.h +++ b/src/wx/film_editor.h @@ -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; }; |
