Last active
January 11, 2018 17:38
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Makie, GeometryTypes, Colors | |
using Reactive | |
using Juno | |
using DSP | |
using LibSndFile, FileIO | |
using PortAudio, SampledSignals | |
using BenchmarkTools | |
N = 1024 # size of audio read | |
N2 = N÷2+1 # size of rfft output | |
D = 200 # number of bins to display | |
M = 20 # number of lines to draw | |
src = PortAudioStream(1, 2, blocksize=N) | |
buf = Array{Float32}(N) | |
fftbuf = Array{Complex{Float32}}(N2) | |
magbuf = Array{Float32}(N2) | |
fftplan = plan_rfft(buf; flags=FFTW.EXHAUSTIVE) | |
scene = Scene(resolution=(500,500)) | |
ax = axis(0:0.1:1, 0:0.1:1, 0:0.1:0.5) | |
center!(scene) | |
ls = map(1:M) do _ | |
yoffset = to_node(to_value(scene[:time])) | |
offset = lift_node(scene[:time], yoffset) do t, yoff | |
Point3f0(0.0f0, (t-yoff)*4, 0.0f0) | |
end | |
l = lines(linspace(0,1,D), 0.0f0, zeros(Float32, D), | |
offset=offset, color=(:black, 0.1)) | |
(yoffset, l) | |
end | |
while isopen(scene[:screen]) | |
for (yoffset, line) in ls | |
isopen(scene[:screen]) || break | |
read!(src, buf) | |
A_mul_B!(fftbuf, fftplan, buf) | |
@. magbuf = log(clamp(abs(fftbuf), 0.0001, Inf))/10+1 | |
line[:z] = magbuf[1:D] | |
push!(yoffset, to_value(scene[:time])) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment