From 81a8503c1dde87a7873bf2c551eb68d18f39982e Mon Sep 17 00:00:00 2001 From: Joris Kraak Date: Tue, 25 Mar 2014 16:02:42 +0100 Subject: [PATCH] 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 --- examples/mutable_streaming_node.jl | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 examples/mutable_streaming_node.jl 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