bbc-vamp-plugins  1.0
Rhythm.h
1 
18 #ifndef _RHYTHM_H_
19 #define _RHYTHM_H_
20 
21 #define _USE_MATH_DEFINES
22 
23 #include <cmath>
24 #include <complex>
25 #include <vector>
26 #include <algorithm>
27 #include <vamp-sdk/Plugin.h>
28 
29 using std::string;
30 using std::vector;
31 using std::complex;
32 using std::abs;
33 using std::cos;
34 
153 class Rhythm : public Vamp::Plugin {
154  public:
156  Rhythm(float inputSampleRate);
157  virtual ~Rhythm();
158  string getIdentifier() const;
159  string getName() const;
160  string getDescription() const;
161  string getMaker() const;
162  int getPluginVersion() const;
163  string getCopyright() const;
164  InputDomain getInputDomain() const;
165  size_t getPreferredBlockSize() const;
166  size_t getPreferredStepSize() const;
167  size_t getMinChannelCount() const;
168  size_t getMaxChannelCount() const;
169  ParameterList getParameterDescriptors() const;
170  float getParameter(string identifier) const;
171  void setParameter(string identifier, float value);
172  ProgramList getPrograms() const;
173  string getCurrentProgram() const;
174  void selectProgram(string name);
175  OutputList getOutputDescriptors() const;
176  bool initialise(size_t channels, size_t stepSize, size_t blockSize);
177  void reset();
178  FeatureSet process(const float * const *inputBuffers,
179  Vamp::RealTime timestamp);
180  FeatureSet getRemainingFeatures();
182 
183  protected:
184  void calculateBandFreqs();
185  float halfHanning(float n);
186  float canny(float n);
187  float findRemainder(vector<int> peaks, int thisPeak);
188  float findTempo(vector<int> peaks);
189  float findMeanPeak(vector<float> signal, vector<int> peaks, int shift);
190  void findCorrelationPeaks(vector<float> autocor_in, float percentile_in,
191  int windowLength_in, int shift_in,
192  vector<int>& peaks_out, vector<int>& valleys_out);
193  void autocorrelation(vector<float> signal_in, int startShift_in,
194  int endShift_in, vector<float>& autocor_out);
195  void findOnsetPeaks(vector<float> onset_in, int windowLength_in,
196  vector<int>& peaks_out);
197  void movingAverage(vector<float> signal_in, int windowLength_in,
198  float threshold_in, vector<float>& average_out,
199  vector<float>& difference_out);
200  void normalise(vector<float> signal_in, vector<float>& normalised_out);
201  void halfHannConvolve(vector<vector<float> >& envelope_out);
202  void cannyConvolve(vector<vector<float> > envelope_in,
203  vector<float>& onset_out);
204 
206  int m_blockSize, m_stepSize;
207  float m_sampleRate;
209 
210  int numBands;
211  float *bandHighFreq;
215  float cannyShape;
216  float *cannyWindow;
217  vector<vector<float> > intensity;
218  float threshold;
221  int max_bpm;
222  int min_bpm;
223 };
224 
225 #endif
int halfHannLength
Definition: Rhythm.h:212
vector< vector< float > > intensity
Definition: Rhythm.h:217
float threshold
Definition: Rhythm.h:218
Calculates rhythmic features of a signal, including onsets and tempo.
Definition: Rhythm.h:153
float * bandHighFreq
Definition: Rhythm.h:211
int min_bpm
Definition: Rhythm.h:222
int cannyLength
Definition: Rhythm.h:214
void calculateBandFreqs()
Definition: Rhythm.cpp:565
int average_window
Definition: Rhythm.h:219
int peak_window
Definition: Rhythm.h:220
int max_bpm
Definition: Rhythm.h:221
float * cannyWindow
Definition: Rhythm.h:216
float * halfHannWindow
Definition: Rhythm.h:213
int numBands
Definition: Rhythm.h:210
float cannyShape
Definition: Rhythm.h:215