// Directions: run the shred, control parameters on keyboard with // l to increase x, j to decrease x, i to increase r in a big step, // k to decrease r in a big step, 8 to increase r in a small step // 9 to decrease r in a small step // ===== our music making stuff ===== SndBuf buf => Gain g => dac; "data/dustpond.wav" => buf.read; 0.5 => g.gain; // parameters for INF // change r from 0.0 (sine) to 4.0 (noise) // increase with i, decrease with k 1.0 => float r; // change inital x from -pi/2.0 to pi/2.0 // increase with l, decrease with j pi/4.0 => float x; 100000 => int iterations; // ===== set up the keyboard controls ===== Hid hi; HidMsg msg; // which keyboard 0 => int device; // open keyboard (get device number from command line) if( !hi.openKeyboard( device ) ) me.exit(); <<< "keyboard '" + hi.name() + "' ready", "" >>>; fun void key( ) { while( true ) { // wait on event hi => now; // get one or more messages while( hi.recv( msg ) ) { // check for action type if( msg.isButtonDown() ) { if( msg.ascii == 76 ) { // increase x x + pi/16.0 => x; <<< "x: ", x >>>; } if( msg.ascii == 74 ) { // decrease x x - pi/16.0 => x; <<< "x: ", x >>>; } if( msg.ascii == 73 ) { // increase r // allow for r to go beyond stated boundaries r + 0.1 => r; <<< "r: ", r >>>; } if( msg.ascii == 75 ) { // decrease r // allow for r to go beyond above stated boundaries r - 0.1 => r; <<< "r: ", r >>>; } if( msg.ascii == 56) { // increase r by a little bit if( r < 4.0 ) { r + 0.001 => r; } <<< "r: ", r >>>; } if( msg.ascii == 57) { if( r > -4.0 ) { r + 0.001 => r; } <<< "r: ", r >>>; } } } } } spork ~ key( ); // make sounds based on sin map! for( 0 => int i; i < iterations; i++ ) { // compute next value of x Math.sin(r*x) => x; // set buffer sample position Math.fabs( x*buf.samples( ) ) $ int => buf.pos; <<< x >>>; // advance time 1000::ms => now; // this should be sample by sample, but chuck can't handle it... } 209::second => now; // THOUGHTS: // MAKE CONTROLS FOR r and x // so we can manipulate it and get crazy sounds // how can we map this to something like granular synthesis? // how about the number of iterations? resetting