pcmSoftClip function
Soft clips the input
to a range from -1 to 1 and returns
the result.
If the samples are already in this range, nothing happens to the samples.
input
is copied into native memory.
If you are using a BufferedOpusDecoder, take a look at it's pcmSoftClipOutputBuffer
method instead, since it avoids unnecessary memory copying.
Implementation
Float32List pcmSoftClip({required Float32List input, required int channels}) {
Pointer<Float> nativePcm = opus.allocator.call<Float>(input.length);
nativePcm.asTypedList(input.length).setAll(0, input);
Pointer<Float> nativeBuffer = opus.allocator.call<Float>(channels);
try {
opus.decoder.opus_pcm_soft_clip(
nativePcm, input.length ~/ channels, channels, nativeBuffer);
return Float32List.fromList(nativePcm.asTypedList(input.length));
} finally {
opus.allocator.free(nativePcm);
opus.allocator.free(nativeBuffer);
}
}