转换 FFT 数据以匹配 ComputeSpectrum FFT 输出
我习惯使用 SoundMixer.computeSpectrum
,但我需要从麦克风即时获取一些数据(并且我无法将 SoundMixer 与麦克风一起使用)。
我在翻译 FFT 数据时遇到问题(来自 this class),如这个出色的频谱分析示例所示 以匹配 computeSpectrum
的 ByteArray
输出。我现有的代码是为了处理从computeSpectrum接收的数据而构建的(将FFT设置为true)。
任何帮助表示赞赏!
I'm used to using SoundMixer.computeSpectrum
, but I need to get some data on-the-fly from the microphone (and I can't use the SoundMixer with the microphone).
I'm having trouble translating the FFT data (from this class) as shown in this excellent spectral analysis example to match the ByteArray
output from computeSpectrum
. My existing code is built to handle the data received from computeSpectrum
(with FFT
set to true
).
Any help is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您链接的示例代码中,
m_mag
向量包含频谱数据本身。如果您想修改它以使用旨在与computeSpectrum一起使用的现有代码,您应该将此向量中的值写入ByteArray
,如下所示:您的现有代码然后可以直接查看
fftBytes
,而不是调用computeSpectrum
。请注意,我们在ByteArray
末尾再次复制这些值,以模拟computeSpectrum
始终返回立体声数据,但麦克风是单声道的事实。您还可以通过调整现有代码以接受单声道数据并查看m_mag
向量(而不是将其全部写入ByteArray
)来获得一点速度。此外,您可能需要将代码顶部的
SAMPLE_RATE
和N
常量更改为44100
和9
分别。这将匹配每个通道返回 256 个值(以 44100Hz 采样)的默认computeSpectrum
行为。In the sample code you have linked, the
m_mag
vector contains the spectrum data itself. If you want to modify it to work with existing code that is designed to work withcomputeSpectrum
, you should write the values in this vector to aByteArray
like so:Your existing code can then look at
fftBytes
directly instead of callingcomputeSpectrum
. Note that we copy the values a second time at the end of theByteArray
, to simulate the fact thatcomputeSpectrum
always returns stereo data, but the microphone is mono. You could also gain a little bit of speed by adjusting your existing code to accept mono data and to look at them_mag
vector, instead of writing it all to aByteArray
.Additionally, you may want to change the
SAMPLE_RATE
andN
constants at the top of the code to44100
and9
respectively. This will match the defaultcomputeSpectrum
behavior of returning 256 values per channel, sampled at 44100Hz.