Table of Contents

Class InterpolatingSampleReader

Namespace
NAudio.Dsp
Assembly
NAudio.Core.dll

Reads a SampleSource at an arbitrary, per-sample-varying playback rate with interpolation, honouring the source's loop mode. This is the core pitch-shifting primitive of the sampler/synth: each voice owns one reader and supplies a playback increment (in source samples per output sample) that may change every sample under vibrato, pitch-bend or a pitch envelope. Unlike WdlResampler (a fixed-ratio block resampler), the increment is free to move continuously. Allocation-free in steady state.

public sealed class InterpolatingSampleReader
Inheritance
InterpolatingSampleReader
Inherited Members

Constructors

InterpolatingSampleReader(SampleSource)

Creates a reader positioned at the start of the source.

public InterpolatingSampleReader(SampleSource source)

Parameters

source SampleSource

Properties

Ended

True once the reader has run past the end of the playable data.

public bool Ended { get; }

Property Value

bool

Position

The current fractional read position, in source sample indices.

public double Position { get; }

Property Value

double

Quality

Interpolation quality. Defaults to Hermite, the recommended general-purpose setting.

public InterpolationQuality Quality { get; set; }

Property Value

InterpolationQuality

Methods

Read(double)

Reads one output sample at the given playback increment and advances the read position. Returns 0 once the reader has ended.

public float Read(double increment)

Parameters

increment double

Source samples to advance per output sample (1.0 = native pitch).

Returns

float

Read(Span<float>, double)

Renders a block of output samples at a constant increment, returning the number of samples written before the reader ended (the remainder of the buffer is left untouched). While the read position stays inside the contiguous "safe window" — away from the loop seam, the crossfade zone and the ends — the samples are produced by tight per-quality loops; output is bit-identical to repeated Read(double) calls at the same increment.

public int Read(Span<float> buffer, double increment)

Parameters

buffer Span<float>

Destination buffer.

increment double

Source samples to advance per output sample.

Returns

int

Release()

Signals note-off. For UntilRelease the reader stops looping and plays through to the end; for other modes it has no effect on looping.

public void Release()

Reset(SampleSource)

Re-seats the reader on a (possibly different) source and rewinds it to the source's start, clearing the ended/looped/release state — leaving the reader exactly as a newly constructed one, but without allocating. Quality is preserved. Intended for pooled consumers (e.g. sampler voices) that reuse one reader across many notes.

public void Reset(SampleSource source)

Parameters

source SampleSource

The sample source to read from.