encode method
Encode one frame of interleaved float PCM (frameSize * channels values; frameSize in {120, 240, 480, 960}).
Implementation
Uint8List encode(Float32List pcm) {
_checkNotDisposed();
final frame = pcm.length ~/ channels;
final inPtr = calloc<Float>(pcm.length);
inPtr.asTypedList(pcm.length).setAll(0, pcm);
final outPtr = calloc<Uint8>(1500);
final n = _encode(_handle, inPtr, frame, outPtr, 1500);
Uint8List out;
if (n <= 0) {
out = Uint8List(0);
} else {
out = Uint8List.fromList(outPtr.asTypedList(n));
}
calloc.free(inPtr);
calloc.free(outPtr);
if (n < 0) {
throw StateError('opus encode failed ($n)');
}
return out;
}