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) :
25 Plugin(inputSampleRate),
36 if (m_ibuf) del_fvec(m_ibuf);
37 if (m_pbuf) del_fvec(m_pbuf);
41 Silence::getIdentifier() const
43 return "aubiosilence";
47 Silence::getName() const
49 return "Aubio Silence Detector";
53 Silence::getDescription() const
55 return "Detect levels below a certain threshold";
59 Silence::getMaker() const
61 return "Paul Brossier (plugin by Chris Cannam)";
65 Silence::getPluginVersion() const
71 Silence::getCopyright() const
77 Silence::initialise(size_t channels, size_t stepSize, size_t blockSize)
80 std::cerr << "Silence::initialise: channels must be 1" << std::endl;
84 m_stepSize = stepSize;
85 m_blockSize = blockSize;
87 m_ibuf = new_fvec(stepSize);
88 m_pbuf = new_fvec(stepSize);
100 Silence::getPreferredStepSize() const
106 Silence::getPreferredBlockSize() const
111 Silence::ParameterList
112 Silence::getParameterDescriptors() const
115 ParameterDescriptor desc;
117 desc = ParameterDescriptor();
118 desc.identifier = "silencethreshold";
119 desc.name = "Silence Threshold";
120 desc.description = "Threshold for silence detection";
121 desc.minValue = -120;
123 desc.defaultValue = -80;
125 desc.isQuantized = false;
126 list.push_back(desc);
132 Silence::getParameter(std::string param) const
134 if (param == "silencethreshold") {
142 Silence::setParameter(std::string param, float value)
144 if (param == "silencethreshold") {
150 Silence::getOutputDescriptors() const
156 d.identifier = "silent";
157 d.name = "Silent Regions";
158 d.description = "Return an interval covering each silent region";
159 d.hasFixedBinCount = true;
161 d.hasKnownExtents = false;
162 d.sampleType = OutputDescriptor::VariableSampleRate;
164 d.hasDuration = true;
167 d.identifier = "noisy";
168 d.name = "Non-Silent Regions";
169 d.description = "Return an interval covering each non-silent region";
170 d.hasFixedBinCount = true;
172 d.hasKnownExtents = false;
173 d.sampleType = OutputDescriptor::VariableSampleRate;
175 d.hasDuration = true;
178 d.identifier = "silencelevel";
179 d.name = "Silence Test";
180 d.description = "Return a function that switches from 1 to 0 when silence falls, and back again when it ends";
181 d.hasFixedBinCount = true;
183 d.hasKnownExtents = true;
186 d.isQuantized = true;
188 d.sampleType = OutputDescriptor::VariableSampleRate;
196 Silence::process(const float *const *inputBuffers,
197 Vamp::RealTime timestamp)
199 for (size_t i = 0; i < m_stepSize; ++i) {
200 fvec_set_sample(m_ibuf, inputBuffers[0][i], i);
203 bool silent = aubio_silence_detection(m_ibuf, m_threshold);
204 FeatureSet returnFeatures;
206 if (m_first || m_prevSilent != silent) {
208 Vamp::RealTime featureStamp = timestamp;
210 if ((silent && !m_first) || !silent) {
216 if (incr > m_stepSize/8) incr = m_stepSize/8;
219 vec.length = incr * 4;
221 for (size_t i = 0; i < m_stepSize - incr * 4; i += incr) {
222 vec.data = m_ibuf->data + i;
223 bool subsilent = aubio_silence_detection(&vec, m_threshold);
224 if (silent == subsilent) {
230 if (silent && (off == 0)) {
231 for (size_t i = 0; i < m_stepSize - incr; i += incr) {
232 vec.data = m_pbuf->data + m_stepSize - i - incr;
233 bool subsilent = aubio_silence_detection(&vec, m_threshold);
242 featureStamp = timestamp + Vamp::RealTime::frame2RealTime
243 (off, lrintf(m_inputSampleRate));
247 feature.hasTimestamp = true;
248 feature.timestamp = featureStamp;
249 feature.values.push_back(silent ? 0 : 1);
250 returnFeatures[2].push_back(feature);
252 feature.values.clear();
255 feature.timestamp = m_lastChange;
256 feature.hasDuration = true;
257 feature.duration = featureStamp - m_lastChange;
259 // non-silent regions feature
260 // (becoming silent, so this is a non-silent region)
261 returnFeatures[1].push_back(feature);
263 // silent regions feature
264 // (becoming non-silent, so this is a silent region)
265 returnFeatures[0].push_back(feature);
268 m_lastChange = featureStamp;
270 m_prevSilent = silent;
274 // swap ibuf and pbuf data pointers, so that this block's data is
275 // available in pbuf when processing the next block, without
276 // having to allocate new storage for it
277 smpl_t *tmpdata = m_ibuf->data;
278 m_ibuf->data = m_pbuf->data;
279 m_pbuf->data = tmpdata;
281 m_lastTimestamp = timestamp;
283 return returnFeatures;
287 Silence::getRemainingFeatures()
289 FeatureSet returnFeatures;
291 // std::cerr << "Silence::getRemainingFeatures: m_lastTimestamp = " << m_lastTimestamp << ", m_lastChange = " << m_lastChange << ", m_apiVersion = " << m_apiVersion << ", m_prevSilent = " << m_prevSilent << std::endl;
293 if (m_lastTimestamp > m_lastChange) {
296 feature.hasTimestamp = true;
298 feature.timestamp = m_lastChange;
299 feature.hasDuration = true;
300 feature.duration = m_lastTimestamp - m_lastChange;
302 // silent regions feature
303 returnFeatures[0].push_back(feature);
305 // non-silent regions feature
306 returnFeatures[1].push_back(feature);
310 Feature silenceTestFeature;
311 silenceTestFeature.hasTimestamp = true;
312 silenceTestFeature.timestamp = m_lastTimestamp;
313 silenceTestFeature.values.push_back(0);
314 returnFeatures[2].push_back(silenceTestFeature);
318 return returnFeatures;