public void TestLoadVersusSave() { WaveFormat original; original.FormatTag = 0x1A2B; original.ChannelCount = 42; original.SamplesPerSecond = 123456789; original.AverageBytesPerSecond = 987654321; original.BlockAlignment = 1928; using (MemoryStream memoryStream = new MemoryStream()) { { BinaryWriter writer = new BinaryWriter(memoryStream); WaveFormat.Save(writer, ref original); } memoryStream.Position = 0; { WaveFormat restored; BinaryReader reader = new BinaryReader(memoryStream); int restoredFileLength = WaveFormat.Load(reader, out restored); Assert.AreEqual(WaveFormat.Size, restoredFileLength); Assert.AreEqual(original.FormatTag, restored.FormatTag); Assert.AreEqual(original.ChannelCount, restored.ChannelCount); Assert.AreEqual(original.SamplesPerSecond, restored.SamplesPerSecond); Assert.AreEqual(original.AverageBytesPerSecond, restored.AverageBytesPerSecond); Assert.AreEqual(original.BlockAlignment, restored.BlockAlignment); } } }
/// <summary>Saves the WaveFormat information structure into a binary stream</summary> /// <param name="writer">Writer through which to write the WaveFormat structure</param> /// <param name="chunkSize">Total size of the format info chunk</param> /// <param name="waveFormatEx">Wave format structure to be written to the file</param> /// <remarks> /// Note that this writes chunkSize + 8 bytes. The additional 8 bytes result from /// the chunk's header that provides the chunk signature and size you indicate. /// </remarks> public static void Save( BinaryWriter writer, int chunkSize, ref WaveFormatEx waveFormatEx ) { WaveFormat.Save(writer, chunkSize, ref waveFormatEx.WaveFormat); writer.Write((UInt16)waveFormatEx.BitsPerSample); writer.Write((UInt16)waveFormatEx.ExtraInformationSize); }
/// <summary>Write a format chunk using the old WaveFormat structure</summary> /// <param name="waveFormat">WaveFormat structure to write into the chunk</param> public void WriteChunk(ref WaveFormat waveFormat) { WaveFormat.Save(this.writer, ref waveFormat); }