简体   繁体   English

使用Bass库绘制音频频谱

[英]Drawing audio spectrum with Bass library

How can I draw an spectrum for an given audio file with Bass library ? 如何使用Bass库为给定的音频文件绘制频谱

I mean the chart similar to what Audacity generates: 我的意思是图表类似于Audacity生成的图表: 在此处输入图片说明

I know that I can get the FFT data for given time t (when I play the audio) with: 我知道我可以在给定的时间t (当播放音频时)获得FFT数据:

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 . 这样,我每次获得t数组中的1024个值。 Am I right that the values in that array are signal amplitudes ( dB )? 我对那个数组中的值是信号幅度( dB )正确吗? If so, how the frequency ( Hz ) is associated with those values? 如果是这样,频率( Hz )与这些值如何关联? 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). 我正在使用C ++版本,但是其他语言的示例也很好(我可以将其转换)。

From the documentation, that flag will cause the FFT magnitude to be computed, and from the sounds of it, it is the linear magnitude. 从文档中可以看出,该标志将导致计算FFT幅度,而从声音来看,它就是线性幅度。

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

(I'm not sure whether audio file samples are a measurement of intensity or pressure. What's a microphone output linearly related to?) (我不确定音频文件样本是强度还是压力的度量。与线性相关的麦克风输出是什么?)

Also, it indicates the length of the input and the length of the FFT match, but half the FFT (corresponding to negative frequencies) is discarded. 同样,它表示输入的长度和FFT匹配的长度,但是FFT的一半(对应于负频率)被丢弃。 Therefore the highest FFT frequency will be one-half the sampling frequency. 因此,最高的FFT频率将是采样频率的一半。 This occurs at N/2. 这发生在N / 2。 The docs actually say 文档实际上说

For example, with a 2048 sample FFT, there will be 1024 floating-point values returned. 例如,使用2048个样本FFT,将返回1024个浮点值。 If the BASS_DATA_FIXED flag is used, then the FFT values will be in 8.24 fixed-point form rather than floating-point. 如果使用了BASS_DATA_FIXED标志,则FFT值将采用8.24定点形式而不是浮点形式。 Each value, or "bin", ranges from 0 to 1 (can actually go higher if the sample data is floating-point and not clipped). 每个值(或“ bin”)的范围为0到1(如果样本数据是浮点且未裁剪,则实际上可以更高)。 The 1st bin contains the DC component, the 2nd contains the amplitude at 1/2048 of the channel's sample rate, followed by the amplitude at 2/2048, 3/2048, etc. 第一个bin包含DC分量,第二个bin包含通道采样率的1/2048处的幅度,其次是2 / 2048、3 / 2048等处的幅度。

That seems pretty clear. 这似乎很清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM