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
|
# All AudioStream subtypes should have a mixer and info field
|
||||||
abstract AudioStream
|
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
|
# Info about the hardware device
|
||||||
type DeviceInfo
|
type DeviceInfo
|
||||||
sample_rate::Integer
|
sample_rate::Integer
|
||||||
|
@ -28,6 +32,7 @@ end
|
||||||
include("nodes.jl")
|
include("nodes.jl")
|
||||||
include("portaudio.jl")
|
include("portaudio.jl")
|
||||||
include("sndfile.jl")
|
include("sndfile.jl")
|
||||||
|
include("operators.jl")
|
||||||
|
|
||||||
############ Exported Functions #############
|
############ Exported Functions #############
|
||||||
|
|
||||||
|
|
26
src/nodes.jl
26
src/nodes.jl
|
@ -1,9 +1,8 @@
|
||||||
export SinOsc, AudioMixer, ArrayPlayer, AudioInput
|
|
||||||
|
|
||||||
#### SinOsc ####
|
#### SinOsc ####
|
||||||
|
|
||||||
# Generates a sin tone at the given frequency
|
# Generates a sin tone at the given frequency
|
||||||
|
|
||||||
|
export SinOsc
|
||||||
type SinOsc <: AudioNode
|
type SinOsc <: AudioNode
|
||||||
active::Bool
|
active::Bool
|
||||||
deactivate_cond::Condition
|
deactivate_cond::Condition
|
||||||
|
@ -22,6 +21,26 @@ function render(node::SinOsc, device_input::AudioBuf, info::DeviceInfo)
|
||||||
return sin(phase), is_active(node)
|
return sin(phase), is_active(node)
|
||||||
end
|
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 ####
|
#### AudioMixer ####
|
||||||
|
|
||||||
# Mixes a set of inputs equally
|
# Mixes a set of inputs equally
|
||||||
|
@ -30,6 +49,7 @@ end
|
||||||
typealias MaybeAudioNode Union(AudioNode, Nothing)
|
typealias MaybeAudioNode Union(AudioNode, Nothing)
|
||||||
const MAX_MIXER_INPUTS = 32
|
const MAX_MIXER_INPUTS = 32
|
||||||
|
|
||||||
|
export AudioMixer
|
||||||
type AudioMixer <: AudioNode
|
type AudioMixer <: AudioNode
|
||||||
active::Bool
|
active::Bool
|
||||||
deactivate_cond::Condition
|
deactivate_cond::Condition
|
||||||
|
@ -96,6 +116,7 @@ end
|
||||||
|
|
||||||
# Plays a AudioBuf by rendering it out piece-by-piece
|
# Plays a AudioBuf by rendering it out piece-by-piece
|
||||||
|
|
||||||
|
export ArrayPlayer
|
||||||
type ArrayPlayer <: AudioNode
|
type ArrayPlayer <: AudioNode
|
||||||
active::Bool
|
active::Bool
|
||||||
deactivate_cond::Condition
|
deactivate_cond::Condition
|
||||||
|
@ -154,6 +175,7 @@ end
|
||||||
|
|
||||||
# Renders incoming audio input from the hardware
|
# Renders incoming audio input from the hardware
|
||||||
|
|
||||||
|
export AudioInput
|
||||||
type AudioInput <: AudioNode
|
type AudioInput <: AudioNode
|
||||||
active::Bool
|
active::Bool
|
||||||
deactivate_cond::Condition
|
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
|
defaultOutputDevice::PaDeviceIndex
|
||||||
end
|
end
|
||||||
|
|
||||||
type AudioDevice
|
type PortAudioInterface <: AudioInterface
|
||||||
name::String
|
name::String
|
||||||
host_api::String
|
host_api::String
|
||||||
max_input_channels::Int
|
max_input_channels::Int
|
||||||
|
@ -152,10 +152,10 @@ function get_portaudio_devices()
|
||||||
init_portaudio()
|
init_portaudio()
|
||||||
device_count = ccall((:Pa_GetDeviceCount, "libportaudio"), PaDeviceIndex, ())
|
device_count = ccall((:Pa_GetDeviceCount, "libportaudio"), PaDeviceIndex, ())
|
||||||
pa_devices = [get_device_info(i) for i in 0:(device_count - 1)]
|
pa_devices = [get_device_info(i) for i in 0:(device_count - 1)]
|
||||||
[AudioDevice(bytestring(d.name),
|
[PortAudioInterface(bytestring(d.name),
|
||||||
bytestring(get_host_api_info(d.host_api).name),
|
bytestring(get_host_api_info(d.host_api).name),
|
||||||
d.max_input_channels,
|
d.max_input_channels,
|
||||||
d.max_output_channels)
|
d.max_output_channels)
|
||||||
for d in pa_devices]
|
for d in pa_devices]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue