// line noise with interpolation - http://emoc.org/hackpact/ - sep 2009 0 => int deviceNum; Hid hi; HidMsg msg; if( !hi.openMouse( deviceNum ) ) me.exit(); Step s => dac; .5 => s.gain; 50 => int length; // length of a segment 0 => int i; Std.rand2f(-1,1) => float n; Std.rand2f(-1,1) => float n1; 1::samp => dur d; 0 => int interpolation; fun void sound() { while (1::samp => now) { if (i < length) { if (interpolation == 0) { cosine_interpolation(n, n1, i$float/length) => s.next; } else { linear_interpolation(n, n1, i$float/length) => s.next; } i++; } else { 0 => i; n1 => n; Std.rand2f(-1,1) => n1; } } } fun float cosine_interpolation(float a, float b, float x) { (1 - Math.cos(x * 3.1415927)) * .5 => float f; return a*(1-f) + b*f; } fun float linear_interpolation(float a, float b, float x) { return a*(1-x) + b*x; } fun void switch_interpolation() { if (interpolation == 0) { 1 => interpolation; <<<"linear interpolation">>>; } else { 0 => interpolation; <<<"cosine interpolation">>>; } } spork ~ sound(); while(true) { hi => now; while( hi.recv( msg ) ) { if( msg.isMouseMotion() ) { if( msg.deltaX ) { // move the mouse fast from left to right to modify segment length length + Math.sgn(msg.deltaX/3)$int => length; if (length < 5) 5 => length; if (length > 100) 100 => length; <<>>; } } else if( msg.isButtonDown() ) { // left button resets segment size // right button switch between linear & cosine interpolation if (msg.which == 0) 50 => length; if (msg.which == 1) switch_interpolation(); } } }