summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-05-10 00:15:44 +0100
committerCarl Hetherington <cth@carlh.net>2015-05-10 00:15:44 +0100
commitfc96a4b3d6985f28db6bc0e9418e98cc5bec87e3 (patch)
treee6866c8006ccf4fb400bfb8e8481a4f1142fb2e3 /src
parent55002ca15ba288002aeedf3867fb9d07b7b653f0 (diff)
7fd73c0cf1f723896826c77fec3720c5c404d4e8 from master; tidy audio analysis dialogue and add overall peak.
Diffstat (limited to 'src')
-rw-r--r--src/lib/analyse_audio_job.cc14
-rw-r--r--src/lib/analyse_audio_job.h3
-rw-r--r--src/lib/audio_analysis.cc16
-rw-r--r--src/lib/audio_analysis.h18
-rw-r--r--src/wx/audio_dialog.cc73
-rw-r--r--src/wx/audio_dialog.h6
-rw-r--r--src/wx/audio_panel.cc2
-rw-r--r--src/wx/film_viewer.cc11
-rw-r--r--src/wx/wx_util.cc14
-rw-r--r--src/wx/wx_util.h2
10 files changed, 130 insertions, 29 deletions
diff --git a/src/lib/analyse_audio_job.cc b/src/lib/analyse_audio_job.cc
index 079fe884e..cdf623876 100644
--- a/src/lib/analyse_audio_job.cc
+++ b/src/lib/analyse_audio_job.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2015 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
@@ -39,6 +39,8 @@ AnalyseAudioJob::AnalyseAudioJob (shared_ptr<const Film> f, shared_ptr<AudioCont
, _content (c)
, _done (0)
, _samples_per_point (1)
+ , _overall_peak (0)
+ , _overall_peak_frame (0)
{
}
@@ -81,6 +83,7 @@ AnalyseAudioJob::run ()
set_progress (t.seconds() / _film->length().seconds());
}
+ _analysis->set_peak (_overall_peak, DCPTime::from_frames (_overall_peak_frame, _film->audio_frame_rate ()));
_analysis->write (content->audio_analysis_path ());
set_progress (1);
@@ -101,6 +104,15 @@ AnalyseAudioJob::analyse (shared_ptr<const AudioBuffers> b)
_current[j][AudioPoint::RMS] += pow (s, 2);
_current[j][AudioPoint::PEAK] = max (_current[j][AudioPoint::PEAK], fabsf (s));
+ float const as = fabs (s);
+
+ _current[j][AudioPoint::PEAK] = max (_current[j][AudioPoint::PEAK], as);
+
+ if (as > _overall_peak) {
+ _overall_peak = as;
+ _overall_peak_frame = _done + i;
+ }
+
if ((_done % _samples_per_point) == 0) {
_current[j][AudioPoint::RMS] = sqrt (_current[j][AudioPoint::RMS] / _samples_per_point);
_analysis->add_point (j, _current[j]);
diff --git a/src/lib/analyse_audio_job.h b/src/lib/analyse_audio_job.h
index 6f64dd272..0f9605eed 100644
--- a/src/lib/analyse_audio_job.h
+++ b/src/lib/analyse_audio_job.h
@@ -52,6 +52,9 @@ private:
int64_t _samples_per_point;
std::vector<AudioPoint> _current;
+ float _overall_peak;
+ AudioFrame _overall_peak_frame;
+
boost::shared_ptr<AudioAnalysis> _analysis;
static const int _num_points;
diff --git a/src/lib/audio_analysis.cc b/src/lib/audio_analysis.cc
index 19a0d876e..ee34b0d80 100644
--- a/src/lib/audio_analysis.cc
+++ b/src/lib/audio_analysis.cc
@@ -22,6 +22,7 @@
#include "cross.h"
#include <boost/filesystem.hpp>
#include <stdint.h>
+#include <inttypes.h>
#include <cmath>
#include <cassert>
#include <cstdio>
@@ -115,6 +116,17 @@ AudioAnalysis::AudioAnalysis (boost::filesystem::path filename)
}
}
+ /* These may not exist in old analysis files, so be careful
+ about reading them.
+ */
+
+ float peak;
+ DCPTime::Type peak_time;
+ if (fscanf (f, "%f%" SCNd64, &peak, &peak_time) == 2) {
+ _peak = peak;
+ _peak_time = DCPTime (peak_time);
+ }
+
fclose (f);
}
@@ -164,6 +176,10 @@ AudioAnalysis::write (boost::filesystem::path filename)
}
}
+ if (_peak) {
+ fprintf (f, "%f%" PRId64, _peak.get (), _peak_time.get().get ());
+ }
+
fclose (f);
boost::filesystem::rename (tmp, filename);
}
diff --git a/src/lib/audio_analysis.h b/src/lib/audio_analysis.h
index 865d64781..1872c57ad 100644
--- a/src/lib/audio_analysis.h
+++ b/src/lib/audio_analysis.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2015 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
@@ -24,7 +24,9 @@
#ifndef DCPOMATIC_AUDIO_ANALYSIS_H
#define DCPOMATIC_AUDIO_ANALYSIS_H
+#include "types.h"
#include <boost/filesystem.hpp>
+#include <boost/optional.hpp>
#include <vector>
/** @class AudioPoint
@@ -69,15 +71,29 @@ public:
AudioAnalysis (boost::filesystem::path);
void add_point (int c, AudioPoint const & p);
+ void set_peak (float peak, DCPTime time) {
+ _peak = peak;
+ _peak_time = time;
+ }
AudioPoint get_point (int c, int p) const;
int points (int c) const;
int channels () const;
+ boost::optional<float> peak () const {
+ return _peak;
+ }
+
+ boost::optional<DCPTime> peak_time () const {
+ return _peak_time;
+ }
+
void write (boost::filesystem::path);
private:
std::vector<std::vector<AudioPoint> > _data;
+ boost::optional<float> _peak;
+ boost::optional<DCPTime> _peak_time;
};
#endif
diff --git a/src/wx/audio_dialog.cc b/src/wx/audio_dialog.cc
index 1d41fc185..1ce0f38a8 100644
--- a/src/wx/audio_dialog.cc
+++ b/src/wx/audio_dialog.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2015 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
@@ -29,31 +29,43 @@ using boost::shared_ptr;
using boost::bind;
using boost::optional;
-AudioDialog::AudioDialog (wxWindow* parent)
+AudioDialog::AudioDialog (wxWindow* parent, shared_ptr<Film> film)
: wxDialog (parent, wxID_ANY, _("Audio"), wxDefaultPosition, wxSize (640, 512), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE)
+ , _film (film)
, _plot (0)
{
+ wxFont subheading_font (*wxNORMAL_FONT);
+ subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
+
wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
+
+ wxBoxSizer* left = new wxBoxSizer (wxVERTICAL);
_plot = new AudioPlot (this);
- sizer->Add (_plot, 1, wxALL | wxEXPAND, 12);
+ left->Add (_plot, 1, wxALL | wxEXPAND, 12);
+ _peak_time = new wxStaticText (this, wxID_ANY, wxT (""));
+ left->Add (_peak_time, 0, wxALL, 12);
+
+ sizer->Add (left, 1, wxALL, 12);
- wxBoxSizer* side = new wxBoxSizer (wxVERTICAL);
+ wxBoxSizer* right = new wxBoxSizer (wxVERTICAL);
{
wxStaticText* m = new wxStaticText (this, wxID_ANY, _("Channels"));
- side->Add (m, 1, wxALIGN_CENTER_VERTICAL | wxTOP, 16);
+ m->SetFont (subheading_font);
+ right->Add (m, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM, 16);
}
for (int i = 0; i < MAX_DCP_AUDIO_CHANNELS; ++i) {
_channel_checkbox[i] = new wxCheckBox (this, wxID_ANY, std_to_wx (audio_channel_name (i)));
- side->Add (_channel_checkbox[i], 1, wxEXPAND | wxALL, 3);
+ right->Add (_channel_checkbox[i], 0, wxEXPAND | wxALL, 3);
_channel_checkbox[i]->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&AudioDialog::channel_clicked, this, _1));
}
{
wxStaticText* m = new wxStaticText (this, wxID_ANY, _("Type"));
- side->Add (m, 1, wxALIGN_CENTER_VERTICAL | wxTOP, 16);
+ m->SetFont (subheading_font);
+ right->Add (m, 1, wxALIGN_CENTER_VERTICAL | wxTOP, 16);
}
wxString const types[] = {
@@ -63,20 +75,21 @@ AudioDialog::AudioDialog (wxWindow* parent)
for (int i = 0; i < AudioPoint::COUNT; ++i) {
_type_checkbox[i] = new wxCheckBox (this, wxID_ANY, types[i]);
- side->Add (_type_checkbox[i], 1, wxEXPAND | wxALL, 3);
+ right->Add (_type_checkbox[i], 0, wxEXPAND | wxALL, 3);
_type_checkbox[i]->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&AudioDialog::type_clicked, this, _1));
}
{
wxStaticText* m = new wxStaticText (this, wxID_ANY, _("Smoothing"));
- side->Add (m, 1, wxALIGN_CENTER_VERTICAL | wxTOP, 16);
+ m->SetFont (subheading_font);
+ right->Add (m, 1, wxALIGN_CENTER_VERTICAL | wxTOP, 16);
}
_smoothing = new wxSlider (this, wxID_ANY, AudioPlot::max_smoothing / 2, 1, AudioPlot::max_smoothing);
_smoothing->Bind (wxEVT_SCROLL_THUMBTRACK, boost::bind (&AudioDialog::smoothing_changed, this));
- side->Add (_smoothing, 1, wxEXPAND);
+ right->Add (_smoothing, 0, wxEXPAND);
- sizer->Add (side, 0, wxALL, 12);
+ sizer->Add (right, 0, wxALL, 12);
SetSizer (sizer);
sizer->Layout ();
@@ -107,14 +120,14 @@ AudioDialog::try_to_load_analysis ()
if (!boost::filesystem::exists (_content->audio_analysis_path())) {
_plot->set_analysis (shared_ptr<AudioAnalysis> ());
+ _analysis.reset ();
_analysis_finished_connection = _content->analyse_audio (bind (&AudioDialog::analysis_finished, this));
return;
}
- shared_ptr<AudioAnalysis> a;
-
- a.reset (new AudioAnalysis (_content->audio_analysis_path ()));
- _plot->set_analysis (a);
+ _analysis.reset (new AudioAnalysis (_content->audio_analysis_path ()));
+ _plot->set_analysis (_analysis);
+ setup_peak_time ();
/* Set up some defaults if no check boxes are checked */
@@ -173,6 +186,7 @@ AudioDialog::content_changed (int p)
{
if (p == AudioContentProperty::AUDIO_GAIN) {
_plot->set_gain (_content->audio_gain ());
+ setup_peak_time ();
} else if (p == AudioContentProperty::AUDIO_MAPPING) {
try_to_load_analysis ();
}
@@ -196,3 +210,32 @@ AudioDialog::smoothing_changed ()
{
_plot->set_smoothing (_smoothing->GetValue ());
}
+
+void
+AudioDialog::setup_peak_time ()
+{
+ if (!_analysis || !_analysis->peak ()) {
+ return;
+ }
+
+ shared_ptr<Film> film = _film.lock ();
+ if (!film) {
+ return;
+ }
+
+ float peak_dB = 20 * log10 (_analysis->peak().get()) + _content->audio_gain();
+
+ _peak_time->SetLabel (
+ wxString::Format (
+ _("Peak is %.2fdB at %s"),
+ peak_dB,
+ time_to_timecode (_analysis->peak_time().get(), film->video_frame_rate ()).data ()
+ )
+ );
+
+ if (peak_dB > -3) {
+ _peak_time->SetForegroundColour (wxColour (255, 0, 0));
+ } else {
+ _peak_time->SetForegroundColour (wxColour (0, 0, 0));
+ }
+}
diff --git a/src/wx/audio_dialog.h b/src/wx/audio_dialog.h
index b27785292..aef8ea944 100644
--- a/src/wx/audio_dialog.h
+++ b/src/wx/audio_dialog.h
@@ -29,7 +29,7 @@ class Film;
class AudioDialog : public wxDialog
{
public:
- AudioDialog (wxWindow *);
+ AudioDialog (wxWindow *, boost::shared_ptr<Film> film);
void set_content (boost::shared_ptr<AudioContent>);
@@ -40,9 +40,13 @@ private:
void smoothing_changed ();
void try_to_load_analysis ();
void analysis_finished ();
+ void setup_peak_time ();
boost::shared_ptr<AudioContent> _content;
+ boost::shared_ptr<AudioAnalysis> _analysis;
+ boost::weak_ptr<Film> _film;
AudioPlot* _plot;
+ wxStaticText* _peak_time;
wxCheckBox* _channel_checkbox[MAX_DCP_AUDIO_CHANNELS];
wxCheckBox* _type_checkbox[AudioPoint::COUNT];
wxSlider* _smoothing;
diff --git a/src/wx/audio_panel.cc b/src/wx/audio_panel.cc
index 2a41aeb2d..4d783ca9d 100644
--- a/src/wx/audio_panel.cc
+++ b/src/wx/audio_panel.cc
@@ -217,7 +217,7 @@ AudioPanel::show_clicked ()
return;
}
- _audio_dialog = new AudioDialog (this);
+ _audio_dialog = new AudioDialog (this, _parent->film ());
_audio_dialog->Show ();
_audio_dialog->set_content (ac.front ());
}
diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc
index 311ec734c..0938d52a4 100644
--- a/src/wx/film_viewer.cc
+++ b/src/wx/film_viewer.cc
@@ -354,16 +354,7 @@ FilmViewer::set_position_text ()
double const fps = _film->video_frame_rate ();
/* Count frame number from 1 ... not sure if this is the best idea */
_frame_number->SetLabel (wxString::Format (wxT("%d"), int (rint (_position.seconds() * fps)) + 1));
-
- double w = _position.seconds ();
- int const h = (w / 3600);
- w -= h * 3600;
- int const m = (w / 60);
- w -= m * 60;
- int const s = floor (w);
- w -= s;
- int const f = rint (w * fps);
- _timecode->SetLabel (wxString::Format (wxT("%02d:%02d:%02d.%02d"), h, m, s, f));
+ _timecode->SetLabel (time_to_timecode (_position, fps));
}
void
diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc
index e9c07c91f..9c13cfbcb 100644
--- a/src/wx/wx_util.cc
+++ b/src/wx/wx_util.cc
@@ -330,3 +330,17 @@ context_translation (wxString s)
return t;
}
+
+wxString
+time_to_timecode (DCPTime t, float fps)
+{
+ double w = t.seconds ();
+ int const h = (w / 3600);
+ w -= h * 3600;
+ int const m = (w / 60);
+ w -= m * 60;
+ int const s = floor (w);
+ w -= s;
+ int const f = rint (w * fps);
+ return wxString::Format (wxT("%02d:%02d:%02d.%02d"), h, m, s, f);
+}
diff --git a/src/wx/wx_util.h b/src/wx/wx_util.h
index dfa0fca5e..f2ab2d8c5 100644
--- a/src/wx/wx_util.h
+++ b/src/wx/wx_util.h
@@ -24,6 +24,7 @@
#ifndef DCPOMATIC_WX_UTIL_H
#define DCPOMATIC_WX_UTIL_H
+#include "lib/dcpomatic_time.h"
#include <wx/wx.h>
#include <wx/gbsizer.h>
#include <boost/function.hpp>
@@ -65,6 +66,7 @@ extern wxString std_to_wx (std::string);
extern void dcpomatic_setup_i18n ();
extern wxString context_translation (wxString);
extern std::string string_client_data (wxClientData* o);
+extern wxString time_to_timecode (DCPTime t, float fps);
extern void checked_set (wxFilePickerCtrl* widget, std::string value);
extern void checked_set (wxSpinCtrl* widget, int value);