public void OneInTwoOutShouldConvertMonoToStereo()
 {
     var input1 = new TestSampleProvider(32000, 1);
     float[] expected = new float[] { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9 };
     var mp = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 2);
     EnsureReadsExpected(mp, expected);
 }
        public void StereoInTwoOutShouldCopyStereo()
        {
            var input1 = new TestSampleProvider(32000, 2);

            float[] expected = new float[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 };
            var     mp       = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 2);
        }
        public void ConnectInputToOutputThrowsExceptionForInvalidOutput()
        {
            var input1 = new TestSampleProvider(32000, 2);
            var mp     = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 1);

            Assert.Throws <ArgumentException>(() => mp.ConnectInputToOutput(1, 1));
        }
 public void OneInOneOutShouldCopyInReadMethod()
 {
     var input1 = new TestSampleProvider(32000, 1);
     float[] expected = new float[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
     var mp = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 1);
     EnsureReadsExpected(mp, expected);
 }
Пример #5
0
        public void WaveFormatReturnsSourceWaveFormat()
        {
            var source = new TestSampleProvider(10, 1); // 10 samples per second
            var fade   = new FadeInOutSampleProvider(source);

            Assert.AreSame(source.WaveFormat, fade.WaveFormat);
        }
 public void TwoInOneOutShouldSelectLeftChannel()
 {
     var input1 = new TestSampleProvider(32000, 2);
     float[] expected = new float[] { 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 };
     var mp = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 1);
     mp.AssertReadsExpected(expected);
 }
        public void OutputChannelCountIsCorrect()
        {
            var input1 = new TestSampleProvider(32000, 1);
            var mp     = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 3);

            Assert.AreEqual(3, mp.OutputChannelCount);
        }
Пример #8
0
        public void FadeDurationCanBeLongerThanOneRead()
        {
            var source = new TestSampleProvider(10, 1); // 10 samples per second

            source.UseConstValue = true;
            source.ConstValue    = 100;
            var fade = new FadeInOutSampleProvider(source);

            fade.BeginFadeIn(1000);
            float[] buffer = new float[4];
            int     read   = fade.Read(buffer, 0, 4);

            Assert.AreEqual(4, read);
            Assert.AreEqual(0, buffer[0]); // start of fade-in
            Assert.AreEqual(10, buffer[1]);
            Assert.AreEqual(20, buffer[2], 0.0001);
            Assert.AreEqual(30, buffer[3], 0.0001);

            read = fade.Read(buffer, 0, 4);
            Assert.AreEqual(4, read);
            Assert.AreEqual(40, buffer[0], 0.0001);
            Assert.AreEqual(50, buffer[1], 0.0001);
            Assert.AreEqual(60, buffer[2], 0.0001);
            Assert.AreEqual(70, buffer[3], 0.0001);

            read = fade.Read(buffer, 0, 4);
            Assert.AreEqual(4, read);
            Assert.AreEqual(80, buffer[0], 0.0001);
            Assert.AreEqual(90, buffer[1], 0.0001);
            Assert.AreEqual(100, buffer[2], 0.0001);
            Assert.AreEqual(100, buffer[3]);
        }
        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);
        }
        public void ThrowsExceptionIfSampleRatesDiffer()
        {
            var input1 = new TestSampleProvider(32000, 2);
            var input2 = new TestSampleProvider(44100, 1);

            Assert.Throws <ArgumentException>(() => new MultiplexingSampleProvider(new ISampleProvider[] { input1, input2 }, 1));
        }
Пример #11
0
        public void WaveFormatIsSampeAsSource()
        {
            var source = new TestSampleProvider(32000, 1, 10);
            var osp    = new OffsetSampleProvider(source);

            Assert.AreEqual(source.WaveFormat, osp.WaveFormat);
        }
        public void HasConnectInputToOutputMethod()
        {
            var input1 = new TestSampleProvider(32000, 2);
            var mp     = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 1);

            mp.ConnectInputToOutput(1, 0);
        }
