public static void pitchdetect_test(AudioPlayer pl) { PitchDetection.PitchDetectAlgorithm algorithm = PitchDetection.PitchDetectAlgorithm.Amdf; string[] strFiles = new string[] { "btrombone1.wav", "btrombone2.wav", "cello.wav", "cello2.wav", "flute.wav", "organ.wav", "piano.wav", "sing01.wav", "sing02.wav", "sing03.wav", "trumpet.wav" }; foreach (string s in strFiles) { pitchdetectwav(pl, s, algorithm); } }
// Test between 20Hz and 500Hz. This works very well, although it is hard to eliminate octave errors // This test will play original, then a sine at the frequency it detected. The two should line up. private static void pitchdetectwav(AudioPlayer pl, string strFilename, PitchDetection.PitchDetectAlgorithm algorithm) { string strInstdir = mediadir + @"pitchdetect\"; WaveAudio w = new WaveAudio(strInstdir + strFilename); if (w.getNumChannels() != 1) { w.setNumChannels(1, true); } double dfreq = PitchDetection.DetectPitch(w, 50, 500, algorithm); WaveAudio testPitch = new Triangle(dfreq, 0.7).CreateWaveAudio(1.0); pl.Play(w); pl.Play(testPitch); }