I've added FftPitchDetector.cs into my project, but I'm not sure how to use it.
My code:
private void sourceStream_DataAvailable(object sender, NAudio.Wave.WaveInEventArgs e)
{
if (waveWriter == null) return;
byte[] buffer = e.Buffer;
float sample32 = 0;
int bytesRecorded = e.BytesRecorded;
float[] floats = new float[buffer.Length];
waveWriter.Write(buffer, 0, bytesRecorded);
for (int index = 0; index < e.BytesRecorded; index += 2)
{
short sample = (short)((buffer[index + 1] << 8) |
buffer[index + 0]);
sample32 = sample / 32768f;
sampleAggregator.Add(sample32);
}
floats = bytesToFloats(buffer);
FftPitchDetector PitchDetect = new FftPitchDetector(sample32);
**PitchDetect.DetectPitch(XXXXXX, XXXXXXXXXXX);**
}
private static float[] bytesToFloats(byte[] bytes)
{
float[] floats = new float[bytes.Length / 2];
for (int i = 0; i < bytes.Length; i += 2)
{
floats[i / 2] = bytes[i] | (bytes[i + 1] << 8);
}
return floats;
}
Which parameters I should put inside PitchDetect.DetectPitch(XXXXXX, XXXXXXXXXXX); ??
How can I get the input frequency using FftPitchDetector.cs?
Thank you!
FftPitchDetector.cs
from where? Care to provide a link? – Oysterman