andrew@0: /* andrew@0: * OnsetDetectionFunction.h andrew@0: * andrew@0: * andrew@0: * Created by Adam Stark on 22/03/2011. andrew@0: * Copyright 2011 Queen Mary University of London. All rights reserved. andrew@0: * andrew@0: */ andrew@0: andrew@0: #ifndef __RTONSETDF_H andrew@0: #define __RTONSETDF_H andrew@0: andrew@0: //#include "fftw3.h" andrew@0: #include "accFFT.h" andrew@0: andrew@0: typedef double fft_complex[2]; andrew@0: andrew@0: class OnsetDetectionFunction andrew@0: { andrew@0: public: andrew@0: OnsetDetectionFunction(); // Constructor andrew@0: OnsetDetectionFunction(int arg_hsize,int arg_fsize,int arg_df_type,int arg_win_type); // Constructor (with arguments) andrew@0: ~OnsetDetectionFunction(); // Destructor andrew@0: void initialise(int arg_hsize,int arg_fsize,int arg_df_type,int arg_win_type); // Initialisation Function Venetian@8: Venetian@8: double getDFsample(float inputbuffer[]); andrew@0: double getDFsample(double inputbuffer[]); // process input buffer and calculate detection function sample andrew@0: void set_df_type(int arg_df_type); // set the detection function type andrew@0: andrew@4: int framesize; // audio framesize andrew@4: int hopsize; // audio hopsize andrew@0: private: andrew@0: andrew@0: void perform_FFT(); // perform the FFT on the data in 'frame' andrew@0: andrew@0: double energy_envelope(); // calculate energy envelope detection function sample andrew@0: double energy_difference(); // calculate energy difference detection function sample andrew@0: double spectral_difference(); // calculate spectral difference detection function sample andrew@0: double spectral_difference_hwr(); // calculate spectral difference (half wave rectified) detection function sample andrew@0: double phase_deviation(); // calculate phase deviation detection function sample andrew@0: double complex_spectral_difference(); // calculate complex spectral difference detection function sample andrew@0: double complex_spectral_difference_hwr(); // calculate complex spectral difference detection function sample (half-wave rectified) andrew@0: double high_frequency_content(); // calculate high frequency content detection function sample andrew@0: double high_frequency_spectral_difference(); // calculate high frequency spectral difference detection function sample andrew@0: double high_frequency_spectral_difference_hwr(); // calculate high frequency spectral difference detection function sample (half-wave rectified) andrew@0: andrew@0: void set_win_rectangular(); // calculate a Rectangular window andrew@0: void set_win_hanning(); // calculate a Hanning window andrew@0: void set_win_hamming(); // calculate a Hamming window andrew@0: void set_win_blackman(); // calculate a Blackman window andrew@0: void set_win_tukey(); // calculate a Tukey window andrew@0: andrew@0: andrew@0: double princarg(double phaseval); // set phase values between [-pi, pi] andrew@0: andrew@0: andrew@0: double pi; // pi, the constant andrew@4: andrew@0: int df_type; // type of detection function andrew@0: andrew@0: accFFT *fft; andrew@0: fft_complex *out; andrew@0: double *in; andrew@0: andrew@0: //fftw_plan p; // create fft plan andrew@0: //fftw_complex *in; // to hold complex fft values for input andrew@0: //fftw_complex *out; // to hold complex fft values for output andrew@0: andrew@0: andrew@0: int initialised; // flag indicating whether buffers and FFT plans have been initialised andrew@0: andrew@0: andrew@0: double *frame; // audio frame andrew@0: double *window; // window andrew@0: double *wframe; // windowed frame andrew@0: andrew@0: double energy_sum_old; // to hold the previous energy sum value andrew@0: andrew@0: double *mag; // magnitude spectrum andrew@0: double *mag_old; // previous magnitude spectrum andrew@0: andrew@0: double *phase; // FFT phase values andrew@0: double *phase_old; // previous phase values andrew@0: double *phase_old_2; // second order previous phase values andrew@0: andrew@0: }; andrew@0: andrew@0: andrew@0: #endif