qm-dsp
1.8
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 QM DSP Library 00005 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2008-2009 Matthew Davies and QMUL. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #ifndef DOWNBEAT_H 00017 #define DOWNBEAT_H 00018 00019 #include <vector> 00020 #include <cstddef> 00021 00022 #include "dsp/rateconversion/Decimator.h" 00023 00024 using std::vector; 00025 00026 class FFTReal; 00027 00038 class DownBeat 00039 { 00040 public: 00051 DownBeat(float originalSampleRate, 00052 size_t decimationFactor, 00053 size_t dfIncrement); 00054 ~DownBeat(); 00055 00056 void setBeatsPerBar(int bpb); 00057 00072 void findDownBeats(const float *audio, // downsampled 00073 size_t audioLength, // after downsampling 00074 const vector<double> &beats, 00075 vector<int> &downbeats); 00076 00086 void getBeatSD(vector<double> &beatsd) const; 00087 00097 void pushAudioBlock(const float *audio); 00098 00102 const float *getBufferedAudio(size_t &length) const; 00103 00107 void resetAudioBuffer(); 00108 00109 private: 00110 typedef vector<int> i_vec_t; 00111 typedef vector<vector<int> > i_mat_t; 00112 typedef vector<double> d_vec_t; 00113 typedef vector<vector<double> > d_mat_t; 00114 00115 void makeDecimators(); 00116 double measureSpecDiff(d_vec_t oldspec, d_vec_t newspec); 00117 00118 int m_bpb; 00119 float m_rate; 00120 size_t m_factor; 00121 size_t m_increment; 00122 Decimator *m_decimator1; 00123 Decimator *m_decimator2; 00124 float *m_buffer; 00125 float *m_decbuf; 00126 size_t m_bufsiz; 00127 size_t m_buffill; 00128 size_t m_beatframesize; 00129 double *m_beatframe; 00130 FFTReal *m_fft; 00131 double *m_fftRealOut; 00132 double *m_fftImagOut; 00133 d_vec_t m_beatsd; 00134 }; 00135 00136 #endif