Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

dynamical-system added

  • Loading branch information...
commit cba70b50e1abe43f299a021dbf541d10550828db 1 parent 93cceee
Hongchan Choi authored November 01, 2012
60  dynamical-system/dyn-del-ins-pitches.ck
... ...
@@ -0,0 +1,60 @@
  1
+// dyn-del-ins.ck
  2
+// demo of dynamical system tones playing preset pitch sequence
  3
+
  4
+public class MapTick
  5
+{
  6
+
  7
+	Gain x => Gain x1;
  8
+	x => Gain x2;
  9
+	x => Gain x2b => x2;
  10
+	3 => x1.op; 
  11
+	3 => x2.op;
  12
+// clarinet-like pitches, envelope moved to map
  13
+	Step c => Envelope e => Gain a0 => Gain out;
  14
+	c => Gain a1 => x1 => out;
  15
+	c => Gain a2 => x2 => out;
  16
+		
  17
+	out => dac => DelayL d => OneZero lpf => Gain loop => x;
  18
+
  19
+	fun void startNote( float f, float a)
  20
+	{
  21
+		1.0::second/f => d.delay;
  22
+		a => a0.gain;
  23
+		-0.7 => a1.gain;
  24
+		2.0 => a2.gain;
  25
+		0.95 => loop.gain;
  26
+		150::ms => dur t => e.duration;
  27
+		e.keyOn();
  28
+	}
  29
+	fun void stopNote()
  30
+	{
  31
+		0.0 => loop.gain;
  32
+		e.keyOff();
  33
+	}
  34
+}
  35
+
  36
+// to write soundfile specify file name
  37
+string writeName;
  38
+"/zap/dyn.wav" => writeName;
  39
+if (writeName!="")
  40
+{
  41
+	dac => WvOut o => blackhole;
  42
+	writeName => o.wavFilename;
  43
+}
  44
+
  45
+MapTick ins;
  46
+// our notes
  47
+[ 61, 63, 65, 66, 68, 66, 65, 63 , 65, 66, 68, 66, 65, 63 , 65, 66, 68, 66, 65, 63 ] @=> int notes[];
  48
+notes.cap() => int numTones;
  49
+
  50
+for( int ctr; ctr < numTones; ctr++ )
  51
+{
  52
+	(((ctr)$float)/(numTones-1$float)) => float ramp;
  53
+	-0.4 + (ramp * (-0.5 - -0.4)) => float a0;
  54
+    	<<< "a0:", a0 >>>;
  55
+	notes[ctr] => int keynum;
  56
+	ins.startNote(Std.mtof(keynum),a0);
  57
+	250::ms => now;
  58
+	ins.stopNote();
  59
+100::ms => now;
  60
+}
60  dynamical-system/dyn-del-ins.ck
... ...
@@ -0,0 +1,60 @@
  1
+// dyn-del-ins.ck
  2
+// demo of dynamical system tones, same as dyn-ins.ck
  3
+// but with delay and low-pass filter in feedback
  4
+
  5
+public class MapTick
  6
+{
  7
+
  8
+	Gain x => Gain x1;
  9
+	x => Gain x2;
  10
+	x => Gain x2b => x2;
  11
+	3 => x1.op; 
  12
+	3 => x2.op;
  13
+	Step c;
  14
+	c => Gain a0 => Gain out;
  15
+	c => Gain a1 => x1 => out;
  16
+	c => Gain a2 => x2 => out;
  17
+		
  18
+	out => Envelope e => dac => DelayL d => OneZero lpf => Gain loop => x;
  19
+
  20
+	fun void startNote( float f)
  21
+	{
  22
+// set delay to constant, 500 Hz = 2 msec
  23
+		2.0::ms => d.delay;
  24
+		f => a0.gain;
  25
+		-0.7 => a1.gain;
  26
+		2.0 => a2.gain;
  27
+		0.95 => loop.gain;
  28
+		10::ms => dur t => e.duration;
  29
+		e.keyOn();
  30
+	}
  31
+	fun void stopNote()
  32
+	{
  33
+		e.keyOff();
  34
+	}
  35
+}
  36
+
  37
+// to write soundfile specify file name
  38
+string writeName;
  39
+"/zap/dyn.wav" => writeName;
  40
+if (writeName!="")
  41
+{
  42
+	dac => WvOut o => blackhole;
  43
+	writeName => o.wavFilename;
  44
+}
  45
