1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
4 Vamp feature extraction plugins using Paul Brossier's Aubio library.
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006-2008 Chris Cannam and QMUL.
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
24 Silence::Silence(float inputSampleRate, unsigned int apiVersion) :
25 Plugin(inputSampleRate),
26 m_apiVersion(apiVersion),
34 if (m_apiVersion == 1) {
35 cerr << "vamp-aubio: WARNING: using compatibility version 1 of the Vamp API for silence\n"
36 << "detector plugin: upgrade your host to v2 for proper duration support" << endl;
42 if (m_ibuf) del_fvec(m_ibuf);
43 if (m_pbuf) del_fvec(m_pbuf);
44 if (m_tmpptrs) delete[] m_tmpptrs;
48 Silence::getIdentifier() const
50 return "aubiosilence";
54 Silence::getName() const
56 return "Aubio Silence Detector";
60 Silence::getDescription() const
62 return "Detect levels below a certain threshold";
66 Silence::getMaker() const
68 return "Paul Brossier (plugin by Chris Cannam)";
72 Silence::getPluginVersion() const
74 if (m_apiVersion == 1) return 2;
79 Silence::getCopyright() const
85 Silence::initialise(size_t channels, size_t stepSize, size_t blockSize)
87 m_channelCount = channels;
88 m_stepSize = stepSize;
89 m_blockSize = blockSize;
91 m_ibuf = new_fvec(stepSize, channels);
92 m_pbuf = new_fvec(stepSize, channels);
93 m_tmpptrs = new smpl_t *[channels];
105 Silence::getPreferredStepSize() const
111 Silence::getPreferredBlockSize() const
116 Silence::ParameterList
117 Silence::getParameterDescriptors() const
120 ParameterDescriptor desc;
122 desc = ParameterDescriptor();
123 desc.identifier = "silencethreshold";
124 desc.name = "Silence Threshold";
125 desc.minValue = -120;
127 desc.defaultValue = -80;
129 desc.isQuantized = false;
130 list.push_back(desc);
136 Silence::getParameter(std::string param) const
138 if (param == "silencethreshold") {
146 Silence::setParameter(std::string param, float value)
148 if (param == "silencethreshold") {
154 Silence::getOutputDescriptors() const
160 if (m_apiVersion == 1) {
162 d.identifier = "silencestart";
163 d.name = "Beginnings of Silent Regions";
164 d.description = "Return a single instant at the point where each silent region begins";
165 d.hasFixedBinCount = true;
167 d.hasKnownExtents = false;
168 d.sampleType = OutputDescriptor::VariableSampleRate;
172 d.identifier = "silenceend";
173 d.name = "Ends of Silent Regions";
174 d.description = "Return a single instant at the point where each silent region ends";
175 d.hasFixedBinCount = true;
177 d.hasKnownExtents = false;
178 d.sampleType = OutputDescriptor::VariableSampleRate;
184 d.identifier = "silent";
185 d.name = "Silent Regions";
186 d.description = "Return an interval covering each silent region";
187 d.hasFixedBinCount = true;
189 d.hasKnownExtents = false;
190 d.sampleType = OutputDescriptor::VariableSampleRate;
192 d.hasDuration = true;
195 d.identifier = "noisy";
196 d.name = "Non-Silent Regions";
197 d.description = "Return an interval covering each non-silent region";
198 d.hasFixedBinCount = true;
200 d.hasKnownExtents = false;
201 d.sampleType = OutputDescriptor::VariableSampleRate;
203 d.hasDuration = true;
207 d.identifier = "silencelevel";
208 d.name = "Silence Test";
209 d.description = "Return a function that switches from 1 to 0 when silence falls, and back again when it ends";
210 d.hasFixedBinCount = true;
212 d.hasKnownExtents = true;
215 d.isQuantized = true;
217 d.sampleType = OutputDescriptor::VariableSampleRate;
225 Silence::process(const float *const *inputBuffers,
226 Vamp::RealTime timestamp)
228 for (size_t i = 0; i < m_stepSize; ++i) {
229 for (size_t j = 0; j < m_channelCount; ++j) {
230 fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
234 bool silent = aubio_silence_detection(m_ibuf, m_threshold);
235 FeatureSet returnFeatures;
237 if (m_first || m_prevSilent != silent) {
239 Vamp::RealTime featureStamp = timestamp;
241 if ((silent && !m_first) || !silent) {
247 if (incr > m_stepSize/8) incr = m_stepSize/8;
250 vec.length = incr * 4;
251 vec.channels = m_channelCount;
252 vec.data = m_tmpptrs;
254 for (size_t i = 0; i < m_stepSize - incr * 4; i += incr) {
255 for (size_t j = 0; j < m_channelCount; ++j) {
256 m_tmpptrs[j] = m_ibuf->data[j] + i;
258 bool subsilent = aubio_silence_detection(&vec, m_threshold);
259 if (silent == subsilent) {
265 if (silent && (off == 0)) {
266 for (size_t i = 0; i < m_stepSize - incr; i += incr) {
267 for (size_t j = 0; j < m_channelCount; ++j) {
268 m_tmpptrs[j] = m_pbuf->data[j] + m_stepSize - i - incr;
270 bool subsilent = aubio_silence_detection(&vec, m_threshold);
279 featureStamp = timestamp + Vamp::RealTime::frame2RealTime
280 (off, lrintf(m_inputSampleRate));
284 feature.hasTimestamp = true;
285 feature.timestamp = featureStamp;
286 feature.values.push_back(silent ? 0 : 1);
287 returnFeatures[2].push_back(feature);
289 feature.values.clear();
291 if (m_apiVersion == 1) {
293 returnFeatures[0].push_back(feature);
295 returnFeatures[1].push_back(feature);
299 feature.timestamp = m_lastChange;
300 feature.hasDuration = true;
301 feature.duration = featureStamp - m_lastChange;
303 // becoming silent, so this is a non-silent region
304 returnFeatures[1].push_back(feature);
306 // becoming non-silent, so this is a silent region
307 returnFeatures[0].push_back(feature);
310 m_lastChange = featureStamp;
313 m_prevSilent = silent;
317 // swap ibuf and pbuf data pointers, so that this block's data is
318 // available in pbuf when processing the next block, without
319 // having to allocate new storage for it
320 smpl_t **tmpdata = m_ibuf->data;
321 m_ibuf->data = m_pbuf->data;
322 m_pbuf->data = tmpdata;
324 m_lastTimestamp = timestamp;
326 return returnFeatures;
330 Silence::getRemainingFeatures()
332 FeatureSet returnFeatures;
335 if (m_lastTimestamp > m_lastChange) {
337 feature.hasTimestamp = true;
338 feature.timestamp = m_lastChange;
339 feature.hasDuration = true;
340 feature.duration = m_lastTimestamp - m_lastChange;
342 returnFeatures[0].push_back(feature);
344 returnFeatures[1].push_back(feature);