Пример #13
0
        public void CorrectOffset()
        {
            var stereoSampleProvider = new TestSampleProvider(44100, 2)
            {
                UseConstValue = true,
                ConstValue    = 1
            };
            var mono = stereoSampleProvider.ToMono();

            var bufferLength = 30;
            var offset       = 10;
            var samples      = 10;

            // [10,20) in buffer will be filled with 1
            var buffer = new float[bufferLength];
            var read   = mono.Read(buffer, offset, samples);

            Assert.AreEqual(samples, read, "samples read");

            for (int i = 0; i < bufferLength; i++)
            {
                var sample = buffer[i];

                if (i < offset || i >= offset + samples)
                {
                    Assert.AreEqual(0, sample, "not in Read range");
                }
                else
                {
                    Assert.AreNotEqual(0, sample, "in Read range");
                }
            }
        }
 public void InputChannelCountIsCorrect()
 {
     var input1 = new TestSampleProvider(32000, 2);
     var input2 = new TestSampleProvider(32000, 1);
     var mp = new MultiplexingSampleProvider(new ISampleProvider[] { input1, input2 }, 1);
     Assert.AreEqual(3, mp.InputChannelCount);
 }
        public void FadeDurationCanBeLongerThanOneRead()
        {
            var source = new TestSampleProvider(10, 1); // 10 samples per second
            source.UseConstValue = true;
            source.ConstValue = 100;
            var fade = new FadeInOutSampleProvider(source);
            fade.BeginFadeIn(1000);
            float[] buffer = new float[4];
            int read = fade.Read(buffer, 0, 4);
            Assert.AreEqual(4, read);
            Assert.AreEqual(0, buffer[0]); // start of fade-in
            Assert.AreEqual(10, buffer[1]);
            Assert.AreEqual(20, buffer[2], 0.0001);
            Assert.AreEqual(30, buffer[3], 0.0001);

            read = fade.Read(buffer, 0, 4);
            Assert.AreEqual(4, read);
            Assert.AreEqual(40, buffer[0], 0.0001);
            Assert.AreEqual(50, buffer[1], 0.0001);
            Assert.AreEqual(60, buffer[2], 0.0001);
            Assert.AreEqual(70, buffer[3], 0.0001);

            read = fade.Read(buffer, 0, 4);
            Assert.AreEqual(4, read);
            Assert.AreEqual(80, buffer[0], 0.0001);
            Assert.AreEqual(90, buffer[1], 0.0001);
            Assert.AreEqual(100, buffer[2], 0.0001);
            Assert.AreEqual(100, buffer[3]);
        }
Пример #16
0
        public void CantSetNonBlockAlignedDelayBySamples()
        {
            var source = new TestSampleProvider(32000, 2);
            var osp = new OffsetSampleProvider(source);

            var ex = Assert.Throws<ArgumentException>(() => osp.DelayBySamples = 3);
            Assert.That(ex.Message.Contains("DelayBySamples"));
        }
Пример #17
0
        public void CanAddLeadOut()
        {
            var source = new TestSampleProvider(32000, 1, 10);
            var osp = new OffsetSampleProvider(source) {LeadOutSamples = 5};

            var expected = new float[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0 };
            osp.AssertReadsExpected(expected);
        }
 public void DefaultShouldPassStraightThrough()
 {
     var source = new TestSampleProvider(32000, 1);
     var osp = new OffsetSampleProvider(source);
     
     var expected = new float[] { 0, 1, 2, 3, 4, 5, 6 };
     osp.AssertReadsExpected(expected);
 }
        public void SettingPreDelayUsingTimeSpanReturnsCorrectTimeSpan()
        {
            var source = new TestSampleProvider(100, 2) { Position = 10 };
            var osp = new OffsetSampleProvider(source) { DelayBy = TimeSpan.FromSeconds(2.5) };

            Assert.AreEqual(2500, (int) osp.DelayBy.TotalMilliseconds);
            Assert.AreEqual(500, osp.DelayBySamples);
        }
        public void CanTake()
        {
            var source = new TestSampleProvider(32000, 1);
            var osp = new OffsetSampleProvider(source) {TakeSamples = 7};

            var expected = new float[] { 0, 1, 2, 3, 4, 5, 6 };
            osp.AssertReadsExpected(expected, 10);
        }
        public void CanSkipOver()
        {
            var source = new TestSampleProvider(32000, 1);
            var osp = new OffsetSampleProvider(source) {SkipOverSamples = 17};

            var expected = new float[] { 17,18,19,20,21,22,23,24 };
            osp.AssertReadsExpected(expected);
        }
        public void CanAddPreDelay()
        {
            var source = new TestSampleProvider(32000, 1) {Position = 10};
            var osp = new OffsetSampleProvider(source) {DelayBySamples = 5};

            var expected = new float[] { 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15 };
            osp.AssertReadsExpected(expected);
        }
        public void OneInOneOutShouldCopyInReadMethod()
        {
            var input1 = new TestSampleProvider(32000, 1);

            float[] expected = new float[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var     mp       = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 1);

            mp.AssertReadsExpected(expected);
        }
