public void PerformanceTest() { var input1 = new TestSampleProvider(32000, 1); var input2 = new TestSampleProvider(32000, 1); var input3 = new TestSampleProvider(32000, 1); var input4 = new TestSampleProvider(32000, 1); var mp = new MultiplexingSampleProvider(new ISampleProvider[] { input1, input2, input3, input4 }, 4); mp.ConnectInputToOutput(0, 3); mp.ConnectInputToOutput(1, 2); mp.ConnectInputToOutput(2, 1); mp.ConnectInputToOutput(3, 0); float[] buffer = new float[input1.WaveFormat.AverageBytesPerSecond / 4]; Stopwatch s = new Stopwatch(); var duration = s.Time(() => { // read one hour worth of audio for (int n = 0; n < 60 * 60; n++) { mp.Read(buffer, 0, buffer.Length); } }); Console.WriteLine("Performance test took {0}ms", duration); }
private void EnsureReadsExpected(MultiplexingSampleProvider mp, float[] expected) { float[] buffer = new float[expected.Length]; var read = mp.Read(buffer, 0, expected.Length); Assert.AreEqual(expected.Length, read); Assert.AreEqual(expected, buffer); }
public void ReadReturnsZeroIfSingleInputHasReachedEnd() { var input1 = new TestSampleProvider(32000, 1, 0); float[] expected = new float[] { }; var mp = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 1); float[] buffer = new float[10]; var read = mp.Read(buffer, 0, buffer.Length); Assert.AreEqual(0, read); }
public void ShouldZeroOutBufferIfInputStopsShort() { var input1 = new TestSampleProvider(32000, 1, 6); float[] expected = new float[] { 0, 1, 2, 3, 4, 5, 0, 0, 0, 0 }; var mp = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 1); float[] buffer = new float[10]; for (int n = 0; n < buffer.Length; n++) { buffer[n] = 99; } var read = mp.Read(buffer, 0, buffer.Length); Assert.AreEqual(6, read); Assert.AreEqual(expected, buffer); }
public int Read(float[] buffer, int offset, int count) { return(multiplexer.Read(buffer, offset, count)); }