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