Resampler class

Reusable native resampler with cached context and buffers.

Unlike Resample.process, this class creates the native resampling context once and reuses it across multiple calls to process or processInto. This avoids repeated native setup and buffer allocation when resampling many blocks with the same configuration.

The native context is released by close. If close is not called, cleanup is still attempted by the finalizer inherited from NativeHandle, but callers should prefer explicit disposal.

Example:

final resampler = Resampler(origFreq: 16000, newFreq: 8000);

final x1 = SignalGenerator.sine(
  n: 1024,
  freqHz: 440.0,
  sampleRate: 16000.0,
);
final y1 = resampler.process(x1);

final x2 = SignalGenerator.sine(
  n: 2048,
  freqHz: 880.0,
  sampleRate: 16000.0,
);
final out = Float32List(resampler.outLenFor(x2.length));
final written = resampler.processInto(x2, out);
final y2 = out.sublist(0, written);

resampler.close();

Use reset if you want to reset native state between calls. Use outLenFor to compute the required output buffer size for a given input.

Inheritance

Constructors

Resampler({required int origFreq, required int newFreq, int lowpassFilterWidth = 6, double rolloff = 0.99, ResamplingMethod method = ResamplingMethod.sincHann, double? beta})
Creates and owns a reusable resampling context for repeated calls.
factory

Properties

beta double?
final
hashCode int
The hash code for this object.
no setterinherited
isClosed bool
Whether close() has been called.
no setterinherited
lowpassFilterWidth int
final
method ResamplingMethod
final
newFreq int
final
origFreq int
final
res → _ResamplerResource
Throws if closed; returns the native resource otherwise.
no setterinherited
rolloff double
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() → void
Deterministic cleanup.
inherited
freeBuffers() → void
Releases any cached input/output scratch buffers while keeping the context.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
outLenFor(int inputLength) int
Returns the output length for an input block of inputLength samples.
process(Float32List input) Float32List
Resamples input using the cached native context and reusable buffers.
processInto(Float32List input, Float32List out) int
Zero-allocation output API for repeated use.
reset() → void
Resets native resampling state for subsequent calls on the same instance.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited