21 lines
553 B
Julia
21 lines
553 B
Julia
#=
|
|
This example illustrates synthesizing a long tone in small pieces
|
|
and routing it to the default audio output device using `write()`.
|
|
=#
|
|
|
|
using PortAudio: PortAudioStream, write
|
|
|
|
stream = PortAudioStream(0, 1; warn_xruns=false)
|
|
|
|
function play_tone(stream, freq::Real, duration::Real; buf_size::Int = 1024)
|
|
S = stream.sample_rate
|
|
current = 1
|
|
while current < duration*S
|
|
x = 0.7 * sin.(2π * (current .+ (1:buf_size)) * freq / S)
|
|
write(stream, x)
|
|
current += buf_size
|
|
end
|
|
nothing
|
|
end
|
|
|
|
play_tone(stream, 440, 2)
|