2 * Copyright (C) 2015 Robin Gareus <robin@gareus.org>
3 * Copyright (C) 2015-2017 Paul Davis <paul@linuxaudiosystems.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "ardour/ebur128_analysis.h"
28 using namespace ARDOUR;
31 /* need a static initializer function for this */
33 EBUr128Analysis::EBUr128Analysis (float sr)
34 : AudioAnalyser (sr, X_("libardourvampplugins:ebur128"))
40 EBUr128Analysis::~EBUr128Analysis()
45 EBUr128Analysis::run (Readable* src)
49 samplecnt_t len = src->readable_length();
51 uint32_t n_channels = src->n_channels();
52 Plugin::FeatureSet features;
55 if (!plugin->initialise (n_channels, stepsize, bufsize)) {
59 float** bufs = (float**) malloc(n_channels * sizeof(float*));
60 for (uint32_t c = 0; c < n_channels; ++c) {
61 bufs[c] = (float*) malloc(bufsize * sizeof(float));
66 to_read = min ((len - pos), (samplecnt_t) bufsize);
68 for (uint32_t c = 0; c < n_channels; ++c) {
69 if (src->read (bufs[c], pos, to_read, c) != to_read) {
72 /* zero fill buffer if necessary */
73 if (to_read != bufsize) {
74 memset (bufs[c] + to_read, 0, (bufsize - to_read) * sizeof (float));
78 plugin->process (bufs, RealTime::fromSeconds ((double) pos / sample_rate));
80 pos += min (stepsize, to_read);
87 features = plugin->getRemainingFeatures ();
89 if (use_features (features, 0)) {
96 for (uint32_t c = 0; c < n_channels; ++c) {
105 EBUr128Analysis::use_features (Plugin::FeatureSet& features, ostream* out)
107 if (features.empty() || features.size() != 2) {
110 _loudness = features[0][0].values[0];
111 _loudness_range = features[1][0].values[0];