diff --git a/examples/mutable_streaming_node.jl b/examples/mutable_streaming_node.jl new file mode 100644 index 0000000..ba6b681 --- /dev/null +++ b/examples/mutable_streaming_node.jl @@ -0,0 +1,40 @@ +# 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