private void ParseSubchunks(Stream input, RiffChunk chunk, long size) { var num = input.Position + size; while (num - input.Position > 8L) { RiffChunk chunk1; ParseChunk(input, out chunk1); chunk.AddSubchunk(chunk1); } input.Position = num; }
private static void WriteChunk(RiffChunk chunk, Stream stream) { var binaryWriter = new BinaryWriter(stream); binaryWriter.Write(Encoding.ASCII.GetBytes(chunk.Id)); binaryWriter.Write((uint)chunk.Size); binaryWriter.Write(chunk.Data); foreach (var chunk1 in chunk.Subchunks) { WriteChunk(chunk1, stream); } if (chunk.Size % 2L == 0L) { return; } binaryWriter.Write((byte)0); }
private void ParseFormatChunk(RiffChunk chunk) { var binaryReader = new BinaryReader(new MemoryStream(chunk.Data)); FormatTag = binaryReader.ReadUInt16(); Channels = binaryReader.ReadUInt16(); SamplesPerSec = binaryReader.ReadUInt32(); AvgBytesPerSec = binaryReader.ReadUInt32(); BlockAlign = binaryReader.ReadUInt16(); if (binaryReader.BaseStream.Length - binaryReader.BaseStream.Position > 0L) { BitsPerSample = binaryReader.ReadUInt16(); } if (binaryReader.BaseStream.Length - binaryReader.BaseStream.Position > 0L) { int count = binaryReader.ReadUInt16(); FormatExtension = binaryReader.ReadBytes(count); } binaryReader.Close(); }
private void UpdateFormatChunk(RiffChunk chunk) { using (var memoryStream = new MemoryStream(22)) { var binaryWriter = new BinaryWriter(memoryStream); binaryWriter.Write(FormatTag); binaryWriter.Write(Channels); binaryWriter.Write(SamplesPerSec); binaryWriter.Write(AvgBytesPerSec); binaryWriter.Write(BlockAlign); binaryWriter.Write(BitsPerSample); if (FormatExtension != null) { binaryWriter.Write((ushort)FormatExtension.Length); binaryWriter.Write(FormatExtension); } else { binaryWriter.Write((ushort)0); } chunk.Data = memoryStream.ToArray(); } }
public void RemoveSubchunk(RiffChunk subchunk) { _subchunks.Remove(subchunk); }
public void InsertSubchunk(RiffChunk subchunk, int index) { _subchunks.Insert(index, subchunk); }
public void AddSubchunk(RiffChunk subchunk) { _subchunks.Add(subchunk); }
private void UpdateDataChunk(RiffChunk chunk) { chunk.Data = AudioData; }
private void ParseDataChunk(RiffChunk chunk) { AudioData = chunk.Data; }