From d572febd57e507b7d04dfa2111f048f11dfca4d1 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Wed, 18 Apr 2012 00:03:46 +0200 Subject: fixed SampOsc and integrated it as oscillator into lfo --- lib/SampOsc.ck | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/SampOsc.ck b/lib/SampOsc.ck index bc5feda..6bbb3a9 100644 --- a/lib/SampOsc.ck +++ b/lib/SampOsc.ck @@ -4,6 +4,7 @@ */ public class SampOsc extends SndBuf { 1 => float __freq; /* pseudo-private */ + fun float freq(float f) { return f => __freq; @@ -13,14 +14,30 @@ public class SampOsc extends SndBuf { return __freq; } - /* FIXME: not independant from cwd when instantiated */ - "lib/pulse.wav" => read; - 1 => rate; - + /* + * Wait till next loop point but no longer than 100::ms, + * so frequency changes get applied with a maximum of 100::ms latency. + * NOTE: Due to a ChucK bug, simply killing and restarting the shred + * does not work very well. + */ fun void __loop() /* pseudo-private */ { - while (second/__freq => now) - 0 => pos; + now => time last_trigger; + + while (second/__freq => dur interval) { + if (last_trigger+interval - now > 100::ms) { + 100::ms => now; + } else { + interval +=> last_trigger; + if (last_trigger >= now) + last_trigger => now; + 0 => pos; + } + } } spork ~ __loop(); + + /* FIXME: not independant from cwd when instantiated */ + "lib/pulse.wav" => read; + 1 => rate; } -- cgit v1.2.3