0

How can I draw an spectrum for an given audio file with Bass library?

I mean the chart similar to what Audacity generates: enter image description here

I know that I can get the FFT data for given time t (when I play the audio) with:

float fft[1024];
BASS_ChannelGetData(chan, fft, BASS_DATA_FFT2048); // get the FFT data

That way I get 1024 values in array for each time t. Am I right that the values in that array are signal amplitudes (dB)? If so, how the frequency (Hz) is associated with those values? By the index?

I am an programmer, but I am not experienced with audio processing at all. So I don't know what to do, with the data I have, to plot the needed spectrum.

I am working with C++ version, but examples in other languages are just fine (I can convert them).

4

1 回答 1

2

从文档中,该标志将导致计算 FFT 幅度,从它的声音来看,它是线性幅度。

dB = 10 * log10(intensity);
dB = 20 * log10(pressure);

(我不确定音频文件样本是强度还是压力的测量值。麦克风输出与什么线性相关?)

此外,它表示输入的长度和 FFT 匹配的长度,但丢弃了一半的 FFT(对应于负频率)。因此,最高 FFT 频率将是采样频率的二分之一。这发生在 N/2。文档实际上说

例如,对于 2048 个样本 FFT,将返回 1024 个浮点值。如果使用 BASS_DATA_FIXED 标志,则 FFT 值将采用 8.24 定点形式而不是浮点形式。每个值或“bin”的范围从 0 到 1(如果样本数据是浮点数且未裁剪,则实际上可以更高)。第一个 bin 包含 DC 分量,第二个 bin 包含通道采样率的 1/2048 处的幅度,然后是 2/2048、3/2048 处的幅度等。

这似乎很清楚。

于 2015-03-17T22:15:01.723 回答