Merge pull request #36 from mroavi/julia1

Upgraded audiometer.jl and spectrum.jl
This commit is contained in:
Spencer Russell 2019-07-30 08:58:34 -04:00 committed by GitHub
commit 577d7adfef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -9,7 +9,7 @@ function micmeter(metersize)
println("Press Ctrl-C to quit")
while true
block = read(mic, 512)
blockmax = maximum(abs(block)) # find the maximum value in the block
blockmax = maximum(abs.(block)) # find the maximum value in the block
signalmax = max(signalmax, blockmax) # keep the maximum value ever
print("\r") # reset the cursor to the beginning of the line
printmeter(metersize, blockmax, signalmax)
@ -25,11 +25,11 @@ function printmeter(metersize, signal, peak)
blankchars = max(0, peakpos-meterchars-1)
for position in 1:meterchars
print_with_color(barcolor(metersize, position), ">")
printstyled(">", color=barcolor(metersize, position))
end
print(" " ^ blankchars)
print_with_color(barcolor(metersize, peakpos), "|")
printstyled("|", color=barcolor(metersize, peakpos))
print(" " ^ (metersize - peakpos))
end

View file

@ -3,7 +3,7 @@
module SpectrumExample
using GR, PortAudio, SampledSignals
using GR, PortAudio, SampledSignals, FFTW
const N = 1024
const stream = PortAudioStream(1, 0, blocksize=N)
@ -14,7 +14,7 @@ const fs = Float32[float(f) for f in domain(fft(buf)[fmin..fmax])]
while true
read!(stream, buf)
plot(fs, abs(fft(buf)[fmin..fmax]), xlim=(fs[1],fs[end]), ylim=(0,100))
plot(fs, abs.(fft(buf)[fmin..fmax]), xlim=(fs[1],fs[end]), ylim=(0,100))
end
end