now exporting nodes and can play SinOsc

This commit is contained in:
Spencer Russell 2013-12-22 17:27:29 -05:00
parent 7806ead4ec
commit 3a29b40c97

View file

@ -1,7 +1,11 @@
module PortAudio module PortAudio
# simple interface
export play export play
# AudioNodes
export SinOsc, AudioMixer, ArrayPlayer, AudioInput
typealias PaTime Cdouble typealias PaTime Cdouble
typealias PaError Cint typealias PaError Cint
typealias PaSampleFormat Culong typealias PaSampleFormat Culong
@ -47,10 +51,10 @@ end
# Generates a sin tone at the given frequency # Generates a sin tone at the given frequency
type SinOsc <: AudioNode type SinOsc <: AudioNode
freq::FloatingPoint freq::Real
phase::FloatingPoint phase::FloatingPoint
function SinOsc(freq::FloatingPoint) function SinOsc(freq::Real)
new(freq, 0.0) new(freq, 0.0)
end end
end end
@ -119,16 +123,25 @@ end
############ Exported Functions ############# ############ Exported Functions #############
function register(node::AudioNode, stream::AudioStream) function play(node::AudioNode, stream::AudioStream)
stream.root_node = node stream.root_node = node
end end
function play(node::AudioNode)
global _stream
if _stream == nothing
_stream = open_stream()
end
play(node, _stream)
end
function play(arr::AudioBuf, stream::AudioStream) function play(arr::AudioBuf, stream::AudioStream)
# TODO: use a mixer as the root node so multiple playbacks get mixed
player = ArrayPlayer(arr) player = ArrayPlayer(arr)
register(player, stream) register(player, stream)
end end
function play(arr) function play(arr::AudioBuf)
global _stream global _stream
if _stream == nothing if _stream == nothing
_stream = open_stream() _stream = open_stream()