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.
25 Silence::Silence(float inputSampleRate) :
26 Plugin(inputSampleRate),
38 if (m_ibuf) del_fvec(m_ibuf);
39 if (m_pbuf) del_fvec(m_pbuf);
40 if (m_tmpptrs) delete[] m_tmpptrs;
44 Silence::getIdentifier() const
46 return "aubiosilence";
50 Silence::getName() const
52 return "Aubio Silence Detector";
56 Silence::getDescription() const
58 return "Detect levels below a certain threshold";
62 Silence::getMaker() const
64 return "Paul Brossier (plugin by Chris Cannam)";
68 Silence::getPluginVersion() const
74 Silence::getCopyright() const
80 Silence::initialise(size_t channels, size_t stepSize, size_t blockSize)
82 m_channelCount = channels;
83 m_stepSize = stepSize;
84 m_blockSize = blockSize;
86 m_ibuf = new_fvec(stepSize, channels);
87 m_pbuf = new_fvec(stepSize, channels);
88 m_tmpptrs = new smpl_t *[channels];
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 = -70;
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
154 d.identifier = "silencestart";
155 d.name = "Starts of Silent Regions";
156 d.description = "Return a single instant at the point where each silent region begins";
157 d.hasFixedBinCount = true;
159 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;
170 d.identifier = "silencelevel";
171 d.name = "Silence Test";
172 d.description = "Return a function that switches from 1 to 0 when silence falls, and back again when it ends";
173 d.hasFixedBinCount = true;
175 d.hasKnownExtents = true;
178 d.isQuantized = true;
180 d.sampleType = OutputDescriptor::VariableSampleRate;
187 Silence::process(const float *const *inputBuffers,
188 Vamp::RealTime timestamp)
190 for (size_t i = 0; i < m_stepSize; ++i) {
191 for (size_t j = 0; j < m_channelCount; ++j) {
192 fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
196 bool silent = aubio_silence_detection(m_ibuf, m_threshold);
197 FeatureSet returnFeatures;
199 if (m_first || m_prevSilent != silent) {
201 Vamp::RealTime featureStamp = timestamp;
203 if ((silent && !m_first) || !silent) {
209 if (incr > m_stepSize/8) incr = m_stepSize/8;
212 vec.length = incr * 4;
213 vec.channels = m_channelCount;
214 vec.data = m_tmpptrs;
217 std::cerr << "silence at " << timestamp << std::endl;
220 for (size_t i = 0; i < m_stepSize - incr * 4; i += incr) {
221 for (size_t j = 0; j < m_channelCount; ++j) {
222 m_tmpptrs[j] = m_ibuf->data[j] + i;
224 bool subsilent = aubio_silence_detection(&vec, m_threshold);
225 if (silent == subsilent) {
226 std::cerr << "silent == subsilent at " << i << " after" << std::endl;
232 if (silent && (off == 0)) {
233 for (size_t i = 0; i < m_stepSize - incr; i += incr) {
234 for (size_t j = 0; j < m_channelCount; ++j) {
235 m_tmpptrs[j] = m_pbuf->data[j] + m_stepSize - i - incr;
237 bool subsilent = aubio_silence_detection(&vec, m_threshold);
239 std::cerr << "non-silence at " << i << " samples before" << std::endl;
243 std::cerr << "silence at " << i << " samples before" << std::endl;
249 featureStamp = timestamp + Vamp::RealTime::frame2RealTime
250 (off, lrintf(m_inputSampleRate));
254 feature.hasTimestamp = true;
255 feature.timestamp = featureStamp;
256 feature.values.push_back(silent ? 0 : 1);
257 returnFeatures[2].push_back(feature);
258 feature.values.clear();
261 returnFeatures[0].push_back(feature);
263 returnFeatures[1].push_back(feature);
266 m_prevSilent = silent;
270 // swap ibuf and pbuf data pointers, so that this block's data is
271 // available in pbuf when processing the next block, without
272 // having to allocate new storage for it
273 smpl_t **tmpdata = m_ibuf->data;
274 m_ibuf->data = m_pbuf->data;
275 m_pbuf->data = tmpdata;
277 return returnFeatures;
281 Silence::getRemainingFeatures()