| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #pragma once |
|
|
| #include <vector> |
| #include <cmath> |
| #include <cstdint> |
|
|
| class MelFilterBank { |
| public: |
| struct Config { |
| int sampling_rate; |
| int n_mels; |
| int n_fft; |
| int hop_length; |
|
|
| Config() : sampling_rate(24000), n_mels(100), n_fft(1024), hop_length(256) {} |
| }; |
|
|
| MelFilterBank(); |
|
|
| |
| |
| |
| int Init(const Config& config = Config()); |
|
|
| |
| |
| |
| |
| std::vector<float> Extract(const std::vector<float>& samples, int sample_rate); |
|
|
| |
| |
| |
| static int ComputeNumFrames(int num_samples, int hop_length); |
|
|
| const Config& GetConfig() const { return m_config; } |
|
|
| private: |
| Config m_config; |
|
|
| |
| std::vector<float> m_mel_basis; |
| int m_n_freqs; |
|
|
| |
| std::vector<float> m_window; |
|
|
| void CreateMelFilterbank(); |
| void CreateWindow(); |
|
|
| |
| void ComputeSTFT(const std::vector<float>& samples, |
| std::vector<float>& spec_real, |
| std::vector<float>& spec_imag, |
| int& num_frames); |
| }; |
|
|