我已将 FftPitchDetector.cs 添加到我的项目中,但我不确定如何使用它。
我的代码:
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;
}
我应该把哪些参数放在PitchDetect.DetectPitch(XXXXXX, XXXXXXXXXXXX); ??
如何使用 FftPitchDetector.cs 获取输入频率?
谢谢!