annotate src/OnsetDetectionFunction.h @ 46:af7739411685

Added all source code
author Adam Stark <adamstark@users.noreply.github.com>
date Tue, 21 Jan 2014 00:10:11 +0000
parents
children 2b94d3d2fb9d
rev   line source
adamstark@46 1 //=======================================================================
adamstark@46 2 /** @file OnsetDetectionFunction.h
adamstark@46 3 * @brief A class for calculating onset detection functions
adamstark@46 4 * @author Adam Stark
adamstark@46 5 * @copyright Copyright (C) 2008-2014 Queen Mary University of London
adamstark@46 6 *
adamstark@46 7 * This program is free software: you can redistribute it and/or modify
adamstark@46 8 * it under the terms of the GNU General Public License as published by
adamstark@46 9 * the Free Software Foundation, either version 3 of the License, or
adamstark@46 10 * (at your option) any later version.
adamstark@46 11 *
adamstark@46 12 * This program is distributed in the hope that it will be useful,
adamstark@46 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
adamstark@46 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
adamstark@46 15 * GNU General Public License for more details.
adamstark@46 16 *
adamstark@46 17 * You should have received a copy of the GNU General Public License
adamstark@46 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
adamstark@46 19 */
adamstark@46 20 //=======================================================================
adamstark@46 21
adamstark@46 22 #ifndef __RTONSETDF_H
adamstark@46 23 #define __RTONSETDF_H
adamstark@46 24
adamstark@46 25 #include "fftw3.h"
adamstark@46 26
adamstark@46 27 class OnsetDetectionFunction
adamstark@46 28 {
adamstark@46 29 public:
adamstark@46 30 OnsetDetectionFunction(); // Constructor
adamstark@46 31 OnsetDetectionFunction(int arg_hsize,int arg_fsize,int arg_df_type,int arg_win_type); // Constructor (with arguments)
adamstark@46 32 ~OnsetDetectionFunction(); // Destructor
adamstark@46 33 void initialise(int arg_hsize,int arg_fsize,int arg_df_type,int arg_win_type); // Initialisation Function
adamstark@46 34
adamstark@46 35 double getDFsample(double inputbuffer[]); // process input buffer and calculate detection function sample
adamstark@46 36 void set_df_type(int arg_df_type); // set the detection function type
adamstark@46 37
adamstark@46 38 private:
adamstark@46 39
adamstark@46 40 void perform_FFT(); // perform the FFT on the data in 'frame'
adamstark@46 41
adamstark@46 42 double energy_envelope(); // calculate energy envelope detection function sample
adamstark@46 43 double energy_difference(); // calculate energy difference detection function sample
adamstark@46 44 double spectral_difference(); // calculate spectral difference detection function sample
adamstark@46 45 double spectral_difference_hwr(); // calculate spectral difference (half wave rectified) detection function sample
adamstark@46 46 double phase_deviation(); // calculate phase deviation detection function sample
adamstark@46 47 double complex_spectral_difference(); // calculate complex spectral difference detection function sample
adamstark@46 48 double complex_spectral_difference_hwr(); // calculate complex spectral difference detection function sample (half-wave rectified)
adamstark@46 49 double high_frequency_content(); // calculate high frequency content detection function sample
adamstark@46 50 double high_frequency_spectral_difference(); // calculate high frequency spectral difference detection function sample
adamstark@46 51 double high_frequency_spectral_difference_hwr(); // calculate high frequency spectral difference detection function sample (half-wave rectified)
adamstark@46 52
adamstark@46 53 void set_win_rectangular(); // calculate a Rectangular window
adamstark@46 54 void set_win_hanning(); // calculate a Hanning window
adamstark@46 55 void set_win_hamming(); // calculate a Hamming window
adamstark@46 56 void set_win_blackman(); // calculate a Blackman window
adamstark@46 57 void set_win_tukey(); // calculate a Tukey window
adamstark@46 58
adamstark@46 59
adamstark@46 60 double princarg(double phaseval); // set phase values between [-pi, pi]
adamstark@46 61
adamstark@46 62
adamstark@46 63 double pi; // pi, the constant
adamstark@46 64
adamstark@46 65 int framesize; // audio framesize
adamstark@46 66 int hopsize; // audio hopsize
adamstark@46 67 int df_type; // type of detection function
adamstark@46 68
adamstark@46 69 fftw_plan p; // create fft plan
adamstark@46 70 fftw_complex *in; // to hold complex fft values for input
adamstark@46 71 fftw_complex *out; // to hold complex fft values for output
adamstark@46 72
adamstark@46 73 int initialised; // flag indicating whether buffers and FFT plans have been initialised
adamstark@46 74
adamstark@46 75
adamstark@46 76 double *frame; // audio frame
adamstark@46 77 double *window; // window
adamstark@46 78 double *wframe; // windowed frame
adamstark@46 79
adamstark@46 80 double energy_sum_old; // to hold the previous energy sum value
adamstark@46 81
adamstark@46 82 double *mag; // magnitude spectrum
adamstark@46 83 double *mag_old; // previous magnitude spectrum
adamstark@46 84
adamstark@46 85 double *phase; // FFT phase values
adamstark@46 86 double *phase_old; // previous phase values
adamstark@46 87 double *phase_old_2; // second order previous phase values
adamstark@46 88
adamstark@46 89 };
adamstark@46 90
adamstark@46 91
adamstark@46 92 #endif