adamstark@5: //======================================================================= adamstark@5: /** @file OnsetDetectionFunction.h adamstark@5: * @brief A class for calculating onset detection functions adamstark@5: * @author Adam Stark adamstark@5: * @copyright Copyright (C) 2008-2014 Queen Mary University of London adamstark@5: * adamstark@5: * This program is free software: you can redistribute it and/or modify adamstark@5: * it under the terms of the GNU General Public License as published by adamstark@5: * the Free Software Foundation, either version 3 of the License, or adamstark@5: * (at your option) any later version. adamstark@5: * adamstark@5: * This program is distributed in the hope that it will be useful, adamstark@5: * but WITHOUT ANY WARRANTY; without even the implied warranty of adamstark@5: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the adamstark@5: * GNU General Public License for more details. adamstark@5: * adamstark@5: * You should have received a copy of the GNU General Public License adamstark@5: * along with this program. If not, see . adamstark@5: */ adamstark@5: //======================================================================= adamstark@5: adamstark@5: #ifndef __RTONSETDF_H adamstark@5: #define __RTONSETDF_H adamstark@5: adamstark@5: #include "fftw3.h" adamstark@5: adamstark@5: class OnsetDetectionFunction adamstark@5: { adamstark@5: public: adamstark@5: OnsetDetectionFunction(); // Constructor adamstark@5: OnsetDetectionFunction(int arg_hsize,int arg_fsize,int arg_df_type,int arg_win_type); // Constructor (with arguments) adamstark@5: ~OnsetDetectionFunction(); // Destructor adamstark@5: void initialise(int arg_hsize,int arg_fsize,int arg_df_type,int arg_win_type); // Initialisation Function adamstark@5: adamstark@5: double getDFsample(double inputbuffer[]); // process input buffer and calculate detection function sample adamstark@5: void set_df_type(int arg_df_type); // set the detection function type adamstark@5: adamstark@5: private: adamstark@5: adamstark@5: void perform_FFT(); // perform the FFT on the data in 'frame' adamstark@5: adamstark@5: double energy_envelope(); // calculate energy envelope detection function sample adamstark@5: double energy_difference(); // calculate energy difference detection function sample adamstark@5: double spectral_difference(); // calculate spectral difference detection function sample adamstark@5: double spectral_difference_hwr(); // calculate spectral difference (half wave rectified) detection function sample adamstark@5: double phase_deviation(); // calculate phase deviation detection function sample adamstark@5: double complex_spectral_difference(); // calculate complex spectral difference detection function sample adamstark@5: double complex_spectral_difference_hwr(); // calculate complex spectral difference detection function sample (half-wave rectified) adamstark@5: double high_frequency_content(); // calculate high frequency content detection function sample adamstark@5: double high_frequency_spectral_difference(); // calculate high frequency spectral difference detection function sample adamstark@5: double high_frequency_spectral_difference_hwr(); // calculate high frequency spectral difference detection function sample (half-wave rectified) adamstark@5: adamstark@5: void set_win_rectangular(); // calculate a Rectangular window adamstark@5: void set_win_hanning(); // calculate a Hanning window adamstark@5: void set_win_hamming(); // calculate a Hamming window adamstark@5: void set_win_blackman(); // calculate a Blackman window adamstark@5: void set_win_tukey(); // calculate a Tukey window adamstark@5: adamstark@5: adamstark@5: double princarg(double phaseval); // set phase values between [-pi, pi] adamstark@5: adamstark@5: adamstark@5: double pi; // pi, the constant adamstark@5: adamstark@5: int framesize; // audio framesize adamstark@5: int hopsize; // audio hopsize adamstark@5: int df_type; // type of detection function adamstark@5: adamstark@5: fftw_plan p; // create fft plan adamstark@5: fftw_complex *in; // to hold complex fft values for input adamstark@5: fftw_complex *out; // to hold complex fft values for output adamstark@5: adamstark@5: int initialised; // flag indicating whether buffers and FFT plans have been initialised adamstark@5: adamstark@5: adamstark@5: double *frame; // audio frame adamstark@5: double *window; // window adamstark@5: double *wframe; // windowed frame adamstark@5: adamstark@5: double energy_sum_old; // to hold the previous energy sum value adamstark@5: adamstark@5: double *mag; // magnitude spectrum adamstark@5: double *mag_old; // previous magnitude spectrum adamstark@5: adamstark@5: double *phase; // FFT phase values adamstark@5: double *phase_old; // previous phase values adamstark@5: double *phase_old_2; // second order previous phase values adamstark@5: adamstark@5: }; adamstark@5: adamstark@5: adamstark@5: #endif