예제 #1
0
        public void WaveFormat_ReadWrite()
        {
            // Create WaveFormat object
            WaveFormat format = WaveFormat.Create(WaveFormatTag.WAVE_FORMAT_IEEE_FLOAT, 48000, 32, 2, 8, 384000);

            // Write WaveFormat object out to a memory stream
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            format.WriteTo(writer);

            // Verify written bytes for equality
            byte[] streamBytes = stream.ToArray();
            this.MarshalAndVerify(format, streamBytes);

            // Read WaveFormat back from the stream and verify
            stream.Seek(0, SeekOrigin.Begin);
            WaveFormat copy = WaveFormat.FromStream(stream, Marshal.SizeOf(format));

            Assert.AreEqual(format, copy);
        }
예제 #2
0
        public void WaveFormatEx_ReadWrite()
        {
            // Create WaveFormat object
            byte[]     extraInfo = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
            WaveFormat format    = WaveFormatEx.Create(WaveFormatTag.WAVE_FORMAT_EXTENSIBLE, 48000, 32, 2, 8, 384000, extraInfo);

            // Write WaveFormat object out to a memory stream
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            format.WriteTo(writer);

            // Verify written bytes for equality
            byte[] streamBytes = stream.ToArray();
            this.MarshalAndVerify(format, streamBytes);

            // Read WaveFormat back from the stream and verify
            stream.Seek(0, SeekOrigin.Begin);
            WaveFormat copy = WaveFormat.FromStream(stream, Marshal.SizeOf <WaveFormat>() + extraInfo.Length);

            Assert.AreEqual(format, copy);
        }
예제 #3
0
 public override void Read(BinaryReader reader)
 {
     WaveFormat = WaveFormat.FromStream(reader);
 }
예제 #4
0
 public static Sound LoadWaveFromStream(Stream stream)
 {
     return(Sound.FromWave(WaveFormat.FromStream(stream)));
 }