summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2012-04-18 00:03:46 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2012-04-18 00:03:46 +0200
commitd572febd57e507b7d04dfa2111f048f11dfca4d1 (patch)
treef247822132494cb535decd3a5a59d62f60488fc9
parentc5ab57c1494f96a063ae6ea7744221db4d659ab4 (diff)
downloaddigitale-debutanten-d572febd57e507b7d04dfa2111f048f11dfca4d1.tar.gz
fixed SampOsc and integrated it as oscillator into lfo
-rw-r--r--lfo.ck33
-rw-r--r--lib/SampOsc.ck29
2 files changed, 47 insertions, 15 deletions
diff --git a/lfo.ck b/lfo.ck
index a988dc0..c784f48 100644
--- a/lfo.ck
+++ b/lfo.ck
@@ -1,12 +1,14 @@
/*
* Configurable LFOs
*/
-UGen @lfo[2]; // FIXME: ChucK bug prevents elegant initialization
+UGen @lfo[3]; // FIXME: ChucK bug prevents elegant initialization with [new ..., ...]
new SinOsc @=> lfo[0];
new PulseOsc @=> lfo[1];
+new SampOsc @=> lfo[2];
+10 => lfo[2].gain; /* preamp, to get value range 0 to 1000 */
Step lfo_freq;
-for (0 => int i; i < lfo.cap(); i++)
+for (0 => int i; i < 2 /*lfo.cap()*/; i++)
lfo_freq => lfo[i];
0 => int cur_lfo;
@@ -35,6 +37,13 @@ change_lfo(int new_lfo)
lfo[cur_lfo] =< lfo_gain;
/* rechuck lfo */
lfo[new_lfo => cur_lfo] => lfo_gain;
+
+ if (cur_lfo == 2 /* SampOsc */) {
+ /* switch off base freq */
+ 0 => base.gain;
+ } else {
+ 1 => base.gain;
+ }
}
/*
@@ -63,18 +72,24 @@ while (min => now) {
if (channel == 0 && cmd == 0xB0) {
<<< "Channel:", channel, "Command:", cmd, "Controller:", msg.data2, "Value:", value >>>;
- if (msg.data2 == 22)
+ if (msg.data2 == 22) {
value => rev.gain;
- else if (msg.data2 == 13)
+ } else if (msg.data2 == 13) {
100 + value*900 => base.next;
- else if (msg.data2 == 12)
+ /* base freq slider is sample rate for SampOsc */
+ value*2 => (lfo[2] $ SampOsc).rate;
+ } else if (msg.data2 == 12) {
value*100 => lfo_gain.gain;
- else if (msg.data2 == 21)
- value*20 => lfo_freq.next;
- else if (msg.data2 == 31)
+ } else if (msg.data2 == 21) {
+ /* setting lfo_freq does not influence SampOsc! */
+ value*20 => lfo_freq.next => (lfo[2] $ SampOsc).freq;
+ } else if (msg.data2 == 31) {
change_lfo(0);
- else if (msg.data2 == 41)
+ } else if (msg.data2 == 41) {
change_lfo(1);
+ } else if (msg.data2 == 30) {
+ change_lfo(2);
+ }
/*else if (msg.data2 == 9)
value $ int => lfo.harmonics;*/
}
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;
}