comparison src/OnsetDetectionFunction.h @ 96:c58f01834337

Merge branch 'release/1.0.4'
author Adam Stark <adamstark.uk@gmail.com>
date Sat, 18 Jun 2016 10:50:06 +0100
parents 4aa362058011
children 8fb1610c9192
comparison
equal deleted inserted replaced
87:496d12635af8 96:c58f01834337
20 //======================================================================= 20 //=======================================================================
21 21
22 #ifndef __ONSETDETECTIONFUNCTION_H 22 #ifndef __ONSETDETECTIONFUNCTION_H
23 #define __ONSETDETECTIONFUNCTION_H 23 #define __ONSETDETECTIONFUNCTION_H
24 24
25 #ifdef USE_FFTW
25 #include "fftw3.h" 26 #include "fftw3.h"
27 #endif
28
29 #ifdef USE_KISS_FFT
30 #include "kiss_fft.h"
31 #endif
32
26 #include <vector> 33 #include <vector>
27 34
28 //======================================================================= 35 //=======================================================================
29 /** The type of onset detection function to calculate */ 36 /** The type of onset detection function to calculate */
30 enum OnsetDetectionFunctionType 37 enum OnsetDetectionFunctionType
61 /** Constructor that defaults the onset detection function type to ComplexSpectralDifferenceHWR 68 /** Constructor that defaults the onset detection function type to ComplexSpectralDifferenceHWR
62 * and the window type to HanningWindow 69 * and the window type to HanningWindow
63 * @param hopSize_ the hop size in audio samples 70 * @param hopSize_ the hop size in audio samples
64 * @param frameSize_ the frame size in audio samples 71 * @param frameSize_ the frame size in audio samples
65 */ 72 */
66 OnsetDetectionFunction(int hopSize_,int frameSize_); 73 OnsetDetectionFunction (int hopSize_, int frameSize_);
67 74
68 75
69 /** Constructor 76 /** Constructor
70 * @param hopSize_ the hop size in audio samples 77 * @param hopSize_ the hop size in audio samples
71 * @param frameSize_ the frame size in audio samples 78 * @param frameSize_ the frame size in audio samples
72 * @param onsetDetectionFunctionType_ the type of onset detection function to use - (see OnsetDetectionFunctionType) 79 * @param onsetDetectionFunctionType_ the type of onset detection function to use - (see OnsetDetectionFunctionType)
73 * @param windowType the type of window to use (see WindowType) 80 * @param windowType the type of window to use (see WindowType)
74 */ 81 */
75 OnsetDetectionFunction(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType_); 82 OnsetDetectionFunction (int hopSize_, int frameSize_, int onsetDetectionFunctionType_, int windowType_);
76 83
77 /** Destructor */ 84 /** Destructor */
78 ~OnsetDetectionFunction(); 85 ~OnsetDetectionFunction();
79 86
80 /** Initialisation function for only updating hop size and frame size (and not window type 87 /** Initialisation function for only updating hop size and frame size (and not window type
81 * or onset detection function type 88 * or onset detection function type
82 * @param hopSize_ the hop size in audio samples 89 * @param hopSize_ the hop size in audio samples
83 * @param frameSize_ the frame size in audio samples 90 * @param frameSize_ the frame size in audio samples
84 */ 91 */
85 void initialise(int hopSize_,int frameSize_); 92 void initialise (int hopSize_, int frameSize_);
86 93
87 /** Initialisation Function 94 /** Initialisation Function
88 * @param hopSize_ the hop size in audio samples 95 * @param hopSize_ the hop size in audio samples
89 * @param frameSize_ the frame size in audio samples 96 * @param frameSize_ the frame size in audio samples
90 * @param onsetDetectionFunctionType_ the type of onset detection function to use - (see OnsetDetectionFunctionType) 97 * @param onsetDetectionFunctionType_ the type of onset detection function to use - (see OnsetDetectionFunctionType)
91 * @param windowType the type of window to use (see WindowType) 98 * @param windowType the type of window to use (see WindowType)
92 */ 99 */
93 void initialise(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType_); 100 void initialise (int hopSize_, int frameSize_, int onsetDetectionFunctionType_, int windowType_);
94 101
95 /** Process input frame and calculate detection function sample 102 /** Process input frame and calculate detection function sample
96 * @param buffer a pointer to an array containing the audio samples to be processed 103 * @param buffer a pointer to an array containing the audio samples to be processed
97 * @returns the onset detection function sample 104 * @returns the onset detection function sample
98 */ 105 */
99 double calculateOnsetDetectionFunctionSample(double *buffer); 106 double calculateOnsetDetectionFunctionSample (double* buffer);
100 107
101 /** Set the detection function type 108 /** Set the detection function type
102 * @param onsetDetectionFunctionType_ the type of onset detection function to use - (see OnsetDetectionFunctionType) 109 * @param onsetDetectionFunctionType_ the type of onset detection function to use - (see OnsetDetectionFunctionType)
103 */ 110 */
104 void setOnsetDetectionFunctionType(int onsetDetectionFunctionType_); 111 void setOnsetDetectionFunctionType (int onsetDetectionFunctionType_);
105 112
106 private: 113 private:
107 114
108 /** Perform the FFT on the data in 'frame' */ 115 /** Perform the FFT on the data in 'frame' */
109 void performFFT(); 116 void performFFT();
160 * @param phaseVal the phase value to process 167 * @param phaseVal the phase value to process
161 * @returns the wrapped phase value 168 * @returns the wrapped phase value
162 */ 169 */
163 double princarg(double phaseVal); 170 double princarg(double phaseVal);
164 171
172 void initialiseFFT();
173 void freeFFT();
165 174
166 double pi; /**< pi, the constant */ 175 double pi; /**< pi, the constant */
167 176
168 int frameSize; /**< audio framesize */ 177 int frameSize; /**< audio framesize */
169 int hopSize; /**< audio hopsize */ 178 int hopSize; /**< audio hopsize */
170 int onsetDetectionFunctionType; /**< type of detection function */ 179 int onsetDetectionFunctionType; /**< type of detection function */
171 int windowType; /**< type of window used in calculations */ 180 int windowType; /**< type of window used in calculations */
172 181
182 //=======================================================================
183 #ifdef USE_FFTW
173 fftw_plan p; /**< fftw plan */ 184 fftw_plan p; /**< fftw plan */
174 fftw_complex *complexIn; /**< to hold complex fft values for input */ 185 fftw_complex* complexIn; /**< to hold complex fft values for input */
175 fftw_complex *complexOut; /**< to hold complex fft values for output */ 186 fftw_complex* complexOut; /**< to hold complex fft values for output */
176 187 #endif
188
189 #ifdef USE_KISS_FFT
190 kiss_fft_cfg cfg; /**< Kiss FFT configuration */
191 kiss_fft_cpx* fftIn; /**< FFT input samples, in complex form */
192 kiss_fft_cpx* fftOut; /**< FFT output samples, in complex form */
193 std::vector<std::vector<double> > complexOut;
194 #endif
195
196 //=======================================================================
177 bool initialised; /**< flag indicating whether buffers and FFT plans are initialised */ 197 bool initialised; /**< flag indicating whether buffers and FFT plans are initialised */
178 198
179 std::vector<double> frame; /**< audio frame */ 199 std::vector<double> frame; /**< audio frame */
180 std::vector<double> window; /**< window */ 200 std::vector<double> window; /**< window */
181 201