+
  46
+
  47
+MapTick ins;
  48
+
  49
+20 => int numTones;
  50
+
  51
+for( int ctr; ctr < numTones; ctr++ )
  52
+{
  53
+	(((ctr)$float)/(numTones-1$float)) => float ramp;
  54
+	-0.3 + (ramp * (-0.7 - -0.3)) => float a0;
  55
+    	<<< "a0:", a0 >>>;
  56
+	ins.startNote(a0);
  57
+	400::ms => now;
  58
+	ins.stopNote();
  59
+	100::ms => now;
  60
+}
70  dynamical-system/dyn-ins.ck
... ...
@@ -0,0 +1,70 @@
  1
+// dyn-ins.ck
  2
+// demo of dynamical system tones
  3
+
  4
+// uses the same iterated map on a second-order
  5
+// polynomial function as in dyn-notes.ck
  6
+
  7
+class MapTick
  8
+{
  9
+// implement the map in unit generaros
  10
+// a0 + (a1 * x) + (a2 * x * x);
  11
+// chuck-1.2.0.8 disallows duplicate input connections
  12
+
  13
+	Gain x => Gain x1;
  14
+	x => Gain x2;
  15
+	x => Gain x2b => x2;
  16
+
  17
+// multiply inputs
  18
+	3 => x1.op; 
  19
+	3 => x2.op;
  20
+
  21
+	Step c; // provide a constant signal of 1.0
  22
+	c => Gain a0 => Gain out;
  23
+	c => Gain a1 => x1 => out;
  24
+	c => Gain a2 => x2 => out;
  25
+		
  26
+	out => Envelope e => dac => x;
  27
+
  28
+	fun void startNote( float c)
  29
+	// modify a0 coefficient
  30
+	{
  31
+		c => a0.gain;
  32
+		-0.7 => a1.gain;
  33
+		2.0 => a2.gain;
  34
+		e.keyOn();
  35
+		50::ms => dur t => e.duration;
  36
+	}
  37
+	fun void stopNote()
  38
+	{
  39
+		e.keyOff();
  40
+	}
  41
+}
  42
+
  43
+// to write soundfile specify file name
  44
+string writeName;
  45
+"/zap/dyn.wav" => writeName;
  46
+if (writeName!="")
  47
+{
  48
+	dac => WvOut o => blackhole;
  49
+	writeName => o.wavFilename;
  50
+}
  51
+
  52
+
  53
+// how many tones to play in the demo
  54
+15 => int numTones;
  55
+// instantiate one MapTick object, call it "ins"
  56
+MapTick ins;
  57
+
  58
+// loop by one tone at a time
  59
+for( int ctr; ctr < numTones; ctr++ )
  60
+{
  61
+// calculate a ramp that increases over the demo
  62
+	(((ctr)$float)/(numTones-1$float)) => float ramp;
  63
+// ramp the a0 coefficient and print
  64
+	-0.3 + (ramp * (-0.7 - -0.3)) => float a0;
  65
+    	<<< "a0:", a0 >>>;
  66
+	ins.startNote(a0);
  67
+	400::ms => now;
  68
+	ins.stopNote();
  69
+	100::ms => now;
  70
+}
71  dynamical-system/dyn-notes-ins.ck
... ...
@@ -0,0 +1,71 @@
  1
+// dyn-notes-ins.ck
  2
+// use same dynamical system for tones as for pitches
  3
+// based on dyn-notes.ck and dyn-del-ins.ck
  4
+
  5
+fun float map( float  x, float  a0)
  6
+{
  7
+	-0.7 => float a1;
  8
+	2.0 => float a2;
  9
+	return a0 + (a1 * x) + (a2 * x * x);
  10
+}
  11
+
  12
+public class MapTick
  13
+{
  14
+
  15
+	Gain x => Gain x1;
  16
+	x => Gain x2;
  17
+	x => Gain x2b => x2;
  18
+	3 => x1.op; 
  19
+	3 => x2.op;
  20
+// clarinet-like pitches, envelope moved to map
  21
+	Step c => Envelope e => Gain a0 => Gain out;
  22
+	c => Gain a1 => x1 => out;
  23
+	c => Gain a2 => x2 => out;
  24
+		
  25
+	out => dac => DelayL d => OneZero lpf => Gain loop => x;
  26
+
  27
+	fun void startNote( float f, float a)
  28
+	{
  29
+		1.0::second/f => d.delay;
  30
+		a => a0.gain;
  31
+		-0.7 => a1.gain;
  32
+		2.0 => a2.gain;
  33
+		0.95 => loop.gain;
  34
+		150::ms => dur t => e.duration;
  35
+		e.keyOn();
  36
+	}
  37
+	fun void stopNote()
  38
+	{
  39
+		0.0 => loop.gain;
  40
+		e.keyOff();
  41
+	}
  42
+}
  43
