annotate FChTransformF0gram.h @ 20:7964cc5ad98f spect

Correct the time-alignment of the output blocks
author Chris Cannam
date Thu, 04 Oct 2018 13:32:47 +0100
parents ce62ed201de8
children 2c54d83a196f
rev   line source
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@7 16 */
Chris@0 17
Chris@0 18 // Remember to use a different guard symbol in each header!
Chris@12 19 #ifndef FCHTRANSFORMF0GRAM_H
Chris@12 20 #define FCHTRANSFORMF0GRAM_H
Chris@7 21
Chris@0 22 #define _USE_MATH_DEFINES
Chris@0 23 #include <cmath>
Chris@0 24 #include <vamp-sdk/Plugin.h>
Chris@14 25 #include <vamp-sdk/FFT.h>
Chris@0 26 #include <complex>
Chris@0 27 #include <iostream>
Chris@0 28 #include <fstream>
Chris@0 29 #include <string.h>
Chris@0 30
Chris@0 31 using namespace std;
Chris@0 32 using std::string;
Chris@0 33
Chris@14 34 using _VampPlugin::Vamp::FFTReal;
Chris@14 35
Chris@15 36 class FChTransformF0gram : public Vamp::Plugin
Chris@15 37 {
Chris@0 38 public:
Chris@15 39 enum ProcessingMode {
Chris@15 40 ModeF0Gram,
Chris@15 41 ModeSpectrogram,
Chris@15 42 ModeRoughSpectrogram
Chris@15 43 };
Chris@15 44
Chris@15 45 FChTransformF0gram(ProcessingMode mode, float inputSampleRate);
Chris@0 46 virtual ~FChTransformF0gram();
Chris@0 47
Chris@0 48 string getIdentifier() const;
Chris@0 49 string getName() const;
Chris@0 50 string getDescription() const;
Chris@0 51 string getMaker() const;
Chris@0 52 string getCopyright() const;
Chris@0 53 int getPluginVersion() const;
Chris@0 54
Chris@0 55 InputDomain getInputDomain() const;
Chris@0 56 size_t getMinChannelCount() const;
Chris@0 57 size_t getMaxChannelCount() const;
Chris@0 58 size_t getPreferredStepSize() const;
Chris@0 59 size_t getPreferredBlockSize() const;
Chris@0 60
Chris@0 61 ParameterList getParameterDescriptors() const;
Chris@0 62 float getParameter(string identifier) const;
Chris@0 63 void setParameter(string identifier, float value);
Chris@0 64
Chris@0 65 ProgramList getPrograms() const;
Chris@0 66
Chris@0 67 OutputList getOutputDescriptors() const;
Chris@0 68
Chris@0 69 bool initialise(size_t channels, size_t stepSize, size_t blockSize);
Chris@0 70 void reset();
Chris@0 71
Chris@0 72 FeatureSet process(const float *const *inputBuffers,
Chris@7 73 Vamp::RealTime timestamp);
Chris@0 74
Chris@0 75 FeatureSet getRemainingFeatures();
Chris@0 76
Chris@0 77 protected:
Chris@15 78 ProcessingMode m_processingMode;
Chris@20 79 bool m_initialised;
Chris@10 80 int m_stepSize;
Chris@10 81 int m_blockSize;
Chris@0 82 float m_fs; // input sampling rate (inputSampleRate)
Chris@20 83 float *m_inputBuffer;
Chris@0 84
Chris@0 85 // plugin-specific data and methods go here
Chris@0 86
Chris@0 87 // ============= WARPING PARAMETERS =============
Chris@0 88
Chris@0 89 double m_fmax; // maximum frequency of interest (Hz)
Chris@10 90 int m_nfft; // number of fft points (controls zero-padding)
Chris@10 91 int m_hop; // hop in samples in the upsampled signal
Chris@16 92
Chris@10 93 int m_num_f0s; // number of f0 values in F0gram grid
Chris@0 94 double *m_f0s; // vector of f0 values
Chris@0 95
Chris@0 96 typedef struct {
Chris@10 97 int nsamps_twarp; // number of samples of the warped signal frame
Chris@0 98 double alpha_max; // maximum value of normalized frequency deviation (alpha)
Chris@10 99 int num_warps; // number of warpings
Chris@10 100 int fact_over_samp; // oversampling factor
Chris@10 101 int alpha_dist; // distribution of alpha values, 'lin' or 'log' (0 - 1)
Chris@0 102 } warping_parameters;
Chris@0 103
Chris@0 104 warping_parameters m_warp_params;
Chris@0 105
Chris@0 106 // ============= F0-GRAM PARAMETERS =============
Chris@0 107
Chris@0 108 typedef struct {
Chris@0 109 double f0min; // minimun fundamental frequency
Chris@10 110 int num_octs; // number of octaves
Chris@10 111 int num_f0s_per_oct; // number of f0s per octave
Chris@10 112 int num_f0_hyps; // number of f0 hypotesis to extract
Chris@0 113 bool prefer; // whether to use a f0 preference guassian function
Chris@10 114 int prefer_mean; // mean of f0 preference function (MIDI number for C4)
Chris@10 115 int prefer_stdev; // stdev of f0 preference function (stdev in MIDI numbers)
Chris@0 116 } f0_parameters;
Chris@0 117
Chris@0 118 f0_parameters m_f0_params;
Chris@15 119
Chris@15 120 enum F0GramMode {
Chris@15 121 AllBinsOfBestDirection,
Chris@15 122 BestBinOfAllDirections
Chris@15 123 };
Chris@15 124 F0GramMode m_f0gram_mode;
Chris@0 125
Chris@0 126 // ======== GATHERED LOG SPECTRUM PARAMETERS =======
Chris@0 127
Chris@0 128 typedef struct {
Chris@0 129 bool HP_logS; //high-pass logS
Chris@0 130 int att_subharms; // whether to attenuate subharmonics
Chris@0 131 // model parameter variables (default values)
Chris@0 132 double median_poly_coefs[3];
Chris@0 133 double sigma_poly_coefs[3];
Chris@0 134 } glogs_parameters;
Chris@0 135
Chris@0 136 glogs_parameters m_glogs_params;
Chris@0 137
Chris@0 138 // ============= WARPING DESIGN =============
Chris@0 139
Chris@0 140 typedef struct {
Chris@0 141 double fs_orig; // sampling frequency after oversampling
Chris@0 142 double fs_warp; // sampling frequency of warped signal
Chris@0 143 double *chirp_rates; // chirp rates
Chris@10 144 int nsamps_torig; // number of samples of the original signal frame
Chris@10 145 int *pos_int; // index of previous sample to do the warping by interpolation efficiently
Chris@0 146 double *pos_frac; // fractional value to do the warping by interpolation efficiently
Chris@0 147 } warping_design;
Chris@0 148
Chris@0 149 warping_design m_warpings;
Chris@0 150 // LPFWindow
Chris@0 151 double *mp_LPFWindow;
Chris@0 152 double *LPF_time;
Chris@14 153 double *LPF_frequency;
Chris@14 154 FFTReal *fft_forward_LPF; // two of these as they have different sizes
Chris@14 155 FFTReal *fft_inverse_LPF;
Chris@7 156 // timeWindow
Chris@7 157 double *m_timeWindow;
Chris@7 158 // Warpings
Chris@7 159 double *x_warping;
Chris@7 160 // Hanning window
Chris@7 161 double *mp_HanningWindow;
Chris@7 162 // FChT plan & transformed data structs
Chris@7 163 double *m_absFanChirpTransform;
Chris@14 164 double *m_auxFanChirpTransform;
Chris@14 165 FFTReal *fft_xwarping;
Chris@7 166 // GLogS
Chris@7 167 double *m_glogs_f0;
Chris@7 168 double *m_glogs;
Chris@10 169 int *m_glogs_n;
Chris@10 170 int *m_glogs_index;
Chris@10 171 int *m_glogs_posint;
Chris@7 172 double *m_glogs_posfrac;
Chris@7 173 double *m_glogs_interp;
Chris@10 174 int m_glogs_harmonic_count;
Chris@10 175 int m_glogs_num_f0s;
Chris@10 176 int m_glogs_init_f0s;
Chris@10 177 int *m_glogs_third_harmonic_posint;
Chris@7 178 double *m_glogs_third_harmonic_posfrac;
Chris@7 179 double *m_glogs_third_harmonic;
Chris@10 180 int *m_glogs_fifth_harmonic_posint;
Chris@7 181 double *m_glogs_fifth_harmonic_posfrac;
Chris@7 182 double *m_glogs_fifth_harmonic;
Chris@7 183 double *m_glogs_f0_preference_weights;
Chris@7 184 double *m_glogs_median_correction;
Chris@7 185 double *m_glogs_sigma_correction;
Chris@0 186 // auxiliar methods
Chris@7 187 void design_GLogS();
Chris@0 188 void design_FChT();
Chris@0 189 void define_warps_linear_chirps(double *, double *);
Chris@0 190 void design_warps(double *, double *, double *);
Chris@0 191 void design_LPF();
Chris@0 192 void clean_LPF();
Chris@0 193 void apply_LPF();
Chris@7 194 void design_time_window();
Chris@0 195 };
Chris@0 196
Chris@0 197
Chris@0 198 #endif