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-plugins.
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 Mfcc::Mfcc(float inputSampleRate) :
34 Plugin(inputSampleRate),
35 m_ibuf(0), // input fvec_t, set in initialise
36 m_pvoc(0), // aubio_pvoc_t, set in reset
37 m_ispec(0), // cvec_t, set in initialise
38 m_mfcc(0), // aubio_mfcc_t, set in reset
39 m_ovec(0), // output fvec_t, set in initialise
40 m_nfilters(40), // parameter
41 m_ncoeffs(13), // parameter
42 m_stepSize(0), // host parameter
43 m_blockSize(0) // host parameter
49 if (m_mfcc) del_aubio_mfcc(m_mfcc);
50 if (m_pvoc) del_aubio_pvoc(m_pvoc);
51 if (m_ibuf) del_fvec(m_ibuf);
52 if (m_ispec) del_cvec(m_ispec);
53 if (m_ovec) del_fvec(m_ovec);
57 Mfcc::getIdentifier() const
65 return "Aubio Mfcc Extractor";
69 Mfcc::getDescription() const
71 return "Extract Mel-Frequency Cepstrum Coefficients";
75 Mfcc::getMaker() const
77 return "Paul Brossier";
81 Mfcc::getPluginVersion() const
87 Mfcc::getCopyright() const
93 Mfcc::initialise(size_t channels, size_t stepSize, size_t blockSize)
96 std::cerr << "Mfcc::initialise: channels must be 1" << std::endl;
100 m_stepSize = stepSize;
101 m_blockSize = blockSize;
103 m_ibuf = new_fvec(stepSize);
104 m_ispec = new_cvec(blockSize);
105 m_ovec = new_fvec(m_ncoeffs);
115 if (m_pvoc) del_aubio_pvoc(m_pvoc);
116 if (m_mfcc) del_aubio_mfcc(m_mfcc);
118 m_pvoc = new_aubio_pvoc(m_blockSize, m_stepSize);
120 m_mfcc = new_aubio_mfcc(m_blockSize, m_nfilters, m_ncoeffs,
121 lrintf(m_inputSampleRate));
126 Mfcc::getPreferredStepSize() const
132 Mfcc::getPreferredBlockSize() const
138 Mfcc::getParameterDescriptors() const
142 ParameterDescriptor desc;
143 desc.identifier = "nfilters";
144 desc.name = "Number of filters";
145 desc.description = "Size of mel filterbank used to compute MFCCs (fixed to 40 for now)";
148 desc.defaultValue = 40;
149 desc.isQuantized = true;
150 desc.quantizeStep = 1;
151 list.push_back(desc);
153 desc = ParameterDescriptor();
154 desc.identifier = "ncoeffs";
155 desc.name = "Number of coefficients";
156 desc.description = "Number of output coefficients to compute";
159 desc.defaultValue = 13;
160 desc.isQuantized = true;
161 desc.quantizeStep = 1;
162 list.push_back(desc);
168 Mfcc::getParameter(std::string param) const
170 if (param == "ncoeffs") {
172 } else if (param == "nfilters") {
180 Mfcc::setParameter(std::string param, float value)
182 if (param == "nfilters") {
183 m_nfilters = lrintf(value);
184 } else if (param == "ncoeffs") {
185 m_ncoeffs = lrintf(value);
190 Mfcc::getOutputDescriptors() const
195 d.identifier = "mfcc";
196 d.name = "Mel-Frequency Cepstrum Coefficients";
197 d.description = "List of detected Mel-Frequency Cepstrum Coefficients";
199 d.hasFixedBinCount = true;
200 d.binCount = m_ncoeffs;
201 d.isQuantized = true;
202 d.quantizeStep = 1.0;
203 d.sampleType = OutputDescriptor::OneSamplePerStep;
210 Mfcc::process(const float *const *inputBuffers,
211 UNUSED Vamp::RealTime timestamp)
213 FeatureSet returnFeatures;
215 if (m_stepSize == 0) {
216 std::cerr << "Mfcc::process: Mfcc plugin not initialised" << std::endl;
217 return returnFeatures;
219 if (m_ncoeffs == 0) {
220 std::cerr << "Mfcc::process: Mfcc plugin not initialised" << std::endl;
221 return returnFeatures;
224 for (size_t i = 0; i < m_stepSize; ++i) {
225 fvec_set_sample(m_ibuf, inputBuffers[0][i], i);
228 aubio_pvoc_do(m_pvoc, m_ibuf, m_ispec);
229 aubio_mfcc_do(m_mfcc, m_ispec, m_ovec);
232 for (uint_t i = 0; i < m_ovec->length; i++) {
233 float value = m_ovec->data[i];
234 feature.values.push_back(value);
237 returnFeatures[0].push_back(feature);
238 return returnFeatures;
242 Mfcc::getRemainingFeatures()