kaldi-native-fbank C++ API
Kaldi-compatible feature extraction C++ API
Loading...
Searching...
No Matches
stft.h
Go to the documentation of this file.
1
18
26
27#ifndef KALDI_NATIVE_FBANK_CSRC_STFT_H_
28#define KALDI_NATIVE_FBANK_CSRC_STFT_H_
29
30#include <cstdint>
31#include <memory>
32#include <string>
33#include <vector>
34
35namespace knf {
36
40struct StftConfig {
42 int32_t n_fft = 0;
43
45 int32_t hop_length = 0;
46
49 int32_t win_length = 0;
50
53 std::string window_type;
54
57 bool center = true;
58
60 std::string pad_mode = "reflect";
61
63 bool normalized = false;
64
66 std::vector<float> window;
67
69 std::string ToString() const;
70};
71
75struct StftResult {
78 std::vector<float> real;
79
82 std::vector<float> imag;
83
85 int32_t num_frames = 0;
86};
87
94class Stft {
95 public:
97 explicit Stft(const StftConfig &config);
98
101
107 StftResult Compute(const float *data, int32_t n) const;
108
109 private:
110 class Impl;
111 std::unique_ptr<Impl> impl_;
112};
113
114} // namespace knf
115
116#endif // KALDI_NATIVE_FBANK_CSRC_STFT_H_
Stft(const StftConfig &config)
Construct with the given config.
~Stft()
Destructor.
StftResult Compute(const float *data, int32_t n) const
Compute the STFT of a waveform.
This file is part of kaldi-native-fbank.
Definition feature-cmvn.h:42
Configuration for Stft.
Definition stft.h:40
bool normalized
If true, scale the FFT by 1/sqrt(n_fft) instead of 1.
Definition stft.h:63
bool center
If true, the signal is padded by n_fft/2 on both sides (using pad_mode) and the frames are centered a...
Definition stft.h:57
std::string pad_mode
Padding mode used when center is true; currently only "reflect".
Definition stft.h:60
std::vector< float > window
Explicit window coefficients; if specified, window_type is ignored.
Definition stft.h:66
int32_t hop_length
Number of samples between successive frames.
Definition stft.h:45
std::string ToString() const
Return the config as a string.
std::string window_type
Window type; see GetWindow() in feature-window.h for the supported types and their formulas.
Definition stft.h:53
int32_t win_length
Window size in samples; must be <= n_fft.
Definition stft.h:49
int32_t n_fft
FFT size; should be a power of two.
Definition stft.h:42
Result of Stft::Compute().
Definition stft.h:75
int32_t num_frames
Number of frames in real/imag.
Definition stft.h:85
std::vector< float > real
Real parts of the spectra, [num_frames, n_fft/2+1], flattened in row major.
Definition stft.h:78
std::vector< float > imag
Imaginary parts of the spectra, [num_frames, n_fft/2+1], flattened in row major.
Definition stft.h:82