supernova: fix for small audio vector sizes
[supercollider.git] / examples / pieces / some_constellations.scd
blobcf460805a21559834fcec89911910bae3237d963
1 // some small pieces
2 // Julian Rohrhuber, 2007
5 // stereo half-life
8         var activity, nAtoms, tHalf, n;
9         
10         tHalf = 3.92; // Radon-219, discovered 1904 by Giesel and Debierne.
11         nAtoms = 1e+5; // ca. 3.6e-14 mg 
13         n = max(0, nAtoms - PulseCount.ar(LocalIn.ar(2)));
14         activity = Dust.ar( n * 2.log / tHalf);
15         LocalOut.ar(activity);
16         activity;
17 }.play;
21 // a bath
24         var sources, u, uu, above, aside;
25         above = MouseY.kr(0, 2).round(1);
26         aside = MouseX.kr(1, 1.6);
27         sources = [ 
28                 WhiteNoise.ar([0.3, 0.3]), 
29                 PinkNoise.ar([1, 1]),
30                 LFDNoise3.ar(10000) 
31                 * 0.1
32         ];
33         u = SelectX.ar(
34                 LFDNoise1.kr(4).range(0, sources.size), 
35                 sources
36         ) * 0.1;
37         u = u + DelayN.ar(u, 0.1, [0.001, 0.0012], 0.1);
38         
39         uu = u.collect {|chan|
40                                 RLPF.ar(
41                                         u, 
42                                         { rrand(100.0, 340) * aside }.dup(4), 
43                                         0.2
44                                 ).sum
45                         };
46         uu = CombL.ar(uu.reverse, 0.05, 0.05, 0.3, 0.3) * LFNoise2.kr(0.2).max(0) + uu;
47         SelectX.ar(above.lag(0.4), [u, uu]) * 2;
48 }.play;
52 // IBM thinkpad
54 SynthDef("ibm", {
55                 OffsetOut.ar(0, Pulse.ar(1000, 0.5, EnvGen.ar(Env.linen(0, 0.01, 0, 0.1), doneAction:2)))
56 }).add;
58 fork {
59         var coin = 0.5;
60         loop {
61                 if(coin.coin) { coin = rrand(0.1, 1) };
62                 (coin * (1 + 0.5.rand2) * 20).wait;
63                 (instrument: \ibm).play;
64         }
69 // dial history
72         var pat, trig, rate, which, mfv, numbers, both, dial, sig, n = 8;
73         mfv = [[697, 770, 852, 941], [1209, 1336, 1477, 1633]];
74         numbers = [[3, 1]] ++ {:[a,b], a<-(0..2), b<-(0..2)}.all;
75         n = Dwhite(7, 12, inf);
76         rate = Dseq([ Dwhite(2, 7, 1), Dbrown(0.1, 0.2, 0.01, n) ], inf);
77         
78         trig = Trig.kr(TDuty.kr(rate, 0, Dseq((1..10), inf)), 0.09);
79         pat = Latch.kr(trig, trig);
80         which = Hasher.kr(pat * MouseX.kr).range(0, numbers.size).trunc.poll(trig, "");
81         both = Select.kr(which, numbers);
82         dial = Select.kr(both, mfv.flop);
83         sig = SinOsc.ar(dial) * 0.05 * trig;
84         [0, 
85         DelayC.ar(
86                 sig,
87                 0.2,
88                 LFDNoise3.kr(0.5).range(0, 0.01)
89         ) 
90         + GrayNoise.ar(0.01) + HPF.ar(GrayNoise.ar(0.02), 3000)]
91 }.play
95 // sturmian sequencer
97 var rules, axiom;
98 "MathLib".include; // needs MathLib
100 rules = [
101         "0" -> "01",
102         "1" -> "0"
105 axiom = "0";
108         Splay.ar({ |i|
109                 var str = axiom.rewriteString(rules, i + 6);
110                 var dt = 2 ** i.neg * 10;
111                 var trig = TDuty.ar(dt, 0, 
112                         Dseq(str.collectAs(_.digit, Array).postln)
113                 );
114                 var freq = ExpRand(200, i + 1 / 7 * 10100);
115                 Ringz.ar(trig, freq * [1, 1.2, 1.5], ExpRand(2 ** i.neg * 0.1, 1.101) ).sum.distort
116         }.dup(7), 0.5) * 0.3
117 }.play;
122 // sturmian sequencer II
124 var rules, axiom;
125 "MathLib".include; // needs MathLib
127 rules = [
128         "0" -> "01",
129         "1" -> "0"
132 axiom = "0";
135         var n = 7, trig = 0;
136         
137         Splay.ar({ |i|
138                 var str = axiom.rewriteString(rules, i + 6);
139                 var dt = 2 ** (n - i).neg * 20;
140                 var trig = TDuty.ar(dt, 0, 
141                         Dseq(str.collectAs(_.digit, Array), inf)
142                 );
143                 var freq = TExpRand.kr(200, (n - i) / n * 10100, trig);
144                 trig = BPF.ar(trig, LFNoise2.kr(0.1, 0.02, 1) * freq, 0.2);
145                 Ringz.ar(trig, freq * [1, 1.1, 1.2], ExpRand(2 ** i.neg * 0.1, 0.5)).sum.distort;
146                 
147         }.dup(n), 0.5) * 0.3
148 }.play;
151 // sturmian sequencer III
153 var rules, axiom;
154 "MathLib".include; // needs MathLib
156 rules = [
157         "0" -> "01",
158         "1" -> "0"
161 axiom = "0";
164         var n = 9;
165         Splay.ar({ |i|
166                 var str = axiom.rewriteString(rules, i + 6);
167                 var dt = SampleDur.ir / (n - i + 2) * MouseX.kr(1, SampleRate.ir, 2);
168                 TDuty.ar(dt, 0, 
169                         Dseq(str.collectAs(_.digit, Array) - 0.5, inf)
170                 );
171         }.dup(n), 0.5) * 0.3
172 }.play;
178 // practise in the abstract
180 SynthDef(\strings, { arg out, freq=440, amp=0.1, gate=1, pan, freqLag=0.2;
181                                         var env, in, delay, f1, f2;
182                                         f1 = freq.lag(freqLag);
183                                         f2 = freq.lag(freqLag * 0.5);
184                                         delay = 0.25 / f2;
185                                         env = Env.asr(0, 1, 0.3);
186                                         in = WhiteNoise.ar(180);
187                                         in = CombL.ar(in, delay, delay, 1);
188                                         in = Resonz.ar(in, f1, 0.001).abs;
189                                         in = in * EnvGen.kr(env, gate, doneAction:2);
190                                         Out.ar(out, Pan2.ar(in, pan, amp));
191 }).add;
194 Pdef(\vi,
195         Pbind(
196         \instrument, \strings,
197         \degree, Pseq([
198                                 Pn(\rest, 2),
199                                 Pshuf([0, 2, 3, 5], 10), 
200                                 Pseq([\rest], { 9.rand })
201                                 ], inf) 
202                                 + Prand([0, 0, 0, [0, 3], [0, 1]], inf),
203         \dur, Pseq([1, 2, 0.3, 0.5, 0.5], inf) + (Prand([0.3, 0, 0.2], inf) * 0.1),
204         \detune, Pseg(Pwhite(-2, 2, inf), 1.3)
205        )
206 ).play
212 // chainsaw
214 var f, g;
216 f = { | saw |
217         var freq, u, amp, rate;
218         
219         rate = ExpRand(0.1, 2);
220         freq = if(0.6.coin) { 
221                 LFNoise1.kr(rate.dup).exprange(0.01, 10) 
222         } { 
223                 LFNoise1.kr(rate.dup).exprange(10, 50) 
224         };
225         u = LFSaw.kr(LinExp.kr(saw, -1, 1, freq, freq * LFNoise1.kr(rate.dup).exprange(2, 10)));
226         u = if(0.5.coin) { 
227                 u * [1 - saw, saw.reverse].choose 
228         } { 
229                 u * LFSaw.kr(freq * 0.1, 0, 0.1, 1) 
230         };
231         
232         u.clip2(1.0)
233                 
236 g = { | func, n=5 | 
237         n.do { func = func <> func }; 
238         func 
241 play {
242         var freq;
243         freq = g.(f, 4).value(LFSaw.kr(0.2 * [1, 1.1])).exprange(6, 11000);
244         BPF.ar(Saw.ar(freq).product, [70, 800, 9000, 5242], 0.2).sum.dup * 0.3