首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >led矩阵上的音频可视化工具

led矩阵上的音频可视化工具
EN

Stack Overflow用户
提问于 2014-06-27 23:00:00
回答 1查看 1.8K关注 0票数 0

我的需求是播放一个音频文件,并将其内容放在均衡器方面的8x8矩阵上,就像适用于BeagleBone或RaspberryPI的频谱分析仪一样在Piccolo中做到了这一点。这不需要麦克风的环境分析:只需在同一块板上播放音乐时进行可视化即可。

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

语言可能是C或C++,但如果是Python code.For就更好了这有像Timesideaubio这样的库,但我无法找到如何像Piccolo一样填充leds矩阵,尽管我已经测试了一些示例。

EN

回答 1

Stack Overflow用户

发布于 2014-07-04 02:42:17

要获得一个粗略的8波段、8级持续谱估计(在Python中,使用numpy):

代码语言:javascript
运行
复制
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点)波形之外,这应该会给你一个想法。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24454964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档