32#ifndef KALDI_NATIVE_FBANK_CSRC_MEL_COMPUTATIONS_H_
33#define KALDI_NATIVE_FBANK_CSRC_MEL_COMPUTATIONS_H_
93 std::string
norm =
"slaney";
103 std::ostringstream os;
104 os <<
"num_bins: " <<
num_bins <<
"\n";
105 os <<
"low_freq: " <<
low_freq <<
"\n";
106 os <<
"high_freq: " <<
high_freq <<
"\n";
107 os <<
"vtln_low: " <<
vtln_low <<
"\n";
108 os <<
"vtln_high: " <<
vtln_high <<
"\n";
109 os <<
"debug_mel: " <<
debug_mel <<
"\n";
110 os <<
"htk_mode: " <<
htk_mode <<
"\n";
112 os <<
"norm: " <<
norm <<
"\n";
139 return 700.0f * (expf(mel_freq / 1127.0f) - 1.0f);
146 return 1127.0f * logf(1.0f + freq / 700.0f);
156 if (mel_freq <= 15) {
157 return 200.0f / 3 * mel_freq;
164 return 1000 * expf((mel_freq - 15) * 0.06875177742094911f);
175 return freq * 3 / 200.0f;
182 return 15 + 14.545078505785561f * logf(freq / 1000);
239 float vtln_low_cutoff,
240 float vtln_high_cutoff,
244 float vtln_warp_factor,
float freq);
254 float low_freq,
float high_freq,
255 float vtln_warp_factor,
float mel_freq);
283 MelBanks(
const float *weights, int32_t num_rows, int32_t num_cols);
305 void Compute(
const float *fft_energies,
float *mel_energies_out)
const;
308 int32_t
NumBins()
const {
return bins_.size(); }
318 float vtln_warp_factor);
324 float vtln_warp_factor);
329 std::vector<std::pair<int32_t, std::vector<float>>> bins_;
333 bool htk_mode_ =
false;
334 int32_t num_fft_bins_ = -1;
static float MelScale(float freq)
HTK mel scale: convert Hz to mel frequency.
Definition mel-computations.h:145
MelBanks(const MelBanksOptions &opts, const FrameExtractionOptions &frame_opts, float vtln_warp_factor)
Construct kaldi-compatible mel banks.
std::vector< float > GetMatrix() const
Return the mel filter weights as a flattened 2-d matrix of shape [num_mel_bins, num_fft_bins/2+1],...
static float InverseMelScaleSlaney(float mel_freq)
Slaney mel scale: convert mel frequency to Hz.
Definition mel-computations.h:155
static float MelScaleSlaney(float freq)
Slaney mel scale: convert Hz to mel frequency.
Definition mel-computations.h:173
MelBanks(const float *weights, int32_t num_rows, int32_t num_cols)
Initialize with a 2-d weights matrix.
static float VtlnWarpMelFreq(float vtln_low_cutoff, float vtln_high_cutoff, float low_freq, float high_freq, float vtln_warp_factor, float mel_freq)
Piecewise-linear VTLN warping function in the mel domain.
static float InverseMelScale(float mel_freq)
HTK mel scale: convert mel frequency to Hz.
Definition mel-computations.h:138
int32_t NumBins() const
Return the number of mel bins.
Definition mel-computations.h:308
static float VtlnWarpFreq(float vtln_low_cutoff, float vtln_high_cutoff, float low_freq, float high_freq, float vtln_warp_factor, float freq)
Piecewise-linear VTLN warping function in the frequency domain.
void Compute(const float *fft_energies, float *mel_energies_out) const
Compute mel energies (note: NOT log energies).
Waveform windowing and frame extraction.
This file is part of kaldi-native-fbank.
Definition feature-cmvn.h:42
std::ostream & operator<<(std::ostream &os, const FbankOptions &opts)
Write the options to the stream, one option per line.
void ComputeLifterCoeffs(float Q, std::vector< float > *coeffs)
Compute liftering coefficients (scaling on cepstral coeffs).
Options for constructing triangular mel-filterbank bins.
Definition mel-computations.h:58
bool floor_to_int_bin
Used only when is_librosa is true: floor the bin edges to integers.
Definition mel-computations.h:99
float vtln_low
VTLN lower cutoff of the warping function.
Definition mel-computations.h:70
int32_t num_bins
Number of triangular mel-frequency bins, e.g. 25.
Definition mel-computations.h:60
std::string norm
Used only when is_librosa is true.
Definition mel-computations.h:93
float high_freq
Upper frequency cutoff; 0 means no cutoff, negative values are added to the Nyquist frequency to get ...
Definition mel-computations.h:67
bool htk_mode
htk_mode is a "hidden" config.
Definition mel-computations.h:82
float vtln_high
VTLN upper cutoff of the warping function: if negative, added to the Nyquist frequency to get the cut...
Definition mel-computations.h:74
bool debug_mel
Print out debugging information for mel bin computation.
Definition mel-computations.h:77
std::string ToString() const
Return the options as a string.
Definition mel-computations.h:102
float low_freq
Lower frequency cutoff, e.g. 20.
Definition mel-computations.h:63
bool use_slaney_mel_scale
Used only when is_librosa is true: use the Slaney mel scale.
Definition mel-computations.h:96
bool is_librosa
If true, use librosa-style mel filters instead of kaldi-style ones.
Definition mel-computations.h:88