renderInterleaved method

void renderInterleaved(
  1. List<double> destination, {
  2. int offset = 0,
  3. int? length,
})
Renders the waveform as a stereo interleaved signal. The audio renderer. The destination buffer.

Implementation

void renderInterleaved(List<double> destination, {int offset = 0, int? length}) {
  if (destination.length % 2 != 0) {
    throw "The length of the destination buffer must be even.";
  }

  int sampleCount = 0;

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

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

  render(left, right);

  for (var t = 0; t < sampleCount; t++) {
    destination[offset + t * 2 + 0] = left[t];
    destination[offset + t * 2 + 1] = right[t];
  }
}