private void WriteVbrHeader(bool isPlaceholder) { var buffer = new byte[GetFrameLength(_mpegVersion, 64000, _sampleRate, 0)]; if (!isPlaceholder) { uint header = _firstFrameHeader; int dataOffset = GetFrameDataOffset(_mpegVersion, _channelMode); header &= 0xFFFE0DFF; // Clear CRC, bitrate, and padding fields header |= (uint)(_mpegVersion == 3 ? 5 : 8) << 12; // 64 kbit/sec BitHelper.CopyBytes(buffer, 0, BigEndianBitConverter.GetBytes(header)); BitHelper.CopyBytes(buffer, dataOffset, BigEndianBitConverter.GetBytes(0x58696E67)); // "Xing" BitHelper.CopyBytes(buffer, dataOffset + 4, BigEndianBitConverter.GetBytes((uint)0x7)); // Flags BitHelper.CopyBytes(buffer, dataOffset + 8, BigEndianBitConverter.GetBytes((uint)_frameOffsets.Count)); // Frame count BitHelper.CopyBytes(buffer, dataOffset + 12, BigEndianBitConverter.GetBytes(_totalFrameLength)); // File length for (int i = 0; i < 100; i++) { int frameIndex = (int)((i / 100.0) * _frameOffsets.Count); buffer[dataOffset + 16 + i] = (byte)(_frameOffsets[frameIndex] / (double)_totalFrameLength * 256.0); } } _fileStream.Write(buffer, 0, buffer.Length); }