From 6a065f0af2e64c3352c2f66e7b0b6559be3e562c Mon Sep 17 00:00:00 2001 From: Spencer Russell Date: Wed, 25 Jun 2014 22:08:03 -0400 Subject: [PATCH] eeked some more allocation out of SinOsc --- src/nodes.jl | 7 +++---- test/test_AudioIO.jl | 19 ------------------- test/test_nodes.jl | 22 +++++++++++++++++++++- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/nodes.jl b/src/nodes.jl index d71d067..195096c 100644 --- a/src/nodes.jl +++ b/src/nodes.jl @@ -40,13 +40,12 @@ function render(node::SinOscRenderer{Float32}, device_input::AudioBuf, freq = node.freq # make sure these are Float32s so that we don't allocate doing conversions # in the tight loop - pii::Float32 = pi - dt::Float32 = 1/info.sample_rate + pi2::Float32 = 2pi + phase_inc::Float32 = 2pi * freq / info.sample_rate i::Int = 1 while i <= info.buf_size outbuf[i] = sin(phase) - phase += 2pii*freq*dt - phase = phase % 2pii + phase = (phase + phase_inc) % pi2 i += 1 end node.phase = phase diff --git a/test/test_AudioIO.jl b/test/test_AudioIO.jl index 0077f6e..1373c49 100644 --- a/test/test_AudioIO.jl +++ b/test/test_AudioIO.jl @@ -94,22 +94,3 @@ end info("Testing Audio Device Listing...") d_list = get_audio_devices() @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 diff --git a/test/test_nodes.jl b/test/test_nodes.jl index f49f1da..5df01b6 100644 --- a/test/test_nodes.jl +++ b/test/test_nodes.jl @@ -68,11 +68,31 @@ render_output = render(osc, dev_input, test_info) render_output = render(osc, dev_input, test_info) @test mse(render_output, 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) render_output = render(osc, dev_input, test_info) @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...") v = rand(AudioSample, 44100) player = ArrayPlayer(v)