// Template for auditory streaming homework // try me, I don't break into multiple streams... why? // answer: the streaming illusion demonstrates grouping by similarity // here there is only one group of sounds and therefore only one stream //////////////////////////////////////////////////////////////// // play a cycle of pitches 4 => int nPitches; // array to hold midi pitches (key numbers) int keyn[nPitches]; [ 60, 62, 64, 66 ] @=> keyn; 4 => int nchans; //////////////////////////////////////////////////////////////// // against a cycle of a different length varying instrument parameters 3 => int nInsts; // arrays to hold loudnesses, pitch register transposition, channel, instrument type float loud[nInsts]; float loud2[nInsts]; float tran[nInsts]; int chan[nInsts]; StkInstrument inst[nInsts]; StkInstrument inst2[nInsts]; JCRev r; .01 => float rmix; .5 => float rmixmax; .1 => r.gain; rmix => r.mix; 5::ms => dur minduration; 100::ms => dur maxduration; // loudness contour .9 => float fade; [ fade/2, fade/2, fade/2 ] @=> loud @=> loud2; // pitch register contour [ 1.0, 1.0, 1.0 ] @=> tran; // e.g., 2.0 for octave higher, 4.0 for two octaves, etc. // channel contour [ 0, 0, 0 ] @=> chan; // StkInstrument physical models to choose from // BandedWG BlowBotl Bowed Brass Clarinet // Flute StifKarp ModalBar Saxofony // instantiate 3 instruments and set their output channels Saxofony x @=> inst[0] => r => Binaural.pssp[chan[0]]; Saxofony y @=> inst[1] => r => Binaural.pssp[chan[1]]; Saxofony z @=> inst[2] => r => Binaural.pssp[chan[2]]; BlowHole u @=> inst2[0] => r => Binaural.pssp[chan[0]]; BlowHole v @=> inst2[1] => r => Binaural.pssp[chan[1]]; BlowHole w @=> inst2[2] => r => Binaural.pssp[chan[2]]; .5 => float reedinit; 20 => float reedmax; inst[0].controlChange(2, reedinit); inst[1].controlChange(2, reedinit); inst[2].controlChange(2, reedinit); //////////////////////////////////////////////////////////////// // global parameters 100::ms => dur duration; // set a common note duration 10.0 => dac.gain; // bump up the output level 1000::ms => dur ioi; // starting inter-onset interval (inverse of tempo) 10::ms => dur minIoi; // accelerate to this smallest ioi 0 => int p; // which pitch is next 0 => int i; // which instrument is next //[ 10.0, 30.0, 100.0 ] @=> float reed[]; // per-instrument amount, 0.0 ? 127.0 10::second + now => time endSecI; while( now < endSecI ) { <<< p, i >>>; // print pitch index, instrument index Std.mtof( keyn[p] ) * tran[i] => inst[i].freq; // assign pitch as freq loud[i] => inst[i].noteOn; // start note duration => now; // wait 0.1 => inst[i].noteOff; // stop note 1.2 *=> reedinit; if (reedinit > reedmax) reedmax => reedinit; if(i==0) inst[i].controlChange(2, reedinit); //inst[i].controlChange( 2, reed[i] ); // reed stiffness //p % n @=> chan[i, i, i]; make sound go around in a circle //r=< Binaural; r => Binaural.pssp[chan[p%nchans]]; p++; i++; // increment note and instrument (p % nPitches) => p; // cycle pitch through full array (i % nInsts) => i; // cycle instrument through full array // advance time by interval and calculate the next time interval ioi => now; ioi * 0.8 => ioi; // accelerate if (ioi < minIoi) minIoi => ioi;// can't go faster than minIoi } 6::second + now => time endSecII; while( now < endSecII ) { <<< p, i >>>; // print pitch index, instrument index Std.mtof( keyn[p] ) * tran[i] => inst[i].freq; // assign pitch as freq loud[i] => inst[i].noteOn; // start note duration => now; // wait 0.1 => inst[i].noteOff; // stop note .99 *=> duration; if (duration < minduration) minduration => duration; //r=< Binaural; r => Binaural.pssp[chan[p%nchans]]; p++; i++; // increment note and instrument (p % nPitches) => p; // cycle pitch through full array (i % nInsts) => i; // cycle instrument through full array // advance time by interval and calculate the next time interval ioi => now; ioi * 0.99 => ioi; // accelerate if (ioi < minIoi) minIoi => ioi;// can't go faster than minIoi } 7::second + now => time endSecIII; while( now < endSecIII ) { [fade/2.2, fade/2.2, fade/2.2] @=> loud; [(.7-fade)/2.2, (.7-fade)/2.2, (.7-fade)/2.2] @=> loud2; <<< p, i >>>; Std.mtof( keyn[p] ) * tran[i] => inst[i].freq => inst2[i].freq; // assign pitch as freq loud[i] => inst[i].noteOn; // start note loud2[i] => inst2[i].noteOn; duration => now; // wait 0.1 => inst[i].noteOff; // stop note 0.1 => inst2[i].noteOff; // stop note .99 *=> duration; if (duration < minduration) minduration => duration; 1.05 *=> rmix; rmix => r.mix; if (rmix > rmixmax) rmixmax => rmix; //r=< Binaural; r => Binaural.pssp[chan[p%nchans]]; p++; i++; // increment note and instrument (p % nPitches) => p; // cycle pitch through full array (i % nInsts) => i; // cycle instrument through full array // advance time by interval and calculate the next time interval ioi => now; ioi * 0.99 => ioi; // accelerate fade*.99 => fade; if (ioi < minIoi) minIoi => ioi;// can't go faster than minIoi } 25::second+now => time endSecV; while( now < endSecV ) { <<< p, i >>>; // print pitch index, instrument index Std.rand2(40, 900) => inst2[i].freq; // assign pitch as freq loud[i] => inst2[i].noteOn; // start note duration => now; // wait 0.1 => inst2[i].noteOff; // stop note //inst[i].controlChange( 2, reed[i] ); // reed stiffness 1.01 *=> duration; if (duration < maxduration) maxduration => duration; 1.05 *=> rmix; rmix => r.mix; if (rmix > rmixmax) rmixmax => rmix; //r=< Binaural; r => Binaural.pssp[chan[p%nchans]]; p++; i++; // increment note and instrument (p % nPitches) => p; // cycle pitch through full array (i % nInsts) => i; // cycle instrument through full array // advance time by interval and calculate the next time interval ioi => now; ioi * 1.02 => ioi; // deccelerate if (ioi < minIoi) minIoi => ioi;// can't go faster than minIoi }