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 Copyright (C) 2006-2015 Paul Brossier <piem@aubio.org>
8 This file is part of vamp-aubio.
10 vamp-aubio is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
15 vamp-aubio is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with aubio. If not, see <http://www.gnu.org/licenses/>.
33 SpecDesc::SpecDesc(float inputSampleRate) :
34 Plugin(inputSampleRate),
40 m_specdesctype(SpecDescFlux)
46 if (m_specdesc) del_aubio_specdesc(m_specdesc);
47 if (m_pvoc) del_aubio_pvoc(m_pvoc);
48 if (m_ibuf) del_fvec(m_ibuf);
49 if (m_ispec) del_cvec(m_ispec);
50 if (m_out) del_fvec(m_out);
54 SpecDesc::getIdentifier() const
56 return "aubiospecdesc";
60 SpecDesc::getName() const
62 return "Aubio Spectral Descriptor";
66 SpecDesc::getDescription() const
68 return "Compute spectral descriptor";
72 SpecDesc::getMaker() const
74 return "Paul Brossier";
78 SpecDesc::getPluginVersion() const
84 SpecDesc::getCopyright() const
90 SpecDesc::initialise(size_t channels, size_t stepSize, size_t blockSize)
93 std::cerr << "SpecDesc::initialise: channels must be 1" << std::endl;
97 m_stepSize = stepSize;
98 m_blockSize = blockSize;
100 m_ibuf = new_fvec(stepSize);
101 m_ispec = new_cvec(blockSize);
112 if (m_pvoc) del_aubio_pvoc(m_pvoc);
113 if (m_specdesc) del_aubio_specdesc(m_specdesc);
115 m_specdesc = new_aubio_specdesc
116 (const_cast<char *>(getAubioNameForSpecDescType(m_specdesctype)),
119 m_pvoc = new_aubio_pvoc(m_blockSize, m_stepSize);
123 SpecDesc::getPreferredStepSize() const
129 SpecDesc::getPreferredBlockSize() const
131 return 2 * getPreferredStepSize();
134 SpecDesc::ParameterList
135 SpecDesc::getParameterDescriptors() const
139 ParameterDescriptor desc;
140 desc.identifier = "specdesctype";
141 desc.name = "Spectral Descriptor Type";
142 desc.description = "Type of spectral descriptor to use";
145 desc.defaultValue = (int)SpecDescFlux;
146 desc.isQuantized = true;
147 desc.quantizeStep = 1;
148 desc.valueNames.push_back("Spectral Flux");
149 desc.valueNames.push_back("Spectral Centroid");
150 desc.valueNames.push_back("Spectral Spread");
151 desc.valueNames.push_back("Spectral Skewness");
152 desc.valueNames.push_back("Spectral Kurtosis");
153 desc.valueNames.push_back("Spectral Slope");
154 desc.valueNames.push_back("Spectral Decrease");
155 desc.valueNames.push_back("Spectral Rolloff");
156 list.push_back(desc);
162 SpecDesc::getParameter(std::string param) const
164 if (param == "specdesctype") {
165 return m_specdesctype;
172 SpecDesc::setParameter(std::string param, float value)
174 if (param == "specdesctype") {
175 switch (lrintf(value)) {
176 case 0: m_specdesctype = SpecDescFlux; break;
177 case 1: m_specdesctype = SpecDescCentroid; break;
178 case 2: m_specdesctype = SpecDescSpread; break;
179 case 3: m_specdesctype = SpecDescSkeweness; break;
180 case 4: m_specdesctype = SpecDescKurtosis; break;
181 case 5: m_specdesctype = SpecDescSlope; break;
182 case 6: m_specdesctype = SpecDescDecrease; break;
183 case 7: m_specdesctype = SpecDescRolloff; break;
189 SpecDesc::getOutputDescriptors() const
194 d.identifier = "specdesc";
195 d.name = "Spectral descriptor output";
196 d.description = "Output of the spectral descpriptor";
198 d.isQuantized = true;
199 d.quantizeStep = 1.0;
200 d.sampleType = OutputDescriptor::OneSamplePerStep;
207 SpecDesc::process(const float *const *inputBuffers,
208 __attribute__((unused)) Vamp::RealTime timestamp)
210 for (size_t i = 0; i < m_stepSize; ++i) {
211 fvec_set_sample(m_ibuf, inputBuffers[0][i], i);
214 aubio_pvoc_do(m_pvoc, m_ibuf, m_ispec);
215 aubio_specdesc_do(m_specdesc, m_ispec, m_out);
217 FeatureSet returnFeatures;
220 specdesc.hasTimestamp = false;
221 specdesc.values.push_back(m_out->data[0]);
222 returnFeatures[0].push_back(specdesc);
224 return returnFeatures;
228 SpecDesc::getRemainingFeatures()