Deploying FftPitchDetector in C #

I added FftPitchDetector.cs to my project, but I'm not sure how to use it.

My code is:

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; } 

What parameters should I put inside PitchDetect.DetectPitch (XXXXXX, XXXXXXXXXXX); ??

How to get input frequency using FftPitchDetector.cs?

Thanks!

0
source share
1 answer

I wrote an accompanying article explaining how this code works, which can be accessed here . Basically, you pass in an array of samples and a number indicating how many samples are in this array (in case it does not match the length of the array). It returns the frequency in Hz. However, remember that this code is simply trying to select a musical note so that it can determine how much the pitch is shifted for the auto-tuning effect, so it only looks for values ​​in a certain range and may not actually return the loudest frequency of the incoming signal.

+1
source

Source: https://habr.com/ru/post/1015002/


All Articles