annotate src/OnsetDetectionFunction.h @ 64:d3c52c6b3905

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