/* Krishan Kumar Controls a clarinet physical model it prints when it begins and reports how long the note is the program runs in real time starting the note at TIME 0 and ends when it has nothing left to do command line: chuck clip_clar.ck */ //this function will play a single Clarinet note! //A lot of the inputs are defined for you to control the parameters of the model :-) fun void playNoteClip(dur length, int pitch, float vibFreq, float vibGain, float breathPressure, float noiseGain, int cresc ) { //our clarinet Clarinet c => dac; //if cresc, long attack time if(cresc == 1) spork ~ clarGain(c, length); // set physical model parameters noiseGain => c.noiseGain; vibFreq => c.vibratoFreq; vibGain => c.vibratoGain; breathPressure => c.pressure; Std.mtof( pitch ) => c.freq; //making a small tail for the note so it doesn't clip length / 10 => dur noteTail; //start note <<<"\tnote start at",now/second,"seconds">>>; Math.random2f( .6, .9 ) => c.noteOn; //note the method of starting and stopping the physical model //play note length - noteTail => now; //end note 1 => c.noteOff; noteTail => now; <<<"\tnote end at",now/second,"seconds">>>; } //this function controls the gain of the Clarinet over the course of a note, and is bounded by that note length //it is designed to be called within playNoteClip() fun void clarGain(Clarinet c, dur length) { now + length => time later; while ( now < later ) { //values go from 0 to 1 - as now approaches later, the second half (in the //parentheses) goes to 0. 1 - ((later - now) / length) => c.gain; 10::samp => now; } } 1::second => dur silDur; //********* SPORK THINGS HERE TO MAKE A CLARINET SOUND! *************// spork ~ playNoteClip(1::second, 72, 0, 0, 1.0, 0.5, 5); now + 1::second => now; now + silDur => now; spork ~ playNoteClip(2::second, 74, 3.0, 0.3, 1.0, 0.5, 5); now + 2::second => now; now + silDur => now; spork ~ playNoteClip(5::second, 76, 3.0, 0.3, 1.0, 0.5, 1); now + 5::second => now; now + silDur => now; spork ~ playNoteClip(1::second, 77, 3.0, 0.3, 1.0, 0.5, 1); now + silDur => now; spork ~ playNoteClip(1::second, 79, 3.0, 0.3, 1.0, 0.5, 1); now + silDur => now; spork ~ playNoteClip(1::second, 81, 3.0, 0.3, 1.0, 0.5, 1); now + silDur => now; now + silDur => now; spork ~ playNoteClip(1::second, 77, 3.0, 0.3, 1.0, 0.5, 1); now + silDur => now; spork ~ playNoteClip(1::second, 79, 3.0, 0.3, 1.0, 0.5, 1); now + silDur => now; spork ~ playNoteClip(1::second, 81, 3.0, 0.3, 1.0, 0.5, 1); now + silDur => now; now + silDur => now; // last item in this program is this print statement <<<"program end at",now/second,"seconds">>>; // and with nothing left to do this program exits