Esempio n. 1
0
        public void AudioBuffer_Persist()
        {
            byte[]      rawBytes = new byte[] { 1, 2, 3, 4, 5, 6 };
            var         wf       = WaveFormatEx.Create(WaveFormatTag.WAVE_FORMAT_APTX, 16000, 16, 2, 0, 16000);
            AudioBuffer buffer   = new AudioBuffer(rawBytes, wf);
            AudioBuffer bresult  = default(AudioBuffer);

            var p1    = Pipeline.Create();
            var store = Store.Create(p1, "audio", null);

            Generators.Return(p1, buffer).Write("audio", store);
            p1.RunAsync();

            var p2     = Pipeline.Create();
            var store2 = Store.Open(p2, "audio", null);

            store2.OpenStream <AudioBuffer>("audio").Do(b => bresult = b);
            p2.RunAsync();
            System.Threading.Thread.Sleep(100);
            p1.Dispose();
            p2.Dispose();

            Assert.AreEqual(6, bresult.Length);
            Assert.AreEqual(6, bresult.Data.Length);
            Assert.AreEqual(wf, bresult.Format);
            CollectionAssert.AreEqual(rawBytes, bresult.Data);
        }
Esempio n. 2
0
        public void WaveFormatEx_MarshalIncorrectNullExtraInfo()
        {
            // Create WaveFormat object
            WaveFormat format = WaveFormatEx.Create(WaveFormatTag.WAVE_FORMAT_EXTENSIBLE, 48000, 32, 2, 8, 384000, null);

            // 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);
        }
Esempio n. 3
0
        public void WaveFormatEx_MarshalIncorrectExtraSize()
        {
            // 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);

            // Fiddle with the length to make it incorrect
            format.ExtraSize = (ushort)(extraInfo.Length + 1);

            // 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);
        }
Esempio n. 4
0
        public void AudioBuffer_Serialize()
        {
            byte[]      rawBytes = new byte[] { 1, 2, 3, 4, 5, 6 };
            var         wf       = WaveFormatEx.Create(WaveFormatTag.WAVE_FORMAT_APTX, 16000, 16, 2, 0, 16000);
            AudioBuffer buffer   = new AudioBuffer(rawBytes, wf);

            var writer = new BufferWriter(100);

            Serializer.Serialize(writer, buffer, new SerializationContext());
            AudioBuffer bresult = default(AudioBuffer);

            Serializer.Deserialize(new BufferReader(writer.Buffer), ref bresult, new SerializationContext());

            Assert.AreEqual(6, bresult.Length);
            Assert.AreEqual(6, bresult.Data.Length);
            Assert.AreEqual(wf, bresult.Format);
            CollectionAssert.AreEqual(rawBytes, bresult.Data);
        }
Esempio n. 5
0
        public void WaveFormatEx_NullExtraInfo()
        {
            // Define "native" WAVEFORMATEX structure
            byte[] formatBytes = new byte[]
            {
                0xfe, 0xff,             // FormatTag = WAVE_FORMAT_EXTENSIBLE (0xfeff)
                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 = WaveFormatEx.Create(WaveFormatTag.WAVE_FORMAT_EXTENSIBLE, 48000, 32, 2, 8, 384000, null);

            // Verify against expected
            this.MarshalAndVerify(format, formatBytes);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        public void WaveFormatEx_Create()
        {
            // Define "native" WAVEFORMATEX structure
            byte[] formatBytes = new byte[]
            {
                0xfe, 0xff,                                                                   // FormatTag = WAVE_FORMAT_EXTENSIBLE (0xfeff)
                0x02, 0x00,                                                                   // Channels = 2
                0x80, 0xbb, 0x00, 0x00,                                                       // SamplesPerSec = 48000
                0x00, 0xdc, 0x05, 0x00,                                                       // AvgBytesPerSec = 384000
                0x08, 0x00,                                                                   // BlockAlign = 8
                0x20, 0x00,                                                                   // BitsPerSample = 32
                0x16, 0x00,                                                                   // ExtraSize = 22
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, // ExtraInfo
            };

            // Create equivalent managed 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);

            // Verify against expected
            this.MarshalAndVerify(format, formatBytes);
        }
Esempio n. 9
0
        public void WaveFormatEx_Equality()
        {
            // 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 an identical WaveFormat object and check for equality
            byte[]     extraInfoCopy = 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 copy          = WaveFormatEx.Create(WaveFormatTag.WAVE_FORMAT_EXTENSIBLE, 48000, 32, 2, 8, 384000, extraInfoCopy);

            Assert.AreEqual(format, copy);

            // Make multiple copies each with a field modified and verify inequality
            copy = WaveFormatEx.Create(WaveFormatTag.WAVE_FORMAT_EXTENSIBLE, 48000, 32, 2, 8, 384000);
            Assert.AreNotEqual(format, copy);
            copy = WaveFormatEx.Create(WaveFormatTag.WAVE_FORMAT_EXTENSIBLE, 16000, 32, 2, 8, 384000, extraInfoCopy);
            Assert.AreNotEqual(format, copy);
            copy = WaveFormatEx.Create(WaveFormatTag.WAVE_FORMAT_EXTENSIBLE, 48000, 16, 2, 8, 384000, extraInfoCopy);
            Assert.AreNotEqual(format, copy);
            copy = WaveFormatEx.Create(WaveFormatTag.WAVE_FORMAT_EXTENSIBLE, 48000, 32, 1, 8, 384000, extraInfoCopy);
            Assert.AreNotEqual(format, copy);
            copy = WaveFormatEx.Create(WaveFormatTag.WAVE_FORMAT_EXTENSIBLE, 48000, 32, 2, 4, 384000, extraInfoCopy);
            Assert.AreNotEqual(format, copy);
            copy = WaveFormatEx.Create(WaveFormatTag.WAVE_FORMAT_EXTENSIBLE, 48000, 32, 2, 8, 32000, extraInfoCopy);
            Assert.AreNotEqual(format, copy);
            extraInfoCopy = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
            copy          = WaveFormatEx.Create(WaveFormatTag.WAVE_FORMAT_EXTENSIBLE, 48000, 32, 2, 8, 384000, extraInfoCopy);
            Assert.AreNotEqual(format, copy);
            extraInfoCopy = new byte[] { 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
            copy          = WaveFormatEx.Create(WaveFormatTag.WAVE_FORMAT_EXTENSIBLE, 48000, 32, 2, 8, 384000, extraInfoCopy);
            Assert.AreNotEqual(format, copy);

            // Test null and reference equality
            copy = format;
            Assert.AreEqual(format, copy);
            copy = null;
            Assert.AreNotEqual(format, copy);
        }