glintResample function
Resample interleaved float PCM (±1.0) from srIn to srOut with a
Kaiser-windowed sinc kernel (anti-aliased, unity passband). pcm is
frames * channels interleaved samples. Pass-through (a copy) when the
rates match.
Implementation
Float32List glintResample(Float32List pcm, int channels, int srIn, int srOut) {
if (channels <= 0 || pcm.isEmpty) return Float32List(0);
final lib = _loadLibrary();
final fn = lib.lookupFunction<_ResampleNative, _Resample>('glint_resample');
final free = lib.lookupFunction<_FreeNative, _Free>('glint_free');
final inPtr = calloc<Float>(pcm.length);
inPtr.asTypedList(pcm.length).setAll(0, pcm);
final outFrames = calloc<Int32>();
try {
final inFrames = pcm.length ~/ channels;
final ptr = fn(inPtr, inFrames, channels, srIn, srOut, outFrames);
if (ptr == nullptr) return Float32List(0);
final total = outFrames.value * channels;
final out = Float32List.fromList(ptr.asTypedList(total));
free(ptr.cast<Void>());
return out;
} finally {
calloc.free(inPtr);
calloc.free(outFrames);
}
}