kaldi-native-fbank C++ API
Kaldi-compatible feature extraction C++ API
Loading...
Searching...
No Matches
feature-mfcc.h
Go to the documentation of this file.
1
22
39
40#ifndef KALDI_NATIVE_FBANK_CSRC_FEATURE_MFCC_H_
41#define KALDI_NATIVE_FBANK_CSRC_FEATURE_MFCC_H_
42
43#include <cstdint>
44#include <map>
45#include <sstream>
46#include <string>
47#include <vector>
48
52
53namespace knf {
54
63
66
68 int32_t num_ceps = 13;
69
71 bool use_energy = true;
72
76 float energy_floor = 0.0;
77
79 bool raw_energy = true;
80
83 float cepstral_lifter = 22.0;
84
89 bool htk_compat = false;
90
92 MfccOptions() { mel_opts.num_bins = 23; }
93
95 std::string ToString() const {
96 std::ostringstream os;
97 os << "MfccOptions(";
98 os << "frame_opts=" << frame_opts.ToString() << ", ";
99 os << "mel_opts=" << mel_opts.ToString() << ", ";
100
101 os << "num_ceps=" << num_ceps << ", ";
102 os << "use_energy=" << (use_energy ? "True" : "False") << ", ";
103 os << "energy_floor=" << energy_floor << ", ";
104 os << "raw_energy=" << (raw_energy ? "True" : "False") << ", ";
105 os << "cepstral_lifter=" << cepstral_lifter << ", ";
106 os << "htk_compat=" << (htk_compat ? "True" : "False") << ")";
107
108 return os.str();
109 }
110};
111
113std::ostream &operator<<(std::ostream &os, const MfccOptions &opts);
114
127 public:
130
132 explicit MfccComputer(const MfccOptions &opts);
133
136
138 int32_t Dim() const { return opts_.num_ceps; }
139
142 bool NeedRawLogEnergy() const { return opts_.use_energy && opts_.raw_energy; }
143
146 return opts_.frame_opts;
147 }
148
150 const MfccOptions &GetOptions() const { return opts_; }
151
173 void Compute(float signal_raw_log_energy, float vtln_warp,
174 std::vector<float> *signal_frame, float *feature);
175
176 private:
179 const MelBanks *GetMelBanks(float vtln_warp);
180
181 MfccOptions opts_;
182 float log_energy_floor_;
183 std::map<float, MelBanks *> mel_banks_;
184 Rfft rfft_;
185
187 std::vector<float> mel_energies_;
188
189 std::vector<float>
190 lifter_coeffs_;
191
194 std::vector<float> dct_matrix_;
195};
196
197} // namespace knf
198
199#endif // KALDI_NATIVE_FBANK_CSRC_FEATURE_MFCC_H_
Triangular mel-filterbank bins.
Definition mel-computations.h:133
~MfccComputer()
Destructor; frees the cached MelBanks.
const MfccOptions & GetOptions() const
Return the options this computer was constructed with.
Definition feature-mfcc.h:150
MfccOptions Options
Option type accepted by this computer.
Definition feature-mfcc.h:129
void Compute(float signal_raw_log_energy, float vtln_warp, std::vector< float > *signal_frame, float *feature)
Function that computes one frame of features from one frame of signal.
const FrameExtractionOptions & GetFrameOptions() const
Return the frame-extraction options.
Definition feature-mfcc.h:145
int32_t Dim() const
Return the dimension of the output features: num_ceps.
Definition feature-mfcc.h:138
bool NeedRawLogEnergy() const
If true, compute log_energy_pre_window but after dithering and dc removal.
Definition feature-mfcc.h:142
MfccComputer(const MfccOptions &opts)
Construct from the given options.
n-point real discrete Fourier transform, where n is even, n >= 2.
Definition rfft.h:44
Waveform windowing and frame extraction.
Copyright 2009-2011 Phonexia s.r.o.; Microsoft Corporation 2016 Johns Hopkins University (author: Dan...
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.
Copyright (c) 2022 Xiaomi Corporation (authors: Fangjun Kuang).
Options for extracting frames from a waveform.
Definition feature-window.h:57
Options for constructing triangular mel-filterbank bins.
Definition mel-computations.h:58
Options for computing MFCC features.
Definition feature-mfcc.h:60
float energy_floor
Floor on energy (absolute, not relative) in MFCC computation.
Definition feature-mfcc.h:76
MelBanksOptions mel_opts
Options for the mel filter banks; see MelBanksOptions.
Definition feature-mfcc.h:65
bool htk_compat
If true, put energy or C0 last and use a factor of sqrt(2) on C0.
Definition feature-mfcc.h:89
bool raw_energy
If true, compute energy before preemphasis and windowing.
Definition feature-mfcc.h:79
std::string ToString() const
Return the options as a string.
Definition feature-mfcc.h:95
int32_t num_ceps
Number of cepstra in MFCC computation (including C0), e.g. 13.
Definition feature-mfcc.h:68
float cepstral_lifter
Constant that controls scaling of MFCCs (HTK liftering).
Definition feature-mfcc.h:83
FrameExtractionOptions frame_opts
Options for frame extraction; see FrameExtractionOptions.
Definition feature-mfcc.h:62
bool use_energy
Use energy (not C0) in MFCC computation.
Definition feature-mfcc.h:71
MfccOptions()
Construct with the default options: 23 mel bins, 13 cepstra.
Definition feature-mfcc.h:92