write method

void write(
  1. IWavSamplesStorage chunk
)

Append audio chunks to the end of the data chunk.

Implementation

void write(IWavSamplesStorage chunk) {
  if (_isClosed) {
    throw StateError("WavWriter is already closed");
  }
  if (chunk.channels != format.numChannels) {
    throw ArgumentError("Chunks channels must match the format channels");
  }

  int bytesPerSample = format.containerBitsPerSample ~/ 8;
  int dataCkSize = format.blockAlign * chunk.length;
  var data = ByteData(dataCkSize);

  chunk.writeStorage(data, numEndianess, bytesPerSample);

  file.writeFromSync(data.buffer.asUint8List());
  _numSamples += chunk.length;
}