void WriteFmtChunk([NotNull] AudioInfo audioInfo)
 {
     // ReSharper disable once PossibleNullReferenceException
     _writer.BeginChunk("fmt ", 16);
     _writer.Write((ushort)1);
     _writer.Write((ushort)audioInfo.Channels);
     _writer.Write((uint)audioInfo.SampleRate);
     _writer.Write((uint)(_bytesPerSample * audioInfo.Channels * audioInfo.SampleRate));
     _writer.Write((ushort)(_bytesPerSample * audioInfo.Channels));
     _writer.Write((ushort)audioInfo.BitsPerSample);
     _writer.FinishChunk();
 }
        public void Initialize(Stream stream, AudioInfo info, AudioMetadata metadata, SettingDictionary settings)
        {
            _bitsPerSample  = info.BitsPerSample;
            _bytesPerSample = (int)Math.Ceiling(info.BitsPerSample / 8.0);
            _writer         = new RiffWriter(stream);

            // Pre-allocate the entire stream to avoid fragmentation
            var estimatedSize = 44 + info.FrameCount * info.Channels * _bytesPerSample;

            estimatedSize += estimatedSize % 2;
            stream.SetLength(estimatedSize);

            _writer.Initialize("WAVE");
            WriteFmtChunk(info);
            // ReSharper disable once PossibleNullReferenceException
            _writer.BeginChunk("data");
        }