// generate random number in uniform distribution [0,1] fun float uniform() { return Std.rand2f(0,1); } // generate a random number in exponentail distribution fun float expo( float alpha ) { return -Math.log(1-uniform()) / alpha; } // synthesis Impulse i => LPF lpf => dac; 800 => lpf.freq; 2 => lpf.Q; 1 => lpf.gain; // number of expected events per second 100 => float N; // counter 0 => int count; // how long 10::second => dur T; // compute when to stop now + T => time later; // target cutoff frequency 5000 => float target_freq; // spork spork ~ ramp(); // go! while( now < later ) { // fire! 1 => i.next; // sets cutoff/resonance of LPF // 500 + uniform()*500 => lpf.freq; // count the number of events count++; // wait until the next event expo( N )::second => now; } // the final report <<< "expected:", T/second * N, "actual:", count >>>; // done (this will crash everything) // Machine.crash(); // ramp function fun void ramp() { // our slew .005 => float slew; // infinite time loop while( true ) { // update cutoff/resonance of LPF (target_freq - lpf.freq())*slew + lpf.freq() => lpf.freq; // advance time 5::ms => now; } }