Example #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);
        }
Example #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();
        }
Example #3
0
        public void Initial_Buffer_Is_Zeroed_Out()
        {
            var numSamples = 1024;

            using (var fixture = new AudioSampleBuffer(2, numSamples))
            {
                var readPtr = fixture.GetReadPointer(0);
                while (numSamples-- > 0)
                {
                    Assert.AreEqual(0, *(readPtr++));
                }
                numSamples = 1024;
                readPtr    = fixture.GetReadPointer(1);
                while (numSamples-- > 0)
                {
                    Assert.AreEqual(0, *(readPtr++));
                }
            }
        }
Example #4
0
        public void Set_Sample_Stores_Value()
        {
            using (var fixture = new AudioSampleBuffer(2, 1024))
            {
                var readPtr = fixture.GetReadPointer(1);

                fixture.SetSample(1, 20, 127);

                Assert.AreEqual(127.0f, *(readPtr + 20));
            }
        }
Example #5
0
        public void Add_Sample_Updates_Prior_Value()
        {
            using (var fixture = new AudioSampleBuffer(2, 1024))
            {
                var readPtr = fixture.GetReadPointer(1);

                fixture.SetSample(1, 20, 127.0f);
                fixture.AddSample(1, 20, 23.0f);

                Assert.AreEqual(127.0f + 23.0f, *(readPtr + 20));
            }
        }
Example #6
0
        public void Can_Clear_Single_Channel()
        {
            var numSamples = 1024;

            using (var fixture = new AudioSampleBuffer(3, numSamples))
            {
                var readPtr  = fixture.GetReadPointer(1);
                var writePtr = fixture.GetWritePointer(0);
                for (var i = 0; i < 3 * 1024; ++i)
                {
                    *writePtr++ = 127.0f;
                }
                Assert.AreEqual(127.0f, *readPtr);
                fixture.ClearChannel(1);
                Assert.AreEqual(0f, *readPtr);
            }
        }