#ifndef KALDI_NATIVE_FBANK_CSRC_FEATURE_MFCC_H_
#define KALDI_NATIVE_FBANK_CSRC_FEATURE_MFCC_H_
#include <cstdint>
#include <map>
#include <sstream>
#include <string>
#include <vector>
#include "feature-window.h"
#include "mel-computations.h"
#include "rfft.h"
namespace knf {
struct MfccOptions {
FrameExtractionOptions frame_opts;
MelBanksOptions mel_opts;
int32_t num_ceps = 13;
bool use_energy = true;
float energy_floor = 0.0;
bool raw_energy = true;
float cepstral_lifter = 22.0;
bool htk_compat = false;
MfccOptions() { mel_opts.num_bins = 23; }
std::string ToString() const {
std::ostringstream os;
os << "MfccOptions(";
os << "frame_opts=" << frame_opts.ToString() << ", ";
os << "mel_opts=" << mel_opts.ToString() << ", ";
os << "num_ceps=" << num_ceps << ", ";
os << "use_energy=" << (use_energy ? "True" : "False") << ", ";
os << "energy_floor=" << energy_floor << ", ";
os << "raw_energy=" << (raw_energy ? "True" : "False") << ", ";
os << "cepstral_lifter=" << cepstral_lifter << ", ";
os << "htk_compat=" << (htk_compat ? "True" : "False") << ")";
return os.str();
}
};
std::ostream &operator<<(std::ostream &os, const MfccOptions &opts);
class MfccComputer {
public:
using Options = MfccOptions;
explicit MfccComputer(const MfccOptions &opts);
~MfccComputer();
int32_t Dim() const { return opts_.num_ceps; }
bool NeedRawLogEnergy() const { return opts_.use_energy && opts_.raw_energy; }
const FrameExtractionOptions &GetFrameOptions() const {
return opts_.frame_opts;
}
const MfccOptions &GetOptions() const { return opts_; }
void Compute(float signal_raw_log_energy, float vtln_warp,
std::vector<float> *signal_frame, float *feature);
private:
const MelBanks *GetMelBanks(float vtln_warp);
MfccOptions opts_;
float log_energy_floor_;
std::map<float, MelBanks *> mel_banks_; Rfft rfft_;
std::vector<float> mel_energies_;
std::vector<float> lifter_coeffs_;
std::vector<float> dct_matrix_;
};
}
#endif