Пример #24
0
        public void CorrectOutputFormat()
        {
            var stereoSampleProvider = new TestSampleProvider(44100, 2);
            var mono = stereoSampleProvider.ToMono(0f, 1f);

            Assert.AreEqual(WaveFormatEncoding.IeeeFloat, mono.WaveFormat.Encoding);
            Assert.AreEqual(1, mono.WaveFormat.Channels);
            Assert.AreEqual(44100, mono.WaveFormat.SampleRate);
        }
Пример #25
0
        public void CantSetLeadOutSamplesAfterCallingRead()
        {
            var source = new TestSampleProvider(32000, 1);
            var osp = new OffsetSampleProvider(source);
            var buffer = new float[10];
            osp.Read(buffer, 0, buffer.Length);

            Assert.Throws<InvalidOperationException>(() => osp.LeadOutSamples = 4);
        }
        public void OneInTwoOutShouldConvertMonoToStereo()
        {
            var input1 = new TestSampleProvider(32000, 1);

            float[] expected = new float[] { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9 };
            var     mp       = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 2);

            mp.AssertReadsExpected(expected);
        }
        public void TwoInOneOutShouldSelectLeftChannel()
        {
            var input1 = new TestSampleProvider(32000, 2);

            float[] expected = new float[] { 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 };
            var     mp       = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 1);

            mp.AssertReadsExpected(expected);
        }
Пример #28
0
        public void CantSetNonBlockAlignedLeadOutSamples()
        {
            var source = new TestSampleProvider(32000, 2);
            var osp    = new OffsetSampleProvider(source);

            var ex = Assert.Throws <ArgumentException>(() => osp.LeadOutSamples = 3);

            Assert.That(ex.Message.Contains("LeadOutSamples"));
        }
Пример #29
0
        public void DefaultShouldPassStraightThrough()
        {
            var source = new TestSampleProvider(32000, 1);
            var osp    = new OffsetSampleProvider(source);

            var expected = new float[] { 0, 1, 2, 3, 4, 5, 6 };

            osp.AssertReadsExpected(expected);
        }
Пример #30
0
 public void WithOneInputReadsToTheEnd()
 {
     var input1 = new TestSampleProvider(44100, 2, 2000);
     var msp = new MixingSampleProvider(new [] { input1});
     var buffer = new float[1000];
     Assert.AreEqual(buffer.Length, msp.Read(buffer, 0, buffer.Length));
     // randomly check one value
     Assert.AreEqual(567, buffer[567]);
 }
        public void CanAddPreDelayUsingTimeSpan()
        {
            var source = new TestSampleProvider(100, 1) { Position = 10 };
            var osp = new OffsetSampleProvider(source) { DelayBy = TimeSpan.FromSeconds(1) };

            var expected = Enumerable.Range(0,100).Select(x => 0f)
                            .Concat(Enumerable.Range(10,10).Select(x => (float)x)).ToArray();
            osp.AssertReadsExpected(expected);
        }
Пример #32
0
 public void WithOneInputReturnsSamplesReadIfNotEnoughToFullyRead()
 {
     var input1 = new TestSampleProvider(44100, 2, 800);
     var msp = new MixingSampleProvider(new[] { input1 });
     var buffer = new float[1000];
     Assert.AreEqual(800, msp.Read(buffer, 0, buffer.Length));
     // randomly check one value
     Assert.AreEqual(567, buffer[567]);
 }
