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

            // Create an identical WaveFormat object and check for equality
            WaveFormat copy = WaveFormat.Create(WaveFormatTag.WAVE_FORMAT_IEEE_FLOAT, 48000, 32, 2, 8, 384000);

            Assert.AreEqual(format, copy);

            // Make multiple copies each with a field modified and verify inequality
            copy = WaveFormat.Create(WaveFormatTag.WAVE_FORMAT_PCM, 48000, 32, 2, 8, 384000);
            Assert.AreNotEqual(format, copy);
            copy = WaveFormat.Create(WaveFormatTag.WAVE_FORMAT_IEEE_FLOAT, 16000, 32, 2, 8, 384000);
            Assert.AreNotEqual(format, copy);
            copy = WaveFormat.Create(WaveFormatTag.WAVE_FORMAT_IEEE_FLOAT, 48000, 16, 2, 8, 384000);
            Assert.AreNotEqual(format, copy);
            copy = WaveFormat.Create(WaveFormatTag.WAVE_FORMAT_IEEE_FLOAT, 48000, 32, 1, 8, 384000);
            Assert.AreNotEqual(format, copy);
            copy = WaveFormat.Create(WaveFormatTag.WAVE_FORMAT_IEEE_FLOAT, 48000, 32, 2, 4, 384000);
            Assert.AreNotEqual(format, copy);
            copy = WaveFormat.Create(WaveFormatTag.WAVE_FORMAT_IEEE_FLOAT, 48000, 32, 2, 8, 32000);
            Assert.AreNotEqual(format, copy);

            // Test null and reference equality
            copy = format;
            Assert.AreEqual(format, copy);
            copy = null;
            Assert.AreNotEqual(format, copy);
        }
예제 #2
0
        public void WaveFormat_CreateCopy()
        {
            // Create WaveFormat object
            WaveFormat format = WaveFormat.Create(WaveFormatTag.WAVE_FORMAT_IEEE_FLOAT, 48000, 32, 2, 8, 384000);

            // Create a copy and check for equality
            WaveFormat copy = WaveFormat.Create(format);

            Assert.AreEqual(format, copy);
        }
예제 #3
0
        public void WaveFormat_MarshalIncorrectNonZeroExtraSize()
        {
            // Create WaveFormat object
            WaveFormat format = WaveFormat.Create(WaveFormatTag.WAVE_FORMAT_EXTENSIBLE, 48000, 32, 2, 8, 384000);

            // Fiddle with the length to make it non-zero
            format.ExtraSize = 16;

            // Write WaveFormat object out to a memory stream (should throw expected exception)
            IntPtr formatPtr = Marshal.AllocHGlobal(WaveFormat.MarshalSizeOf(format));

            WaveFormat.MarshalToPtr(format, formatPtr);
            Marshal.FreeHGlobal(formatPtr);
        }
예제 #4
0
        public void WaveFormatEx_CreateCopy()
        {
            // Create WaveFormatEx 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);

            // Create a copy and check for equality
            WaveFormat copy = WaveFormat.Create(format);

            Assert.IsTrue(copy is WaveFormatEx);
            Assert.AreEqual(format, copy);

            // Create WaveFormatEx object (with no extra bytes)
            format = WaveFormatEx.Create(WaveFormatTag.WAVE_FORMAT_EXTENSIBLE, 48000, 32, 2, 8, 384000);

            // Create a copy and check for equality
            copy = WaveFormat.Create(format);
            Assert.IsTrue(copy is WaveFormatEx);
            Assert.AreEqual(format, copy);
        }
예제 #5
0
        public void WaveFormat_Create()
        {
            // Define "native" WAVEFORMATEX structure
            byte[] formatBytes = new byte[]
            {
                0x03, 0x00,             // FormatTag = 3
                0x02, 0x00,             // Channels = 2
                0x80, 0xbb, 0x00, 0x00, // SamplesPerSec = 48000
                0x00, 0xdc, 0x05, 0x00, // AvgBytesPerSec = 384000
                0x08, 0x00,             // BlockAlign = 8
                0x20, 0x00,             // BitsPerSample = 32
                0x00, 0x00,             // ExtraSize = 0
            };

            // Create equivalent managed WaveFormat object
            WaveFormat format = WaveFormat.Create(WaveFormatTag.WAVE_FORMAT_IEEE_FLOAT, 48000, 32, 2, 8, 384000);

            // Verify against expected
            this.MarshalAndVerify(format, formatBytes);
        }
예제 #6
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);
        }