# [chuck-users] Matrix of Impulse Generators

Philipp Blume pgbluster at gmail.com
Tue Feb 4 19:11:56 EST 2014

```Dear all,

Question from a rank ChucK beginner

There's something about envelopes or gain or shreduling that I don't
understand.

I created a Cartesian matrix of impulse generators, whose frequencies are
given as mx+ny {x,y btw -3 and 3) where the gain & 'tempo' of each
generator is correlated with its distance from a line segment (a1,b1 -
a2,b2) - later on I will be manipulating x,y,a1,b1,a2, and b2.

This code runs well for a while, but within a few seconds or minutes it
starts to get overwhelmed. The death is both spectacular and quite moving,
but how do I keep it within bounds so it sounds perpetually like it does in
the first 5-10 seconds?

550 => float x;
440 => float y;
3 => float a1;
0 => float b1;
0 => float a2;
-2 => float b2;

fun void iGen(int i1, int j1) {
while(true) {
Euclid(i1,j1,a1,b1) + Euclid(i1,j1,a2,b2) => float dist;
<<< dist >>>;
SinOsc s => ADSR e => dac;
e.set(35::ms, 8::ms, .1, 200::ms);
Math.pow(0.65,(dist)) => s.gain;
i1*x + j1*y => s.freq;
e.keyOn();
(440)::ms => now;
e.keyOff();
(440*Math.pow(1.2,dist))::ms => now;
}
}

fun float Euclid(float p, float q, float r, float s) {
return Math.sqrt(Math.pow((p-r),2) + Math.pow((q-s),2));
}

for(-3 => int i; i<4; i++) {
for (-3 => int j; j<4; j++) {
if (i != 0 && j != 0) {
spork ~ iGen(i,j);
}
}
}

while (x != y) {
500::ms=>now;
}

--
Philipp Blume
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20140204/911ce233/attachment.htm>
```