bbc-vamp-plugins
1.0
|
00001 00018 #ifndef _RHYTHM_H_ 00019 #define _RHYTHM_H_ 00020 00021 #define _USE_MATH_DEFINES 00022 00023 #include <cmath> 00024 #include <complex> 00025 #include <vector> 00026 #include <algorithm> 00027 #include <vamp-sdk/Plugin.h> 00028 00029 using std::string; 00030 using std::vector; 00031 using std::complex; 00032 using std::abs; 00033 using std::cos; 00034 00153 class Rhythm : public Vamp::Plugin { 00154 public: 00156 Rhythm(float inputSampleRate); 00157 virtual ~Rhythm(); 00158 string getIdentifier() const; 00159 string getName() const; 00160 string getDescription() const; 00161 string getMaker() const; 00162 int getPluginVersion() const; 00163 string getCopyright() const; 00164 InputDomain getInputDomain() const; 00165 size_t getPreferredBlockSize() const; 00166 size_t getPreferredStepSize() const; 00167 size_t getMinChannelCount() const; 00168 size_t getMaxChannelCount() const; 00169 ParameterList getParameterDescriptors() const; 00170 float getParameter(string identifier) const; 00171 void setParameter(string identifier, float value); 00172 ProgramList getPrograms() const; 00173 string getCurrentProgram() const; 00174 void selectProgram(string name); 00175 OutputList getOutputDescriptors() const; 00176 bool initialise(size_t channels, size_t stepSize, size_t blockSize); 00177 void reset(); 00178 FeatureSet process(const float * const *inputBuffers, 00179 Vamp::RealTime timestamp); 00180 FeatureSet getRemainingFeatures(); 00182 00183 protected: 00184 void calculateBandFreqs(); 00185 float halfHanning(float n); 00186 float canny(float n); 00187 float findRemainder(vector<int> peaks, int thisPeak); 00188 float findTempo(vector<int> peaks); 00189 float findMeanPeak(vector<float> signal, vector<int> peaks, int shift); 00190 void findCorrelationPeaks(vector<float> autocor_in, float percentile_in, 00191 int windowLength_in, int shift_in, 00192 vector<int>& peaks_out, vector<int>& valleys_out); 00193 void autocorrelation(vector<float> signal_in, int startShift_in, 00194 int endShift_in, vector<float>& autocor_out); 00195 void findOnsetPeaks(vector<float> onset_in, int windowLength_in, 00196 vector<int>& peaks_out); 00197 void movingAverage(vector<float> signal_in, int windowLength_in, 00198 float threshold_in, vector<float>& average_out, 00199 vector<float>& difference_out); 00200 void normalise(vector<float> signal_in, vector<float>& normalised_out); 00201 void halfHannConvolve(vector<vector<float> >& envelope_out); 00202 void cannyConvolve(vector<vector<float> > envelope_in, 00203 vector<float>& onset_out); 00204 00206 int m_blockSize, m_stepSize; 00207 float m_sampleRate; 00209 00210 int numBands; 00211 float *bandHighFreq; 00212 int halfHannLength; 00213 float *halfHannWindow; 00214 int cannyLength; 00215 float cannyShape; 00216 float *cannyWindow; 00217 vector<vector<float> > intensity; 00218 float threshold; 00219 int average_window; 00220 int peak_window; 00221 int max_bpm; 00222 int min_bpm; 00223 }; 00224 00225 #endif