private void TestPitchDetection(float[] buffer, IPitchDetector pitchDetector) { 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 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); // alternative pitch detector: // this.pitchDetector = new FftPitchDetector(source.WaveFormat.SampleRate); this.pitchShifter = new SmbPitchShifter(Settings, source.WaveFormat.SampleRate); this.waveBuffer = new WaveBuffer(8192); }
public PitchGeneratorProvider(IWaveProvider sourceProvider, IPitchDetector leftPitchDetector, IPitchDetector rightPitchDetector, FloatDataStereoSplitter stereoSplitter, PitchResultSummaryWriter resultWriter) { if (sourceProvider.WaveFormat.SampleRate != ChromesthesiaConfig.InputAudioSampleRate) { throw new ArgumentException("This provider only works at 44.1kHz"); } if (sourceProvider.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat) { throw new ArgumentException("This provider only works on IEEE floating point audio data"); } this.sourceProvider = sourceProvider; this.stereoSplitter = stereoSplitter; this.resultWriter = resultWriter; this.leftPitchDetector = leftPitchDetector; this.rightPitchDetector = rightPitchDetector; }
/// <summary> /// Instanciate a PitchWaveProvider /// </summary> /// <param name="source">Stream Source</param> /// <param name="ar">Pitch Reference</param> public PitchWaveProvider(IWaveProvider source, Pitch ar) { if (source.WaveFormat.SampleRate != 44100) { throw new ArgumentException("Pitch Detection only works at 44.1kHz"); } if (source.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat) { throw new ArgumentException("Pitch Detection only works on IEEE floating point audio data"); } if (source.WaveFormat.Channels != 1) { throw new ArgumentException("Pitch Detection only works on mono input sources"); } this.source = source; this.pitchDetector = new AutoCorrelator(source.WaveFormat.SampleRate); this.waveBuffer = new WaveBuffer(8192); this.AR = ar; }
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); // alternative pitch detector: // this.pitchDetector = new FftPitchDetector(source.WaveFormat.SampleRate); this.pitchShifter = new SmbPitchShifter(Settings, source.WaveFormat.SampleRate); this.waveBuffer = new WaveBuffer(8192); }