Пример #33
0
        public void CantSetTakeSamplesAfterCallingRead()
        {
            var source = new TestSampleProvider(32000, 1);
            var osp    = new OffsetSampleProvider(source);
            var buffer = new float[10];

            osp.Read(buffer, 0, buffer.Length);

            Assert.Throws <InvalidOperationException>(() => osp.TakeSamples = 4);
        }
        public void TwoInOneOutShouldCanBeConfiguredToSelectRightChannel()
        {
            var input1 = new TestSampleProvider(32000, 2);

            float[] expected = new float[] { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19 };
            var     mp       = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 1);

            mp.ConnectInputToOutput(1, 0);
            mp.AssertReadsExpected(expected);
        }
Пример #35
0
        public void WithOneInputReturnsSamplesReadIfNotEnoughToFullyRead()
        {
            var input1 = new TestSampleProvider(44100, 2, 800);
            var msp    = new MixingSampleProvider(new[] { input1 });
            var buffer = new float[1000];

            Assert.AreEqual(800, msp.Read(buffer, 0, buffer.Length));
            // randomly check one value
            Assert.AreEqual(567, buffer[567]);
        }
Пример #36
0
        public void WithOneInputReadsToTheEnd()
        {
            var input1 = new TestSampleProvider(44100, 2, 2000);
            var msp    = new MixingSampleProvider(new [] { input1 });
            var buffer = new float[1000];

            Assert.AreEqual(buffer.Length, msp.Read(buffer, 0, buffer.Length));
            // randomly check one value
            Assert.AreEqual(567, buffer[567]);
        }
        public void ReadReturnsCountIfOneInputHasEndedButTheOtherHasnt()
        {
            var input1 = new TestSampleProvider(32000, 1, 0);
            var input2 = new TestSampleProvider(32000, 1);

            float[] expected = new float[] { 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7 };
            var     mp       = new MultiplexingSampleProvider(new ISampleProvider[] { input1, input2 }, 2);

            mp.AssertReadsExpected(expected);
        }
Пример #38
0
        public void HandlesSkipOverEntireSourceCorrectly()
        {
            var source = new TestSampleProvider(32000, 1, 10);
            var osp    = new OffsetSampleProvider(source);

            osp.SkipOverSamples = 20;

            var expected = new float[] { };

            osp.AssertReadsExpected(expected, 20);
        }
        public void StereoInTwoOutCanBeConfiguredToSwapLeftAndRight()
        {
            var input1 = new TestSampleProvider(32000, 2);

            float[] expected = new float[] { 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10 };
            var     mp       = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 2);

            mp.ConnectInputToOutput(0, 1);
            mp.ConnectInputToOutput(1, 0);
            mp.AssertReadsExpected(expected);
        }
        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 LeftChannelOnly()
 {
     var stereoStream = new TestSampleProvider(44100,1).ToStereo(1.0f, 0.0f);
     var buffer = new float[2000];
     var read = stereoStream.Read(buffer, 0, 2000);
     Assert.AreEqual(2000, read);
     for (int n = 0; n < read; n+=2)
     {
         Assert.AreEqual(n/2, buffer[n], String.Format("left sample[{0}]",n));
         Assert.AreEqual(0, buffer[n+1], String.Format("right sample[{0}]",n+1));
     }
 }
Пример #42
0
        public void CanSkipOver()
        {
            var source = new TestSampleProvider(32000, 1);
            var osp    = new OffsetSampleProvider(source)
            {
                SkipOverSamples = 17
            };

            var expected = new float[] { 17, 18, 19, 20, 21, 22, 23, 24 };

            osp.AssertReadsExpected(expected);
        }
