decodeFloat method
解码 Opus 音频数据包为 PCM 样本(32 位浮点数)
input Opus 编码数据包
fec 前向纠错标志
返回解码后的浮点 PCM 样本(范围通常在 -1.0, 1.0 之间)
抛出 OpusException 如果解码失败
Implementation
Float32List decodeFloat(Uint8List input, {bool fec = false}) {
final decoder = _decoder;
if (decoder == null) {
throw StateError('Decoder has been disposed');
}
final maxSamples = (sampleRate * channels.value * 0.12).ceil();
final output = calloc<Float>(maxSamples);
final decodedSize = calloc<UintPtr>();
final error = calloc<OpusError>();
try {
final inputPtr = calloc<Uint8>(input.length);
inputPtr.asTypedList(input.length).setAll(0, input);
final res = bindings.decode_float(
decoder,
inputPtr,
input.length,
output,
maxSamples,
fec,
decodedSize,
error,
);
calloc.free(inputPtr);
if (res != 0) {
final errorMsg = extractErrorMessage(error);
throw OpusException(error.ref.code, errorMsg);
}
final size = decodedSize.value;
final result = Float32List(size);
final outputList = output.asTypedList(size);
result.setAll(0, outputList);
return result;
} finally {
freeError(error);
calloc.free(output);
calloc.free(decodedSize);
}
}