1
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
6
An API for audio analysis and feature extraction plugins.
8
Centre for Digital Music, Queen Mary, University of London.
9
This file copyright 2006 Dan Stowell.
11
Permission is hereby granted, free of charge, to any person
12
obtaining a copy of this software and associated documentation
13
files (the "Software"), to deal in the Software without
14
restriction, including without limitation the rights to use, copy,
15
modify, merge, publish, distribute, sublicense, and/or sell copies
16
of the Software, and to permit persons to whom the Software is
17
furnished to do so, subject to the following conditions:
19
The above copyright notice and this permission notice shall be
20
included in all copies or substantial portions of the Software.
22
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
26
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
27
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
Except as contained in this notice, the names of the Centre for
31
Digital Music; Queen Mary, University of London; and Chris Cannam
32
shall not be used in advertising or otherwise to promote the sale,
33
use or other dealings in this Software without prior written
37
#include "AmplitudeFollower.h"
51
* An implementation of SuperCollider's amplitude-follower algorithm
52
* as a simple Vamp plugin.
55
AmplitudeFollower::AmplitudeFollower(float inputSampleRate) :
56
Plugin(inputSampleRate),
64
AmplitudeFollower::~AmplitudeFollower()
69
AmplitudeFollower::getIdentifier() const
71
return "amplitudefollower";
75
AmplitudeFollower::getName() const
77
return "Amplitude Follower";
81
AmplitudeFollower::getDescription() const
83
return "Track the amplitude of the audio signal";
87
AmplitudeFollower::getMaker() const
89
return "Vamp SDK Example Plugins";
93
AmplitudeFollower::getPluginVersion() const
99
AmplitudeFollower::getCopyright() const
101
return "Code copyright 2006 Dan Stowell; method from SuperCollider. Freely redistributable (BSD license)";
105
AmplitudeFollower::initialise(size_t channels, size_t stepSize, size_t blockSize)
107
if (channels < getMinChannelCount() ||
108
channels > getMaxChannelCount()) return false;
110
m_stepSize = std::min(stepSize, blockSize);
112
// Translate the coefficients
113
// from their "convenient" 60dB convergence-time values
114
// to real coefficients
115
m_clampcoef = m_clampcoef==0.0 ? 0.0 : exp(log(0.1)/(m_clampcoef * m_inputSampleRate));
116
m_relaxcoef = m_relaxcoef==0.0 ? 0.0 : exp(log(0.1)/(m_relaxcoef * m_inputSampleRate));
122
AmplitudeFollower::reset()
127
AmplitudeFollower::OutputList
128
AmplitudeFollower::getOutputDescriptors() const
132
OutputDescriptor sca;
133
sca.identifier = "amplitude";
134
sca.name = "Amplitude";
135
sca.description = "";
137
sca.hasFixedBinCount = true;
139
sca.hasKnownExtents = false;
140
sca.isQuantized = false;
141
sca.sampleType = OutputDescriptor::OneSamplePerStep;
147
AmplitudeFollower::ParameterList
148
AmplitudeFollower::getParameterDescriptors() const
152
ParameterDescriptor att;
153
att.identifier = "attack";
154
att.name = "Attack time";
155
att.description = "";
159
att.defaultValue = 0.01f;
160
att.isQuantized = false;
164
ParameterDescriptor dec;
165
dec.identifier = "release";
166
dec.name = "Release time";
167
dec.description = "";
171
dec.defaultValue = 0.01f;
172
dec.isQuantized = false;
179
void AmplitudeFollower::setParameter(std::string paramid, float newval)
181
if (paramid == "attack") {
182
m_clampcoef = newval;
183
} else if (paramid == "release") {
184
m_relaxcoef = newval;
188
float AmplitudeFollower::getParameter(std::string paramid) const
190
if (paramid == "attack") {
192
} else if (paramid == "release") {
199
AmplitudeFollower::FeatureSet
200
AmplitudeFollower::process(const float *const *inputBuffers,
201
Vamp::RealTime timestamp)
203
if (m_stepSize == 0) {
204
cerr << "ERROR: AmplitudeFollower::process: "
205
<< "AmplitudeFollower has not been initialised"
210
float previn = m_previn;
212
FeatureSet returnFeatures;
217
for (size_t i = 0; i < m_stepSize; ++i) {
219
val = fabs(inputBuffers[0][i]);
222
val = val + (previn - val) * m_relaxcoef;
224
val = val + (previn - val) * m_clampcoef;
227
if (val > peak) peak = val;
233
// Now store the "feature" (peak amp) for this sample
235
feature.hasTimestamp = false;
236
feature.values.push_back(peak);
237
returnFeatures[0].push_back(feature);
239
return returnFeatures;
242
AmplitudeFollower::FeatureSet
243
AmplitudeFollower::getRemainingFeatures()