How to calculate FFT using NAudio in realtime (ASIO out)

后端 未结 2 1015
别那么骄傲
别那么骄傲 2021-01-06 11:14

I am programming clone of guitar (violin) Hero as a final project for this school year.

The idea is to take input from my electric violin, analyse it via FFT, do so

2条回答
  •  长发绾君心
    2021-01-06 11:44

    The problem was as I thought in conversion between data about samples from Asio (4 bytes in a row in buf array) to float for fft. BitConvertor should do the trick but it somehow makes fft output NaN in my case. So I tried this conversion instead.

    for (int i = 0; i < e.SamplesPerBuffer * 4; i=i+4)
    {
        float sample = Convert.ToSingle(buf[i] + buf[i+1] + buf[i+2] + buf[i+3]);
        sampleAggregator.Add(sample);
    }
    

    And it works very well. Even with 192 000 sample rate.

提交回复
热议问题