+
  44
+// to write soundfile specify file name
  45
+string writeName;
  46
+"/zap/dyn.wav" => writeName;
  47
+if (writeName!="")
  48
+{
  49
+	dac => WvOut o => blackhole;
  50
+	writeName => o.wavFilename;
  51
+}
  52
+
  53
+MapTick ins;
  54
+15 => int numRiffs;
  55
+
  56
+for( int ctr; ctr < numRiffs; ctr++ )
  57
+{
  58
+	(((ctr)$float)/(numRiffs-1$float)) => float ramp;
  59
+	0.1 => float x;
  60
+	-0.3 + (ramp * (-0.7 - -0.3)) => float a0;
  61
+    	<<< "a0:", a0 >>>;
  62
+	for( int i; i < 10; i++ )
  63
+	{
  64
+		map(x, a0) => x;
  65
+		Math.min (Math.max ( (440.0 + (x * 220.0)), 50.0), 4000.0) => float freq;
  66
+		ins.startNote(freq, -0.4);
  67
+	        100::ms => now;
  68
+		ins.stopNote();
  69
+	}
  70
+	500::ms => now;
  71
+}
69  dynamical-system/dyn-notes.ck
... ...
@@ -0,0 +1,69 @@
  1
+// dyn-notes.ck
  2
+// demo of dynamical system melodies
  3
+
  4
+// uses this iterated map, a second-order
  5
+// polynomial function 
  6
+fun float mapTick( float  x, float  a0)
  7
+{
  8
+// set the constants in the polynomial
  9
+	-0.7 => float a1;
  10
+	2.0 => float a2;
  11
+// return the next value of the map
  12
+	return a0 + (a1 * x) + (a2 * x * x);
  13
+}
  14
+
  15
+// to write soundfile specify file name
  16
+string writeName;
  17
+"/zap/dyn.wav" => writeName;
  18
+if (writeName!="")
  19
+{
  20
+	dac => WvOut o => blackhole;
  21
+	writeName => o.wavFilename;
  22
+}
  23
+
  24
+public class Clarenv
  25
+{
  26
+// STK Clarinet with envelope
  27
+	Clarinet m => Envelope e => dac;
  28
+// method to play
  29
+	fun void startNote( float f)
  30
+	{
  31
+	        f => m.freq;
  32
+		1.0 => m.startBlowing;
  33
+		e.keyOn();
  34
+		50::ms => dur t => e.duration;
  35
+	}
  36
+// method to stop
  37
+	fun void stopNote()
  38
+	{
  39
+		e.keyOff();
  40
+		1.0 => m.stopBlowing;
  41
+	}
  42
+}
  43
+
  44
+// how many phrases to play in the demo
  45
+15 => int numRiffs;
  46
+// instantiate one Clare object, call it "ins"
  47
+Clarenv ins;
  48
+
  49
+// loop by one phrase at a time
  50
+for( int ctr; ctr < numRiffs; ctr++ )
  51
+{
  52
+// calculate a ramp that increases from 0 to 1 over the phrases
  53
+	(((ctr)$float)/(numRiffs-1$float)) => float ramp;
  54
+// set the initial condition the same for each phrase
  55
+	0.1 => float x;
  56
+// ramp the a0 coefficient and print it
  57
+	-0.3 + (ramp * (-0.7 - -0.3)) => float a0;
  58
+    	<<< "a0:", a0 >>>;
  59
+// play a 10-note phrase with melody based on iterated map
  60
+	for( int i; i < 10; i++ )
  61
+	{
  62
+		mapTick(x, a0) => x;
  63
+		Math.min (Math.max ( (440.0 + (x * 220.0)), 50.0), 4000.0) => float freq;
  64
+		ins.startNote(freq);
  65
+	        100::ms => now;
  66
+		ins.stopNote();
  67
+	}
  68
+	500::ms => now;
  69
+}

0 notes on commit cba70b5

Please sign in to comment.
Something went wrong with that request. Please try again.