annotate FChTransformF0gram.h @ 15:0a860992b4f4 spect

Break out the plugin into three different plugins (using the same class in different modes) in order to provide simplistic and more sophisticated spectrograms as well as the f0-gram. Remove the program support, since it doesn't work usefully anyway (it just overrides the user's preferred settings).
author Chris Cannam
date Wed, 03 Oct 2018 13:16:09 +0100
parents 44b86c346a5a
children ce62ed201de8
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@10 79 int m_stepSize;
Chris@10 80 int m_blockSize;
Chris@0 81 float m_fs; // input sampling rate (inputSampleRate)
Chris@0 82
Chris@0 83 // plugin-specific data and methods go here
Chris@0 84
Chris@0 85 // ============= WARPING PARAMETERS =============
Chris@0 86
Chris@0 87 double m_fmax; // maximum frequency of interest (Hz)
Chris@10 88 int m_nfft; // number of fft points (controls zero-padding)
Chris@10 89 int m_hop; // hop in samples in the upsampled signal
Chris@10 90 int m_num_f0s; // number of f0 values in F0gram grid
Chris@0 91 //vector<float> m_f0s; // vector of f0 values
Chris@0 92 double *m_f0s; // vector of f0 values
Chris@0 93
Chris@0 94 typedef struct {
Chris@10 95 int nsamps_twarp; // number of samples of the warped signal frame
Chris@0 96 double alpha_max; // maximum value of normalized frequency deviation (alpha)
Chris@10 97 int num_warps; // number of warpings
Chris@10 98 int fact_over_samp; // oversampling factor
Chris@10 99 int alpha_dist; // distribution of alpha values, 'lin' or 'log' (0 - 1)
Chris@0 100 } warping_parameters;
Chris@0 101
Chris@0 102 warping_parameters m_warp_params;
Chris@0 103
Chris@0 104 // ============= F0-GRAM PARAMETERS =============
Chris@0 105
Chris@0 106 typedef struct {
Chris@0 107 double f0min; // minimun fundamental frequency
Chris@10 108 int num_octs; // number of octaves
Chris@10 109 int num_f0s_per_oct; // number of f0s per octave
Chris@10 110 int num_f0_hyps; // number of f0 hypotesis to extract
Chris@0 111 bool prefer; // whether to use a f0 preference guassian function
Chris@10 112 int prefer_mean; // mean of f0 preference function (MIDI number for C4)
Chris@10 113 int prefer_stdev; // stdev of f0 preference function (stdev in MIDI numbers)
Chris@0 114 } f0_parameters;
Chris@0 115
Chris@0 116 f0_parameters m_f0_params;
Chris@15 117
Chris@15 118 enum F0GramMode {
Chris@15 119 AllBinsOfBestDirection,
Chris@15 120 BestBinOfAllDirections
Chris@15 121 };
Chris@15 122 F0GramMode m_f0gram_mode;
Chris@0 123
Chris@0 124 // ======== GATHERED LOG SPECTRUM PARAMETERS =======
Chris@0 125
Chris@0 126 typedef struct {
Chris@0 127 bool HP_logS; //high-pass logS
Chris@0 128 int att_subharms; // whether to attenuate subharmonics
Chris@0 129 // model parameter variables (default values)
Chris@0 130 double median_poly_coefs[3];
Chris@0 131 double sigma_poly_coefs[3];
Chris@0 132 } glogs_parameters;
Chris@0 133
Chris@0 134 glogs_parameters m_glogs_params;
Chris@0 135
Chris@0 136 // ============= WARPING DESIGN =============
Chris@0 137
Chris@0 138 typedef struct {
Chris@0 139 double fs_orig; // sampling frequency after oversampling
Chris@0 140 double fs_warp; // sampling frequency of warped signal
Chris@0 141 double *chirp_rates; // chirp rates
Chris@10 142 int nsamps_torig; // number of samples of the original signal frame
Chris@10 143 int *pos_int; // index of previous sample to do the warping by interpolation efficiently
Chris@0 144 double *pos_frac; // fractional value to do the warping by interpolation efficiently
Chris@0 145 } warping_design;
Chris@0 146
Chris@0 147 warping_design m_warpings;
Chris@0 148 // LPFWindow
Chris@0 149 double *mp_LPFWindow;
Chris@0 150 double *LPF_time;
Chris@14 151 double *LPF_frequency;
Chris@14 152 FFTReal *fft_forward_LPF; // two of these as they have different sizes
Chris@14 153 FFTReal *fft_inverse_LPF;
Chris@7 154 // timeWindow
Chris@7 155 double *m_timeWindow;
Chris@7 156 // Warpings
Chris@7 157 double *x_warping;
Chris@7 158 // Hanning window
Chris@7 159 double *mp_HanningWindow;
Chris@7 160 // FChT plan & transformed data structs
Chris@7 161 double *m_absFanChirpTransform;
Chris@14 162 double *m_auxFanChirpTransform;
Chris@14 163 FFTReal *fft_xwarping;
Chris@7 164 // GLogS
Chris@7 165 double *m_glogs_f0;
Chris@7 166 double *m_glogs;
Chris@10 167 int *m_glogs_n;
Chris@10 168 int *m_glogs_index;
Chris@10 169 int *m_glogs_posint;
Chris@7 170 double *m_glogs_posfrac;
Chris@7 171 double *m_glogs_interp;
Chris@10 172 int m_glogs_harmonic_count;
Chris@10 173 int m_glogs_num_f0s;
Chris@10 174 int m_glogs_init_f0s;
Chris@10 175 int *m_glogs_third_harmonic_posint;
Chris@7 176 double *m_glogs_third_harmonic_posfrac;
Chris@7 177 double *m_glogs_third_harmonic;
Chris@10 178 int *m_glogs_fifth_harmonic_posint;
Chris@7 179 double *m_glogs_fifth_harmonic_posfrac;
Chris@7 180 double *m_glogs_fifth_harmonic;
Chris@7 181 double *m_glogs_f0_preference_weights;
Chris@7 182 double *m_glogs_median_correction;
Chris@7 183 double *m_glogs_sigma_correction;
Chris@0 184 // auxiliar methods
Chris@7 185 void design_GLogS();
Chris@0 186 void design_FChT();
Chris@0 187 void define_warps_linear_chirps(double *, double *);
Chris@0 188 void design_warps(double *, double *, double *);
Chris@0 189 void design_LPF();
Chris@0 190 void clean_LPF();
Chris@0 191 void apply_LPF();
Chris@7 192 void design_time_window();
Chris@0 193 };
Chris@0 194
Chris@0 195
Chris@0 196 #endif