appendSilence method

void appendSilence(
  1. int msLength,
  2. WaveBuilderSilenceType silenceType
)

Append msLength milliseconds of silence to our wave file. silenceType determines whether we start the counter for silence from the beginning of the last sample or the end.

Implementation

void appendSilence(int msLength, WaveBuilderSilenceType silenceType) {
  var byteRate = _frequency * _bitRate ~/ 8;
  var length = (msLength * byteRate ~/ 1000) * _numChannels;
  if (silenceType == WaveBuilderSilenceType.BeginningOfLastSample) {
    if (length > _lastSampleSize) {
      length -= _lastSampleSize;
    } else {
      _outputBytes.removeRange(_outputBytes.length - _lastSampleSize + length,
          _outputBytes.length);
      length = 0;
    }
  }

  _outputBytes.addAll(List<int>.filled(length, 0));
}