|
marvin 0.0.1
Pure C++ audio helper library
|
A windowed sinc interpolator, suitable for use in a realtime context. More...
#include <marvin_Interpolators.h>
Public Member Functions | |
| WindowedSincInterpolator () | |
| WindowedSincInterpolator (SampleType alpha) | |
| SampleType | interpolate (std::span< SampleType > sampleContext, SampleType ratio) |
A windowed sinc interpolator, suitable for use in a realtime context.
Uses a lookup table precomputed at construction time for optimization purposes, and bakes the selected window function into the lookup table. For a non-integer subsample, the resulting point on the Sinc curve will be a lerp between the closest two points in the table. Input should contain N - 1 history samples, followed by the latest sample. For example, in the case of N=4, The input should be in the form [x[n-3], x[n-2], x[n-1], x[n]].
In the case of N=8, it should be in the form [x[n-7], x[n-6], x[n-5], x[n-4], x[n-3], x[n-2], x[n-1], x[n]].
The interpolator will introduce N / 2 samples of latency (determined by assuming a fixed ratio of 0, and counting the number of samples it takes an impulse to be output). For example, a signal [a, b, c, d, e, f, g, .......], with N=4 would be output as [0, 0, a, b, c, d ......].
To really belabour the point, the inputs passed to the interpolator for the above impulse and N=4 would be:
Usage Example:
|
inline |
Constructs a WindowedSincInterpolator with a sine window applied to the lookup table.
|
inlineexplicit |
Constructs a WindowedSincInterpolator with a tukey window applied to the lookup table.
| alpha | At 0, the window is rectangular, and at 1, the window is a hann window. |
|
inlinenodiscard |
Performs the interpolation. See the detailed description for an explanation of the formatting needed for sampleContext.
| sampleContext | An array like containing N-1 previous samples, followed by the current sample. Must be the same size as N. |
| ratio | The 0 to 1 subsample position of the interpolation. For an input block [a b c d], when ratio = 0, the output will be b. When ratio = 1, the output will be c. When ratio = 0.5, the output will be the sinc interpolated midpoint between b and c, which is left to the reader's imagination. |