public void Can_Allocate_New_Buffer() { using (var fixture = new AudioSampleBuffer(2, 1024)) { Assert.NotNull(fixture); } }
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); }
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(); }
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)); } }
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)); } }
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); } }
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++)); } } }
public void TestArrayEquals() { var f1 = LinearArray(0, 100); var f2 = LinearArray(0, 100); var f3 = LinearArray(1, 100); Assert.IsTrue(AudioEngine.ArrayEquals(f1, f2)); Assert.IsTrue(!AudioEngine.ArrayEquals(f1, f3)); var asb1 = new AudioSampleBuffer(WaveOutput.InternalFormat); var asb2 = new AudioSampleBuffer(WaveOutput.InternalFormat); var f4 = new[] { asb1, asb2 }; var f5 = new[] { asb1, asb2 }; var f6 = new[] { asb2, asb1 }; var f7 = new[] { asb1, null }; var f8 = new[] { asb1, null }; Assert.IsTrue(AudioEngine.ArrayEquals(f5, f4)); Assert.IsTrue(!AudioEngine.ArrayEquals(f5, f6)); Assert.IsTrue(!AudioEngine.ArrayEquals(f5, f7)); Assert.IsTrue(AudioEngine.ArrayEquals(f8, f7)); }