vamp-true-peak: collect peak locations >= -1dBTP
authorRobin Gareus <robin@gareus.org>
Fri, 12 Feb 2016 11:38:54 +0000 (12:38 +0100)
committerRobin Gareus <robin@gareus.org>
Fri, 12 Feb 2016 11:38:54 +0000 (12:38 +0100)
libs/vamp-plugins/TruePeak.cpp
libs/vamp-plugins/TruePeak.h

index 3e2ba74004cc84a24d7be355fdb6da9d7fadb9f8..82c56c88f3ff4c13c70071d373b7b10db0853443 100644 (file)
@@ -386,32 +386,32 @@ TruePeakdsp::process (float const *d, int n)
        _src.out_data = _buf;
        _src.process ();
 
-       float m = _res ? 0 : _m;
-       float p = _res ? 0 : _p;
+       float x = 0;
        float v;
        float *b = _buf;
        while (n--) {
                v = fabsf(*b++);
-               if (v > m) m = v;
-               if (v > p) p = v;
+               if (v > x) x = v;
                v = fabsf(*b++);
-               if (v > m) m = v;
-               if (v > p) p = v;
+               if (v > x) x = v;
                v = fabsf(*b++);
-               if (v > m) m = v;
-               if (v > p) p = v;
+               if (v > x) x = v;
                v = fabsf(*b++);
-               if (v > m) m = v;
-               if (v > p) p = v;
+               if (v > x) x = v;
        }
 
        if (_res) {
-               _m = m;
-               _p = p;
+               _m = x;
                _res = false;
-       } else {
-               if (m > _m) { _m = m; }
-               if (p > _p) { _p = p; }
+       } else if (x > _m) {
+               _m = x;
+       }
+
+       if (_res_peak) {
+               _p = x;
+               _res_peak = false;
+       } else if (x > _p) {
+               _p = x;
        }
 }
 
@@ -426,6 +426,7 @@ void
 TruePeakdsp::read (float &m, float &p)
 {
        _res = true;
+       _res_peak = true;
        m = _m;
        p = _p;
 }
@@ -469,6 +470,7 @@ using namespace TruePeakMeter;
 VampTruePeak::VampTruePeak(float inputSampleRate)
     : Plugin(inputSampleRate)
     , m_blockSize(0)
+    , m_rate (inputSampleRate)
 {
 }
 
@@ -554,6 +556,17 @@ VampTruePeak::getOutputDescriptors() const
        zc.sampleType = OutputDescriptor::OneSamplePerStep;
        list.push_back(zc);
 
+       zc.identifier = "peaks";
+       zc.name = "TruePeakPeaks";
+       zc.description = "Location of Peaks above -1dBTP";
+       zc.unit = "sec";
+       zc.hasFixedBinCount = true;
+       zc.binCount = 0;
+       zc.hasKnownExtents = false;
+       zc.isQuantized = false;
+       zc.sampleType = OutputDescriptor::OneSamplePerStep;
+       list.push_back(zc);
+
        return list;
 }
 
@@ -570,7 +583,12 @@ VampTruePeak::process(const float *const *inputBuffers,
 
        _meter.process (inputBuffers[0], m_blockSize);
 
-       // TODO return momentary
+       // TODO optional (not rt safe)
+       if (_meter.read () >= .89125 /* -1dBTP */) {
+               long f = Vamp::RealTime::realTime2Frame (timestamp, m_rate);
+               _above_m1.values.push_back ((float) f);
+       }
+
        return FeatureSet();
 }
 
@@ -587,5 +605,8 @@ VampTruePeak::getRemainingFeatures()
        dbtp.values.push_back(p);
        returnFeatures[0].push_back(dbtp);
 
+       _above_m1.hasTimestamp = false;
+       returnFeatures[1].push_back(_above_m1);
+
        return returnFeatures;
 }
index 792788ef6b7f3f01c57decc86d2728e4fc2021b3..5e3ff9d2c2cee28eb37df15e933eb6b608ded032 100644 (file)
@@ -130,6 +130,7 @@ private:
        float      _m;
        float      _p;
        bool       _res;
+       bool       _res_peak;
        float     *_buf;
        Resampler  _src;
 };
@@ -169,6 +170,8 @@ protected:
 
 private:
        TruePeakMeter::TruePeakdsp _meter;
+       Feature _above_m1;
+       unsigned int m_rate;
 };
 
 #endif