private void Test() { float[] buffer = new float[4096]; IPitchDetector pitchDetector = new AutoCorrelator(44100); for (int midiNoteNumber = 45; midiNoteNumber < 63; midiNoteNumber++) { float freq = (float)(8.175 * Math.Pow(1.05946309, midiNoteNumber)); SetFrequency(buffer, freq); float detectedPitch = pitchDetector.DetectPitch(buffer, buffer.Length); // since the autocorrelator works with a lag, give it two shots at the same buffer detectedPitch = pitchDetector.DetectPitch(buffer, buffer.Length); Console.WriteLine("Testing for {0:F2}Hz, got {1:F2}Hz", freq, detectedPitch); //Assert.AreEqual(detectedPitch, freq, 0.5); } }
public void TestEmptyBufferDoesntDetectAPitch() { AutoCorrelator autoCorrelator = new AutoCorrelator(sampleRate); float pitch = autoCorrelator.DetectPitch(new float[1024], 1024); Assert.AreEqual(0f,pitch); }