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.minValue = -120;
122 desc.defaultValue = -80;
124 desc.isQuantized = false;
125 list.push_back(desc);
131 Silence::getParameter(std::string param) const
133 if (param == "silencethreshold") {
141 Silence::setParameter(std::string param, float value)
143 if (param == "silencethreshold") {
149 Silence::getOutputDescriptors() const
155 d.identifier = "silent";
156 d.name = "Silent Regions";
157 d.description = "Return an interval covering each silent region";
158 d.hasFixedBinCount = true;
160 d.hasKnownExtents = false;
161 d.sampleType = OutputDescriptor::VariableSampleRate;
163 d.hasDuration = true;
166 d.identifier = "noisy";
167 d.name = "Non-Silent Regions";
168 d.description = "Return an interval covering each non-silent region";
169 d.hasFixedBinCount = true;
171 d.hasKnownExtents = false;
172 d.sampleType = OutputDescriptor::VariableSampleRate;
174 d.hasDuration = true;
177 d.identifier = "silencelevel";
178 d.name = "Silence Test";
179 d.description = "Return a function that switches from 1 to 0 when silence falls, and back again when it ends";
180 d.hasFixedBinCount = true;
182 d.hasKnownExtents = true;
185 d.isQuantized = true;
187 d.sampleType = OutputDescriptor::VariableSampleRate;
195 Silence::process(const float *const *inputBuffers,
196 Vamp::RealTime timestamp)
198 for (size_t i = 0; i < m_stepSize; ++i) {
199 fvec_write_sample(m_ibuf, inputBuffers[0][i], i);
202 bool silent = aubio_silence_detection(m_ibuf, m_threshold);
203 FeatureSet returnFeatures;
205 if (m_first || m_prevSilent != silent) {
207 Vamp::RealTime featureStamp = timestamp;
209 if ((silent && !m_first) || !silent) {
215 if (incr > m_stepSize/8) incr = m_stepSize/8;
218 vec.length = incr * 4;
220 for (size_t i = 0; i < m_stepSize - incr * 4; i += incr) {
221 vec.data = m_ibuf->data + i;
222 bool subsilent = aubio_silence_detection(&vec, m_threshold);
223 if (silent == subsilent) {
229 if (silent && (off == 0)) {
230 for (size_t i = 0; i < m_stepSize - incr; i += incr) {
231 vec.data = m_pbuf->data + m_stepSize - i - incr;
232 bool subsilent = aubio_silence_detection(&vec, m_threshold);
241 featureStamp = timestamp + Vamp::RealTime::frame2RealTime
242 (off, lrintf(m_inputSampleRate));
246 feature.hasTimestamp = true;
247 feature.timestamp = featureStamp;
248 feature.values.push_back(silent ? 0 : 1);
249 returnFeatures[2].push_back(feature);
251 feature.values.clear();
254 feature.timestamp = m_lastChange;
255 feature.hasDuration = true;
256 feature.duration = featureStamp - m_lastChange;
258 // non-silent regions feature
259 // (becoming silent, so this is a non-silent region)
260 returnFeatures[1].push_back(feature);
262 // silent regions feature
263 // (becoming non-silent, so this is a silent region)
264 returnFeatures[0].push_back(feature);
267 m_lastChange = featureStamp;
269 m_prevSilent = silent;
273 // swap ibuf and pbuf data pointers, so that this block's data is
274 // available in pbuf when processing the next block, without
275 // having to allocate new storage for it
276 smpl_t *tmpdata = m_ibuf->data;
277 m_ibuf->data = m_pbuf->data;
278 m_pbuf->data = tmpdata;
280 m_lastTimestamp = timestamp;
282 return returnFeatures;
286 Silence::getRemainingFeatures()
288 FeatureSet returnFeatures;
290 // std::cerr << "Silence::getRemainingFeatures: m_lastTimestamp = " << m_lastTimestamp << ", m_lastChange = " << m_lastChange << ", m_apiVersion = " << m_apiVersion << ", m_prevSilent = " << m_prevSilent << std::endl;
292 if (m_lastTimestamp > m_lastChange) {
295 feature.hasTimestamp = true;
297 feature.timestamp = m_lastChange;
298 feature.hasDuration = true;
299 feature.duration = m_lastTimestamp - m_lastChange;
301 // silent regions feature
302 returnFeatures[0].push_back(feature);
304 // non-silent regions feature
305 returnFeatures[1].push_back(feature);
309 Feature silenceTestFeature;
310 silenceTestFeature.hasTimestamp = true;
311 silenceTestFeature.timestamp = m_lastTimestamp;
312 silenceTestFeature.values.push_back(0);
313 returnFeatures[2].push_back(silenceTestFeature);
317 return returnFeatures;