renderMonoInt16 method

void renderMonoInt16(
  1. ArrayInt16 destination, {
  2. int offset = 0,
  3. int? length,
})
Renders the waveform as a monaural signal with 16-bit quantization. The audio renderer. The destination buffer.

Implementation

void renderMonoInt16(ArrayInt16 destination, {int offset = 0, int? length})
{
    if (destination.bytes.lengthInBytes % 2 != 0)
    {
        throw "Invalid destination length";
    }

    int sampleCount = 0;

    if (length != null) {
      sampleCount = length;
    } else {
      sampleCount = destination.bytes.lengthInBytes ~/ 2;
      sampleCount -= offset;
    }

    List<double> left = List<double>.filled(sampleCount, 0);
    List<double> right = List<double>.filled(sampleCount, 0);

    render(left, right);

    for (var t = 0; t < sampleCount; t++)
    {
        int sample = (16384 * (left[t] + right[t])).toInt();
        destination[offset + t] = sample;
    }
}