adds LinRamp node
This commit is contained in:
parent
a334a44a2e
commit
bf2e5bfb84
2 changed files with 42 additions and 0 deletions
30
src/nodes.jl
30
src/nodes.jl
|
@ -178,3 +178,33 @@ end
|
|||
typealias AudioInput AudioNode{InputRenderer}
|
||||
AudioInput(channel::Int) = AudioInput(InputRenderer(channel))
|
||||
export AudioInput
|
||||
|
||||
#### Ramp ####
|
||||
|
||||
type LinRampRenderer <: AudioRenderer
|
||||
start::AudioSample
|
||||
finish::AudioSample
|
||||
dur::Float32
|
||||
end
|
||||
|
||||
typealias LinRamp AudioNode{LinRampRenderer}
|
||||
function LinRamp(start::Real, finish::Real, dur::Real)
|
||||
LinRamp(LinRampRenderer(start, finish, dur))
|
||||
end
|
||||
export LinRamp
|
||||
|
||||
|
||||
function render(node::LinRampRenderer, device_input::AudioBuf, info::DeviceInfo)
|
||||
ramp_samples = int(node.dur * info.sample_rate)
|
||||
block_samples = min(ramp_samples, info.buf_size)
|
||||
out_block = Array(AudioSample, block_samples)
|
||||
for i in 1:block_samples
|
||||
out_block[i] = node.start + ((i-1) / ramp_samples) *
|
||||
(node.finish - node.start)
|
||||
end
|
||||
node.dur -= block_samples / info.sample_rate
|
||||
node.start += block_samples / ramp_samples * (node.finish - node.start)
|
||||
|
||||
return out_block
|
||||
end
|
||||
|
||||
|
|
|
@ -91,3 +91,15 @@ info("Testing Gain...")
|
|||
gained = TestNode() * 0.75
|
||||
render_output = render(gained, dev_input, test_info)
|
||||
@test render_output == 0.75 * AudioSample[1:test_info.buf_size]
|
||||
|
||||
info("Testing LinRamp...")
|
||||
ramp = LinRamp(0.25, 0.80, 1)
|
||||
expected = convert(AudioBuf, linspace(0.25, 0.80, test_info.sample_rate+1))
|
||||
render_output = render(ramp, dev_input, test_info)
|
||||
@test render_output == expected[1:test_info.buf_size]
|
||||
# TODO: there seems to be some slight error in the 2nd block. I THINK it's just
|
||||
# floating point stuff, but we should probably check to be sure
|
||||
#render_output = render(ramp, dev_input, test_info)
|
||||
#println("expected: $(expected[test_info.buf_size+1:test_info.buf_size+10])")
|
||||
#println("output: $(render_output[1:10])")
|
||||
#@test render_output == expected[(test_info.buf_size+1):(2*test_info.buf_size)]
|
||||
|
|
Loading…
Reference in a new issue