annotate src/OnsetDetectionFunction.h @ 22:a8e3e95d14e4 develop

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