Example #1
0
        public AutoTuneWaveProvider(IWaveProvider source, AutoTuneSettings autoTuneSettings)
        {
            this.autoTuneSettings = autoTuneSettings;
            if (source.WaveFormat.SampleRate != 44100)
                throw new ArgumentException("AutoTune only works at 44.1kHz");
            if (source.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat)
                throw new ArgumentException("AutoTune only works on IEEE floating point audio data");
            if (source.WaveFormat.Channels != 1)
                throw new ArgumentException("AutoTune only works on mono input sources");

            this.source = source;
            this.pitchDetector = new AutoCorrelator(source.WaveFormat.SampleRate);
            this.pitchShifter = new SmbPitchShifter(Settings);
            this.waveBuffer = new WaveBuffer(8192);
        }
Example #2
0
        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 TestSineWaveDetectionAutocorrelator()
 {
     float[] buffer = new float[4096];
     IPitchDetector pitchDetector = new AutoCorrelator(sampleRate);
     TestPitchDetection(buffer, pitchDetector);
 }
 public void TestEmptyBufferDoesntDetectAPitch()
 {
     AutoCorrelator autoCorrelator = new AutoCorrelator(sampleRate);
     float pitch = autoCorrelator.DetectPitch(new float[1024], 1024);
     Assert.AreEqual(0f,pitch);
 }