led矩阵上的音频可视化器



我的需要是播放一个音频文件,并有它的内容在一个8x8矩阵在均衡器方面,在短笛很像频谱分析仪适用于BeagleBone或RaspberryPI。这并不需要来自麦克风的环境分析:只需要在同一板上播放音乐时的可视化。

Adafruit制作了一个库,使led矩阵控制容易,缺少的主要是音频分析到每个音频块的矩阵。

语言可能是C或c++,但最好是在Python代码中。为此,有很好的库,如Timeside和aubio,但我无法找到如何填充led矩阵的方式与Piccolo相同,即使我已经测试了一些例子。

要获得粗略的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点的)波形,这应该给你的想法。

相关内容

  • 没有找到相关文章

最新更新