问题描述
我要生成的音频频谱的MP3音频文件(如看到)。基本上这个问题需要计算所述音频信号的FFT。我该怎么做我的C / C编程这++?
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 do I program this in C/C++?
我已经看了几个开源库如,我真的不知道如何使用这些用于我的问题。任何帮助将大大AP preciated。在此先感谢!
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!
推荐答案
有相当多的相似/相关的SO已经这是值得一读的答案包含了很多有用的信息和建议的问题,但在本质上你要做到这一点:
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:
- 转换音频数据(例如INT - >浮动,独立的L / R通道)
- 申请适合(如的)
- 申请FFT(注:如果使用的输入数组的典型的复杂到复杂FFT然后设置虚部为零)
- 首先计算N / 2 FFT输出纸盒幅度(
的sqrt(重*重新+ IM * IM)
) - 可选转换幅度分贝(日志)规模(
20 * log10的(大小)
) - 剧情N / 2(日志)幅度值
要格式化要求的FFT
- 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
请注意,虽然FFTW是一个非常好,非常快的FFT它可能是一个有点势不可挡对于初学者 - 这也是非常昂贵的,如果你想将它作为一个商业产品的一部分 - 我建议开始的来代替。
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.
这篇关于如何生成使用FFT C ++中的音频频谱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!