/// <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="waveFormat">Wave format structure to be written to the file</param>
        public static void Save(BinaryWriter writer, ref WaveFormatExtensible waveFormat)
        {
            WaveFormatEx.Save(writer, WaveFormatExtensible.Size, ref waveFormat.FormatEx);

            writer.Write((UInt16)waveFormat.ValidBitsPerSample);
            writer.Write((UInt32)waveFormat.ChannelMask);

            byte[] subFormatGuidBytes = waveFormat.SubFormat.ToByteArray();
            writer.Write(subFormatGuidBytes, 0, 16);
        }
示例#2
0
        public void TestLoadVersusSave()
        {
            WaveFormatEx original;

            original.WaveFormat.FormatTag             = 0x1A2B;
            original.WaveFormat.ChannelCount          = 42;
            original.WaveFormat.SamplesPerSecond      = 123456789;
            original.WaveFormat.AverageBytesPerSecond = 987654321;
            original.WaveFormat.BlockAlignment        = 1928;
            original.BitsPerSample        = 9182;
            original.ExtraInformationSize = 22222;

            using (MemoryStream memoryStream = new MemoryStream()) {
                {
                    BinaryWriter writer = new BinaryWriter(memoryStream);
                    WaveFormatEx.Save(writer, ref original);
                }

                memoryStream.Position = 0;

                {
                    WaveFormatEx restored;

                    BinaryReader reader             = new BinaryReader(memoryStream);
                    int          restoredFileLength = WaveFormatEx.Load(reader, out restored);

                    Assert.AreEqual(WaveFormatEx.Size, restoredFileLength);
                    Assert.AreEqual(
                        original.WaveFormat.FormatTag, restored.WaveFormat.FormatTag
                        );
                    Assert.AreEqual(
                        original.WaveFormat.ChannelCount, restored.WaveFormat.ChannelCount
                        );
                    Assert.AreEqual(
                        original.WaveFormat.SamplesPerSecond, restored.WaveFormat.SamplesPerSecond
                        );
                    Assert.AreEqual(
                        original.WaveFormat.AverageBytesPerSecond, restored.WaveFormat.AverageBytesPerSecond
                        );
                    Assert.AreEqual(
                        original.WaveFormat.BlockAlignment, restored.WaveFormat.BlockAlignment
                        );
                    Assert.AreEqual(original.BitsPerSample, restored.BitsPerSample);
                    Assert.AreEqual(original.ExtraInformationSize, restored.ExtraInformationSize);
                }
            }
        }
示例#3
0
 /// <summary>Write a format chunk using the WaveFormatEx structure</summary>
 /// <param name="waveFormatEx">
 ///   Extended WaveFormat structure to write into the chunk
 /// </param>
 public void WriteChunk(ref WaveFormatEx waveFormatEx)
 {
     WaveFormatEx.Save(this.writer, ref waveFormatEx);
 }