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 Tempo::Tempo(float inputSampleRate) :
26 Plugin(inputSampleRate),
33 m_onsettype(aubio_onset_specdiff),
46 if (m_onsetdet) aubio_onsetdetection_free(m_onsetdet);
47 if (m_ibuf) del_fvec(m_ibuf);
48 if (m_onset) del_fvec(m_onset);
49 if (m_fftgrain) del_cvec(m_fftgrain);
50 if (m_pv) del_aubio_pvoc(m_pv);
51 if (m_peakpick) del_aubio_peakpicker(m_peakpick);
52 if (m_beattracking) del_aubio_beattracking(m_beattracking);
53 if (m_dfframe) del_fvec(m_dfframe);
54 if (m_btout) del_fvec(m_btout);
58 Tempo::getName() const
64 Tempo::getDescription() const
66 return "Aubio Tempo Detector";
70 Tempo::getMaker() const
72 return "Paul Brossier (plugin by Chris Cannam)";
76 Tempo::getPluginVersion() const
82 Tempo::getCopyright() const
88 Tempo::initialise(size_t channels, size_t stepSize, size_t blockSize)
90 m_channelCount = channels;
91 m_stepSize = stepSize;
92 m_blockSize = blockSize;
94 m_ibuf = new_fvec(stepSize, channels);
95 m_onset = new_fvec(1, channels);
96 m_fftgrain = new_cvec(blockSize, channels);
97 m_pv = new_aubio_pvoc(blockSize, stepSize, channels);
98 m_peakpick = new_aubio_peakpicker(m_threshold);
100 m_onsetdet = new_aubio_onsetdetection(m_onsettype, blockSize, channels);
102 m_delay = Vamp::RealTime::frame2RealTime(3 * stepSize,
103 lrintf(m_inputSampleRate));
105 m_lastBeat = Vamp::RealTime::zeroTime - m_delay - m_delay;
107 m_winlen = 512*512/stepSize;
108 m_dfframe = new_fvec(m_winlen,channels);
109 m_btstep = m_winlen/4;
110 m_btout = new_fvec(m_btstep,channels);
111 m_beattracking = new_aubio_beattracking(m_winlen,channels);
122 Tempo::getPreferredStepSize() const
128 Tempo::getPreferredBlockSize() const
130 return 2 * getPreferredStepSize();
134 Tempo::getParameterDescriptors() const
138 ParameterDescriptor desc;
139 desc.name = "onsettype";
140 desc.description = "Onset Detection Function Type";
143 desc.defaultValue = (int)aubio_onset_complex;
144 desc.isQuantized = true;
145 desc.quantizeStep = 1;
146 desc.valueNames.push_back("Energy Based");
147 desc.valueNames.push_back("Spectral Difference");
148 desc.valueNames.push_back("High-Frequency Content");
149 desc.valueNames.push_back("Complex Domain");
150 desc.valueNames.push_back("Phase Deviation");
151 desc.valueNames.push_back("Kullback-Liebler");
152 desc.valueNames.push_back("Modified Kullback-Liebler");
153 list.push_back(desc);
155 desc = ParameterDescriptor();
156 desc.name = "peakpickthreshold";
157 desc.description = "Peak Picker Threshold";
160 desc.defaultValue = 0.3;
161 desc.isQuantized = false;
162 list.push_back(desc);
164 desc = ParameterDescriptor();
165 desc.name = "silencethreshold";
166 desc.description = "Silence Threshold";
167 desc.minValue = -120;
169 desc.defaultValue = -90;
171 desc.isQuantized = false;
172 list.push_back(desc);
178 Tempo::getParameter(std::string param) const
180 if (param == "onsettype") {
182 } else if (param == "peakpickthreshold") {
184 } else if (param == "silencethreshold") {
192 Tempo::setParameter(std::string param, float value)
194 if (param == "onsettype") {
195 switch (lrintf(value)) {
196 case 0: m_onsettype = aubio_onset_energy; break;
197 case 1: m_onsettype = aubio_onset_specdiff; break;
198 case 2: m_onsettype = aubio_onset_hfc; break;
199 case 3: m_onsettype = aubio_onset_complex; break;
200 case 4: m_onsettype = aubio_onset_phase; break;
201 case 5: m_onsettype = aubio_onset_kl; break;
202 case 6: m_onsettype = aubio_onset_mkl; break;
204 } else if (param == "peakpickthreshold") {
206 } else if (param == "silencethreshold") {
212 Tempo::getOutputDescriptors() const
219 d.description = "Beats";
220 d.hasFixedBinCount = true;
222 d.sampleType = OutputDescriptor::VariableSampleRate;
230 Tempo::process(float **inputBuffers, Vamp::RealTime timestamp)
232 for (size_t i = 0; i < m_stepSize; ++i) {
233 for (size_t j = 0; j < m_channelCount; ++j) {
234 fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
238 aubio_pvoc_do(m_pv, m_ibuf, m_fftgrain);
239 aubio_onsetdetection(m_onsetdet, m_fftgrain, m_onset);
241 if ( m_btcounter == m_btstep - 1 ) {
242 aubio_beattracking_do(m_beattracking,m_dfframe,m_btout);
244 for (size_t i = 0 ; i < m_winlen - m_btstep; i++ )
245 m_dfframe->data[0][i] = m_dfframe->data[0][i+m_btstep];
246 for (size_t i = m_winlen - m_btstep ; i < m_winlen; i++ )
247 m_dfframe->data[0][i] = 0.;
252 bool isonset = aubio_peakpick_pimrt_wt( m_onset, m_peakpick,
253 &(m_dfframe->data[0][m_winlen - m_btstep + m_btcounter]));
257 /* check if any of the predicted beat correspond to the current time */
258 for (size_t i = 1; i < m_btout->data[0][0]; i++ ) {
259 if (m_btcounter == m_btout->data[0][i]) {
260 if (aubio_silence_detection(m_ibuf, m_silence)) {
269 FeatureSet returnFeatures;
271 if (istactus == true) {
272 if (timestamp - m_lastBeat >= m_delay) {
274 onsettime.hasTimestamp = true;
275 if (timestamp < m_delay) timestamp = m_delay;
276 onsettime.timestamp = timestamp - m_delay;
277 returnFeatures[0].push_back(onsettime);
278 m_lastBeat = timestamp;
282 return returnFeatures;
286 Tempo::getRemainingFeatures()