示例#1
0
        public void Compare_Access_Patterns()
        {
            int runs      = 1000;
            var stopWatch = new Stopwatch();

            var numSamples = 1024;

            var fixture = new AudioSampleBuffer(1, numSamples);

            stopWatch.Start();
            for (int i = 0; i != runs; ++i)
            {
                for (int j = 0; j < numSamples; j++)
                {
                    if (_testBuffer[0][j] != 0)
                    {
                        Assert.Fail();
                    }
                }
            }

            stopWatch.Stop();
            var arrayTime = stopWatch.ElapsedTicks;

            stopWatch.Restart();
            for (int i = 0; i != runs; ++i)
            {
                var readPtr = fixture.GetReadPointer(0);
                for (int j = 0; j < numSamples; j++)
                {
                    if (*(readPtr++) != 0)
                    {
                        Assert.Fail();
                    }
                }
            }

            stopWatch.Stop();
            var pointerTime = stopWatch.ElapsedTicks;

            stopWatch.Restart();
            for (int i = 0; i != runs; ++i)
            {
                for (int j = 0; j < numSamples; j++)
                {
                    if (fixture.GetSample(0, j) != 0)
                    {
                        Assert.Fail();
                    }
                }
            }

            stopWatch.Stop();
            var accessorTime = stopWatch.ElapsedTicks;

            fixture.Dispose();

            Console.WriteLine("Pointer: {0} vs Accessor: {1} vs Array: {2}", pointerTime, accessorTime, arrayTime);
        }
示例#2
0
        public void Can_Write_And_Read_Back()
        {
            var fixture  = new AudioSampleBuffer(2, 1024);
            var writePtr = fixture.GetWritePointer(0);

            (*writePtr) = 126.0f;

            Assert.AreEqual(126.0f, *fixture.GetReadPointer(0));
            fixture.Dispose();
        }