annotate src/OnsetDetectionFunction.h @ 60:bf256abf1dd4

Did more commenting. Added documentation.
author Adam Stark <adamstark@users.noreply.github.com>
date Sat, 25 Jan 2014 18:17:51 +0000
parents ba3fc238ccad
children deb49a2590f3
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@38 26
adamstark@57 27 //=======================================================================
adamstark@60 28 /** The type of onset detection function to calculate */
adamstark@57 29 enum OnsetDetectionFunctionType
adamstark@57 30 {
adamstark@57 31 EnergyEnvelope,
adamstark@57 32 EnergyDifference,
adamstark@57 33 SpectralDifference,
adamstark@57 34 SpectralDifferenceHWR,
adamstark@57 35 PhaseDeviation,
adamstark@57 36 ComplexSpectralDifference,
adamstark@57 37 ComplexSpectralDifferenceHWR,
adamstark@57 38 HighFrequencyContent,
adamstark@57 39 HighFrequencySpectralDifference,
adamstark@57 40 HighFrequencySpectralDifferenceHWR
adamstark@57 41 };
adamstark@57 42
adamstark@57 43 //=======================================================================
adamstark@60 44 /** The type of window to use when calculating onset detection function samples */
adamstark@57 45 enum WindowType
adamstark@57 46 {
adamstark@57 47 RectangularWindow,
adamstark@57 48 HanningWindow,
adamstark@57 49 HammingWindow,
adamstark@57 50 BlackmanWindow,
adamstark@57 51 TukeyWindow
adamstark@57 52 };
adamstark@57 53
adamstark@38 54 class OnsetDetectionFunction
adamstark@38 55 {
adamstark@38 56 public:
adamstark@52 57
adamstark@60 58 /** Constructor
adamstark@60 59 * @param hopSize_ the hop size in audio samples
adamstark@60 60 * @param frameSize_ the frame size in audio samples
adamstark@60 61 * @param onsetDetectionFunctionType_ the type of onset detection function to use - (see OnsetDetectionFunctionType)
adamstark@60 62 * @param windowType the type of window to use (see WindowType)
adamstark@60 63 */
adamstark@59 64 OnsetDetectionFunction(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType);
adamstark@52 65
adamstark@52 66 /** Destructor */
adamstark@52 67 ~OnsetDetectionFunction();
adamstark@52 68
adamstark@60 69 /** Initialisation Function
adamstark@60 70 * @param hopSize_ the hop size in audio samples
adamstark@60 71 * @param frameSize_ the frame size in audio samples
adamstark@60 72 * @param onsetDetectionFunctionType_ the type of onset detection function to use - (see OnsetDetectionFunctionType)
adamstark@60 73 * @param windowType the type of window to use (see WindowType)
adamstark@60 74 */
adamstark@59 75 void initialise(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType);
adamstark@38 76
adamstark@60 77 /** Process input frame and calculate detection function sample
adamstark@60 78 * @param buffer a pointer to an array containing the audio samples to be processed
adamstark@60 79 * @returns the onset detection function sample
adamstark@60 80 */
adamstark@59 81 double calculateOnsetDetectionFunctionSample(double *buffer);
adamstark@52 82
adamstark@60 83 /** Set the detection function type
adamstark@60 84 * @param onsetDetectionFunctionType_ the type of onset detection function to use - (see OnsetDetectionFunctionType)
adamstark@60 85 */
adamstark@59 86 void setOnsetDetectionFunctionType(int onsetDetectionFunctionType_);
adamstark@38 87
adamstark@38 88 private:
adamstark@38 89
adamstark@60 90 /** Perform the FFT on the data in 'frame' */
adamstark@59 91 void performFFT();
adamstark@38 92
adamstark@59 93 //=======================================================================
adamstark@60 94 /** Calculate energy envelope detection function sample */
adamstark@59 95 double energyEnvelope();
adamstark@52 96
adamstark@60 97 /** Calculate energy difference detection function sample */
adamstark@59 98 double energyDifference();
adamstark@52 99
adamstark@60 100 /** Calculate spectral difference detection function sample */
adamstark@59 101 double spectralDifference();
adamstark@52 102
adamstark@60 103 /** Calculate spectral difference (half wave rectified) detection function sample */
adamstark@59 104 double spectralDifferenceHWR();
adamstark@52 105
adamstark@60 106 /** Calculate phase deviation detection function sample */
adamstark@59 107 double phaseDeviation();
adamstark@52 108
adamstark@60 109 /** Calculate complex spectral difference detection function sample */
adamstark@59 110 double complexSpectralDifference();
adamstark@52 111
adamstark@60 112 /** Calculate complex spectral difference detection function sample (half-wave rectified) */
adamstark@59 113 double complexSpectralDifferenceHWR();
adamstark@52 114
adamstark@60 115 /** Calculate high frequency content detection function sample */
adamstark@59 116 double highFrequencyContent();
adamstark@52 117
adamstark@60 118 /** Calculate high frequency spectral difference detection function sample */
adamstark@59 119 double highFrequencySpectralDifference();
adamstark@52 120
adamstark@60 121 /** Calculate high frequency spectral difference detection function sample (half-wave rectified) */
adamstark@59 122 double highFrequencySpectralDifferenceHWR();
adamstark@38 123
adamstark@59 124 //=======================================================================
adamstark@60 125 /** Calculate a Rectangular window */
adamstark@59 126 void calculateRectangularWindow();
adamstark@52 127
adamstark@60 128 /** Calculate a Hanning window */
adamstark@59 129 void calculateHanningWindow();
adamstark@52 130
adamstark@60 131 /** Calculate a Hamming window */
adamstark@59 132 void calclulateHammingWindow();
adamstark@52 133
adamstark@60 134 /** Calculate a Blackman window */
adamstark@59 135 void calculateBlackmanWindow();
adamstark@52 136
adamstark@60 137 /** Calculate a Tukey window */
adamstark@59 138 void calculateTukeyWindow();
adamstark@38 139
adamstark@59 140 //=======================================================================
adamstark@60 141 /** Set phase values between [-pi, pi]
adamstark@60 142 * @param phaseVal the phase value to process
adamstark@60 143 * @returns the wrapped phase value
adamstark@60 144 */
adamstark@59 145 double princarg(double phaseVal);
adamstark@38 146
adamstark@38 147
adamstark@52 148 double pi; /**< pi, the constant */
adamstark@38 149
adamstark@59 150 int frameSize; /**< audio framesize */
adamstark@59 151 int hopSize; /**< audio hopsize */
adamstark@59 152 int onsetDetectionFunctionType; /**< type of detection function */
adamstark@38 153
adamstark@59 154 fftw_plan p; /**< fftw plan */
adamstark@59 155 fftw_complex *complexIn; /**< to hold complex fft values for input */
adamstark@59 156 fftw_complex *complexOut; /**< to hold complex fft values for output */
adamstark@38 157
adamstark@52 158 int initialised; /**< flag indicating whether buffers and FFT plans are initialised */
adamstark@52 159
adamstark@52 160 double *frame; /**< audio frame */
adamstark@52 161 double *window; /**< window */
adamstark@38 162
adamstark@59 163 double prevEnergySum; /**< to hold the previous energy sum value */
adamstark@38 164
adamstark@59 165 double *magSpec; /**< magnitude spectrum */
adamstark@59 166 double *prevMagSpec; /**< previous magnitude spectrum */
adamstark@38 167
adamstark@52 168 double *phase; /**< FFT phase values */
adamstark@59 169 double *prevPhase; /**< previous phase values */
adamstark@59 170 double *prevPhase2; /**< second order previous phase values */
adamstark@38 171
adamstark@38 172 };
adamstark@38 173
adamstark@38 174
adamstark@38 175 #endif