summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/analyse_audio_job.cc40
-rw-r--r--src/lib/analyse_audio_job.h6
-rw-r--r--src/lib/audio_analysis.cc7
-rw-r--r--src/lib/audio_analysis.h9
-rw-r--r--src/lib/wscript2
-rw-r--r--src/tools/wscript2
-rw-r--r--src/wx/audio_dialog.cc10
-rw-r--r--src/wx/audio_dialog.h1
8 files changed, 74 insertions, 3 deletions
diff --git a/src/lib/analyse_audio_job.cc b/src/lib/analyse_audio_job.cc
index 1fc09b905..ead36bca1 100644
--- a/src/lib/analyse_audio_job.cc
+++ b/src/lib/analyse_audio_job.cc
@@ -30,6 +30,7 @@
#include "audio_filter_graph.h"
#include "config.h"
extern "C" {
+#include <leqm_nrt.h>
#include <libavutil/channel_layout.h>
#ifdef DCPOMATIC_HAVE_EBUR128_PATCHED_FFMPEG
#include <libavfilter/f_ebur128.h>
@@ -51,6 +52,13 @@ using namespace dcpomatic;
int const AnalyseAudioJob::_num_points = 1024;
+static void add_if_required(vector<double>& v, size_t i, double db)
+{
+ if (v.size() > i) {
+ v[i] = pow(10, db / 20);
+ }
+}
+
/** @param from_zero true to analyse audio from time 0 in the playlist, otherwise begin at Playlist::start */
AnalyseAudioJob::AnalyseAudioJob (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist, bool from_zero)
: Job (film)
@@ -79,6 +87,31 @@ AnalyseAudioJob::AnalyseAudioJob (shared_ptr<const Film> film, shared_ptr<const
if (!_from_zero) {
_start = _playlist->start().get_value_or(DCPTime());
}
+
+ /* XXX: is this right? Especially for more than 5.1? */
+ vector<double> channel_corrections(film->audio_channels(), 1);
+ add_if_required (channel_corrections, 4, -3); // Ls
+ add_if_required (channel_corrections, 5, -3); // Rs
+ add_if_required (channel_corrections, 6, -144); // HI
+ add_if_required (channel_corrections, 7, -144); // VI
+ add_if_required (channel_corrections, 8, -3); // Lc
+ add_if_required (channel_corrections, 9, -3); // Rc
+ add_if_required (channel_corrections, 10, -3); // Lc
+ add_if_required (channel_corrections, 11, -3); // Rc
+ add_if_required (channel_corrections, 12, -144); // DBox
+ add_if_required (channel_corrections, 13, -144); // Sync
+ add_if_required (channel_corrections, 14, -144); // Sign Language
+ add_if_required (channel_corrections, 15, -144); // Unused
+
+ _leqm.reset(new leqm_nrt::Calculator(
+ film->audio_channels(),
+ film->audio_frame_rate(),
+ 24,
+ channel_corrections,
+ 850, // suggested by leqm_nrt CLI source
+ 64, // suggested by leqm_nrt CLI source
+ boost::thread::hardware_concurrency()
+ ));
}
AnalyseAudioJob::~AnalyseAudioJob ()
@@ -169,6 +202,7 @@ AnalyseAudioJob::run ()
_analysis->set_samples_per_point (_samples_per_point);
_analysis->set_sample_rate (_film->audio_frame_rate ());
+ _analysis->set_leqm (_leqm->leq_m());
_analysis->write (_path);
set_progress (1);
@@ -188,11 +222,15 @@ AnalyseAudioJob::analyse (shared_ptr<const AudioBuffers> b, DCPTime time)
int const frames = b->frames ();
int const channels = b->channels ();
+ vector<double> interleaved(frames * channels);
for (int j = 0; j < channels; ++j) {
float* data = b->data(j);
for (int i = 0; i < frames; ++i) {
float s = data[i];
+
+ interleaved[i * channels + j] = s;
+
float as = fabsf (s);
if (as < 10e-7) {
/* We may struggle to serialise and recover inf or -inf, so prevent such
@@ -215,6 +253,8 @@ AnalyseAudioJob::analyse (shared_ptr<const AudioBuffers> b, DCPTime time)
}
}
+ _leqm->add(interleaved);
+
_done += frames;
DCPTime const length = _playlist->length (_film);
diff --git a/src/lib/analyse_audio_job.h b/src/lib/analyse_audio_job.h
index 5d6c091bc..f7cc3e256 100644
--- a/src/lib/analyse_audio_job.h
+++ b/src/lib/analyse_audio_job.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -26,6 +26,8 @@
#include "audio_point.h"
#include "types.h"
#include "dcpomatic_time.h"
+#include <leqm_nrt.h>
+#include <boost/scoped_ptr.hpp>
class AudioBuffers;
class AudioAnalysis;
@@ -76,5 +78,7 @@ private:
boost::shared_ptr<AudioFilterGraph> _ebur128;
std::vector<Filter const *> _filters;
+ boost::scoped_ptr<leqm_nrt::Calculator> _leqm;
+
static const int _num_points;
};
diff --git a/src/lib/audio_analysis.cc b/src/lib/audio_analysis.cc
index 13917cb5f..446fcccef 100644
--- a/src/lib/audio_analysis.cc
+++ b/src/lib/audio_analysis.cc
@@ -93,6 +93,8 @@ AudioAnalysis::AudioAnalysis (boost::filesystem::path filename)
_analysis_gain = f.optional_number_child<double> ("AnalysisGain");
_samples_per_point = f.number_child<int64_t> ("SamplesPerPoint");
_sample_rate = f.number_child<int64_t> ("SampleRate");
+
+ _leqm = f.optional_number_child<double>("Leqm");
}
void
@@ -162,6 +164,10 @@ AudioAnalysis::write (boost::filesystem::path filename)
root->add_child("SamplesPerPoint")->add_child_text (raw_convert<string> (_samples_per_point));
root->add_child("SampleRate")->add_child_text (raw_convert<string> (_sample_rate));
+ if (_leqm) {
+ root->add_child("Leqm")->add_child_text(raw_convert<string>(*_leqm));
+ }
+
doc->write_to_file_formatted (filename.string ());
}
@@ -212,3 +218,4 @@ AudioAnalysis::overall_true_peak () const
return p;
}
+
diff --git a/src/lib/audio_analysis.h b/src/lib/audio_analysis.h
index 3684db96a..99a69edb4 100644
--- a/src/lib/audio_analysis.h
+++ b/src/lib/audio_analysis.h
@@ -116,6 +116,14 @@ public:
_sample_rate = sr;
}
+ void set_leqm (double leqm) {
+ _leqm = leqm;
+ }
+
+ boost::optional<double> leqm () const {
+ return _leqm;
+ }
+
void write (boost::filesystem::path);
float gain_correction (boost::shared_ptr<const Playlist> playlist);
@@ -126,6 +134,7 @@ private:
std::vector<float> _true_peak;
boost::optional<float> _integrated_loudness;
boost::optional<float> _loudness_range;
+ boost::optional<double> _leqm;
/** If this analysis was run on a single piece of
* content we store its gain in dB when the analysis
* happened.
diff --git a/src/lib/wscript b/src/lib/wscript
index ca6786ef2..67bcf8d8b 100644
--- a/src/lib/wscript
+++ b/src/lib/wscript
@@ -193,7 +193,7 @@ def build(bld):
AVCODEC AVUTIL AVFORMAT AVFILTER SWSCALE
BOOST_FILESYSTEM BOOST_THREAD BOOST_DATETIME BOOST_SIGNALS2 BOOST_REGEX
SAMPLERATE POSTPROC TIFF SSH DCP CXML GLIB LZMA XML++
- CURL ZIP FONTCONFIG PANGOMM CAIROMM XMLSEC SUB ICU NETTLE PNG
+ CURL ZIP FONTCONFIG PANGOMM CAIROMM XMLSEC SUB ICU NETTLE PNG LEQM_NRT
"""
if bld.env.TARGET_OSX:
diff --git a/src/tools/wscript b/src/tools/wscript
index c7c953a31..7eeeecddf 100644
--- a/src/tools/wscript
+++ b/src/tools/wscript
@@ -30,7 +30,7 @@ def configure(conf):
def build(bld):
uselib = 'BOOST_THREAD BOOST_DATETIME DCP XMLSEC CXML XMLPP AVFORMAT AVFILTER AVCODEC '
uselib += 'AVUTIL SWSCALE SWRESAMPLE POSTPROC CURL BOOST_FILESYSTEM SSH ZIP CAIROMM FONTCONFIG PANGOMM SUB '
- uselib += 'SNDFILE SAMPLERATE BOOST_REGEX ICU NETTLE RTAUDIO PNG '
+ uselib += 'SNDFILE SAMPLERATE BOOST_REGEX ICU NETTLE RTAUDIO PNG LEQM_NRT '
if bld.env.ENABLE_DISK:
if bld.env.TARGET_LINUX:
diff --git a/src/wx/audio_dialog.cc b/src/wx/audio_dialog.cc
index 2f1f1c826..efc506aff 100644
--- a/src/wx/audio_dialog.cc
+++ b/src/wx/audio_dialog.cc
@@ -89,6 +89,8 @@ AudioDialog::AudioDialog (wxWindow* parent, shared_ptr<Film> film, shared_ptr<Co
left->Add (_integrated_loudness, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP);
_loudness_range = new StaticText (this, wxT (""));
left->Add (_loudness_range, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP);
+ _leqm = new StaticText (this, wxT(""));
+ left->Add (_leqm, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP);
lr_sizer->Add (left, 1, wxALL | wxEXPAND, 12);
@@ -414,6 +416,14 @@ AudioDialog::setup_statistics ()
)
);
}
+
+ if (static_cast<bool>(_analysis->leqm())) {
+ _leqm->SetLabel(
+ wxString::Format(
+ _("LEQ(m) %.2fdB"), _analysis->leqm().get() + _analysis->gain_correction(_playlist)
+ )
+ );
+ }
}
bool
diff --git a/src/wx/audio_dialog.h b/src/wx/audio_dialog.h
index 3a02fd87f..34c174cf4 100644
--- a/src/wx/audio_dialog.h
+++ b/src/wx/audio_dialog.h
@@ -59,6 +59,7 @@ private:
wxStaticText* _true_peak;
wxStaticText* _integrated_loudness;
wxStaticText* _loudness_range;
+ wxStaticText* _leqm;
wxCheckBox* _channel_checkbox[MAX_DCP_AUDIO_CHANNELS];
wxCheckBox* _type_checkbox[AudioPoint::COUNT];
wxSlider* _smoothing;