00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef MELBANDS_H
00020 #define MELBANDS_H
00021
00022 #include <Eigen/StdVector>
00023
00024 #include "Typedefs.h"
00025 #include "Debug.h"
00026
00027 #include "Bands.h"
00028
00053 class MelBands {
00054 public:
00061 enum ScaleType {
00062 STEVENS = 0 ,
00069 FANT = 1 ,
00076 GREENWOOD = 2
00083 };
00084
00085 protected:
00086 Real _lowFrequency;
00087 Real _highFrequency;
00088 int _bandCount;
00089 Real _samplerate;
00090 int _fftSize;
00091 ScaleType _scaleType;
00092
00093 Bands _bands;
00094 MatrixXR _centersLinear;
00095
00096 Real (*_linearToMel)(Real linearFreq);
00097
00098 Real (*_melToLinear)(Real melFreq);
00099
00100 void (*_linearToMelMatrix)(const MatrixXR& linearFreq, MatrixXR* melFreq);
00101
00102 void (*_melToLinearMatrix)(const MatrixXR& melFreq, MatrixXR* linearFreq);
00103
00104 void triangleWindow(MatrixXR* window, Real start, Real stop, Real center = -1, Real height = Real(1.0));
00105
00106 public:
00125 MelBands(Real lowFrequency = 50.0, Real highFrequency = 6000.0, int bandCount = 40, Real samplerate = 44100.0, int fftSize = 1024, ScaleType scaleType = GREENWOOD);
00126
00127 void setup();
00128 void reset();
00129
00142 void process(const MatrixXR& spectrums, MatrixXR* bands);
00143
00149 std::vector<MatrixXR> weights() const;
00150
00156 void bandWeights(int band, MatrixXR* bandWeights) const;
00157
00161 void starts(MatrixXI* result) const;
00162
00166 int bands() const;
00167
00171 void centers(MatrixXR* result) const;
00172
00179 int bandCount() const;
00180
00186 void setBandCount( int count, bool callSetup = true );
00187
00194 Real lowFrequency() const;
00195
00202 void setLowFrequency( Real frequency, bool callSetup = true );
00203
00210 Real highFrequency() const;
00211
00218 void setHighFrequency( Real frequency, bool callSetup = true );
00219
00226 Real samplerate() const;
00227
00233 void setSamplerate( Real frequency, bool callSetup = true );
00234
00241 int fftSize() const;
00242
00249 void setFftSize( int size, bool callSetup = true );
00250
00258 MelBands::ScaleType scaleType() const;
00259
00265 void setScaleType( MelBands::ScaleType type, bool callSetup = true );
00266
00267 };
00268
00269 #endif