PortAudio.jl/examples/mutable_streaming_node.jl
Joris Kraak 81a8503c1d Add mutable streaming node example
This demo requires an input hooked up to the default recording device
and will stream that input to the default output device for 10 seconds,
alternating between a muted and unmuted state every second
2014-03-25 16:02:42 +01:00

40 lines
988 B
Julia

# This demos how real-time audio manipulation can be done using AudioNodes. To
# run it, hook up some input audio to your default recording device and run the
# script. The demo will run for 10 seconds alternating the node between a muted
# and unmuted state
using AudioIO
type MutableNode <: AudioIO.AudioNode
active::Bool
deactivate_cond::Condition
muted::Bool
function MutableNode(muted::Bool)
new(false, Condition(), muted)
end
end
function MutableNode()
MutableNode(false)
end
import AudioIO.render
function render(node::MutableNode, device_input::AudioIO.AudioBuf, info::AudioIO.DeviceInfo)
return device_input .* !node.muted, AudioIO.is_active(node)
end
function mute(node::MutableNode)
node.muted = true
end
function unmute(node::MutableNode)
node.muted = false
end
mutableNode = MutableNode()
AudioIO.play(mutableNode)
muteTransitions = { true => unmute, false => mute }
for i in 1:10
sleep(1)
muteTransitions[mutableNode.muted](mutableNode)
end