Permalink
Browse files

dynamical-system added

  • Loading branch information...
1 parent 93cceee commit cba70b50e1abe43f299a021dbf541d10550828db @hoch hoch committed Nov 1, 2012
@@ -0,0 +1,60 @@
+// dyn-del-ins.ck
+// demo of dynamical system tones playing preset pitch sequence
+
+public class MapTick
+{
+
+ Gain x => Gain x1;
+ x => Gain x2;
+ x => Gain x2b => x2;
+ 3 => x1.op;
+ 3 => x2.op;
+// clarinet-like pitches, envelope moved to map
+ Step c => Envelope e => Gain a0 => Gain out;
+ c => Gain a1 => x1 => out;
+ c => Gain a2 => x2 => out;
+
+ out => dac => DelayL d => OneZero lpf => Gain loop => x;
+
+ fun void startNote( float f, float a)
+ {
+ 1.0::second/f => d.delay;
+ a => a0.gain;
+ -0.7 => a1.gain;
+ 2.0 => a2.gain;
+ 0.95 => loop.gain;
+ 150::ms => dur t => e.duration;
+ e.keyOn();
+ }
+ fun void stopNote()
+ {
+ 0.0 => loop.gain;
+ e.keyOff();
+ }
+}
+
+// to write soundfile specify file name
+string writeName;
+"/zap/dyn.wav" => writeName;
+if (writeName!="")
+{
+ dac => WvOut o => blackhole;
+ writeName => o.wavFilename;
+}
+
+MapTick ins;
+// our notes
+[ 61, 63, 65, 66, 68, 66, 65, 63 , 65, 66, 68, 66, 65, 63 , 65, 66, 68, 66, 65, 63 ] @=> int notes[];
+notes.cap() => int numTones;
+
+for( int ctr; ctr < numTones; ctr++ )
+{
+ (((ctr)$float)/(numTones-1$float)) => float ramp;
+ -0.4 + (ramp * (-0.5 - -0.4)) => float a0;
+ <<< "a0:", a0 >>>;
+ notes[ctr] => int keynum;
+ ins.startNote(Std.mtof(keynum),a0);
+ 250::ms => now;
+ ins.stopNote();
+100::ms => now;
+}
@@ -0,0 +1,60 @@
+// dyn-del-ins.ck
+// demo of dynamical system tones, same as dyn-ins.ck
+// but with delay and low-pass filter in feedback
+
+public class MapTick
+{
+
+ Gain x => Gain x1;
+ x => Gain x2;
+ x => Gain x2b => x2;
+ 3 => x1.op;
+ 3 => x2.op;
+ Step c;
+ c => Gain a0 => Gain out;
+ c => Gain a1 => x1 => out;
+ c => Gain a2 => x2 => out;
+
+ out => Envelope e => dac => DelayL d => OneZero lpf => Gain loop => x;
+
+ fun void startNote( float f)
+ {
+// set delay to constant, 500 Hz = 2 msec
+ 2.0::ms => d.delay;
+ f => a0.gain;
+ -0.7 => a1.gain;
+ 2.0 => a2.gain;
+ 0.95 => loop.gain;
+ 10::ms => dur t => e.duration;
+ e.keyOn();
+ }
+ fun void stopNote()
+ {
+ e.keyOff();
+ }
+}
+
+// to write soundfile specify file name
+string writeName;
+"/zap/dyn.wav" => writeName;
+if (writeName!="")
+{
+ dac => WvOut o => blackhole;
+ writeName => o.wavFilename;
+}
+
+
+MapTick ins;
+
+20 => int numTones;
+
+for( int ctr; ctr < numTones; ctr++ )
+{
+ (((ctr)$float)/(numTones-1$float)) => float ramp;
+ -0.3 + (ramp * (-0.7 - -0.3)) => float a0;
+ <<< "a0:", a0 >>>;
+ ins.startNote(a0);
+ 400::ms => now;
+ ins.stopNote();
+ 100::ms => now;
+}
@@ -0,0 +1,70 @@
+// dyn-ins.ck
+// demo of dynamical system tones
+
+// uses the same iterated map on a second-order
+// polynomial function as in dyn-notes.ck
+
+class MapTick
+{
+// implement the map in unit generaros
+// a0 + (a1 * x) + (a2 * x * x);
+// chuck-1.2.0.8 disallows duplicate input connections
+
+ Gain x => Gain x1;
+ x => Gain x2;
+ x => Gain x2b => x2;
+
+// multiply inputs
+ 3 => x1.op;
+ 3 => x2.op;
+
+ Step c; // provide a constant signal of 1.0
+ c => Gain a0 => Gain out;
+ c => Gain a1 => x1 => out;
+ c => Gain a2 => x2 => out;
+
+ out => Envelope e => dac => x;
+
+ fun void startNote( float c)
+ // modify a0 coefficient
+ {
+ c => a0.gain;
+ -0.7 => a1.gain;
+ 2.0 => a2.gain;
+ e.keyOn();
+ 50::ms => dur t => e.duration;
+ }
+ fun void stopNote()
+ {
+ e.keyOff();
+ }
+}
+
+// to write soundfile specify file name
+string writeName;
+"/zap/dyn.wav" => writeName;
+if (writeName!="")
+{
+ dac => WvOut o => blackhole;
+ writeName => o.wavFilename;
+}
+
+
+// how many tones to play in the demo
+15 => int numTones;
+// instantiate one MapTick object, call it "ins"
+MapTick ins;
+
+// loop by one tone at a time
+for( int ctr; ctr < numTones; ctr++ )
+{
+// calculate a ramp that increases over the demo
+ (((ctr)$float)/(numTones-1$float)) => float ramp;
+// ramp the a0 coefficient and print
+ -0.3 + (ramp * (-0.7 - -0.3)) => float a0;
+ <<< "a0:", a0 >>>;
+ ins.startNote(a0);
+ 400::ms => now;
+ ins.stopNote();
+ 100::ms => now;
+}
@@ -0,0 +1,71 @@
+// dyn-notes-ins.ck
+// use same dynamical system for tones as for pitches
+// based on dyn-notes.ck and dyn-del-ins.ck
+
+fun float map( float x, float a0)
+{
+ -0.7 => float a1;
+ 2.0 => float a2;
+ return a0 + (a1 * x) + (a2 * x * x);
+}
+
+public class MapTick
+{
+
+ Gain x => Gain x1;
+ x => Gain x2;
+ x => Gain x2b => x2;
+ 3 => x1.op;
+ 3 => x2.op;
+// clarinet-like pitches, envelope moved to map
+ Step c => Envelope e => Gain a0 => Gain out;
+ c => Gain a1 => x1 => out;
+ c => Gain a2 => x2 => out;
+
+ out => dac => DelayL d => OneZero lpf => Gain loop => x;
+
+ fun void startNote( float f, float a)
+ {
+ 1.0::second/f => d.delay;
+ a => a0.gain;
+ -0.7 => a1.gain;
+ 2.0 => a2.gain;
+ 0.95 => loop.gain;
+ 150::ms => dur t => e.duration;
+ e.keyOn();
+ }
+ fun void stopNote()
+ {
+ 0.0 => loop.gain;
+ e.keyOff();
+ }
+}
+
+// to write soundfile specify file name
+string writeName;
+"/zap/dyn.wav" => writeName;
+if (writeName!="")
+{
+ dac => WvOut o => blackhole;
+ writeName => o.wavFilename;
+}
+
+MapTick ins;
+15 => int numRiffs;
+
+for( int ctr; ctr < numRiffs; ctr++ )
+{
+ (((ctr)$float)/(numRiffs-1$float)) => float ramp;
+ 0.1 => float x;
+ -0.3 + (ramp * (-0.7 - -0.3)) => float a0;
+ <<< "a0:", a0 >>>;
+ for( int i; i < 10; i++ )
+ {
+ map(x, a0) => x;
+ Math.min (Math.max ( (440.0 + (x * 220.0)), 50.0), 4000.0) => float freq;
+ ins.startNote(freq, -0.4);
+ 100::ms => now;
+ ins.stopNote();
+ }
+ 500::ms => now;
+}
@@ -0,0 +1,69 @@
+// dyn-notes.ck
+// demo of dynamical system melodies
+
+// uses this iterated map, a second-order
+// polynomial function
+fun float mapTick( float x, float a0)
+{
+// set the constants in the polynomial
+ -0.7 => float a1;
+ 2.0 => float a2;
+// return the next value of the map
+ return a0 + (a1 * x) + (a2 * x * x);
+}
+
+// to write soundfile specify file name
+string writeName;
+"/zap/dyn.wav" => writeName;
+if (writeName!="")
+{
+ dac => WvOut o => blackhole;
+ writeName => o.wavFilename;
+}
+
+public class Clarenv
+{
+// STK Clarinet with envelope
+ Clarinet m => Envelope e => dac;
+// method to play
+ fun void startNote( float f)
+ {
+ f => m.freq;
+ 1.0 => m.startBlowing;
+ e.keyOn();
+ 50::ms => dur t => e.duration;
+ }
+// method to stop
+ fun void stopNote()
+ {
+ e.keyOff();
+ 1.0 => m.stopBlowing;
+ }
+}
+
+// how many phrases to play in the demo
+15 => int numRiffs;
+// instantiate one Clare object, call it "ins"
+Clarenv ins;
+
+// loop by one phrase at a time
+for( int ctr; ctr < numRiffs; ctr++ )
+{
+// calculate a ramp that increases from 0 to 1 over the phrases
+ (((ctr)$float)/(numRiffs-1$float)) => float ramp;
+// set the initial condition the same for each phrase
+ 0.1 => float x;
+// ramp the a0 coefficient and print it
+ -0.3 + (ramp * (-0.7 - -0.3)) => float a0;
+ <<< "a0:", a0 >>>;
+// play a 10-note phrase with melody based on iterated map
+ for( int i; i < 10; i++ )
+ {
+ mapTick(x, a0) => x;
+ Math.min (Math.max ( (440.0 + (x * 220.0)), 50.0), 4000.0) => float freq;
+ ins.startNote(freq);
+ 100::ms => now;
+ ins.stopNote();
+ }
+ 500::ms => now;
+}

0 comments on commit cba70b5

Please sign in to comment.