encodeFloat method

Uint8List encodeFloat({
  1. required Float32List input,
  2. int maxOutputSizeBytes = maxDataBytes,
})

Encodes a frame of pcm data, stored as Float32List.

This method behaves just as encode, so see there for more information.

Implementation

Uint8List encodeFloat(
    {required Float32List input, int maxOutputSizeBytes = maxDataBytes}) {
  Pointer<Float> inputNative = opus.allocator.call<Float>(input.length);
  inputNative.asTypedList(input.length).setAll(0, input);
  Pointer<Uint8> outputNative =
      opus.allocator.call<Uint8>(maxOutputSizeBytes);
  int sampleCountPerChannel = input.length ~/ channels;
  int outputLength = opus.encoder.opus_encode_float(_opusEncoder, inputNative,
      sampleCountPerChannel, outputNative, maxOutputSizeBytes);
  try {
    if (outputLength >= opus_defines.OPUS_OK) {
      Uint8List output =
          Uint8List.fromList(outputNative.asTypedList(outputLength));
      return output;
    } else {
      throw OpusException(outputLength);
    }
  } finally {
    opus.allocator.free(inputNative);
    opus.allocator.free(outputNative);
  }
}