class MAGES::Recorder::Utilities::Resampler

Overview

A stateful linear resampler. Unlike LinearResample this carries the fractional phase across calls, so consecutive blocks of a continuous stream join without a discontinuity. More…

class Resampler
{
public:
    // methods

    void Reset();

    int Process(
        float[] src,
        int srcCount,
        int srcRate,
        float[] dst,
        int dstCount,
        int dstRate,
        out int consumed
    );

    int SourceFramesNeeded(int dstCount, int srcRate, int dstRate);
};

Detailed Documentation

A stateful linear resampler. Unlike LinearResample this carries the fractional phase across calls, so consecutive blocks of a continuous stream join without a discontinuity.

The caller must feed the stream contiguously: the next call has to start at the source frame right after the last one Process reported as consumed.

Methods

void Reset()

Forgets all state. Call this whenever the stream is discontinuous.

int Process(
    float[] src,
    int srcCount,
    int srcRate,
    float[] dst,
    int dstCount,
    int dstRate,
    out int consumed
)

Resamples src into dst.

Parameters:

src

Source frames.

srcCount

How many frames of src are valid.

srcRate

Source sample rate (Hz).

dst

Destination frames.

dstCount

How many frames to write to dst at most.

dstRate

Destination sample rate (Hz).

consumed

How many source frames were consumed.

Returns:

The number of destination frames written.

int SourceFramesNeeded(int dstCount, int srcRate, int dstRate)

Source frames required to produce dstCount destination frames from the current phase. Includes the one sample lookahead the interpolation needs.

Parameters:

dstCount

How many destination frames are wanted.

srcRate

Source sample rate (Hz).

dstRate

Destination sample rate (Hz).

Returns:

The number of source frames needed.