Permalink
Browse files

adding Trem extends Chugen and Tremolo sporks update() at sample rate

  • Loading branch information...
1 parent e5be2fe commit 3d5a74689b5198f2b5f3cef8e6c2be37b998e069 Michael Heuer committed Sep 20, 2012
Showing with 334 additions and 0 deletions.
  1. +63 −0 Trem.ck
  2. +72 −0 Tremolo.ck
  3. +98 −0 examples/tremExample.ck
  4. +99 −0 examples/tremoloExample.ck
  5. +2 −0 import.ck
View
@@ -0,0 +1,63 @@
+/*
+
+ LiCK Library for ChucK.
+ Copyright (c) 2007-2012 held jointly by the individual authors.
+
+ This file is part of LiCK.
+
+ LiCK is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ LiCK is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LiCK. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+public class Trem extends Chugen
+{
+ SinOsc sinLfo;
+ SqrOsc sqrLfo;
+ TriOsc triLfo;
+ 0.33 => float sinMix;
+ 0.33 => float sqrMix;
+ 0.33 => float triMix;
+
+ {
+ sinLfo => blackhole;
+ sqrLfo => blackhole;
+ triLfo => blackhole;
+ }
+
+ fun float rate(float rate)
+ {
+ rate => sinLfo.freq;
+ rate => sqrLfo.freq;
+ rate => triLfo.freq;
+ }
+
+ fun float depth(float depth)
+ {
+ depth * sinMix => sinLfo.gain;
+ depth * sqrMix => sqrLfo.gain;
+ depth * triMix => triLfo.gain;
+ }
+
+ fun float tick(float in)
+ {
+ sinLfo.last() * sinMix + sqrLfo.last() * sqrMix + triLfo.last() * triMix => float last;
+ interp(last, -1.0, 1.0, 0.0, 1.0) => gain;
+ return in;
+ }
+
+ fun float interp(float value, float sourceMin, float sourceMax, float targetMin, float targetMax)
+ {
+ return targetMin + (targetMax - targetMin) * ((value - sourceMin) / (sourceMax - sourceMin));
+ }
+}
View
@@ -0,0 +1,72 @@
+/*
+
+ LiCK Library for ChucK.
+ Copyright (c) 2007-2012 held jointly by the individual authors.
+
+ This file is part of LiCK.
+
+ LiCK is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ LiCK is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LiCK. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+public class Tremolo
+{
+ Gain input;
+ Gain tremolo;
+ Gain output;
+ SinOsc sinLfo;
+ SqrOsc sqrLfo;
+ TriOsc triLfo;
+ 0.33 => float sinMix;
+ 0.33 => float sqrMix;
+ 0.33 => float triMix;
+
+ {
+ input => tremolo => output;
+ sinLfo => blackhole;
+ sqrLfo => blackhole;
+ triLfo => blackhole;
+
+ spork ~ update();
+ }
+
+ fun float rate(float rate)
+ {
+ rate => sinLfo.freq;
+ rate => sqrLfo.freq;
+ rate => triLfo.freq;
+ }
+
+ fun float depth(float depth)
+ {
+ depth * sinMix => sinLfo.gain;
+ depth * sqrMix => sqrLfo.gain;
+ depth * triMix => triLfo.gain;
+ }
+
+ fun void update()
+ {
+ while (true)
+ {
+ 1::samp => now;
+ sinLfo.last() * sinMix + sqrLfo.last() * sqrMix + triLfo.last() * triMix => float last;
+ interp(last, -1.0, 1.0, 0.0, 1.0) => tremolo.gain;
+ }
+ }
+
+ fun float interp(float value, float sourceMin, float sourceMax, float targetMin, float targetMax)
+ {
+ return targetMin + (targetMax - targetMin) * ((value - sourceMin) / (sourceMax - sourceMin));
+ }
+}
@@ -0,0 +1,98 @@
+
+Trem trem;
+1.0 => float depth;
+1.0 => float rate;
+
+BeeThree bt;
+220.0 => bt.freq;
+bt.noteOff(1.0);
+
+bt => trem => dac;
+
+500::ms => now;
+
+<<<trem.sinMix, trem.sqrMix, trem.triMix>>>;
+for (0 => int i; i < 4; i++)
+{
+ rate => trem.rate;
+ for (0 => int j; j < 10; j++)
+ {
+ 8.0 * (j+1)/10.0 => depth;
+ depth => trem.depth;
+
+ <<<"trem rate", rate, "depth", depth>>>;
+ bt.noteOn(1.0);
+ 800::ms => now;
+ bt.noteOff(1.0);
+ 200::ms => now;
+ }
+ 2.0 +=> rate;
+}
+
+1.0 => rate;
+1.0 => trem.sinMix;
+0.0 => trem.sqrMix;
+0.0 => trem.triMix;
+<<<trem.sinMix, trem.sqrMix, trem.triMix>>>;
+for (0 => int i; i < 4; i++)
+{
+ rate => trem.rate;
+ for (0 => int j; j < 10; j++)
+ {
+ 8.0 * (j+1)/10.0 => depth;
+ depth => trem.depth;
+
+ <<<"trem rate", rate, "depth", depth>>>;
+ bt.noteOn(1.0);
+ 800::ms => now;
+ bt.noteOff(1.0);
+ 200::ms => now;
+ }
+ 2.0 +=> rate;
+}
+
+1.0 => rate;
+0.0 => trem.sinMix;
+1.0 => trem.sqrMix;
+0.0 => trem.triMix;
+<<<trem.sinMix, trem.sqrMix, trem.triMix>>>;
+for (0 => int i; i < 4; i++)
+{
+ rate => trem.rate;
+ for (0 => int j; j < 10; j++)
+ {
+ 8.0 * (j+1)/10.0 => depth;
+ depth => trem.depth;
+
+ <<<"trem rate", rate, "depth", depth>>>;
+ bt.noteOn(1.0);
+ 800::ms => now;
+ bt.noteOff(1.0);
+ 200::ms => now;
+ }
+ 2.0 +=> rate;
+}
+
+1.0 => rate;
+0.0 => trem.sinMix;
+0.0 => trem.sqrMix;
+1.0 => trem.triMix;
+<<<trem.sinMix, trem.sqrMix, trem.triMix>>>;
+for (0 => int i; i < 4; i++)
+{
+ rate => trem.rate;
+ for (0 => int j; j < 10; j++)
+ {
+ 8.0 * (j+1)/10.0 => depth;
+ depth => trem.depth;
+
+ <<<"trem rate", rate, "depth", depth>>>;
+ bt.noteOn(1.0);
+ 800::ms => now;
+ bt.noteOff(1.0);
+ 200::ms => now;
+ }
+ 2.0 +=> rate;
+}
+
+<<<"done">>>;
@@ -0,0 +1,99 @@
+
+Tremolo tremolo;
+1.0 => float depth;
+1.0 => float rate;
+
+BeeThree bt;
+220.0 => bt.freq;
+bt.noteOff(1.0);
+
+bt => tremolo.input;
+tremolo.output => dac;
+
+500::ms => now;
+
+<<<tremolo.sinMix, tremolo.sqrMix, tremolo.triMix>>>;
+for (0 => int i; i < 4; i++)
+{
+ rate => tremolo.rate;
+ for (0 => int j; j < 10; j++)
+ {
+ 8.0 * (j+1)/10.0 => depth;
+ depth => tremolo.depth;
+
+ <<<"tremolo rate", rate, "depth", depth>>>;
+ bt.noteOn(1.0);
+ 800::ms => now;
+ bt.noteOff(1.0);
+ 200::ms => now;
+ }
+ 2.0 +=> rate;
+}
+
+1.0 => rate;
+1.0 => tremolo.sinMix;
+0.0 => tremolo.sqrMix;
+0.0 => tremolo.triMix;
+<<<tremolo.sinMix, tremolo.sqrMix, tremolo.triMix>>>;
+for (0 => int i; i < 4; i++)
+{
+ rate => tremolo.rate;
+ for (0 => int j; j < 10; j++)
+ {
+ 8.0 * (j+1)/10.0 => depth;
+ depth => tremolo.depth;
+
+ <<<"tremolo rate", rate, "depth", depth>>>;
+ bt.noteOn(1.0);
+ 800::ms => now;
+ bt.noteOff(1.0);
+ 200::ms => now;
+ }
+ 2.0 +=> rate;
+}
+
+1.0 => rate;
+0.0 => tremolo.sinMix;
+1.0 => tremolo.sqrMix;
+0.0 => tremolo.triMix;
+<<<tremolo.sinMix, tremolo.sqrMix, tremolo.triMix>>>;
+for (0 => int i; i < 4; i++)
+{
+ rate => tremolo.rate;
+ for (0 => int j; j < 10; j++)
+ {
+ 8.0 * (j+1)/10.0 => depth;
+ depth => tremolo.depth;
+
+ <<<"tremolo rate", rate, "depth", depth>>>;
+ bt.noteOn(1.0);
+ 800::ms => now;
+ bt.noteOff(1.0);
+ 200::ms => now;
+ }
+ 2.0 +=> rate;
+}
+
+1.0 => rate;
+0.0 => tremolo.sinMix;
+0.0 => tremolo.sqrMix;
+1.0 => tremolo.triMix;
+<<<tremolo.sinMix, tremolo.sqrMix, tremolo.triMix>>>;
+for (0 => int i; i < 4; i++)
+{
+ rate => tremolo.rate;
+ for (0 => int j; j < 10; j++)
+ {
+ 8.0 * (j+1)/10.0 => depth;
+ depth => tremolo.depth;
+
+ <<<"tremolo rate", rate, "depth", depth>>>;
+ bt.noteOn(1.0);
+ 800::ms => now;
+ bt.noteOff(1.0);
+ 200::ms => now;
+ }
+ 2.0 +=> rate;
+}
+
+<<<"done">>>;
View
@@ -244,6 +244,8 @@ Machine.add("RolandTr909.ck");
Machine.add("BigMono.ck");
// delay stuff
+Machine.add("Trem.ck");
+Machine.add("Tremolo.ck");
Machine.add("MonoDelay.ck");
Machine.add("MonoDelayA.ck");
Machine.add("MonoDelayL.ck");

0 comments on commit 3d5a746

Please sign in to comment.