summaryrefslogtreecommitdiff
path: root/libs/vamp-plugins
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2016-02-12 12:38:54 +0100
committerRobin Gareus <robin@gareus.org>2016-02-12 12:38:54 +0100
commita60312cfeaa3b46fd5b8d8bafde7b7f7cb788cc0 (patch)
treece1897bac36be7b12b1fe5445385ea2503c7261f /libs/vamp-plugins
parent4fd47182f2bf2e1a88b5f2f1c880e592addb1bc9 (diff)
vamp-true-peak: collect peak locations >= -1dBTP
Diffstat (limited to 'libs/vamp-plugins')
-rw-r--r--libs/vamp-plugins/TruePeak.cpp53
-rw-r--r--libs/vamp-plugins/TruePeak.h3
2 files changed, 40 insertions, 16 deletions
diff --git a/libs/vamp-plugins/TruePeak.cpp b/libs/vamp-plugins/TruePeak.cpp
index 3e2ba74004..82c56c88f3 100644
--- a/libs/vamp-plugins/TruePeak.cpp
+++ b/libs/vamp-plugins/TruePeak.cpp
@@ -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;
}
diff --git a/libs/vamp-plugins/TruePeak.h b/libs/vamp-plugins/TruePeak.h
index 792788ef6b..5e3ff9d2c2 100644
--- a/libs/vamp-plugins/TruePeak.h
+++ b/libs/vamp-plugins/TruePeak.h
@@ -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