PortAudio.jl/examples/spectrum.jl

21 lines
506 B
Julia
Raw Permalink Normal View History

2016-03-28 06:27:58 +02:00
# plot a real-time spectrogram. This example is adapted from the GR example
# at http://gr-framework.org/examples/audio_ex.html
module SpectrumExample
using GR, PortAudio, SampledSignals
const N = 1024
2016-03-28 18:20:47 +02:00
const stream = PortAudioStream(1, 0, bufsize=N)
const buf = read(stream, N)
const fmin = 0Hz
const fmax = 10000Hz
const fs = Float32[float(f) for f in domain(fft(buf)[fmin..fmax])]
while true
read!(stream, buf)
2016-03-28 18:20:47 +02:00
plot(fs, abs(fft(buf)[fmin..fmax]), xlim=(fs[1],fs[end]), ylim=(0,100))
end
end