EBU/VAMP: clang-format and reduce scope

This commit is contained in:
Robin Gareus 2021-04-03 23:42:09 +02:00
parent 1890cc234f
commit e3a6fab05e
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
4 changed files with 525 additions and 508 deletions

View file

@ -1,5 +1,3 @@
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/* /*
Vamp Vamp
@ -31,11 +29,10 @@
#include "EBUr128.h" #include "EBUr128.h"
using std::string;
using std::vector;
using std::cerr; using std::cerr;
using std::endl; using std::endl;
using std::string;
using std::vector;
VampEBUr128::VampEBUr128 (float inputSampleRate) VampEBUr128::VampEBUr128 (float inputSampleRate)
: Plugin (inputSampleRate) : Plugin (inputSampleRate)
@ -86,8 +83,9 @@ VampEBUr128::getCopyright() const
bool bool
VampEBUr128::initialise (size_t channels, size_t stepSize, size_t blockSize) VampEBUr128::initialise (size_t channels, size_t stepSize, size_t blockSize)
{ {
if (channels < getMinChannelCount() || if (channels < getMinChannelCount () || channels > getMaxChannelCount ()) {
channels > getMaxChannelCount()) return false; return false;
}
m_stepSize = std::min (stepSize, blockSize); m_stepSize = std::min (stepSize, blockSize);
m_channels = channels; m_channels = channels;

View file

@ -1,5 +1,3 @@
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/* /*
Vamp Vamp
@ -32,6 +30,7 @@
#define _EBUR128_PLUGIN_H_ #define _EBUR128_PLUGIN_H_
#include <vamp-sdk/Plugin.h> #include <vamp-sdk/Plugin.h>
#include "ebu_r128_proc.h" #include "ebu_r128_proc.h"
class VampEBUr128 : public Vamp::Plugin class VampEBUr128 : public Vamp::Plugin
@ -40,12 +39,21 @@ public:
VampEBUr128 (float inputSampleRate); VampEBUr128 (float inputSampleRate);
virtual ~VampEBUr128 (); virtual ~VampEBUr128 ();
size_t getMinChannelCount() const { return 1; } size_t getMinChannelCount () const
size_t getMaxChannelCount() const { return 2; } {
return 1;
}
size_t getMaxChannelCount () const
{
return 2;
}
bool initialise (size_t channels, size_t stepSize, size_t blockSize); bool initialise (size_t channels, size_t stepSize, size_t blockSize);
void reset (); void reset ();
InputDomain getInputDomain() const { return TimeDomain; } InputDomain getInputDomain () const
{
return TimeDomain;
}
std::string getIdentifier () const; std::string getIdentifier () const;
std::string getName () const; std::string getName () const;
@ -56,8 +64,7 @@ public:
OutputList getOutputDescriptors () const; OutputList getOutputDescriptors () const;
FeatureSet process(const float *const *inputBuffers, FeatureSet process (const float* const* inputBuffers, Vamp::RealTime timestamp);
Vamp::RealTime timestamp);
FeatureSet getRemainingFeatures (); FeatureSet getRemainingFeatures ();
@ -66,8 +73,7 @@ protected:
size_t m_channels; size_t m_channels;
private: private:
Fons::Ebu_r128_proc ebu; FonsEBU::Ebu_r128_proc ebu;
}; };
#endif #endif

View file

@ -19,10 +19,9 @@
// //
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
#include <string.h>
#include <math.h>
#include "ebu_r128_proc.h" #include "ebu_r128_proc.h"
#include <math.h>
#include <string.h>
#ifdef COMPILER_MSVC #ifdef COMPILER_MSVC
#include <float.h> #include <float.h>
@ -32,54 +31,48 @@
#define isfinite_local isfinite #define isfinite_local isfinite
#endif #endif
namespace Fons { using namespace FonsEBU;
float Ebu_r128_hist::_bin_power [100] = { 0.0f }; float Ebu_r128_proc::Ebu_r128_hist::_bin_power[100] = { 0.0f };
float Ebu_r128_proc::_chan_gain[5] = { 1.0f, 1.0f, 1.0f, 1.41f, 1.41f }; float Ebu_r128_proc::_chan_gain[5] = { 1.0f, 1.0f, 1.0f, 1.41f, 1.41f };
Ebu_r128_proc::Ebu_r128_hist::Ebu_r128_hist ()
Ebu_r128_hist::Ebu_r128_hist (void)
{ {
_histc = new int[751]; _histc = new int[751];
initstat (); initstat ();
reset (); reset ();
} }
Ebu_r128_proc::Ebu_r128_hist::~Ebu_r128_hist ()
Ebu_r128_hist::~Ebu_r128_hist (void)
{ {
delete[] _histc; delete[] _histc;
} }
void
void Ebu_r128_hist::reset (void) Ebu_r128_proc::Ebu_r128_hist::reset ()
{ {
memset (_histc, 0, 751 * sizeof (float)); memset (_histc, 0, 751 * sizeof (float));
_count = 0; _count = 0;
_error = 0; _error = 0;
} }
void
void Ebu_r128_hist::initstat (void) Ebu_r128_proc::Ebu_r128_hist::initstat ()
{
int i;
if (_bin_power [0]) return;
for (i = 0; i < 100; i++)
{ {
if (_bin_power[0])
return;
for (int i = 0; i < 100; i++) {
_bin_power[i] = powf (10.0f, i / 100.0f); _bin_power[i] = powf (10.0f, i / 100.0f);
} }
} }
void
void Ebu_r128_hist::addpoint (float v) Ebu_r128_proc::Ebu_r128_hist::addpoint (float v)
{
int k;
k = (int) floorf (10 * v + 700.5f);
if (k < 0) return;
if (k > 750)
{ {
int k = (int)floorf (10 * v + 700.5f);
if (k < 0)
return;
if (k > 750) {
k = 750; k = 750;
_error++; _error++;
} }
@ -87,8 +80,8 @@ void Ebu_r128_hist::addpoint (float v)
_count++; _count++;
} }
float
float Ebu_r128_hist::integrate (int i) Ebu_r128_proc::Ebu_r128_hist::integrate (int i)
{ {
int j, k, n; int j, k, n;
float s; float s;
@ -96,13 +89,11 @@ float Ebu_r128_hist::integrate (int i)
j = i % 100; j = i % 100;
n = 0; n = 0;
s = 0; s = 0;
while (i <= 750) while (i <= 750) {
{
k = _histc[i++]; k = _histc[i++];
n += k; n += k;
s += k * _bin_power[j++]; s += k * _bin_power[j++];
if (j == 100) if (j == 100) {
{
j = 0; j = 0;
s /= 10.0f; s /= 10.0f;
} }
@ -110,14 +101,13 @@ float Ebu_r128_hist::integrate (int i)
return s / n; return s / n;
} }
void
void Ebu_r128_hist::calc_integ (float *vi, float *th) Ebu_r128_proc::Ebu_r128_hist::calc_integ (float* vi, float* th)
{ {
int k; int k;
float s; float s;
if (_count < 50) if (_count < 50) {
{
*vi = -200.0f; *vi = -200.0f;
return; return;
} }
@ -126,53 +116,62 @@ void Ebu_r128_hist::calc_integ (float *vi, float *th)
// if (th) *th = 10 * log10f (s) - 8.0f; // if (th) *th = 10 * log10f (s) - 8.0f;
// k = (int)(floorf (100 * log10f (s) + 0.5f)) + 620; // k = (int)(floorf (100 * log10f (s) + 0.5f)) + 620;
// Threshold redefined to -10 dB below result of first integration // Threshold redefined to -10 dB below result of first integration
if (th) *th = 10 * log10f (s) - 10.0f; if (th) {
*th = 10 * log10f (s) - 10.0f;
}
k = (int)(floorf (100 * log10f (s) + 0.5f)) + 600; k = (int)(floorf (100 * log10f (s) + 0.5f)) + 600;
if (k < 0) k = 0; if (k < 0) {
k = 0;
}
s = integrate (k); s = integrate (k);
*vi = 10 * log10f (s); *vi = 10 * log10f (s);
} }
void
void Ebu_r128_hist::calc_range (float *v0, float *v1, float *th) Ebu_r128_proc::Ebu_r128_hist::calc_range (float* v0, float* v1, float* th)
{ {
int i, j, k, n; int i, j, k, n;
float a, b, s; float a, b, s;
if (_count < 20) if (_count < 20) {
{
*v0 = -200.0f; *v0 = -200.0f;
*v1 = -200.0f; *v1 = -200.0f;
return; return;
} }
s = integrate (0); s = integrate (0);
if (th) *th = 10 * log10f (s) - 20.0f; if (th) {
*th = 10 * log10f (s) - 20.0f;
}
k = (int)(floorf (100 * log10f (s) + 0.5)) + 500; k = (int)(floorf (100 * log10f (s) + 0.5)) + 500;
if (k < 0) k = 0; if (k < 0) {
for (i = k, n = 0; i <= 750; i++) n += _histc [i]; k = 0;
}
for (i = k, n = 0; i <= 750; i++) {
n += _histc[i];
}
a = 0.10f * n; a = 0.10f * n;
b = 0.95f * n; b = 0.95f * n;
for (i = k, s = 0; s < a; i++) s += _histc [i]; for (i = k, s = 0; s < a; i++) {
for (j = 750, s = n; s > b; j--) s -= _histc [j]; s += _histc[i];
}
for (j = 750, s = n; s > b; j--) {
s -= _histc[j];
}
*v0 = (i - 701) / 10.0f; *v0 = (i - 701) / 10.0f;
*v1 = (j - 699) / 10.0f; *v1 = (j - 699) / 10.0f;
} }
Ebu_r128_proc::Ebu_r128_proc ()
Ebu_r128_proc::Ebu_r128_proc (void)
{ {
reset (); reset ();
} }
Ebu_r128_proc::~Ebu_r128_proc ()
Ebu_r128_proc::~Ebu_r128_proc (void)
{ {
} }
void
void Ebu_r128_proc::init (int nchan, float fsamp) Ebu_r128_proc::init (int nchan, float fsamp)
{ {
_nchan = nchan; _nchan = nchan;
_fsamp = fsamp; _fsamp = fsamp;
@ -181,8 +180,8 @@ void Ebu_r128_proc::init (int nchan, float fsamp)
reset (); reset ();
} }
void
void Ebu_r128_proc::reset (void) Ebu_r128_proc::reset ()
{ {
_integr = false; _integr = false;
_frcnt = _fragm; _frcnt = _fragm;
@ -197,8 +196,8 @@ void Ebu_r128_proc::reset (void)
detect_reset (); detect_reset ();
} }
void
void Ebu_r128_proc::integr_reset (void) Ebu_r128_proc::integr_reset ()
{ {
_hist_M.reset (); _hist_M.reset ();
_hist_S.reset (); _hist_S.reset ();
@ -212,38 +211,45 @@ void Ebu_r128_proc::integr_reset (void)
_div1 = _div2 = 0; _div1 = _div2 = 0;
} }
void
void Ebu_r128_proc::process (int nfram, const float *const *input) Ebu_r128_proc::process (int nfram, const float* const* input)
{ {
int i, k; int i, k;
for (i = 0; i < _nchan; i++) _ipp [i] = input [i]; for (i = 0; i < _nchan; i++) {
while (nfram) _ipp[i] = input[i];
{ }
while (nfram) {
k = (_frcnt < nfram) ? _frcnt : nfram; k = (_frcnt < nfram) ? _frcnt : nfram;
_frpwr += detect_process (k); _frpwr += detect_process (k);
_frcnt -= k; _frcnt -= k;
if (_frcnt == 0) if (_frcnt == 0) {
{
_power[_wrind++] = _frpwr / _fragm; _power[_wrind++] = _frpwr / _fragm;
_frcnt = _fragm; _frcnt = _fragm;
_frpwr = 1e-30f; _frpwr = 1e-30f;
_wrind &= 63; _wrind &= 63;
_loudness_M = addfrags (8); _loudness_M = addfrags (8);
_loudness_S = addfrags (60); _loudness_S = addfrags (60);
if (!isfinite_local(_loudness_M) || _loudness_M < -200.f) _loudness_M = -200.0f;
if (!isfinite_local(_loudness_S) || _loudness_S < -200.f) _loudness_S = -200.0f; if (!isfinite_local (_loudness_M) || _loudness_M < -200.f) {
if (_loudness_M > _maxloudn_M) _maxloudn_M = _loudness_M; _loudness_M = -200.0f;
if (_loudness_S > _maxloudn_S) _maxloudn_S = _loudness_S; }
if (_integr) if (!isfinite_local (_loudness_S) || _loudness_S < -200.f) {
{ _loudness_S = -200.0f;
if (++_div1 == 2) }
{ if (_loudness_M > _maxloudn_M) {
_maxloudn_M = _loudness_M;
}
if (_loudness_S > _maxloudn_S) {
_maxloudn_S = _loudness_S;
}
if (_integr) {
if (++_div1 == 2) {
_hist_M.addpoint (_loudness_M); _hist_M.addpoint (_loudness_M);
_div1 = 0; _div1 = 0;
} }
if (++_div2 == 10) if (++_div2 == 10) {
{
_hist_S.addpoint (_loudness_S); _hist_S.addpoint (_loudness_S);
_div2 = 0; _div2 = 0;
_hist_M.calc_integ (&_integrated, &_integ_thr); _hist_M.calc_integ (&_integrated, &_integ_thr);
@ -251,25 +257,30 @@ void Ebu_r128_proc::process (int nfram, const float *const *input)
} }
} }
} }
for (i = 0; i < _nchan; i++) _ipp [i] += k;
for (i = 0; i < _nchan; i++) {
_ipp[i] += k;
}
nfram -= k; nfram -= k;
} }
} }
float
float Ebu_r128_proc::addfrags (int nfrag) Ebu_r128_proc::addfrags (int nfrag)
{ {
int i, k; int i, k;
float s; float s;
s = 0; s = 0;
k = (_wrind - nfrag) & 63; k = (_wrind - nfrag) & 63;
for (i = 0; i < nfrag; i++) s += _power [(i + k) & 63]; for (i = 0; i < nfrag; i++) {
s += _power[(i + k) & 63];
}
return -0.6976f + 10 * log10f (s / nfrag); return -0.6976f + 10 * log10f (s / nfrag);
} }
void
void Ebu_r128_proc::detect_init (float fsamp) Ebu_r128_proc::detect_init (float fsamp)
{ {
float a, b, c, d, r, u1, u2, w1, w2; float a, b, c, d, r, u1, u2, w1, w2;
@ -277,16 +288,19 @@ void Ebu_r128_proc::detect_init (float fsamp)
w1 = r / 1.12201f; w1 = r / 1.12201f;
w2 = r * 1.12201f; w2 = r * 1.12201f;
u1 = u2 = 1.4085f + 210.0f / fsamp; u1 = u2 = 1.4085f + 210.0f / fsamp;
a = u1 * w1; a = u1 * w1;
b = w1 * w1; b = w1 * w1;
c = u2 * w2; c = u2 * w2;
d = w2 * w2; d = w2 * w2;
r = 1 + a + b; r = 1 + a + b;
_a0 = (1 + c + d) / r; _a0 = (1 + c + d) / r;
_a1 = (2 - 2 * d) / r; _a1 = (2 - 2 * d) / r;
_a2 = (1 - c + d) / r; _a2 = (1 - c + d) / r;
_b1 = (2 - 2 * b) / r; _b1 = (2 - 2 * b) / r;
_b2 = (1 - a + b) / r; _b2 = (1 - a + b) / r;
r = 48.0f / fsamp; r = 48.0f / fsamp;
a = 4.9886075f * r; a = 4.9886075f * r;
b = 6.2298014f * r * r; b = 6.2298014f * r * r;
@ -295,20 +309,22 @@ void Ebu_r128_proc::detect_init (float fsamp)
b *= 4 / r; b *= 4 / r;
_c3 = a + b; _c3 = a + b;
_c4 = b; _c4 = b;
r = 1.004995f / r; r = 1.004995f / r;
_a0 *= r; _a0 *= r;
_a1 *= r; _a1 *= r;
_a2 *= r; _a2 *= r;
} }
void
void Ebu_r128_proc::detect_reset (void) Ebu_r128_proc::detect_reset ()
{ {
for (int i = 0; i < MAXCH; i++) _fst [i].reset (); for (int i = 0; i < MAXCH; i++)
_fst[i].reset ();
} }
float
float Ebu_r128_proc::detect_process (int nfram) Ebu_r128_proc::detect_process (int nfram)
{ {
int i, j; int i, j;
float si, sj; float si, sj;
@ -317,16 +333,14 @@ float Ebu_r128_proc::detect_process (int nfram)
Ebu_r128_fst* S; Ebu_r128_fst* S;
si = 0; si = 0;
for (i = 0, S = _fst; i < _nchan; i++, S++) for (i = 0, S = _fst; i < _nchan; i++, S++) {
{
z1 = S->_z1; z1 = S->_z1;
z2 = S->_z2; z2 = S->_z2;
z3 = S->_z3; z3 = S->_z3;
z4 = S->_z4; z4 = S->_z4;
p = _ipp[i]; p = _ipp[i];
sj = 0; sj = 0;
for (j = 0; j < nfram; j++) for (j = 0; j < nfram; j++) {
{
x = p[j] - _b1 * z1 - _b2 * z2 + 1e-15f; x = p[j] - _b1 * z1 - _b2 * z2 + 1e-15f;
y = _a0 * x + _a1 * z1 + _a2 * z2 - _c3 * z3 - _c4 * z4; y = _a0 * x + _a1 * z1 + _a2 * z2 - _c3 * z3 - _c4 * z4;
z2 = z1; z2 = z1;
@ -335,8 +349,11 @@ float Ebu_r128_proc::detect_process (int nfram)
z3 += y; z3 += y;
sj += y * y; sj += y * y;
} }
if (_nchan == 1) si = 2 * sj; if (_nchan == 1) {
else si += _chan_gain [i] * sj; si = 2 * sj;
} else {
si += _chan_gain[i] * sj;
}
S->_z1 = !isfinite_local (z1) ? 0 : z1; S->_z1 = !isfinite_local (z1) ? 0 : z1;
S->_z2 = !isfinite_local (z2) ? 0 : z2; S->_z2 = !isfinite_local (z2) ? 0 : z2;
S->_z3 = !isfinite_local (z3) ? 0 : z3; S->_z3 = !isfinite_local (z3) ? 0 : z3;
@ -344,5 +361,3 @@ float Ebu_r128_proc::detect_process (int nfram)
} }
return si; return si;
} }
};

View file

@ -18,37 +18,68 @@
// //
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
#ifndef _EBU_R128_PROC_H #ifndef _EBU_R128_PROC_H
#define _EBU_R128_PROC_H #define _EBU_R128_PROC_H
#define MAXCH 5 #define MAXCH 5
namespace Fons { namespace FonsEBU {
class Ebu_r128_proc
{
public:
Ebu_r128_proc ();
~Ebu_r128_proc ();
void init (int nchan, float fsamp);
void reset ();
void process (int nfram, const float* const* input);
void integr_reset ();
void integr_pause () { _integr = false; }
void integr_start () { _integr = true; }
float loudness_M () const { return _loudness_M; }
float maxloudn_M () const { return _maxloudn_M; }
float loudness_S () const { return _loudness_S; }
float maxloudn_S () const { return _maxloudn_S; }
float integrated () const { return _integrated; }
float integ_thr () const { return _integ_thr; }
float range_min () const { return _range_min; }
float range_max () const { return _range_max; }
float range_thr () const { return _range_thr; }
const int* histogram_M () const { return _hist_M._histc; }
const int* histogram_S () const { return _hist_S._histc; }
int hist_M_count () const { return _hist_M._count; }
int hist_S_count () const { return _hist_S._count; }
private:
class Ebu_r128_fst class Ebu_r128_fst
{ {
private: private:
friend class Ebu_r128_proc; friend class Ebu_r128_proc;
void reset (void) { _z1 = _z2 = _z3 = _z4 = 0; } void reset ()
{
_z1 = _z2 = _z3 = _z4 = 0;
}
float _z1, _z2, _z3, _z4; float _z1, _z2, _z3, _z4;
}; };
class Ebu_r128_hist class Ebu_r128_hist
{ {
private: private:
Ebu_r128_hist ();
Ebu_r128_hist (void); ~Ebu_r128_hist ();
~Ebu_r128_hist (void);
friend class Ebu_r128_proc; friend class Ebu_r128_proc;
void reset (void); void reset ();
void initstat (void); void initstat ();
void addpoint (float v); void addpoint (float v);
float integrate (int ind); float integrate (int ind);
void calc_integ (float* vi, float* th); void calc_integ (float* vi, float* th);
@ -61,42 +92,9 @@ private:
static float _bin_power[100]; static float _bin_power[100];
}; };
class Ebu_r128_proc
{
public:
Ebu_r128_proc (void);
~Ebu_r128_proc (void);
void init (int nchan, float fsamp);
void reset (void);
void process (int nfram, const float *const *input);
void integr_reset (void);
void integr_pause (void) { _integr = false; }
void integr_start (void) { _integr = true; }
float loudness_M (void) const { return _loudness_M; }
float maxloudn_M (void) const { return _maxloudn_M; }
float loudness_S (void) const { return _loudness_S; }
float maxloudn_S (void) const { return _maxloudn_S; }
float integrated (void) const { return _integrated; }
float integ_thr (void) const { return _integ_thr; }
float range_min (void) const { return _range_min; }
float range_max (void) const { return _range_max; }
float range_thr (void) const { return _range_thr; }
const int *histogram_M (void) const { return _hist_M._histc; }
const int *histogram_S (void) const { return _hist_S._histc; }
int hist_M_count (void) const { return _hist_M._count; }
int hist_S_count (void) const { return _hist_S._count; }
private:
float addfrags (int nfrag); float addfrags (int nfrag);
void detect_init (float fsamp); void detect_init (float fsamp);
void detect_reset (void); void detect_reset ();
float detect_process (int nfram); float detect_process (int nfram);
bool _integr; // Integration on/off. bool _integr; // Integration on/off.