annotate src/OnsetDetectionFunction.h @ 27:98f7a54faa0c develop

Changed all pointers to arrays in OnsetDetectionFunction into vectors
author Adam <adamstark.uk@gmail.com>
date Tue, 28 Jan 2014 00:19:21 +0000
parents deb49a2590f3
children bddd59087c36
rev   line source
adamstark@5 1 //=======================================================================
adamstark@5 2 /** @file OnsetDetectionFunction.h
adamstark@5 3 * @brief A class for calculating onset detection functions
adamstark@5 4 * @author Adam Stark
adamstark@5 5 * @copyright Copyright (C) 2008-2014 Queen Mary University of London
adamstark@5 6 *
adamstark@5 7 * This program is free software: you can redistribute it and/or modify
adamstark@5 8 * it under the terms of the GNU General Public License as published by
adamstark@5 9 * the Free Software Foundation, either version 3 of the License, or
adamstark@5 10 * (at your option) any later version.
adamstark@5 11 *
adamstark@5 12 * This program is distributed in the hope that it will be useful,
adamstark@5 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
adamstark@5 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
adamstark@5 15 * GNU General Public License for more details.
adamstark@5 16 *
adamstark@5 17 * You should have received a copy of the GNU General Public License
adamstark@5 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
adamstark@5 19 */
adamstark@5 20 //=======================================================================
adamstark@5 21
adamstark@22 22 #ifndef __ONSETDETECTIONFUNCTION_H
adamstark@22 23 #define __ONSETDETECTIONFUNCTION_H
adamstark@5 24
adamstark@5 25 #include "fftw3.h"
adamstark@27 26 #include <vector>
adamstark@5 27
adamstark@20 28 //=======================================================================
adamstark@23 29 /** The type of onset detection function to calculate */
adamstark@20 30 enum OnsetDetectionFunctionType
adamstark@20 31 {
adamstark@20 32 EnergyEnvelope,
adamstark@20 33 EnergyDifference,
adamstark@20 34 SpectralDifference,
adamstark@20 35 SpectralDifferenceHWR,
adamstark@20 36 PhaseDeviation,
adamstark@20 37 ComplexSpectralDifference,
adamstark@20 38 ComplexSpectralDifferenceHWR,
adamstark@20 39 HighFrequencyContent,
adamstark@20 40 HighFrequencySpectralDifference,
adamstark@20 41 HighFrequencySpectralDifferenceHWR
adamstark@20 42 };
adamstark@20 43
adamstark@20 44 //=======================================================================
adamstark@23 45 /** The type of window to use when calculating onset detection function samples */
adamstark@20 46 enum WindowType
adamstark@20 47 {
adamstark@20 48 RectangularWindow,
adamstark@20 49 HanningWindow,
adamstark@20 50 HammingWindow,
adamstark@20 51 BlackmanWindow,
adamstark@20 52 TukeyWindow
adamstark@20 53 };
adamstark@20 54
adamstark@24 55 //=======================================================================
adamstark@24 56 /** A class for calculating onset detection functions. */
adamstark@5 57 class OnsetDetectionFunction
adamstark@5 58 {
adamstark@5 59 public:
adamstark@15 60
adamstark@23 61 /** Constructor
adamstark@23 62 * @param hopSize_ the hop size in audio samples
adamstark@23 63 * @param frameSize_ the frame size in audio samples
adamstark@23 64 * @param onsetDetectionFunctionType_ the type of onset detection function to use - (see OnsetDetectionFunctionType)
adamstark@23 65 * @param windowType the type of window to use (see WindowType)
adamstark@23 66 */
adamstark@22 67 OnsetDetectionFunction(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType);
adamstark@15 68
adamstark@15 69 /** Destructor */
adamstark@15 70 ~OnsetDetectionFunction();
adamstark@15 71
adamstark@23 72 /** Initialisation Function
adamstark@23 73 * @param hopSize_ the hop size in audio samples
adamstark@23 74 * @param frameSize_ the frame size in audio samples
adamstark@23 75 * @param onsetDetectionFunctionType_ the type of onset detection function to use - (see OnsetDetectionFunctionType)
adamstark@23 76 * @param windowType the type of window to use (see WindowType)
adamstark@23 77 */
adamstark@22 78 void initialise(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType);
adamstark@5 79
adamstark@23 80 /** Process input frame and calculate detection function sample
adamstark@23 81 * @param buffer a pointer to an array containing the audio samples to be processed
adamstark@23 82 * @returns the onset detection function sample
adamstark@23 83 */
adamstark@22 84 double calculateOnsetDetectionFunctionSample(double *buffer);
adamstark@15 85
adamstark@23 86 /** Set the detection function type
adamstark@23 87 * @param onsetDetectionFunctionType_ the type of onset detection function to use - (see OnsetDetectionFunctionType)
adamstark@23 88 */
adamstark@22 89 void setOnsetDetectionFunctionType(int onsetDetectionFunctionType_);
adamstark@5 90
adamstark@5 91 private:
adamstark@5 92
adamstark@23 93 /** Perform the FFT on the data in 'frame' */
adamstark@22 94 void performFFT();
adamstark@5 95
adamstark@22 96 //=======================================================================
adamstark@23 97 /** Calculate energy envelope detection function sample */
adamstark@22 98 double energyEnvelope();
adamstark@15 99
adamstark@23 100 /** Calculate energy difference detection function sample */
adamstark@22 101 double energyDifference();
adamstark@15 102
adamstark@23 103 /** Calculate spectral difference detection function sample */
adamstark@22 104 double spectralDifference();
adamstark@15 105
adamstark@23 106 /** Calculate spectral difference (half wave rectified) detection function sample */
adamstark@22 107 double spectralDifferenceHWR();
adamstark@15 108
adamstark@23 109 /** Calculate phase deviation detection function sample */
adamstark@22 110 double phaseDeviation();
adamstark@15 111
adamstark@23 112 /** Calculate complex spectral difference detection function sample */
adamstark@22 113 double complexSpectralDifference();
adamstark@15 114
adamstark@23 115 /** Calculate complex spectral difference detection function sample (half-wave rectified) */
adamstark@22 116 double complexSpectralDifferenceHWR();
adamstark@15 117
adamstark@23 118 /** Calculate high frequency content detection function sample */
adamstark@22 119 double highFrequencyContent();
adamstark@15 120
adamstark@23 121 /** Calculate high frequency spectral difference detection function sample */
adamstark@22 122 double highFrequencySpectralDifference();
adamstark@15 123
adamstark@23 124 /** Calculate high frequency spectral difference detection function sample (half-wave rectified) */
adamstark@22 125 double highFrequencySpectralDifferenceHWR();
adamstark@5 126
adamstark@22 127 //=======================================================================
adamstark@23 128 /** Calculate a Rectangular window */
adamstark@22 129 void calculateRectangularWindow();
adamstark@15 130
adamstark@23 131 /** Calculate a Hanning window */
adamstark@22 132 void calculateHanningWindow();
adamstark@15 133
adamstark@23 134 /** Calculate a Hamming window */
adamstark@22 135 void calclulateHammingWindow();
adamstark@15 136
adamstark@23 137 /** Calculate a Blackman window */
adamstark@22 138 void calculateBlackmanWindow();
adamstark@15 139
adamstark@23 140 /** Calculate a Tukey window */
adamstark@22 141 void calculateTukeyWindow();
adamstark@5 142
adamstark@22 143 //=======================================================================
adamstark@23 144 /** Set phase values between [-pi, pi]
adamstark@23 145 * @param phaseVal the phase value to process
adamstark@23 146 * @returns the wrapped phase value
adamstark@23 147 */
adamstark@22 148 double princarg(double phaseVal);
adamstark@5 149
adamstark@5 150
adamstark@15 151 double pi; /**< pi, the constant */
adamstark@5 152
adamstark@22 153 int frameSize; /**< audio framesize */
adamstark@22 154 int hopSize; /**< audio hopsize */
adamstark@22 155 int onsetDetectionFunctionType; /**< type of detection function */
adamstark@5 156
adamstark@22 157 fftw_plan p; /**< fftw plan */
adamstark@22 158 fftw_complex *complexIn; /**< to hold complex fft values for input */
adamstark@22 159 fftw_complex *complexOut; /**< to hold complex fft values for output */
adamstark@5 160
adamstark@27 161 bool initialised; /**< flag indicating whether buffers and FFT plans are initialised */
adamstark@15 162
adamstark@27 163 std::vector<double> frame; /**< audio frame */
adamstark@27 164 std::vector<double> window; /**< window */
adamstark@5 165
adamstark@22 166 double prevEnergySum; /**< to hold the previous energy sum value */
adamstark@5 167
adamstark@27 168 std::vector<double> magSpec; /**< magnitude spectrum */
adamstark@27 169 std::vector<double> prevMagSpec; /**< previous magnitude spectrum */
adamstark@5 170
adamstark@27 171 std::vector<double> phase; /**< FFT phase values */
adamstark@27 172 std::vector<double> prevPhase; /**< previous phase values */
adamstark@27 173 std::vector<double> prevPhase2; /**< second order previous phase values */
adamstark@5 174
adamstark@5 175 };
adamstark@5 176
adamstark@5 177
adamstark@5 178 #endif