//values that may need to be adjusted depending on conditions "test" => string name; //participant's name or other identifier 60::second => dur introTime; //change to reflect the length of the spoken intro //values that may need to be adjusted depending on which computer is used "C:/Users/Sarah/Documents/Stanford/Spring 2012/251/" => string dir; //file directory on this machine dir +"ChantAndIntro.wav" => string chanting; dir + "sound1.wav" => string bird1; dir + "sound2.wav" => string bird2; dir + "sound3.wav" => string bird3; dir + "sound4.wav" => string bird4; dir + "sound5.wav" => string bird5; dir + "sound6.wav" => string bird6; string filenames[6]; [bird1,bird2,bird3,bird4,bird5,bird6] @=> filenames; //Setup (open txt files for writing to ! (these may need to exist ahead of time dir + name + ".txt" => string logpath; FileIO @ birdlog; new FileIO @=> birdlog; if (!birdlog.open(logpath)) <<<"oops">>>; //read the chanting file sound into chuck and store it in a sndBuf SndBuf chantsound; new SndBuf @=> chantsound; chanting => chantsound.read; //read the bird sounds into chuck and store them in sndBufs SndBuf birdSounds[6]; for (0 => int i;i<6;i++) { new SndBuf @=> birdSounds[i]; filenames[i] => birdSounds[i].read; } //setup the HID objects to track mouse motion/ clicks 0 => int device; 0.0 => float x1; Hid hi; HidMsg msg; if( !hi.openMouse( device ) ) me.exit(); <<< "mouse '" + hi.name() + "' ready...", "" >>>; //start the chant file and wait for the spoken introduction to finish spork~ playChant(chantsound); introTime => now; //Start playing bird sounds and tracking mouse clicks now => time startTime; spork~ playBirds(birdSounds, birdlog); spork~ trackMouse(); //let time pass 6::minute => now; birdlog.close(); //----------------------------------------- // Functions that are called/sporked //----------------------------------------- //play the bird sounds at a random time and pan amount fun void playBirds(SndBuf birds[], FileIO log) { while (true) { //pick a random int between 1 and 6 (which sound to play) Math.rand2(1,6) => int index; //pick a random number to use for pan amount Math.rand2f(-1,1) => float pan; //play a bird sound 0 => birds[index-1].pos; if (index < 5) {0.015 => birds[index-1].gain;} else {0.02 => birds[index-1].gain;} Pan2 p; pan => p.pan; birds[index-1] => p => dac; //write the current time and location of the bird sound to the log 1 => int hmmm; (now-startTime)/second => float currTime; "Bird sound: " + index + " Time: " + currTime +" Locaiton: " + pan + ". \n" => string message; log.write(message); //generate random number Math.rand2f(6.0,15.0) => float waitTime; waitTime::second => now; } } //function to play the chanting track fun void playChant(SndBuf chanting) { 0 => chanting.pos; 0.6 => chanting.gain; chanting => dac; 7::minute => now; } //function to track the locations of mouse clicks fun void trackMouse() { while( true ) { // wait on event hi => now; // loop over messages while( hi.recv( msg ) ) { //track the x location of the mouse //note that the scale is relative to starting point //and therefore not on the same scale as the [-1,1] location values given for sound locations if( msg.isMouseMotion()) { msg.deltaX * 0.001 + x1 => x1; //else if( msg.which == 1 ) msg.fdata => a1; //msg.deltaY * .001+ y1 => y1; } if( msg.isButtonDown() ) { <<< " test val " + x1 >>>; (now - startTime)/second => float myTime; "Mouse Click Time: " + myTime +" Locaiton: " + x1 + ". \n" => string message; birdlog.write(message); } } } }