kaldi-native-fbank C++ API
Kaldi-compatible feature extraction C++ API
Loading...
Searching...
No Matches
feature-fbank.h
Go to the documentation of this file.
1
22
39
40#ifndef KALDI_NATIVE_FBANK_CSRC_FEATURE_FBANK_H_
41#define KALDI_NATIVE_FBANK_CSRC_FEATURE_FBANK_H_
42
43#include <cstdint>
44#include <limits>
45#include <map>
46#include <sstream>
47#include <string>
48#include <vector>
49
53
54namespace knf {
55
66
69
71 bool use_energy = false;
72
76 float energy_floor = 0.0f; // active iff use_energy==true
77
80 bool raw_energy = true; // active iff use_energy==true
81
86 bool htk_compat = false; // active iff use_energy==true
87
89 bool use_log_fbank = true;
90
95 bool use_log_floor = true;
96
100 float eps = std::numeric_limits<float>::epsilon();
101
103 bool use_power = true;
104
106 FbankOptions() { mel_opts.num_bins = 23; }
107
109 std::string ToString() const {
110 std::ostringstream os;
111 os << "frame_opts: \n";
112 os << frame_opts << "\n";
113 os << "\n";
114
115 os << "mel_opts: \n";
116 os << mel_opts << "\n";
117
118 os << "use_energy: " << use_energy << "\n";
119 os << "energy_floor: " << energy_floor << "\n";
120 os << "raw_energy: " << raw_energy << "\n";
121 os << "htk_compat: " << htk_compat << "\n";
122 os << "use_log_fbank: " << use_log_fbank << "\n";
123 os << "use_log_floor: " << use_log_floor << "\n";
124 os << "eps: " << eps << "\n";
125 os << "use_power: " << use_power << "\n";
126 return os.str();
127 }
128};
129
131std::ostream &operator<<(std::ostream &os, const FbankOptions &opts);
132
145 public:
148
150 explicit FbankComputer(const FbankOptions &opts);
151
154
157 int32_t Dim() const {
158 return opts_.mel_opts.num_bins + (opts_.use_energy ? 1 : 0);
159 }
160
163 bool NeedRawLogEnergy() const { return opts_.use_energy && opts_.raw_energy; }
164
167 return opts_.frame_opts;
168 }
169
171 const FbankOptions &GetOptions() const { return opts_; }
172
194 void Compute(float signal_raw_log_energy, float vtln_warp,
195 std::vector<float> *signal_frame, float *feature);
196
197 private:
200 const MelBanks *GetMelBanks(float vtln_warp);
201
202 FbankOptions opts_;
203 float log_energy_floor_;
204 std::map<float, MelBanks *> mel_banks_;
205 Rfft rfft_;
206};
207
208} // namespace knf
209
210#endif // KALDI_NATIVE_FBANK_CSRC_FEATURE_FBANK_H_
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 FbankOptions & GetOptions() const
Return the options this computer was constructed with.
Definition feature-fbank.h:171
bool NeedRawLogEnergy() const
If true, compute log_energy_pre_window but after dithering and dc removal.
Definition feature-fbank.h:163
FbankComputer(const FbankOptions &opts)
Construct from the given options.
~FbankComputer()
Destructor; frees the cached MelBanks.
int32_t Dim() const
Return the dimension of the output features: num_bins, plus 1 if use_energy is true.
Definition feature-fbank.h:157
FbankOptions Options
Option type accepted by this computer.
Definition feature-fbank.h:147
const FrameExtractionOptions & GetFrameOptions() const
Return the frame-extraction options.
Definition feature-fbank.h:166
Triangular mel-filterbank bins.
Definition mel-computations.h:133
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 computing filter-bank features.
Definition feature-fbank.h:63
bool htk_compat
If true, put energy last (if using energy); if false, put energy first.
Definition feature-fbank.h:86
FbankOptions()
Construct with the default options: 23 mel bins.
Definition feature-fbank.h:106
MelBanksOptions mel_opts
Options for the mel filter banks; see MelBanksOptions.
Definition feature-fbank.h:68
bool raw_energy
If true, compute log energy before preemphasis and windowing; if false, compute it after preemphasis ...
Definition feature-fbank.h:80
bool use_energy
If true, append an extra dimension with energy to the filter banks.
Definition feature-fbank.h:71
std::string ToString() const
Return the options as a string.
Definition feature-fbank.h:109
bool use_power
If true (default), use power in filterbank analysis; else magnitude.
Definition feature-fbank.h:103
FrameExtractionOptions frame_opts
Options for frame extraction; see FrameExtractionOptions.
Definition feature-fbank.h:65
bool use_log_fbank
If true (default), produce log-filterbank; else linear.
Definition feature-fbank.h:89
float eps
Value used by the log-zero guard selected by use_log_floor.
Definition feature-fbank.h:100
float energy_floor
Floor on energy (absolute, not relative) in fbank computation.
Definition feature-fbank.h:76
bool use_log_floor
If true (default), use Kaldi's hard floor before the log, i.e.
Definition feature-fbank.h:95
Options for extracting frames from a waveform.
Definition feature-window.h:57
Options for constructing triangular mel-filterbank bins.
Definition mel-computations.h:58