问题
I'm trying to implement an app that plot the spectrum of an audio using bass audio (http://www.un4seen.com/). My understanding is that I will have to:
Get the FFT data from the stream float[] buffer = new float[256]; Bass.BASS_ChannelGetData(handle, buffer, (int)(BASS_DATA_FFT_COMPLEX|BASS_DATA_FFT_NOWINDOW));
For each fft, compute it’s magnitude
Apply a window function to the FFT (Hanning or Hamming will do)
then, draw a beautiful spectrum analysis
The problem however is that:
- It seems that the BASS_DATA_FFT_COMPLEX BassData isn't reachable. I can see it supposed to be available in the documentation http://www.bass.radio42.com/help/html/a13cfef0-1056-bb94-81c4-a4fdf21bd463.htm but I cannot use it since I get an error that BassData does not include such enum
- Further, I'm wondering if what I'm doing is right. To plot a spectrum, should I be simply plot the magnitude of fft or plat the magnitude of fft against the frequency of that fft? In this case, how would I get the frequency corresponding to that fft? I don't mind any code snipped from any language (C/C++, C#, VB, Java, etc..)
Note: I'm not sure if this helps but this is what I'm using: Plotting using Microsoft Chart control. C# with the BASS.NET API by http://www.bass.radio42.com/ Any help and suggestions in greatly appreciated
回答1:
You have mixed up the order of the steps - you need to apply a window function to the time domain data before calculating the FFT. The steps are typically:
1. acquire time domain data
2. apply window function
3. calculate FFT
4. calculate log magnitude of FFT (log(re*re+im*im))
5. plot log magnitude (with appropriate scaling) against frequency
Note that using log magnitude for the Y axis gives you effectively a dB
scale, which is a more natural and useful way to view sound amplitude than a linear magnitude scale.
Normally for visualizing audio etc you apply steps 1 - 5 above on successive blocks of time domain data, typically with an overlap of 50%.
来源:https://stackoverflow.com/questions/16517183/plotting-an-audio-spectrum