annotate src/OnsetDetectionFunction.h @ 57:296af6af6c3d

Replaced switch statements in OnsetDetectionFunction with enums. Renamed lots of functions so that they have better names, in camel case. Added some unit tests for initialisation of BTrack.
author Adam Stark <adamstark@users.noreply.github.com>
date Thu, 23 Jan 2014 15:31:11 +0000
parents 338f5eb29e41
children a8e3e95d14e4
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@38 22 #ifndef __RTONSETDF_H
adamstark@38 23 #define __RTONSETDF_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@52 57 OnsetDetectionFunction(int arg_hsize,int arg_fsize,int arg_df_type,int arg_win_type);
adamstark@52 58
adamstark@52 59 /** Destructor */
adamstark@52 60 ~OnsetDetectionFunction();
adamstark@52 61
adamstark@52 62 /** Initialisation Function */
adamstark@52 63 void initialise(int arg_hsize,int arg_fsize,int arg_df_type,int arg_win_type);
adamstark@38 64
adamstark@52 65 /** process input buffer and calculate detection function sample */
adamstark@53 66 double getDFsample(double *inputbuffer);
adamstark@52 67
adamstark@52 68 /** set the detection function type */
adamstark@52 69 void set_df_type(int arg_df_type);
adamstark@38 70
adamstark@38 71 private:
adamstark@38 72
adamstark@52 73 /** perform the FFT on the data in 'frame' */
adamstark@52 74 void perform_FFT();
adamstark@38 75
adamstark@52 76 /** calculate energy envelope detection function sample */
adamstark@52 77 double energy_envelope();
adamstark@52 78
adamstark@52 79 /** calculate energy difference detection function sample */
adamstark@52 80 double energy_difference();
adamstark@52 81
adamstark@52 82 /** calculate spectral difference detection function sample */
adamstark@52 83 double spectral_difference();
adamstark@52 84
adamstark@52 85 /** calculate spectral difference (half wave rectified) detection function sample */
adamstark@52 86 double spectral_difference_hwr();
adamstark@52 87
adamstark@52 88 /** calculate phase deviation detection function sample */
adamstark@52 89 double phase_deviation();
adamstark@52 90
adamstark@52 91 /** calculate complex spectral difference detection function sample */
adamstark@52 92 double complex_spectral_difference();
adamstark@52 93
adamstark@52 94 /** calculate complex spectral difference detection function sample (half-wave rectified) */
adamstark@52 95 double complex_spectral_difference_hwr();
adamstark@52 96
adamstark@52 97 /** calculate high frequency content detection function sample */
adamstark@52 98 double high_frequency_content();
adamstark@52 99
adamstark@52 100 /** calculate high frequency spectral difference detection function sample */
adamstark@52 101 double high_frequency_spectral_difference();
adamstark@52 102
adamstark@52 103 /** calculate high frequency spectral difference detection function sample (half-wave rectified) */
adamstark@52 104 double high_frequency_spectral_difference_hwr();
adamstark@38 105
adamstark@52 106 /** calculate a Rectangular window */
adamstark@52 107 void set_win_rectangular();
adamstark@52 108
adamstark@52 109 /** calculate a Hanning window */
adamstark@52 110 void set_win_hanning();
adamstark@52 111
adamstark@52 112 /** calculate a Hamming window */
adamstark@52 113 void set_win_hamming();
adamstark@52 114
adamstark@52 115 /** calculate a Blackman window */
adamstark@52 116 void set_win_blackman();
adamstark@52 117
adamstark@52 118 /** calculate a Tukey window */
adamstark@52 119 void set_win_tukey();
adamstark@38 120
adamstark@52 121 /** set phase values between [-pi, pi] */
adamstark@52 122 double princarg(double phaseval);
adamstark@38 123
adamstark@38 124
adamstark@52 125 double pi; /**< pi, the constant */
adamstark@38 126
adamstark@52 127 int framesize; /**< audio framesize */
adamstark@52 128 int hopsize; /**< audio hopsize */
adamstark@52 129 int df_type; /**< type of detection function */
adamstark@38 130
adamstark@52 131 fftw_plan p; /**< create fft plan */
adamstark@52 132 fftw_complex *in; /**< to hold complex fft values for input */
adamstark@52 133 fftw_complex *out; /**< to hold complex fft values for output */
adamstark@38 134
adamstark@52 135 int initialised; /**< flag indicating whether buffers and FFT plans are initialised */
adamstark@52 136
adamstark@52 137 double *frame; /**< audio frame */
adamstark@52 138 double *window; /**< window */
adamstark@52 139 double *wframe; /**< windowed frame */
adamstark@38 140
adamstark@52 141 double energy_sum_old; /**< to hold the previous energy sum value */
adamstark@38 142
adamstark@52 143 double *mag; /**< magnitude spectrum */
adamstark@52 144 double *mag_old; /**< previous magnitude spectrum */
adamstark@38 145
adamstark@52 146 double *phase; /**< FFT phase values */
adamstark@52 147 double *phase_old; /**< previous phase values */
adamstark@52 148 double *phase_old_2; /**< second order previous phase values */
adamstark@38 149
adamstark@38 150 };
adamstark@38 151
adamstark@38 152
adamstark@38 153 #endif