kaldi-native-fbank C++ API
Kaldi-compatible feature extraction C++ API
Loading...
Searching...
No Matches
feature-pitch.h
Go to the documentation of this file.
1
2//
3// Copyright 2013 Pegah Ghahremani
4// 2014 IMSL, PKU-HKUST (author: Wei Shi)
5// 2014 Yanqing Sun, Junjie Wang,
6// Daniel Povey, Korbinian Riedhammer
7// Xin Lei
8// Copyright (c) 2026 Xiaomi Corporation
9//
10// This file is copied/modified from kaldi/src/feat/pitch-functions.h
11//
13//
14// See ../../LICENSE for more information
15
61
62#ifndef KALDI_NATIVE_FBANK_CSRC_FEATURE_PITCH_H_
63#define KALDI_NATIVE_FBANK_CSRC_FEATURE_PITCH_H_
64
65#include <stdint.h>
66
67#include <memory>
68#include <vector>
69
71
72namespace knf {
73
87 float samp_freq = 16000;
88
90 float frame_shift_ms = 10.0;
91
93 float frame_length_ms = 25.0;
94
97 float preemph_coeff = 0.0;
98
100 float min_f0 = 50;
101
103 float max_f0 = 400;
104
107 float soft_min_f0 = 10.0;
108
111 float penalty_factor = 0.1;
112
114 float lowpass_cutoff = 1000;
115
118 float resample_freq = 4000;
119
124 float delta_pitch = 0.005;
125
128 float nccf_ballast = 7000;
129
133
137
145
152 int32_t frames_per_chunk = 0;
153
162
173 int32_t recompute_frame = 500;
174
182
188 bool snip_edges = true;
189
195 int32_t NccfWindowSize() const {
196 return static_cast<int32_t>(resample_freq * frame_length_ms / 1000.0);
197 }
198
200 int32_t NccfWindowShift() const {
201 return static_cast<int32_t>(resample_freq * frame_shift_ms / 1000.0);
202 }
203};
204
220 float pitch_scale = 2.0;
221
223 float pov_scale = 2.0;
224
228 float pov_offset = 0.0;
229
232 float delta_pitch_scale = 10.0;
233
242
246
251
254 int32_t delta_window = 2;
255
258 int32_t delay = 0;
259
262 bool add_pov_feature = true;
263
268
271 bool add_delta_pitch = true;
272
275 bool add_raw_log_pitch = false;
276
278 int32_t Dim() const {
279 return (add_pov_feature ? 1 : 0) + (add_normalized_log_pitch ? 1 : 0) +
280 (add_delta_pitch ? 1 : 0) + (add_raw_log_pitch ? 1 : 0);
281 }
282};
283
312 public:
321 const ProcessPitchOptions &popts = {});
322
324
326 int32_t Dim() const;
327
329 float FrameShiftInSeconds() const;
330
333 int32_t NumFramesReady() const;
334
337 bool IsLastFrame(int32_t frame) const;
338
349 std::vector<float> GetFrame(int32_t frame) const;
350
359 void AcceptWaveform(float sampling_rate, const float *waveform, int32_t n);
360
364
365 private:
366 class Impl;
367 std::unique_ptr<Impl> impl_;
368};
369
390 const ProcessPitchOptions &process_opts,
391 const float *wave, int32_t n);
392
393} // namespace knf
394
395#endif // KALDI_NATIVE_FBANK_CSRC_FEATURE_PITCH_H_
float FrameShiftInSeconds() const
int32_t NumFramesReady() const
std::vector< float > GetFrame(int32_t frame) const
Return the frame-th feature vector.
bool IsLastFrame(int32_t frame) const
void AcceptWaveform(float sampling_rate, const float *waveform, int32_t n)
Add waveform samples to the extractor.
OnlinePitch(const PitchExtractionOptions &opts, const ProcessPitchOptions &popts={})
Construct with the given extraction and post-processing options.
void InputFinished()
Tell the extractor no more waveform will be added; this flushes out the last frames and fixes the fea...
int32_t Dim() const
kaldi-native-fbank/kaldi-native-fbank/csrc/feature-matrix.h
This file is part of kaldi-native-fbank.
Definition feature-cmvn.h:42
MatrixF ComputeAndProcessKaldiPitch(const PitchExtractionOptions &pitch_opts, const ProcessPitchOptions &process_opts, const float *wave, int32_t n)
Batch pitch extraction (kaldi's ComputeAndProcessKaldiPitch).
Eigen::Matrix< float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MatrixF
Row-major feature matrix: rows are frames, columns are features.
Definition feature-matrix.h:26
Options for the raw pitch extraction stage (kaldi's PitchExtractionOptions).
Definition feature-pitch.h:84
int32_t NccfWindowShift() const
Definition feature-pitch.h:200
int32_t NccfWindowSize() const
Definition feature-pitch.h:195
float lowpass_cutoff
Cutoff frequency for the low-pass filter (Hz). Kaldi --lowpass-cutoff.
Definition feature-pitch.h:114
float delta_pitch
The pitch tolerance in pruning lags: the relative change in pitch that the algorithm measures (the la...
Definition feature-pitch.h:124
bool nccf_ballast_online
This is a "hidden config" used only for testing the online pitch extraction.
Definition feature-pitch.h:181
float frame_length_ms
Frame length in milliseconds. Kaldi --frame-length.
Definition feature-pitch.h:93
int32_t frames_per_chunk
Only relevant for ComputeAndProcessKaldiPitch.
Definition feature-pitch.h:152
int32_t max_frames_latency
The maximum number of frames of latency that we allow the pitch processing to introduce,...
Definition feature-pitch.h:144
int32_t lowpass_filter_width
Integer that determines the filter width of the low-pass filter; more gives a sharper filter.
Definition feature-pitch.h:132
float resample_freq
Frequency that we down-sample the signal to.
Definition feature-pitch.h:118
float min_f0
Min F0 to search for (Hz). Kaldi --min-f0.
Definition feature-pitch.h:100
float frame_shift_ms
Frame shift in milliseconds. Kaldi --frame-shift.
Definition feature-pitch.h:90
bool simulate_first_pass_online
Only relevant for ComputeAndProcessKaldiPitch, and only if frames_per_chunk is nonzero.
Definition feature-pitch.h:161
float penalty_factor
Cost factor for F0 change (Viterbi inter-frame penalty).
Definition feature-pitch.h:111
float nccf_ballast
Increasing this factor reduces NCCF for quiet frames, helping ensure pitch continuity in unvoiced reg...
Definition feature-pitch.h:128
bool snip_edges
If false, the incomplete frames near the ending edge won't be snipped, so that the number of frames i...
Definition feature-pitch.h:188
float max_f0
Max F0 to search for (Hz). Kaldi --max-f0.
Definition feature-pitch.h:103
int32_t upsample_filter_width
Integer that determines the filter width when upsampling the NCCF.
Definition feature-pitch.h:136
float preemph_coeff
Preemphasis coefficient (use is deprecated in kaldi; kept for parity).
Definition feature-pitch.h:97
float soft_min_f0
Minimum f0, applied in a soft way; must not exceed min_f0.
Definition feature-pitch.h:107
int32_t recompute_frame
Only relevant for online operation or when emulating online operation (e.g.
Definition feature-pitch.h:173
float samp_freq
Waveform data sample frequency in Hz (must match the waveform).
Definition feature-pitch.h:87
Options for the pitch post-processing stage (kaldi's ProcessPitchOptions).
Definition feature-pitch.h:217
bool add_pov_feature
If true, the warped NCCF is added to the output features (1 dim).
Definition feature-pitch.h:262
int32_t delay
Number of frames by which the pitch information is delayed.
Definition feature-pitch.h:258
bool add_raw_log_pitch
If true, log(pitch) is added to the output features (1 dim).
Definition feature-pitch.h:275
float delta_pitch_scale
Term to scale the final delta log-pitch feature.
Definition feature-pitch.h:232
int32_t Dim() const
Definition feature-pitch.h:278
int32_t delta_window
Number of frames on each side of the central frame to use for the delta window.
Definition feature-pitch.h:254
float pov_scale
The final POV feature is scaled with this value. Kaldi --pov-scale.
Definition feature-pitch.h:223
float pitch_scale
The final normalized-log-pitch feature is scaled with this value.
Definition feature-pitch.h:220
int32_t normalization_left_context
Left-context (in frames) for moving-window normalization of the log pitch.
Definition feature-pitch.h:245
int32_t normalization_right_context
Right-context (in frames) for moving-window normalization of the log pitch; should be reduced in onli...
Definition feature-pitch.h:250
bool add_delta_pitch
If true, the time derivative of log-pitch is added to the output features (1 dim).
Definition feature-pitch.h:271
float delta_pitch_noise_stddev
Standard deviation for the noise we add to the delta log-pitch (before scaling); should be about the ...
Definition feature-pitch.h:241
float pov_offset
An offset that can be added to the final POV feature (useful for online decoding, where we don't do C...
Definition feature-pitch.h:228
bool add_normalized_log_pitch
If true, the log-pitch with POV-weighted mean subtraction over a 1.5 second window is added to the ou...
Definition feature-pitch.h:267