How to generate the audio spectrum using fft in C++? [closed]

徘徊边缘 提交于 2019-11-26 07:58:08

问题


I want to generate an audio spectrum (as seen in this video) of a mp3 audio file. Basically this problem requires calculating the fft of the audio signal. How do I program this in C/C++?

I\'ve looked at a couple of open source libraries such as FFTW and I really don\'t know how to use these for my problem. Any help would be greatly appreciated. Thanks in advance!


回答1:


There are quite a few similar/related questions on SO already which are well worth reading as the answers contain a lot of useful information and advice, but in essence you need to do this:

  • convert audio data to format required by FFT (e.g. int -> float, separate L/R channels)
  • apply suitable window function (e.g. Hann aka Hanning window)
  • apply FFT (NB: if using typical complex-to-complex FFT then set imaginary parts of input array to zero)
  • calculate magnitude of first N/2 FFT output bins (sqrt(re*re + im*im))
  • optionally convert magnitude to dB (log) scale (20 * log10(magnitude))
  • plot N/2 (log) magnitude values

Note that while FFTW is a very good and very fast FFT it may be a little overwhelming for a beginner - it's also very expensive if you want to include it as part of a commercial product - I recommend starting with KissFFT instead.



来源:https://stackoverflow.com/questions/4675457/how-to-generate-the-audio-spectrum-using-fft-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!