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