+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.
#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>
using std::max;
using std::list;
using boost::shared_ptr;
+using boost::dynamic_pointer_cast;
AudioAnalysis::AudioAnalysis (int channels)
{
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;
+}
class Element;
}
+class Playlist;
+
class AudioAnalysis : public boost::noncopyable
{
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;
}
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);
);
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 ();
}
_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 */
/* 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 ();
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 (
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;
-}
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;
*/
-#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>
using boost::dynamic_pointer_cast;
using boost::lexical_cast;
using boost::shared_ptr;
+using boost::optional;
AudioPanel::AudioPanel (ContentPanel* p)
: ContentSubPanel (p, _("Audio"))
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> (
_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 ()
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 ();
_mapping->set (AudioMapping ());
}
setup_description ();
+ setup_peak ();
_sizer->Layout ();
+ } else if (property == AudioContentProperty::AUDIO_GAIN) {
+ setup_peak ();
}
}
_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 ();
+ }
+}
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;
_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> ());
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 ();