Chris@0
|
1 /*
|
Chris@0
|
2 copyright (C) 2011 I. Irigaray, M. Rocamora
|
Chris@0
|
3
|
Chris@0
|
4 This program is free software: you can redistribute it and/or modify
|
Chris@0
|
5 it under the terms of the GNU General Public License as published by
|
Chris@0
|
6 the Free Software Foundation, either version 3 of the License, or
|
Chris@0
|
7 (at your option) any later version.
|
Chris@0
|
8
|
Chris@0
|
9 This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 GNU General Public License for more details.
|
Chris@0
|
13
|
Chris@0
|
14 You should have received a copy of the GNU General Public License
|
Chris@0
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
Chris@0
|
16 */
|
Chris@0
|
17
|
Chris@0
|
18 // Remember to use a different guard symbol in each header!
|
Chris@0
|
19 #ifndef _FCHTRANSFORMF0GRAM_H_
|
Chris@0
|
20 #define _FCHTRANSFORMF0GRAM_H_
|
Chris@0
|
21 #define _USE_MATH_DEFINES
|
Chris@0
|
22 #include <cmath>
|
Chris@0
|
23 #include <vamp-sdk/Plugin.h>
|
Chris@0
|
24 #include <complex>
|
Chris@0
|
25 #include <fftw3.h>
|
Chris@0
|
26 #include <iostream>
|
Chris@0
|
27 #include <fstream>
|
Chris@0
|
28 #include <string.h>
|
Chris@0
|
29
|
Chris@0
|
30 using namespace std;
|
Chris@0
|
31 using std::string;
|
Chris@0
|
32
|
Chris@0
|
33 class FChTransformF0gram : public Vamp::Plugin {
|
Chris@0
|
34 public:
|
Chris@0
|
35 FChTransformF0gram(float inputSampleRate);
|
Chris@0
|
36 virtual ~FChTransformF0gram();
|
Chris@0
|
37
|
Chris@0
|
38 string getIdentifier() const;
|
Chris@0
|
39 string getName() const;
|
Chris@0
|
40 string getDescription() const;
|
Chris@0
|
41 string getMaker() const;
|
Chris@0
|
42 string getCopyright() const;
|
Chris@0
|
43 int getPluginVersion() const;
|
Chris@0
|
44
|
Chris@0
|
45 InputDomain getInputDomain() const;
|
Chris@0
|
46 size_t getMinChannelCount() const;
|
Chris@0
|
47 size_t getMaxChannelCount() const;
|
Chris@0
|
48 size_t getPreferredStepSize() const;
|
Chris@0
|
49 size_t getPreferredBlockSize() const;
|
Chris@0
|
50
|
Chris@0
|
51 ParameterList getParameterDescriptors() const;
|
Chris@0
|
52 float getParameter(string identifier) const;
|
Chris@0
|
53 void setParameter(string identifier, float value);
|
Chris@0
|
54
|
Chris@0
|
55 ProgramList getPrograms() const;
|
Chris@0
|
56 string getCurrentProgram() const;
|
Chris@0
|
57 void selectProgram(string name);
|
Chris@0
|
58
|
Chris@0
|
59 OutputList getOutputDescriptors() const;
|
Chris@0
|
60
|
Chris@0
|
61 bool initialise(size_t channels, size_t stepSize, size_t blockSize);
|
Chris@0
|
62 void reset();
|
Chris@0
|
63
|
Chris@0
|
64 FeatureSet process(const float *const *inputBuffers,
|
Chris@0
|
65 Vamp::RealTime timestamp);
|
Chris@0
|
66
|
Chris@0
|
67 FeatureSet getRemainingFeatures();
|
Chris@0
|
68
|
Chris@0
|
69 protected:
|
Chris@0
|
70
|
Chris@0
|
71 string m_currentProgram;
|
Chris@0
|
72 size_t m_stepSize;
|
Chris@0
|
73 size_t m_blockSize;
|
Chris@0
|
74 float m_fs; // input sampling rate (inputSampleRate)
|
Chris@0
|
75
|
Chris@0
|
76 // plugin-specific data and methods go here
|
Chris@0
|
77
|
Chris@0
|
78 // ============= WARPING PARAMETERS =============
|
Chris@0
|
79
|
Chris@0
|
80 double m_fmax; // maximum frequency of interest (Hz)
|
Chris@0
|
81 size_t m_nfft; // number of fft points (controls zero-padding)
|
Chris@0
|
82 size_t m_hop; // hop in samples in the upsampled signal
|
Chris@0
|
83 size_t m_num_f0s; // number of f0 values in F0gram grid
|
Chris@0
|
84 //vector<float> m_f0s; // vector of f0 values
|
Chris@0
|
85 double *m_f0s; // vector of f0 values
|
Chris@0
|
86
|
Chris@0
|
87 typedef struct {
|
Chris@0
|
88 size_t nsamps_twarp; // number of samples of the warped signal frame
|
Chris@0
|
89 double alpha_max; // maximum value of normalized frequency deviation (alpha)
|
Chris@0
|
90 size_t num_warps; // number of warpings
|
Chris@0
|
91 size_t fact_over_samp; // oversampling factor
|
Chris@0
|
92 size_t alpha_dist; // distribution of alpha values, 'lin' or 'log' (0 - 1)
|
Chris@0
|
93 } warping_parameters;
|
Chris@0
|
94
|
Chris@0
|
95 warping_parameters m_warp_params;
|
Chris@0
|
96
|
Chris@0
|
97 // ============= F0-GRAM PARAMETERS =============
|
Chris@0
|
98
|
Chris@0
|
99 typedef struct {
|
Chris@0
|
100 double f0min; // minimun fundamental frequency
|
Chris@0
|
101 size_t num_octs; // number of octaves
|
Chris@0
|
102 size_t num_f0s_per_oct; // number of f0s per octave
|
Chris@0
|
103 size_t num_f0_hyps; // number of f0 hypotesis to extract
|
Chris@0
|
104 bool prefer; // whether to use a f0 preference guassian function
|
Chris@0
|
105 size_t prefer_mean; // mean of f0 preference function (MIDI number for C4)
|
Chris@0
|
106 size_t prefer_stdev; // stdev of f0 preference function (stdev in MIDI numbers)
|
Chris@0
|
107 } f0_parameters;
|
Chris@0
|
108
|
Chris@0
|
109 f0_parameters m_f0_params;
|
Chris@0
|
110 bool m_f0gram_mode;
|
Chris@0
|
111
|
Chris@0
|
112 // ======== GATHERED LOG SPECTRUM PARAMETERS =======
|
Chris@0
|
113
|
Chris@0
|
114 typedef struct {
|
Chris@0
|
115 bool HP_logS; //high-pass logS
|
Chris@0
|
116 int att_subharms; // whether to attenuate subharmonics
|
Chris@0
|
117 // model parameter variables (default values)
|
Chris@0
|
118 double median_poly_coefs[3];
|
Chris@0
|
119 double sigma_poly_coefs[3];
|
Chris@0
|
120 } glogs_parameters;
|
Chris@0
|
121
|
Chris@0
|
122 glogs_parameters m_glogs_params;
|
Chris@0
|
123
|
Chris@0
|
124 // ============= WARPING DESIGN =============
|
Chris@0
|
125
|
Chris@0
|
126 typedef struct {
|
Chris@0
|
127 double fs_orig; // sampling frequency after oversampling
|
Chris@0
|
128 double fs_warp; // sampling frequency of warped signal
|
Chris@0
|
129 double *chirp_rates; // chirp rates
|
Chris@0
|
130 size_t nsamps_torig; // number of samples of the original signal frame
|
Chris@0
|
131 size_t fact_over_samp; // oversampling factor (use instead warp_params.fact_over_samp)
|
Chris@0
|
132 size_t *pos_int; // index of previous sample to do the warping by interpolation efficiently
|
Chris@0
|
133 double *pos_frac; // fractional value to do the warping by interpolation efficiently
|
Chris@0
|
134 } warping_design;
|
Chris@0
|
135
|
Chris@0
|
136 warping_design m_warpings;
|
Chris@0
|
137 // LPFWindow
|
Chris@0
|
138 double *mp_LPFWindow;
|
Chris@0
|
139 double *LPF_time;
|
Chris@0
|
140 fftw_complex *LPF_frequency;
|
Chris@0
|
141 fftw_plan plan_backward_LPF;
|
Chris@0
|
142 fftw_plan plan_forward_LPF;
|
Chris@0
|
143 // timeWindow
|
Chris@0
|
144 double *m_timeWindow;
|
Chris@0
|
145 // Warpings
|
Chris@0
|
146 double *x_warping;
|
Chris@0
|
147 // Hanning window
|
Chris@0
|
148 double *mp_HanningWindow;
|
Chris@0
|
149 // FChT plan & transformed data structs
|
Chris@0
|
150 double *m_absFanChirpTransform;
|
Chris@0
|
151 fftw_complex *m_auxFanChirpTransform;
|
Chris@0
|
152 fftw_plan plan_forward_xwarping;
|
Chris@0
|
153 // GLogS
|
Chris@0
|
154 double *m_glogs_f0;
|
Chris@0
|
155 double *m_glogs;
|
Chris@0
|
156 size_t *m_glogs_n;
|
Chris@0
|
157 size_t *m_glogs_index;
|
Chris@0
|
158 size_t *m_glogs_posint;
|
Chris@0
|
159 double *m_glogs_posfrac;
|
Chris@0
|
160 double *m_glogs_interp;
|
Chris@0
|
161 size_t m_glogs_harmonic_count;
|
Chris@0
|
162 size_t m_glogs_num_f0s;
|
Chris@0
|
163 size_t m_glogs_init_f0s;
|
Chris@0
|
164 size_t *m_glogs_third_harmonic_posint;
|
Chris@0
|
165 double *m_glogs_third_harmonic_posfrac;
|
Chris@0
|
166 double *m_glogs_third_harmonic;
|
Chris@0
|
167 size_t *m_glogs_fifth_harmonic_posint;
|
Chris@0
|
168 double *m_glogs_fifth_harmonic_posfrac;
|
Chris@0
|
169 double *m_glogs_fifth_harmonic;
|
Chris@0
|
170 double *m_glogs_f0_preference_weights;
|
Chris@0
|
171 double *m_glogs_median_correction;
|
Chris@0
|
172 double *m_glogs_sigma_correction;
|
Chris@0
|
173 double *m_glogs_hf_smoothing_window;
|
Chris@0
|
174 // auxiliar methods
|
Chris@0
|
175 void design_GLogS();
|
Chris@0
|
176 void design_FChT();
|
Chris@0
|
177 void define_warps_linear_chirps(double *, double *);
|
Chris@0
|
178 void design_warps(double *, double *, double *);
|
Chris@0
|
179 void design_LPF();
|
Chris@0
|
180 void clean_LPF();
|
Chris@0
|
181 void apply_LPF();
|
Chris@0
|
182 void design_FFT();
|
Chris@0
|
183 void design_time_window();
|
Chris@0
|
184
|
Chris@0
|
185 // FFT variables
|
Chris@0
|
186 fftw_complex *in, *out;
|
Chris@0
|
187 //TODO verificar que el tipo de datos de in_window es del tipo double, era del tipo float.
|
Chris@0
|
188 double *in_window;
|
Chris@0
|
189 fftw_plan planFFT;
|
Chris@0
|
190 };
|
Chris@0
|
191
|
Chris@0
|
192
|
Chris@0
|
193 #endif
|