adds Gain node with * operator
This commit is contained in:
parent
0d84cb409b
commit
e48c6361fd
4 changed files with 36 additions and 7 deletions
|
@ -19,6 +19,10 @@ abstract AudioNode
|
|||
# All AudioStream subtypes should have a mixer and info field
|
||||
abstract AudioStream
|
||||
|
||||
# An audio interface is usually a physical sound card, but could
|
||||
# be anything you'd want to connect a stream to
|
||||
abstract AudioInterface
|
||||
|
||||
# Info about the hardware device
|
||||
type DeviceInfo
|
||||
sample_rate::Integer
|
||||
|
@ -28,6 +32,7 @@ end
|
|||
include("nodes.jl")
|
||||
include("portaudio.jl")
|
||||
include("sndfile.jl")
|
||||
include("operators.jl")
|
||||
|
||||
############ Exported Functions #############
|
||||
|
||||
|
|
26
src/nodes.jl
26
src/nodes.jl
|
@ -1,9 +1,8 @@
|
|||
export SinOsc, AudioMixer, ArrayPlayer, AudioInput
|
||||
|
||||
#### SinOsc ####
|
||||
|
||||
# Generates a sin tone at the given frequency
|
||||
|
||||
export SinOsc
|
||||
type SinOsc <: AudioNode
|
||||
active::Bool
|
||||
deactivate_cond::Condition
|
||||
|
@ -22,6 +21,26 @@ function render(node::SinOsc, device_input::AudioBuf, info::DeviceInfo)
|
|||
return sin(phase), is_active(node)
|
||||
end
|
||||
|
||||
#### Gain ####
|
||||
export Gain
|
||||
type Gain <: AudioNode
|
||||
active::Bool
|
||||
deactivate_cond::Condition
|
||||
in_node::AudioNode
|
||||
gain::Float32
|
||||
|
||||
function Gain(in_node::AudioNode, gain::Real)
|
||||
new(false, Condition(), in_node, gain)
|
||||
end
|
||||
end
|
||||
|
||||
function render(node::Gain, device_input::AudioBuf, info::DeviceInfo)
|
||||
input, child_active = render(node.in_node, device_input, info)
|
||||
# TODO: should we check the active flag of the input?
|
||||
return input .* node.gain, is_active(node)
|
||||
end
|
||||
|
||||
|
||||
#### AudioMixer ####
|
||||
|
||||
# Mixes a set of inputs equally
|
||||
|
@ -30,6 +49,7 @@ end
|
|||
typealias MaybeAudioNode Union(AudioNode, Nothing)
|
||||
const MAX_MIXER_INPUTS = 32
|
||||
|
||||
export AudioMixer
|
||||
type AudioMixer <: AudioNode
|
||||
active::Bool
|
||||
deactivate_cond::Condition
|
||||
|
@ -96,6 +116,7 @@ end
|
|||
|
||||
# Plays a AudioBuf by rendering it out piece-by-piece
|
||||
|
||||
export ArrayPlayer
|
||||
type ArrayPlayer <: AudioNode
|
||||
active::Bool
|
||||
deactivate_cond::Condition
|
||||
|
@ -154,6 +175,7 @@ end
|
|||
|
||||
# Renders incoming audio input from the hardware
|
||||
|
||||
export AudioInput
|
||||
type AudioInput <: AudioNode
|
||||
active::Bool
|
||||
deactivate_cond::Condition
|
||||
|
|
2
src/operators.jl
Normal file
2
src/operators.jl
Normal file
|
@ -0,0 +1,2 @@
|
|||
*(node::AudioNode, coef::Real) = Gain(node, coef)
|
||||
*(coef::Real, node::AudioNode) = Gain(node, coef)
|
|
@ -135,7 +135,7 @@ type PaHostApiInfo
|
|||
defaultOutputDevice::PaDeviceIndex
|
||||
end
|
||||
|
||||
type AudioDevice
|
||||
type PortAudioInterface <: AudioInterface
|
||||
name::String
|
||||
host_api::String
|
||||
max_input_channels::Int
|
||||
|
@ -152,10 +152,10 @@ function get_portaudio_devices()
|
|||
init_portaudio()
|
||||
device_count = ccall((:Pa_GetDeviceCount, "libportaudio"), PaDeviceIndex, ())
|
||||
pa_devices = [get_device_info(i) for i in 0:(device_count - 1)]
|
||||
[AudioDevice(bytestring(d.name),
|
||||
bytestring(get_host_api_info(d.host_api).name),
|
||||
d.max_input_channels,
|
||||
d.max_output_channels)
|
||||
[PortAudioInterface(bytestring(d.name),
|
||||
bytestring(get_host_api_info(d.host_api).name),
|
||||
d.max_input_channels,
|
||||
d.max_output_channels)
|
||||
for d in pa_devices]
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue