annotate src/OnsetDetectionFunction.h @ 24:deb49a2590f3 develop

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