我需要播放音频文件,并像Piccolo一样在均衡器方面将其内容放在8x8矩阵上,就像适用于BeagleBone或RaspberryPI的频谱分析仪一样。不需要麦克风进行环境分析:在同一块板上播放音乐时只需可视化即可。
Adafruit建立了一个库,使led矩阵控制变得容易,缺少的大部分是音频分析,直到每个音频块的矩阵。
语言可能是C或C++,但如果使用Python代码则最好。为此,有很多好的库,例如Timeside和aubio,但我找不到如何像Piccolo一样填充led矩阵,即使我我们测试了一些例子。
最佳答案
要获得粗略的8频段,8级正在进行的频谱估计(在Python中,使用numpy):
import numpy as np
fftsize = 4096 # about 100ms at 44 kHz; each bin will be ~ 10 Hz
# Band edges to define 8 octave-wide ranges in the FFT output
binedges = [8, 16, 32, 64, 128, 256, 512, 1024, 2048]
nbins = len(binedges)-1
# offsets to get our 48 dB range onto something useful, per band
offsets = [4, 4, 4, 4, 6, 8, 10, 12]
# largest value in ledval
nleds = 8
# scaling of LEDs per doubling in amplitude
ledsPerDoubling = 1.0
# initial value of per-band energy history
binval = 0.001 * np.ones(nbins, np.float)
newbinval = np.zeros(nbins, np.float)
# How rapidly the displays decay after a peak (depends on how often we're called)
decayConst = 0.9
if not_done:
# somehow tap into the most recent 30-100ms of audio.
# Assume we get 44 kHz mono back
waveform = get_latest_waveform()
# find spectrum
spectrum = np.abs(np.fft.rfft(waveform[:fftsize]))
# gather into octave bands
for i in range(nbins-1):
newbinval[i] = np.mean(spectrum[binedges[i]:binedges[i+1]])
# Peak smoothing - decay slowly after large values
binval = np.maximum(newbinval, decayConst*binval)
# Quantize into values 0..8 as the number of leds to light in each column
ledval = np.round(np.maximum(0, np.minimum(nleds,
ledsPerDoubling * np.log2(binval)
+ offsets)))
# Now illuminate ledval[i] LEDs in column i (0..7) ...
除了获取最新的(4096点)波形外,这还可以给您带来启发。
关于python - LED矩阵上的音频可视化器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24454964/