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/>.
26 #include "MelEnergy.h"
33 MelEnergy::MelEnergy(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_melbank(0), // aubio_filterbank_t, set in reset
39 m_ovec(0), // output fvec_t, set in initialise
40 m_nfilters(40), // parameter
41 m_stepSize(0), // host parameter
42 m_blockSize(0) // host parameter
46 MelEnergy::~MelEnergy()
48 if (m_melbank) del_aubio_filterbank(m_melbank);
49 if (m_pvoc) del_aubio_pvoc(m_pvoc);
50 if (m_ibuf) del_fvec(m_ibuf);
51 if (m_ispec) del_cvec(m_ispec);
52 if (m_ovec) del_fvec(m_ovec);
56 MelEnergy::getIdentifier() const
58 return "aubiomelenergy";
62 MelEnergy::getName() const
64 return "Aubio Mel Bands Energy Extractor";
68 MelEnergy::getDescription() const
70 return "Extract energy in each Mel-frequency bands";
74 MelEnergy::getMaker() const
76 return "Paul Brossier";
80 MelEnergy::getPluginVersion() const
86 MelEnergy::getCopyright() const
92 MelEnergy::initialise(size_t channels, size_t stepSize, size_t blockSize)
95 std::cerr << "MelEnergy::initialise: channels must be 1" << std::endl;
99 if (m_nfilters != 40) {
100 std::cerr << "MelEnergy::initialise: number of filters must be 40" << std::endl;
104 m_stepSize = stepSize;
105 m_blockSize = blockSize;
107 m_ibuf = new_fvec(stepSize);
108 m_ispec = new_cvec(blockSize);
109 m_ovec = new_fvec(m_nfilters);
119 if (m_pvoc) del_aubio_pvoc(m_pvoc);
120 if (m_melbank) del_aubio_filterbank(m_melbank);
122 m_pvoc = new_aubio_pvoc(m_blockSize, m_stepSize);
124 m_melbank = new_aubio_filterbank(m_nfilters, m_blockSize);
125 aubio_filterbank_set_mel_coeffs_slaney(m_melbank, lrintf(m_inputSampleRate));
130 MelEnergy::getPreferredStepSize() const
136 MelEnergy::getPreferredBlockSize() const
141 MelEnergy::ParameterList
142 MelEnergy::getParameterDescriptors() const
146 ParameterDescriptor desc;
147 desc.identifier = "nfilters";
148 desc.name = "Number of filters";
149 desc.description = "Size of filterbank used to compute mel bands (fixed to 40 for now)";
152 desc.defaultValue = 40;
153 desc.isQuantized = true;
154 desc.quantizeStep = 1;
155 list.push_back(desc);
161 MelEnergy::getParameter(std::string param) const
163 if (param == "nfilters") {
171 MelEnergy::setParameter(std::string param, float value)
173 if (param == "nfilters") {
174 m_nfilters = lrintf(value);
178 MelEnergy::OutputList
179 MelEnergy::getOutputDescriptors() const
184 d.identifier = "mfcc";
185 d.name = "Mel-Frequency Energy per band";
186 d.description = "List of computed Energies in each Mel-Frequency Band";
188 d.hasFixedBinCount = true;
189 d.binCount = m_nfilters;
190 d.isQuantized = true;
191 d.sampleType = OutputDescriptor::FixedSampleRate;
192 d.sampleRate = OutputDescriptor::OneSamplePerStep;
198 MelEnergy::FeatureSet
199 MelEnergy::process(const float *const *inputBuffers,
200 Vamp::RealTime timestamp)
202 FeatureSet returnFeatures;
204 if (m_stepSize == 0) {
205 std::cerr << "MelEnergy::process: MelEnergy plugin not initialised" << std::endl;
206 return returnFeatures;
208 if (m_nfilters == 0) {
209 std::cerr << "MelEnergy::process: MelEnergy plugin not initialised" << std::endl;
210 return returnFeatures;
213 for (size_t i = 0; i < m_stepSize; ++i) {
214 fvec_set_sample(m_ibuf, inputBuffers[0][i], i);
217 aubio_pvoc_do(m_pvoc, m_ibuf, m_ispec);
218 aubio_filterbank_do(m_melbank, m_ispec, m_ovec);
221 for (uint_t i = 0; i < m_ovec->length; i++) {
222 float value = m_ovec->data[i];
223 feature.values.push_back(value);
226 returnFeatures[0].push_back(feature);
227 return returnFeatures;
230 MelEnergy::FeatureSet
231 MelEnergy::getRemainingFeatures()