Resampler constructor

Resampler({
  1. required int origFreq,
  2. required int newFreq,
  3. int lowpassFilterWidth = 6,
  4. double rolloff = 0.99,
  5. ResamplingMethod method = ResamplingMethod.sincHann,
  6. double? beta,
})

Creates and owns a reusable resampling context for repeated calls.

The context is initialized once and kept alive until close is called.

Implementation

factory Resampler({
  required int origFreq,
  required int newFreq,
  int lowpassFilterWidth = 6,
  double rolloff = 0.99,
  ResamplingMethod method = ResamplingMethod.sincHann,
  double? beta,
}) {
  final ctx = yl_resample_ctx_create(
    origFreq,
    newFreq,
    lowpassFilterWidth,
    rolloff,
    method.value,
    beta ?? 0,
  );
  if (ctx == ffi.nullptr) {
    throw StateError('Failed to create resampling context');
  }

  return Resampler._(
    _ResamplerResource(ctx),
    origFreq: origFreq,
    newFreq: newFreq,
    lowpassFilterWidth: lowpassFilterWidth,
    rolloff: rolloff,
    method: method,
    beta: beta,
  );
}