annotate src/OnsetDetectionFunction.h @ 59:ba3fc238ccad

Renamed many variables, functions and arguments so they have more sensible names. Also removed an apparently redundant variable in OnsetDetectionFunction called wframe
author Adam Stark <adamstark@users.noreply.github.com>
date Fri, 24 Jan 2014 21:45:55 +0000
parents 296af6af6c3d
children 92ee4ace9d46
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@57 28 enum OnsetDetectionFunctionType
adamstark@57 29 {
adamstark@57 30 EnergyEnvelope,
adamstark@57 31 EnergyDifference,
adamstark@57 32 SpectralDifference,
adamstark@57 33 SpectralDifferenceHWR,
adamstark@57 34 PhaseDeviation,
adamstark@57 35 ComplexSpectralDifference,
adamstark@57 36 ComplexSpectralDifferenceHWR,
adamstark@57 37 HighFrequencyContent,
adamstark@57 38 HighFrequencySpectralDifference,
adamstark@57 39 HighFrequencySpectralDifferenceHWR
adamstark@57 40 };
adamstark@57 41
adamstark@57 42 //=======================================================================
adamstark@57 43 enum WindowType
adamstark@57 44 {
adamstark@57 45 RectangularWindow,
adamstark@57 46 HanningWindow,
adamstark@57 47 HammingWindow,
adamstark@57 48 BlackmanWindow,
adamstark@57 49 TukeyWindow
adamstark@57 50 };
adamstark@57 51
adamstark@38 52 class OnsetDetectionFunction
adamstark@38 53 {
adamstark@38 54 public:
adamstark@52 55
adamstark@52 56 /** Constructor */
adamstark@59 57 OnsetDetectionFunction(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType);
adamstark@52 58
adamstark@52 59 /** Destructor */
adamstark@52 60 ~OnsetDetectionFunction();
adamstark@52 61
adamstark@52 62 /** Initialisation Function */
adamstark@59 63 void initialise(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType);
adamstark@38 64
adamstark@59 65 /** process input frame and calculate detection function sample */
adamstark@59 66 double calculateOnsetDetectionFunctionSample(double *buffer);
adamstark@52 67
adamstark@52 68 /** set the detection function type */
adamstark@59 69 void setOnsetDetectionFunctionType(int onsetDetectionFunctionType_);
adamstark@38 70
adamstark@38 71 private:
adamstark@38 72
adamstark@52 73 /** perform the FFT on the data in 'frame' */
adamstark@59 74 void performFFT();
adamstark@38 75
adamstark@59 76 //=======================================================================
adamstark@52 77 /** calculate energy envelope detection function sample */
adamstark@59 78 double energyEnvelope();
adamstark@52 79
adamstark@52 80 /** calculate energy difference detection function sample */
adamstark@59 81 double energyDifference();
adamstark@52 82
adamstark@52 83 /** calculate spectral difference detection function sample */
adamstark@59 84 double spectralDifference();
adamstark@52 85
adamstark@52 86 /** calculate spectral difference (half wave rectified) detection function sample */
adamstark@59 87 double spectralDifferenceHWR();
adamstark@52 88
adamstark@52 89 /** calculate phase deviation detection function sample */
adamstark@59 90 double phaseDeviation();
adamstark@52 91
adamstark@52 92 /** calculate complex spectral difference detection function sample */
adamstark@59 93 double complexSpectralDifference();
adamstark@52 94
adamstark@52 95 /** calculate complex spectral difference detection function sample (half-wave rectified) */
adamstark@59 96 double complexSpectralDifferenceHWR();
adamstark@52 97
adamstark@52 98 /** calculate high frequency content detection function sample */
adamstark@59 99 double highFrequencyContent();
adamstark@52 100
adamstark@52 101 /** calculate high frequency spectral difference detection function sample */
adamstark@59 102 double highFrequencySpectralDifference();
adamstark@52 103
adamstark@52 104 /** calculate high frequency spectral difference detection function sample (half-wave rectified) */
adamstark@59 105 double highFrequencySpectralDifferenceHWR();
adamstark@38 106
adamstark@59 107 //=======================================================================
adamstark@52 108 /** calculate a Rectangular window */
adamstark@59 109 void calculateRectangularWindow();
adamstark@52 110
adamstark@52 111 /** calculate a Hanning window */
adamstark@59 112 void calculateHanningWindow();
adamstark@52 113
adamstark@52 114 /** calculate a Hamming window */
adamstark@59 115 void calclulateHammingWindow();
adamstark@52 116
adamstark@52 117 /** calculate a Blackman window */
adamstark@59 118 void calculateBlackmanWindow();
adamstark@52 119
adamstark@52 120 /** calculate a Tukey window */
adamstark@59 121 void calculateTukeyWindow();
adamstark@38 122
adamstark@59 123 //=======================================================================
adamstark@52 124 /** set phase values between [-pi, pi] */
adamstark@59 125 double princarg(double phaseVal);
adamstark@38 126
adamstark@38 127
adamstark@52 128 double pi; /**< pi, the constant */
adamstark@38 129
adamstark@59 130 int frameSize; /**< audio framesize */
adamstark@59 131 int hopSize; /**< audio hopsize */
adamstark@59 132 int onsetDetectionFunctionType; /**< type of detection function */
adamstark@38 133
adamstark@59 134 fftw_plan p; /**< fftw plan */
adamstark@59 135 fftw_complex *complexIn; /**< to hold complex fft values for input */
adamstark@59 136 fftw_complex *complexOut; /**< to hold complex fft values for output */
adamstark@38 137
adamstark@52 138 int initialised; /**< flag indicating whether buffers and FFT plans are initialised */
adamstark@52 139
adamstark@52 140 double *frame; /**< audio frame */
adamstark@52 141 double *window; /**< window */
adamstark@38 142
adamstark@59 143 double prevEnergySum; /**< to hold the previous energy sum value */
adamstark@38 144
adamstark@59 145 double *magSpec; /**< magnitude spectrum */
adamstark@59 146 double *prevMagSpec; /**< previous magnitude spectrum */
adamstark@38 147
adamstark@52 148 double *phase; /**< FFT phase values */
adamstark@59 149 double *prevPhase; /**< previous phase values */
adamstark@59 150 double *prevPhase2; /**< second order previous phase values */
adamstark@38 151
adamstark@38 152 };
adamstark@38 153
adamstark@38 154
adamstark@38 155 #endif