Mercurial > hg > vamp-aubio-plugins
comparison plugins/Tempo.cpp @ 12:62414aaaaa7e
* Update to new Vamp process()
* Add hack for getting raw tempo out of hacked Aubio
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Tue, 12 Dec 2006 10:42:21 +0000 |
parents | 4493cb063598 |
children | 1169d00391d8 |
comparison
equal
deleted
inserted
replaced
11:dcc20cd836d7 | 12:62414aaaaa7e |
---|---|
19 | 19 |
20 using std::string; | 20 using std::string; |
21 using std::vector; | 21 using std::vector; |
22 using std::cerr; | 22 using std::cerr; |
23 using std::endl; | 23 using std::endl; |
24 | |
25 //#define HAVE_AUBIO_LOCKED_TEMPO_HACK | |
24 | 26 |
25 Tempo::Tempo(float inputSampleRate) : | 27 Tempo::Tempo(float inputSampleRate) : |
26 Plugin(inputSampleRate), | 28 Plugin(inputSampleRate), |
27 m_ibuf(0), | 29 m_ibuf(0), |
28 m_fftgrain(0), | 30 m_fftgrain(0), |
221 d.binCount = 0; | 223 d.binCount = 0; |
222 d.sampleType = OutputDescriptor::VariableSampleRate; | 224 d.sampleType = OutputDescriptor::VariableSampleRate; |
223 d.sampleRate = 0; | 225 d.sampleRate = 0; |
224 list.push_back(d); | 226 list.push_back(d); |
225 | 227 |
228 #ifdef HAVE_AUBIO_LOCKED_TEMPO_HACK | |
229 d.name = "tempo"; | |
230 d.unit = "bpm"; | |
231 d.description = "Tempo"; | |
232 d.hasFixedBinCount = true; | |
233 d.binCount = 1; | |
234 d.hasKnownExtents = false; | |
235 d.isQuantized = false; | |
236 d.sampleType = OutputDescriptor::OneSamplePerStep; | |
237 list.push_back(d); | |
238 #endif | |
239 | |
226 return list; | 240 return list; |
227 } | 241 } |
228 | 242 |
229 Tempo::FeatureSet | 243 Tempo::FeatureSet |
230 Tempo::process(float **inputBuffers, Vamp::RealTime timestamp) | 244 Tempo::process(const float *const *inputBuffers, Vamp::RealTime timestamp) |
231 { | 245 { |
232 for (size_t i = 0; i < m_stepSize; ++i) { | 246 for (size_t i = 0; i < m_stepSize; ++i) { |
233 for (size_t j = 0; j < m_channelCount; ++j) { | 247 for (size_t j = 0; j < m_channelCount; ++j) { |
234 fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i); | 248 fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i); |
235 } | 249 } |
236 } | 250 } |
237 | 251 |
238 aubio_pvoc_do(m_pv, m_ibuf, m_fftgrain); | 252 aubio_pvoc_do(m_pv, m_ibuf, m_fftgrain); |
239 aubio_onsetdetection(m_onsetdet, m_fftgrain, m_onset); | 253 aubio_onsetdetection(m_onsetdet, m_fftgrain, m_onset); |
240 | 254 |
255 #ifdef HAVE_AUBIO_LOCKED_TEMPO_HACK | |
256 float locked_tempo = 0; | |
257 #endif | |
258 | |
241 if ( m_btcounter == m_btstep - 1 ) { | 259 if ( m_btcounter == m_btstep - 1 ) { |
260 #ifdef HAVE_AUBIO_LOCKED_TEMPO_HACK | |
261 aubio_beattracking_do(m_beattracking,m_dfframe,m_btout,&locked_tempo); | |
262 #else | |
242 aubio_beattracking_do(m_beattracking,m_dfframe,m_btout); | 263 aubio_beattracking_do(m_beattracking,m_dfframe,m_btout); |
264 #endif | |
243 /* rotate dfframe */ | 265 /* rotate dfframe */ |
244 for (size_t i = 0 ; i < m_winlen - m_btstep; i++ ) | 266 for (size_t i = 0 ; i < m_winlen - m_btstep; i++ ) |
245 m_dfframe->data[0][i] = m_dfframe->data[0][i+m_btstep]; | 267 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++ ) | 268 for (size_t i = m_winlen - m_btstep ; i < m_winlen; i++ ) |
247 m_dfframe->data[0][i] = 0.; | 269 m_dfframe->data[0][i] = 0.; |
250 } | 272 } |
251 m_btcounter++; | 273 m_btcounter++; |
252 bool isonset = aubio_peakpick_pimrt_wt( m_onset, m_peakpick, | 274 bool isonset = aubio_peakpick_pimrt_wt( m_onset, m_peakpick, |
253 &(m_dfframe->data[0][m_winlen - m_btstep + m_btcounter])); | 275 &(m_dfframe->data[0][m_winlen - m_btstep + m_btcounter])); |
254 bool istactus = 0; | 276 bool istactus = 0; |
255 | |
256 | 277 |
257 /* check if any of the predicted beat correspond to the current time */ | 278 /* 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++ ) { | 279 for (size_t i = 1; i < m_btout->data[0][0]; i++ ) { |
259 if (m_btcounter == m_btout->data[0][i]) { | 280 if (m_btcounter == m_btout->data[0][i]) { |
260 if (aubio_silence_detection(m_ibuf, m_silence)) { | 281 if (aubio_silence_detection(m_ibuf, m_silence)) { |
277 returnFeatures[0].push_back(onsettime); | 298 returnFeatures[0].push_back(onsettime); |
278 m_lastBeat = timestamp; | 299 m_lastBeat = timestamp; |
279 } | 300 } |
280 } | 301 } |
281 | 302 |
303 #ifdef HAVE_AUBIO_LOCKED_TEMPO_HACK | |
304 if (locked_tempo >= 30 && locked_tempo <= 206) { | |
305 if (locked_tempo > 145) locked_tempo /= 2; | |
306 std::cerr << "Locked tempo: " << locked_tempo << std::endl; | |
307 Feature tempo; | |
308 tempo.hasTimestamp = false; | |
309 tempo.values.push_back(locked_tempo); | |
310 returnFeatures[1].push_back(tempo); | |
311 } | |
312 #endif | |
313 | |
282 return returnFeatures; | 314 return returnFeatures; |
283 } | 315 } |
284 | 316 |
285 Tempo::FeatureSet | 317 Tempo::FeatureSet |
286 Tempo::getRemainingFeatures() | 318 Tempo::getRemainingFeatures() |