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)
{
_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;
+ }
}
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;
void
FFmpegDecoder::setup_subtitle ()
{
- if (!_subtitle_stream) {
+ if (!_subtitle_stream || _subtitle_stream->id() >= _format_context->nb_streams) {
return;
}
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];
+}
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;
+/*
+ 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 ());
+}
+/*
+ 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>
public:
AudioDialog (wxWindow *, boost::shared_ptr<Film>);
+ void set_film (boost::shared_ptr<Film>);
+
private:
+ void channel_changed (wxCommandEvent &);
+
AudioPlot* _plot;
+ wxChoice* _channel;
};
+/*
+ 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>
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;
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 &);
: wxPanel (parent)
, _film (f)
, _generally_sensitive (true)
+ , _audio_dialog (0)
{
wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
SetSizer (s);
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);
}
} else {
FileChanged ("");
}
+
+ if (_audio_dialog) {
+ _audio_dialog->set_film (_film);
+ }
film_changed (Film::NAME);
film_changed (Film::USE_DCI_NAME);
_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);
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 ();
}
#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.
std::vector<Format const *> _formats;
bool _generally_sensitive;
+ AudioDialog* _audio_dialog;
};