Пример #43
0
        public void CanTake()
        {
            var source = new TestSampleProvider(32000, 1);
            var osp    = new OffsetSampleProvider(source)
            {
                TakeSamples = 7
            };

            var expected = new float[] { 0, 1, 2, 3, 4, 5, 6 };

            osp.AssertReadsExpected(expected, 10);
        }
        public void CanAddLeadOut()
        {
            var source = new TestSampleProvider(32000, 1, 10);
            var osp    = new OffsetSampleProvider(source)
            {
                LeadOutSamples = 5
            };

            var expected = new float[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0 };

            osp.AssertReadsExpected(expected);
        }
        public void LeftChannelOnly()
        {
            var stereoStream = new TestSampleProvider(44100, 1).ToStereo(1.0f, 0.0f);
            var buffer       = new float[2000];
            var read         = stereoStream.Read(buffer, 0, 2000);

            Assert.AreEqual(2000, read);
            for (int n = 0; n < read; n += 2)
            {
                Assert.AreEqual(n / 2, buffer[n], String.Format("left sample[{0}]", n));
                Assert.AreEqual(0, buffer[n + 1], String.Format("right sample[{0}]", n + 1));
            }
        }
 public void RightChannelOnly()
 {
     var stereoSampleProvider = new TestSampleProvider(44100, 2);
     var mono = stereoSampleProvider.ToMono(0f, 1f);
     var samples = 1000;
     var buffer = new float[samples];
     var read = mono.Read(buffer, 0, buffer.Length);
     Assert.AreEqual(buffer.Length, read, "samples read");
     for (int sample = 0; sample < samples; sample++)
     {
         Assert.AreEqual(1 + 2*sample, buffer[sample], "sample #" + sample);
     }
 }
        public void TwoMonoInTwoOutShouldCreateStereo()
        {
            var input1 = new TestSampleProvider(32000, 1);
            var input2 = new TestSampleProvider(32000, 1)
            {
                Position = 100
            };

            float[] expected = new float[] { 0, 100, 1, 101, 2, 102, 3, 103, 4, 104, 5, 105 };
            var     mp       = new MultiplexingSampleProvider(new ISampleProvider[] { input1, input2 }, 2);

            mp.AssertReadsExpected(expected);
        }
Пример #48
0
        public void RightChannelOnly()
        {
            var stereoSampleProvider = new TestSampleProvider(44100, 2);
            var mono    = stereoSampleProvider.ToMono(0f, 1f);
            var samples = 1000;
            var buffer  = new float[samples];
            var read    = mono.Read(buffer, 0, buffer.Length);

            Assert.AreEqual(buffer.Length, read, "samples read");
            for (int sample = 0; sample < samples; sample++)
            {
                Assert.AreEqual(1 + 2 * sample, buffer[sample], "sample #" + sample);
            }
        }
 public void CanPassTwoProviders()
 {
     // arrange
     var expectedLength = 100;
     var input1 = new TestSampleProvider(44100, 2, 50);
     var input2 = new TestSampleProvider(44100, 2, 50);
     var concatenator = new ConcatenatingSampleProvider(new[] { input1, input2 });
     var buffer = new float[2000];
     
     var read = concatenator.Read(buffer, 0, buffer.Length);
     Assert.AreEqual(expectedLength, read, "read == expectedLength");
     Assert.AreEqual(49, buffer[49]);
     Assert.AreEqual(0, buffer[50]);
     Assert.AreEqual(49, buffer[99]);
 }
 public void CanFadeOut()
 {
     var source = new TestSampleProvider(10, 1); // 10 samples per second
     source.UseConstValue = true;
     source.ConstValue = 100;
     var fade = new FadeInOutSampleProvider(source);
     fade.BeginFadeOut(1000);
     float[] buffer = new float[20];
     int read = fade.Read(buffer, 0, 20);
     Assert.AreEqual(20, read);
     Assert.AreEqual(100, buffer[0]); // start of fade-out
     Assert.AreEqual(50, buffer[5]); // half-way
     Assert.AreEqual(0, buffer[10]); // fully fade out
     Assert.AreEqual(0, buffer[15]); // fully fade out
 }
