/// <summary> /// Writes the prologue of the root chunk to the underlying stream, i.e. all /// bytes up to the first nested chunk. /// </summary> /// <param name="payloadSize"> /// The payload size of the root chunk, i.e. including the gross sizes of the /// nested chunks. /// </param> private void WriteRootChunkPrologue(int payloadSize) { var chunkHeader = new WaveformFileFormat.ChunkHeader(WaveformFileFormat.RootChunkId, payloadSize); WriteChunkHeader(chunkHeader); _stream.WriteString(WaveformFileFormat.RiffType); }
/// <summary> /// Writes the chunk containing the waveform data to the underlying stream. /// </summary> /// <param name="waveForm">The waveform.</param> private void WriteDataChunk(IWaveform waveForm) { var chunkSize = GetDataChunkPayloadSize(waveForm); var chunkHeader = new WaveformFileFormat.ChunkHeader(WaveformFileFormat.DataChunkId, chunkSize); WriteChunkHeader(chunkHeader); WriteFrames(waveForm); }
/// <summary> /// Writes the chunk describing the waveform format to the underlying stream. /// </summary> /// <param name="waveFormFormat">The waveform format.</param> private void WriteFormatChunk(WaveformFormat waveFormFormat) { var chunkSize = WaveformFileFormat.FormatChunkPayloadSize; var chunkHeader = new WaveformFileFormat.ChunkHeader(WaveformFileFormat.FormatChunkId, chunkSize); WriteChunkHeader(chunkHeader); _stream.WriteInt16(WaveformFileFormat.PcmFormatTag); _stream.WriteInt16(waveFormFormat.ChannelsCount); _stream.WriteInt32(waveFormFormat.SamplesPerSecond); _stream.WriteInt32(waveFormFormat.BytesPerSecond); _stream.WriteInt16(waveFormFormat.FrameSize); _stream.WriteInt16(waveFormFormat.BitsPerSample); }
/// <summary> /// Writes the header of any arbitray chunk to the underlying stream. /// </summary> /// <param name="chunkHeader">The chunk header.</param> private void WriteChunkHeader(WaveformFileFormat.ChunkHeader chunkHeader) { _stream.WriteString(chunkHeader.Id); _stream.WriteInt32(chunkHeader.PayloadSize); }