annotate src/OnsetDetectionFunction.h @ 23:92ee4ace9d46 develop

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