#include "film.h"
#include "filter.h"
#include "playlist.h"
-#include "types.h"
#include <dcp/warnings.h>
extern "C" {
#include <leqm_nrt.h>
, _playlist (playlist)
, _set_progress (set_progress)
#ifdef DCPOMATIC_HAVE_EBUR128_PATCHED_FFMPEG
- , _ebur128 (new AudioFilterGraph(film->audio_frame_rate(), film->audio_channels()))
+ , _ebur128(film->audio_frame_rate(), film->audio_channels())
#endif
, _sample_peak (film->audio_channels())
, _sample_peak_frame (film->audio_channels())
{
#ifdef DCPOMATIC_HAVE_EBUR128_PATCHED_FFMPEG
- _filters.push_back (new Filter("ebur128", "ebur128", "audio", "ebur128=peak=true"));
- _ebur128->setup (_filters);
+ _filters.push_back({"ebur128", "ebur128", "audio", "ebur128=peak=true"});
+ _ebur128.setup(_filters);
#endif
_current = std::vector<AudioPoint>(_film->audio_channels());
}
};
- int leqm_channels = film->audio_channels();
auto content = _playlist->content();
if (content.size() == 1 && content[0]->audio) {
- leqm_channels = content[0]->audio->mapping().mapped_output_channels().size();
+ _leqm_channels = 0;
+ for (auto channel: content[0]->audio->mapping().mapped_output_channels()) {
+ /* This means that if, for example, a file only maps C we will
+ * calculate LEQ(m) for L, R and C. I'm not sure if this is
+ * right or not.
+ */
+ _leqm_channels = std::min(film->audio_channels(), channel + 1);
+ }
+ } else {
+ _leqm_channels = film->audio_channels();
}
/* XXX: is this right? Especially for more than 5.1? */
- vector<double> channel_corrections(leqm_channels, 1);
+ vector<double> channel_corrections(_leqm_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, 15, -144); // Unused
_leqm.reset(new leqm_nrt::Calculator(
- leqm_channels,
+ _leqm_channels,
film->audio_frame_rate(),
24,
channel_corrections,
}
-AudioAnalyser::~AudioAnalyser ()
-{
- for (auto i: _filters) {
- delete const_cast<Filter*> (i);
- }
-}
-
-
void
AudioAnalyser::analyse (shared_ptr<AudioBuffers> b, DCPTime time)
{
- LOG_DEBUG_AUDIO_ANALYSIS("Received %1 frames at %2", b->frames(), to_string(time));
+ LOG_DEBUG_AUDIO_ANALYSIS("AudioAnalyser received %1 frames at %2", b->frames(), to_string(time));
DCPOMATIC_ASSERT (time >= _start);
/* In bug #2364 we had a lot of frames arriving here (~47s worth) which
* caused an OOM error on Windows. Check for the number of frames being
#ifdef DCPOMATIC_HAVE_EBUR128_PATCHED_FFMPEG
if (Config::instance()->analyse_ebur128 ()) {
- _ebur128->process (b);
+ _ebur128.process(b);
}
#endif
int const frames = b->frames ();
- int const channels = b->channels ();
- vector<double> interleaved(frames * channels);
+ vector<double> interleaved(frames * _leqm_channels);
- for (int j = 0; j < channels; ++j) {
+ for (int j = 0; j < _leqm_channels; ++j) {
float const* data = b->data(j);
for (int i = 0; i < frames; ++i) {
float s = data[i];
- interleaved[i * channels + j] = s;
+ interleaved[i * _leqm_channels + j] = s;
float as = fabsf (s);
if (as < 10e-7) {
#ifdef DCPOMATIC_HAVE_EBUR128_PATCHED_FFMPEG
if (Config::instance()->analyse_ebur128 ()) {
- void* eb = _ebur128->get("Parsed_ebur128_0")->priv;
+ void* eb = _ebur128.get("Parsed_ebur128_0")->priv;
vector<float> true_peak;
for (int i = 0; i < _film->audio_channels(); ++i) {
true_peak.push_back (av_ebur128_get_true_peaks(eb)[i]);