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@57: //======================================================================= adamstark@57: enum OnsetDetectionFunctionType adamstark@57: { adamstark@57: EnergyEnvelope, adamstark@57: EnergyDifference, adamstark@57: SpectralDifference, adamstark@57: SpectralDifferenceHWR, adamstark@57: PhaseDeviation, adamstark@57: ComplexSpectralDifference, adamstark@57: ComplexSpectralDifferenceHWR, adamstark@57: HighFrequencyContent, adamstark@57: HighFrequencySpectralDifference, adamstark@57: HighFrequencySpectralDifferenceHWR adamstark@57: }; adamstark@57: adamstark@57: //======================================================================= adamstark@57: enum WindowType adamstark@57: { adamstark@57: RectangularWindow, adamstark@57: HanningWindow, adamstark@57: HammingWindow, adamstark@57: BlackmanWindow, adamstark@57: TukeyWindow adamstark@57: }; adamstark@57: adamstark@38: class OnsetDetectionFunction adamstark@38: { adamstark@38: public: adamstark@52: adamstark@52: /** Constructor */ adamstark@52: OnsetDetectionFunction(int arg_hsize,int arg_fsize,int arg_df_type,int arg_win_type); adamstark@52: adamstark@52: /** Destructor */ adamstark@52: ~OnsetDetectionFunction(); adamstark@52: adamstark@52: /** Initialisation Function */ adamstark@52: void initialise(int arg_hsize,int arg_fsize,int arg_df_type,int arg_win_type); adamstark@38: adamstark@52: /** process input buffer and calculate detection function sample */ adamstark@53: double getDFsample(double *inputbuffer); adamstark@52: adamstark@52: /** set the detection function type */ adamstark@52: void set_df_type(int arg_df_type); adamstark@38: adamstark@38: private: adamstark@38: adamstark@52: /** perform the FFT on the data in 'frame' */ adamstark@52: void perform_FFT(); adamstark@38: adamstark@52: /** calculate energy envelope detection function sample */ adamstark@52: double energy_envelope(); adamstark@52: adamstark@52: /** calculate energy difference detection function sample */ adamstark@52: double energy_difference(); adamstark@52: adamstark@52: /** calculate spectral difference detection function sample */ adamstark@52: double spectral_difference(); adamstark@52: adamstark@52: /** calculate spectral difference (half wave rectified) detection function sample */ adamstark@52: double spectral_difference_hwr(); adamstark@52: adamstark@52: /** calculate phase deviation detection function sample */ adamstark@52: double phase_deviation(); adamstark@52: adamstark@52: /** calculate complex spectral difference detection function sample */ adamstark@52: double complex_spectral_difference(); adamstark@52: adamstark@52: /** calculate complex spectral difference detection function sample (half-wave rectified) */ adamstark@52: double complex_spectral_difference_hwr(); adamstark@52: adamstark@52: /** calculate high frequency content detection function sample */ adamstark@52: double high_frequency_content(); adamstark@52: adamstark@52: /** calculate high frequency spectral difference detection function sample */ adamstark@52: double high_frequency_spectral_difference(); adamstark@52: adamstark@52: /** calculate high frequency spectral difference detection function sample (half-wave rectified) */ adamstark@52: double high_frequency_spectral_difference_hwr(); adamstark@38: adamstark@52: /** calculate a Rectangular window */ adamstark@52: void set_win_rectangular(); adamstark@52: adamstark@52: /** calculate a Hanning window */ adamstark@52: void set_win_hanning(); adamstark@52: adamstark@52: /** calculate a Hamming window */ adamstark@52: void set_win_hamming(); adamstark@52: adamstark@52: /** calculate a Blackman window */ adamstark@52: void set_win_blackman(); adamstark@52: adamstark@52: /** calculate a Tukey window */ adamstark@52: void set_win_tukey(); adamstark@38: adamstark@52: /** set phase values between [-pi, pi] */ adamstark@52: double princarg(double phaseval); adamstark@38: adamstark@38: adamstark@52: double pi; /**< pi, the constant */ adamstark@38: adamstark@52: int framesize; /**< audio framesize */ adamstark@52: int hopsize; /**< audio hopsize */ adamstark@52: int df_type; /**< type of detection function */ adamstark@38: adamstark@52: fftw_plan p; /**< create fft plan */ adamstark@52: fftw_complex *in; /**< to hold complex fft values for input */ adamstark@52: fftw_complex *out; /**< to hold complex fft values for output */ adamstark@38: adamstark@52: int initialised; /**< flag indicating whether buffers and FFT plans are initialised */ adamstark@52: adamstark@52: double *frame; /**< audio frame */ adamstark@52: double *window; /**< window */ adamstark@52: double *wframe; /**< windowed frame */ adamstark@38: adamstark@52: double energy_sum_old; /**< to hold the previous energy sum value */ adamstark@38: adamstark@52: double *mag; /**< magnitude spectrum */ adamstark@52: double *mag_old; /**< previous magnitude spectrum */ adamstark@38: adamstark@52: double *phase; /**< FFT phase values */ adamstark@52: double *phase_old; /**< previous phase values */ adamstark@52: double *phase_old_2; /**< second order previous phase values */ adamstark@38: adamstark@38: }; adamstark@38: adamstark@38: adamstark@38: #endif