Пример #51
0
        public void FullyReadCausesPartialBufferToBeZeroedOut()
        {
            var input1 = new TestSampleProvider(44100, 2, 800);
            var msp = new MixingSampleProvider(new[] { input1 });
            msp.ReadFully = true;
            // of 1000 floats of value 9999
            var buffer = Enumerable.Range(1,1000).Select(n => 9999f).ToArray();

            Assert.AreEqual(buffer.Length, msp.Read(buffer, 0, buffer.Length));
            // check we get 800 samples, followed by zeroed out data
            Assert.AreEqual(567f, buffer[567]);
            Assert.AreEqual(799f, buffer[799]);
            Assert.AreEqual(0, buffer[800]);
            Assert.AreEqual(0, buffer[999]);
        }
        public void CanTakeThirtySeconds()
        {
            var source = new TestSampleProvider(16000, 1);
            var osp = new OffsetSampleProvider(source) { Take = TimeSpan.FromSeconds(30) };
            var buffer = new float[16000];
            var totalRead = 0;
            while (true)
            {
                var read = osp.Read(buffer, 0, buffer.Length);
                totalRead += read;
                if (read == 0) break;
                Assert.IsTrue(totalRead <= 480000);

            }
            Assert.AreEqual(480000, totalRead);
        }
        public void CanPassASingleProvider()
        {
            // arrange
            const int expectedLength = 5000;
            var input = new TestSampleProvider(44100, 2, expectedLength);
            var concatenator = new ConcatenatingSampleProvider(new[] {input});
            var buffer = new float[2000];
            var totalRead = 0;

            // act
            while (true)
            {
                var read = concatenator.Read(buffer, 0, buffer.Length);
                if (read == 0) break;
                totalRead += read;
                Assert.That(totalRead <= expectedLength);
            }
            Assert.That(totalRead == expectedLength);
        }
 public void FadeWorksOverSamplePairs()
 {
     var source = new TestSampleProvider(10, 2); // 10 samples per second
     source.UseConstValue = true;
     source.ConstValue = 100;
     var fade = new FadeInOutSampleProvider(source);
     fade.BeginFadeIn(1000);
     float[] buffer = new float[20];
     int read = fade.Read(buffer, 0, 20);
     Assert.AreEqual(20, read);
     Assert.AreEqual(0, buffer[0]); // start of fade-in
     Assert.AreEqual(0, buffer[1]); // start of fade-in
     Assert.AreEqual(50, buffer[10]); // half-way
     Assert.AreEqual(50, buffer[11]); // half-way
     Assert.AreEqual(90, buffer[18], 0.0001); // fully fade in
     Assert.AreEqual(90, buffer[19], 0.0001); // fully fade in
 }
 public void WaveFormatReturnsSourceWaveFormat()
 {
     var source = new TestSampleProvider(10, 1); // 10 samples per second
     var fade = new FadeInOutSampleProvider(source);
     Assert.AreSame(source.WaveFormat, fade.WaveFormat);
 }
        public void HandlesSkipOverEntireSourceCorrectly()
        {
            var source = new TestSampleProvider(32000, 1, 10);
            var osp = new OffsetSampleProvider(source);
            osp.SkipOverSamples = 20;

            var expected = new float[] { };
            osp.AssertReadsExpected(expected, 20);
        }
        public void MaintainsPredelayState()
        {
            var source = new TestSampleProvider(32000, 1) {Position = 10};
            var osp = new OffsetSampleProvider(source) {DelayBySamples = 10};

            var expected = new float[] {0, 0, 0, 0, 0,};
            osp.AssertReadsExpected(expected);
            var expected2 = new float[] {0, 0, 0, 0, 0,};
            osp.AssertReadsExpected(expected2);
            var expected3 = new float[] {10, 11, 12, 13, 14, 15};
            osp.AssertReadsExpected(expected3);
        }
        public void MaintainsTakeState()
        {
            var source = new TestSampleProvider(32000, 1);
            var osp = new OffsetSampleProvider(source) {TakeSamples = 15};

            var expected = new float[] { 0, 1, 2, 3, 4, 5, 6, 7 };
            osp.AssertReadsExpected(expected);
            var expected2 = new float[] { 8, 9, 10, 11, 12, 13, 14 };
            osp.AssertReadsExpected(expected2, 20);
        }
 public void WaveFormatIsSampeAsSource()
 {
     var source = new TestSampleProvider(32000, 1, 10);
     var osp = new OffsetSampleProvider(source);
     Assert.AreEqual(source.WaveFormat, osp.WaveFormat);
 }
 public void TwoInOneOutShouldCanBeConfiguredToSelectRightChannel()
 {
     var input1 = new TestSampleProvider(32000, 2);
     float[] expected = new float[] { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19 };
     var mp = new MultiplexingSampleProvider(new ISampleProvider[] { input1 }, 1);
     mp.ConnectInputToOutput(1, 0);
     EnsureReadsExpected(mp, expected);
 }