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 Chris Cannam.
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),
37 if (m_ibuf) del_fvec(m_ibuf);
38 if (m_pbuf) del_fvec(m_pbuf);
39 if (m_tmpptrs) delete[] m_tmpptrs;
43 Silence::getIdentifier() const
45 return "aubiosilence";
49 Silence::getName() const
51 return "Aubio Silence Detector";
55 Silence::getDescription() const
57 return "Detect levels below a certain threshold";
61 Silence::getMaker() const
63 return "Paul Brossier (plugin by Chris Cannam)";
67 Silence::getPluginVersion() const
73 Silence::getCopyright() const
79 Silence::initialise(size_t channels, size_t stepSize, size_t blockSize)
81 m_channelCount = channels;
82 m_stepSize = stepSize;
83 m_blockSize = blockSize;
85 m_ibuf = new_fvec(stepSize, channels);
86 m_pbuf = new_fvec(stepSize, channels);
87 m_tmpptrs = new smpl_t *[channels];
99 Silence::getPreferredStepSize() const
105 Silence::getPreferredBlockSize() const
110 Silence::ParameterList
111 Silence::getParameterDescriptors() const
114 ParameterDescriptor desc;
116 desc = ParameterDescriptor();
117 desc.identifier = "silencethreshold";
118 desc.name = "Silence Threshold";
119 desc.minValue = -120;
121 desc.defaultValue = -80;
123 desc.isQuantized = false;
124 list.push_back(desc);
130 Silence::getParameter(std::string param) const
132 if (param == "silencethreshold") {
140 Silence::setParameter(std::string param, float value)
142 if (param == "silencethreshold") {
148 Silence::getOutputDescriptors() const
153 d.identifier = "silencestart";
154 d.name = "Beginnings of Silent Regions";
155 d.description = "Return a single instant at the point where each silent region begins";
156 d.hasFixedBinCount = true;
158 d.sampleType = OutputDescriptor::VariableSampleRate;
162 d.identifier = "silenceend";
163 d.name = "Ends of Silent Regions";
164 d.description = "Return a single instant at the point where each silent region ends";
165 d.hasFixedBinCount = true;
167 d.sampleType = OutputDescriptor::VariableSampleRate;
171 d.identifier = "silencelevel";
172 d.name = "Silence Test";
173 d.description = "Return a function that switches from 1 to 0 when silence falls, and back again when it ends";
174 d.hasFixedBinCount = true;
176 d.hasKnownExtents = true;
179 d.isQuantized = true;
181 d.sampleType = OutputDescriptor::VariableSampleRate;
189 Silence::process(const float *const *inputBuffers,
190 Vamp::RealTime timestamp)
192 for (size_t i = 0; i < m_stepSize; ++i) {
193 for (size_t j = 0; j < m_channelCount; ++j) {
194 fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
198 bool silent = aubio_silence_detection(m_ibuf, m_threshold);
199 FeatureSet returnFeatures;
201 if (m_first || m_prevSilent != silent) {
203 Vamp::RealTime featureStamp = timestamp;
205 if ((silent && !m_first) || !silent) {
211 if (incr > m_stepSize/8) incr = m_stepSize/8;
214 vec.length = incr * 4;
215 vec.channels = m_channelCount;
216 vec.data = m_tmpptrs;
218 for (size_t i = 0; i < m_stepSize - incr * 4; i += incr) {
219 for (size_t j = 0; j < m_channelCount; ++j) {
220 m_tmpptrs[j] = m_ibuf->data[j] + 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 for (size_t j = 0; j < m_channelCount; ++j) {
232 m_tmpptrs[j] = m_pbuf->data[j] + m_stepSize - i - incr;
234 bool subsilent = aubio_silence_detection(&vec, m_threshold);
243 featureStamp = timestamp + Vamp::RealTime::frame2RealTime
244 (off, lrintf(m_inputSampleRate));
248 feature.hasTimestamp = true;
249 feature.timestamp = featureStamp;
250 feature.values.push_back(silent ? 0 : 1);
251 returnFeatures[2].push_back(feature);
252 feature.values.clear();
255 returnFeatures[0].push_back(feature);
257 returnFeatures[1].push_back(feature);
260 m_prevSilent = silent;
264 // swap ibuf and pbuf data pointers, so that this block's data is
265 // available in pbuf when processing the next block, without
266 // having to allocate new storage for it
267 smpl_t **tmpdata = m_ibuf->data;
268 m_ibuf->data = m_pbuf->data;
269 m_pbuf->data = tmpdata;
271 return returnFeatures;
275 Silence::getRemainingFeatures()