PortAudio.jl/src/AudioIO.jl

79 lines
1.6 KiB
Julia
Raw Normal View History

module AudioIO
2013-12-11 20:18:36 -05:00
# export the basic API
export play, stop, get_audio_devices
2013-12-21 20:39:47 -05:00
# default stream used when none is given
_stream = nothing
2013-12-21 20:39:47 -05:00
################## Types ####################
typealias AudioSample Float32
# A frame of audio, possibly multi-channel
typealias AudioBuf Array{AudioSample}
# A node in the render tree
abstract AudioNode
# A stream of audio (for instance that writes to hardware)
# All AudioStream subtypes should have a mixer and info field
abstract AudioStream
# Info about the hardware device
type DeviceInfo
sample_rate::Integer
buf_size::Integer
end
include("nodes.jl")
include("portaudio.jl")
2014-01-06 11:24:53 -05:00
include("sndfile.jl")
2013-12-13 02:17:21 -05:00
############ Exported Functions #############
# Play an AudioNode by adding it as an input to the root mixer node
function play(node::AudioNode, stream::AudioStream)
2014-01-13 19:19:56 -05:00
activate(node)
add_input(stream.mixer, node)
return node
end
# If the stream is not given, use the default global PortAudio stream
function play(node::AudioNode)
global _stream
if _stream == nothing
_stream = PortAudioStream()
end
play(node, _stream)
end
function stop(node::AudioNode)
2014-01-13 19:19:56 -05:00
deactivate(node)
node
end
function activate(node::AudioNode)
node.active = true
end
function deactivate(node::AudioNode)
node.active = false
2014-01-13 19:19:56 -05:00
notify(node.deactivate_cond)
end
function is_active(node::AudioNode)
node.active
end
function Base.wait(node::AudioNode)
if is_active(node)
wait(node.deactivate_cond)
end
end
function get_audio_devices()
return get_portaudio_devices()
end
end # module AudioIO