|
kaldi-native-fbank C++ API
Kaldi-compatible feature extraction C++ API
|
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). | |
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.
| 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.
| [in] | samp_rate_in_hz | Input sample rate in Hz (integer, > 0). |
| [in] | samp_rate_out_hz | Output sample rate in Hz (integer, > 0). |
| [in] | filter_cutoff_hz | Low-pass filter cutoff in Hz; must be > 0 and at most half of both sample rates. |
| [in] | num_zeros | Filter sharpness (sinc zeros under the raised-cosine window); more == sharper but less efficient. Around 4 to 10 is typical. |
|
inline |
Return the input sampling rate (for checks, for example).
|
inline |
Return the output sampling rate (for checks, for example).
| 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>.
| [in] | input | The input signal (a piece of it). |
| [in] | input_dim | Number of samples in input. |
| [in] | flush | True if this is the last piece of the signal. |
| [out] | output | The resampled output (resized internally). |
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
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.
| [in] | input | The input signal (a piece of it). |
| [in] | flush | True if this is the last piece of the signal. |
| [out] | output | The resampled output (resized internally). |
| 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.