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
This commit is contained in:
Joris Kraak 2014-03-25 16:02:42 +01:00
parent 7831578955
commit 81a8503c1d

View file

@ -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