2 Copyright (C) 2015 Robin Gareus
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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 framecnt_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), (framecnt_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];