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 file is part of vamp-aubio-plugins.
11 vamp-aubio is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 vamp-aubio is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with aubio. If not, see <http://www.gnu.org/licenses/>.
34 Silence::Silence(float inputSampleRate) :
35 Plugin(inputSampleRate),
46 if (m_ibuf) del_fvec(m_ibuf);
47 if (m_pbuf) del_fvec(m_pbuf);
51 Silence::getIdentifier() const
53 return "aubiosilence";
57 Silence::getName() const
59 return "Aubio Silence Detector";
63 Silence::getDescription() const
65 return "Detect levels below a certain threshold";
69 Silence::getMaker() const
71 return "Paul Brossier (plugin by Chris Cannam)";
75 Silence::getPluginVersion() const
81 Silence::getCopyright() const
87 Silence::initialise(size_t channels, size_t stepSize, size_t blockSize)
90 std::cerr << "Silence::initialise: channels must be 1" << std::endl;
94 m_stepSize = stepSize;
95 m_blockSize = blockSize;
97 m_ibuf = new_fvec(stepSize);
98 m_pbuf = new_fvec(stepSize);
110 Silence::getPreferredStepSize() const
116 Silence::getPreferredBlockSize() const
121 Silence::ParameterList
122 Silence::getParameterDescriptors() const
125 ParameterDescriptor desc;
127 desc = ParameterDescriptor();
128 desc.identifier = "silencethreshold";
129 desc.name = "Silence Threshold";
130 desc.description = "Threshold for silence detection";
131 desc.minValue = -120;
133 desc.defaultValue = -80;
135 desc.isQuantized = false;
136 list.push_back(desc);
142 Silence::getParameter(std::string param) const
144 if (param == "silencethreshold") {
152 Silence::setParameter(std::string param, float value)
154 if (param == "silencethreshold") {
160 Silence::getOutputDescriptors() const
166 d.identifier = "silent";
167 d.name = "Silent Regions";
168 d.description = "Return an interval covering each silent region";
169 d.hasFixedBinCount = true;
171 d.hasKnownExtents = false;
172 d.sampleType = OutputDescriptor::VariableSampleRate;
174 d.hasDuration = true;
177 d.identifier = "noisy";
178 d.name = "Non-Silent Regions";
179 d.description = "Return an interval covering each non-silent region";
180 d.hasFixedBinCount = true;
182 d.hasKnownExtents = false;
183 d.sampleType = OutputDescriptor::VariableSampleRate;
185 d.hasDuration = true;
188 d.identifier = "silencelevel";
189 d.name = "Silence Test";
190 d.description = "Return a function that switches from 1 to 0 when silence falls, and back again when it ends";
191 d.hasFixedBinCount = true;
193 d.hasKnownExtents = true;
196 d.isQuantized = true;
198 d.sampleType = OutputDescriptor::VariableSampleRate;
206 Silence::process(const float *const *inputBuffers,
207 Vamp::RealTime timestamp)
209 for (size_t i = 0; i < m_stepSize; ++i) {
210 fvec_set_sample(m_ibuf, inputBuffers[0][i], i);
213 bool silent = aubio_silence_detection(m_ibuf, m_threshold);
214 FeatureSet returnFeatures;
216 if (m_first || m_prevSilent != silent) {
218 Vamp::RealTime featureStamp = timestamp;
220 if ((silent && !m_first) || !silent) {
226 if (incr > m_stepSize/8) incr = m_stepSize/8;
229 vec.length = incr * 4;
231 for (size_t i = 0; i < m_stepSize - incr * 4; i += incr) {
232 vec.data = m_ibuf->data + i;
233 bool subsilent = aubio_silence_detection(&vec, m_threshold);
234 if (silent == subsilent) {
240 if (silent && (off == 0)) {
241 for (size_t i = 0; i < m_stepSize - incr; i += incr) {
242 vec.data = m_pbuf->data + m_stepSize - i - incr;
243 bool subsilent = aubio_silence_detection(&vec, m_threshold);
252 featureStamp = timestamp + Vamp::RealTime::frame2RealTime
253 (off, lrintf(m_inputSampleRate));
257 feature.hasTimestamp = true;
258 feature.timestamp = featureStamp;
259 feature.values.push_back(silent ? 0 : 1);
260 returnFeatures[2].push_back(feature);
262 feature.values.clear();
265 feature.timestamp = m_lastChange;
266 feature.hasDuration = true;
267 feature.duration = featureStamp - m_lastChange;
269 // non-silent regions feature
270 // (becoming silent, so this is a non-silent region)
271 returnFeatures[1].push_back(feature);
273 // silent regions feature
274 // (becoming non-silent, so this is a silent region)
275 returnFeatures[0].push_back(feature);
278 m_lastChange = featureStamp;
280 m_prevSilent = silent;
284 // swap ibuf and pbuf data pointers, so that this block's data is
285 // available in pbuf when processing the next block, without
286 // having to allocate new storage for it
287 smpl_t *tmpdata = m_ibuf->data;
288 m_ibuf->data = m_pbuf->data;
289 m_pbuf->data = tmpdata;
291 m_lastTimestamp = timestamp;
293 return returnFeatures;
297 Silence::getRemainingFeatures()
299 FeatureSet returnFeatures;
301 // std::cerr << "Silence::getRemainingFeatures: m_lastTimestamp = " << m_lastTimestamp << ", m_lastChange = " << m_lastChange << ", m_apiVersion = " << m_apiVersion << ", m_prevSilent = " << m_prevSilent << std::endl;
303 if (m_lastTimestamp > m_lastChange) {
306 feature.hasTimestamp = true;
308 feature.timestamp = m_lastChange;
309 feature.hasDuration = true;
310 feature.duration = m_lastTimestamp - m_lastChange;
312 // silent regions feature
313 returnFeatures[0].push_back(feature);
315 // non-silent regions feature
316 returnFeatures[1].push_back(feature);
320 Feature silenceTestFeature;
321 silenceTestFeature.hasTimestamp = true;
322 silenceTestFeature.timestamp = m_lastTimestamp;
323 silenceTestFeature.values.push_back(0);
324 returnFeatures[2].push_back(silenceTestFeature);
328 return returnFeatures;