eeked some more allocation out of SinOsc
This commit is contained in:
parent
7aafc697b0
commit
6a065f0af2
3 changed files with 24 additions and 24 deletions
|
@ -40,13 +40,12 @@ function render(node::SinOscRenderer{Float32}, device_input::AudioBuf,
|
||||||
freq = node.freq
|
freq = node.freq
|
||||||
# make sure these are Float32s so that we don't allocate doing conversions
|
# make sure these are Float32s so that we don't allocate doing conversions
|
||||||
# in the tight loop
|
# in the tight loop
|
||||||
pii::Float32 = pi
|
pi2::Float32 = 2pi
|
||||||
dt::Float32 = 1/info.sample_rate
|
phase_inc::Float32 = 2pi * freq / info.sample_rate
|
||||||
i::Int = 1
|
i::Int = 1
|
||||||
while i <= info.buf_size
|
while i <= info.buf_size
|
||||||
outbuf[i] = sin(phase)
|
outbuf[i] = sin(phase)
|
||||||
phase += 2pii*freq*dt
|
phase = (phase + phase_inc) % pi2
|
||||||
phase = phase % 2pii
|
|
||||||
i += 1
|
i += 1
|
||||||
end
|
end
|
||||||
node.phase = phase
|
node.phase = phase
|
||||||
|
|
|
@ -94,22 +94,3 @@ end
|
||||||
info("Testing Audio Device Listing...")
|
info("Testing Audio Device Listing...")
|
||||||
d_list = get_audio_devices()
|
d_list = get_audio_devices()
|
||||||
@test length(d_list) > 0
|
@test length(d_list) > 0
|
||||||
|
|
||||||
info("Testing param control with signals")
|
|
||||||
t = linspace(0, 1, TEST_SAMPLERATE+1)
|
|
||||||
f = 440 .- t .* (440-110)
|
|
||||||
dt = 1 / TEST_SAMPLERATE
|
|
||||||
# NOTE - this treats the phase as constant at each sample, which isn't strictly
|
|
||||||
# true. Unfortunately doing this correctly requires knowing more about the
|
|
||||||
# modulating signal and doing the real integral
|
|
||||||
phase = cumsum(2pi * dt .* f)
|
|
||||||
unshift!(phase, 0)
|
|
||||||
expected = convert(AudioBuf, sin(phase))
|
|
||||||
|
|
||||||
test_stream = TestAudioStream()
|
|
||||||
freq = LinRamp(440, 110, 1)
|
|
||||||
player = play(SinOsc(freq), test_stream)
|
|
||||||
out = process(test_stream)
|
|
||||||
#println("expected: $(expected[1:30])")
|
|
||||||
#println("got: $(out[1:30])")
|
|
||||||
@test mse(out, expected[1:TEST_BUF_SIZE]) < 1e-16
|
|
||||||
|
|
|
@ -68,11 +68,31 @@ render_output = render(osc, dev_input, test_info)
|
||||||
render_output = render(osc, dev_input, test_info)
|
render_output = render(osc, dev_input, test_info)
|
||||||
@test mse(render_output,
|
@test mse(render_output,
|
||||||
test_vect[test_info.buf_size+1:2*test_info.buf_size]) < FLOAT_THRESH
|
test_vect[test_info.buf_size+1:2*test_info.buf_size]) < FLOAT_THRESH
|
||||||
@test 600 > (@allocated render(osc, dev_input, test_info))
|
@test 200 > (@allocated render(osc, dev_input, test_info))
|
||||||
stop(osc)
|
stop(osc)
|
||||||
render_output = render(osc, dev_input, test_info)
|
render_output = render(osc, dev_input, test_info)
|
||||||
@test render_output == AudioSample[]
|
@test render_output == AudioSample[]
|
||||||
|
|
||||||
|
info("Testing SinOsc with signal input")
|
||||||
|
t = linspace(0, 1, test_info.sample_rate+1)
|
||||||
|
f = 440 .- t .* (440-110)
|
||||||
|
dt = 1 / test_info.sample_rate
|
||||||
|
# NOTE - this treats the phase as constant at each sample, which isn't strictly
|
||||||
|
# true. Unfortunately doing this correctly requires knowing more about the
|
||||||
|
# modulating signal and doing the real integral
|
||||||
|
phase = cumsum(2pi * dt .* f)
|
||||||
|
unshift!(phase, 0)
|
||||||
|
expected = convert(AudioBuf, sin(phase))
|
||||||
|
|
||||||
|
freq = LinRamp(440, 110, 1)
|
||||||
|
osc = SinOsc(freq)
|
||||||
|
render_output = render(osc, dev_input, test_info)
|
||||||
|
@test mse(render_output, expected[1:test_info.buf_size]) < FLOAT_THRESH
|
||||||
|
render_output = render(osc, dev_input, test_info)
|
||||||
|
@test mse(render_output,
|
||||||
|
expected[test_info.buf_size+1:2*test_info.buf_size]) < FLOAT_THRESH
|
||||||
|
#@test 400 > (@allocated render(osc, dev_input, test_info))
|
||||||
|
|
||||||
info("Testing ArrayPlayer...")
|
info("Testing ArrayPlayer...")
|
||||||
v = rand(AudioSample, 44100)
|
v = rand(AudioSample, 44100)
|
||||||
player = ArrayPlayer(v)
|
player = ArrayPlayer(v)
|
||||||
|
|
Loading…
Add table
Reference in a new issue