の実装でいくつかの問題に直面していますFFTPitchDetector
。私が実際にやりたいのは、ギター入力からリアルタイムの周波数を取得することです。関数の使用方法がよくわかりませんFftPitchDetector.cs
。何か案が?
private void sourceStream_DataAvailable(object sender, NAudio.Wave.WaveInEventArgs e)
{
if (waveWriter == null) return;
byte[] buffer = e.Buffer;
float[] floats = new float[buffer.Length];
float sample32 = 0;
int bytesRecorded = e.BytesRecorded;
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(floats, bytesRecorded);
Console.WriteLine("{0}",sample32);
}
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;
}
コードを実行すると、次IndexOutOfRangeException was unhandled
の行を指すエラーが発生します
fftBuffer[n * 2] = buffer[n-inFrames] * window(n, frames);
でfftPitchDetector.cs
。私のコードの問題は何ですか?
C# Guitar Tuner のオープン ソース コードはありますか? 私はそれを私のプロジェクトにアウトソーシングしたいと考えています。