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