Example #1
0
        public void GetElapsedTimeSpan_ValidSampleCountAndSampleRate_ReturnsCorrectValue(int sampleRate,
                                                                                         int elapsedSampleCount, TimeSpan expectedResult)
        {
            var result = ElapsedTimeSpanHelper.GetElapsedTimeSpan(sampleRate, elapsedSampleCount);

            result.Should().Be(expectedResult);
        }
        private int SecondsUntilPatternConcluded(IWaveProvider reader)
        {
            var  sampleProvider = reader.ToSampleProvider();
            var  toneDetector   = new TonePatternDetector(_mockConfigurationReader);
            var  buffer         = new float[BufferSize];
            long sampleCount    = 0;

            while (true)
            {
                var bytesRead = sampleProvider.Read(buffer, 0, buffer.Length);
                sampleCount += bytesRead;

                if (bytesRead < buffer.Length)
                {
                    break;
                }

                if (toneDetector.Detected(buffer, sampleProvider.WaveFormat.SampleRate))
                {
                    return(ElapsedTimeSpanHelper.GetElapsedTimeSpan(sampleProvider.WaveFormat.SampleRate, sampleCount).Seconds);
                }
            }

            return(-1);
        }
Example #3
0
        public void GetElapsedTimeSpan_NegativeOrZeroElapseSampleCount_Throws(int invalidElapsedSampleCount)
        {
            const int testSampleRate = 22050;

            Action testCall = () => ElapsedTimeSpanHelper.GetElapsedTimeSpan(testSampleRate, invalidElapsedSampleCount);

            testCall.ShouldThrow <ArgumentException>();
        }
Example #4
0
        public void GetElapsedTimeSpan_NegativeOrZeroSampeRate_Throws(int invalidSampleRate)
        {
            const int testSampleCount = 1024;

            Action testCall = () => ElapsedTimeSpanHelper.GetElapsedTimeSpan(invalidSampleRate, testSampleCount);

            testCall.ShouldThrow <ArgumentException>();
        }