kaldi-native-fbank C++ API
Kaldi-compatible feature extraction C++ API
Loading...
Searching...
No Matches
knf::LinearResample Class Reference

Efficient up/downsampling at linearly spaced output times. More...

#include <resample.h>

Public Member Functions

 LinearResample (int32_t samp_rate_in_hz, int32_t samp_rate_out_hz, float filter_cutoff_hz, int32_t num_zeros)
 Construct the resampler.
void Resample (const VectorF &input, bool flush, VectorF *output)
 Resample (possibly a piece of) a signal.
void Resample (const float *input, int32_t input_dim, bool flush, std::vector< float > *output)
 Convenience overload taking a float pointer + length.
void Reset ()
 Reset the internal state prior to processing a new signal.
int32_t GetInputSamplingRate () const
 Return the input sampling rate (for checks, for example).
int32_t GetOutputSamplingRate () const
 Return the output sampling rate (for checks, for example).

Detailed Description

Efficient up/downsampling at linearly spaced output times.

LinearResample is a special case of ArbitraryResample, where we want to resample a signal at linearly spaced intervals (this means we want to upsample or downsample the signal). It is more efficient than ArbitraryResample because we can construct it just once.

We require that the input and output sampling rate be specified as integers, as this is an easy way to specify that their ratio be rational.

Used by:
OnlinePitch downsamples the waveform from samp_freq to resample_freq before computing the NCCF.
See also
ArbitraryResample, ResampleWaveform

Constructor & Destructor Documentation

◆ LinearResample()

knf::LinearResample::LinearResample ( int32_t samp_rate_in_hz,
int32_t samp_rate_out_hz,
float filter_cutoff_hz,
int32_t num_zeros )

Construct the resampler.

Parameters
[in]samp_rate_in_hzInput sample rate in Hz (integer, > 0).
[in]samp_rate_out_hzOutput sample rate in Hz (integer, > 0).
[in]filter_cutoff_hzLow-pass filter cutoff in Hz; must be > 0 and at most half of both sample rates.
[in]num_zerosFilter sharpness (sinc zeros under the raised-cosine window); more == sharper but less efficient. Around 4 to 10 is typical.

Member Function Documentation

◆ GetInputSamplingRate()

int32_t knf::LinearResample::GetInputSamplingRate ( ) const
inline

Return the input sampling rate (for checks, for example).

◆ GetOutputSamplingRate()

int32_t knf::LinearResample::GetOutputSamplingRate ( ) const
inline

Return the output sampling rate (for checks, for example).

◆ Resample() [1/2]

void knf::LinearResample::Resample ( const float * input,
int32_t input_dim,
bool flush,
std::vector< float > * output )

Convenience overload taking a float pointer + length.

It behaves exactly like Resample(const VectorF &, bool, VectorF *), except that the input is given as a float pointer and the output is a std::vector<float>.

Parameters
[in]inputThe input signal (a piece of it).
[in]input_dimNumber of samples in input.
[in]flushTrue if this is the last piece of the signal.
[out]outputThe resampled output (resized internally).

◆ Resample() [2/2]

void knf::LinearResample::Resample ( const VectorF & input,
bool flush,
VectorF * output )

Resample (possibly a piece of) a signal.

If you call it with flush == true and you have never called it with flush == false, it just resamples the input signal (it resizes the output to a suitable number of samples).

You can also use this function to process a signal a piece at a time. Suppose you break it into piece1, piece2, ... pieceN. You can call

Resample(piece1, &output1, false);
Resample(piece2, &output2, false);
Resample(piece3, &output3, true);
void Resample(const VectorF &input, bool flush, VectorF *output)
Resample (possibly a piece of) a signal.

If you call it with flush == false, it won't output the last few samples but will remember them, so that if you later give it a second piece of the input signal it can process it correctly.

If your most recent call to the object was with flush == false, it will have internal state; you can remove this by calling Reset(). Calling Reset() unnecessarily between signals will not do any harm. Empty input is acceptable.

Parameters
[in]inputThe input signal (a piece of it).
[in]flushTrue if this is the last piece of the signal.
[out]outputThe resampled output (resized internally).

◆ Reset()

void knf::LinearResample::Reset ( )

Reset the internal state prior to processing a new signal.

It is only necessary if you have called Resample(x, y, false) for some signal, leading to a remainder of the signal being saved, but then abandon processing the signal before calling Resample(x, y, true) for the last piece.


The documentation for this class was generated from the following file:
  • /home/runner/work/kaldi-native-fbank/kaldi-native-fbank/kaldi-native-fbank/csrc/resample.h