// Example for auditory streaming demo that doesn't stream // Physical models of instruments to play with // BandedWG BlowBotl Bowed Brass Clarinet // Flute StifKarp ModalBar Saxofony // instantiate 3 instruments Mandolin x => dac; Mandolin y => dac; Mandolin z => dac; // gather them into one array [x, y, z] @=> Mandolin inst[]; // if same, StkInstrument if mixed // array to compensate velocities, if needed [ 0.2, 0.2, 0.2, 0.2, 0.2] @=> float velo[]; 0.8 => float pluck; [ 0, 2, 4, 4, 5] @=> int pos[]; [ 0, 0, 0, 0, 0] @=> int generation[]; // global parameters 150::ms => dur duration1; // set a common note duration 15::ms => dur duration2; // set a common note duration 10.0 => dac.gain; // bump up the output level 1000::ms => dur tempo; // starting tempo 10::ms => dur minTempo; // accelerate to this tempo [ 60, 62, 64, 65, 67, 69, 71, 72, 74, 76, 77, 79, 81, 83] @=> int keyn[]; // array of midi pitches 0 => int n; // which note is next 0 => int i; // which instrument is next dac => Gain g => WvOut w => blackhole; 0.032 => g.gain; "hw3.wav" => w.wavFilename; <<< "writing mono output to file", "hw3.wav" >>>; // infinite time-loop while( true ) { [0, 0, 0] @=> int sort[]; 0 => int curpos; for(0 => int j; j < 3; j++){ (i + j) % inst.cap() => int k; pos[k] + (generation[k] % 7) => curpos; if(curpos < 0) break; (generation[k] / 7) * 12 => int posoffset; Std.mtof( keyn[curpos] + posoffset - 12 ) => inst[k].freq; // assign pitch as freq pluck => inst[k].pluckPos; k => sort[j]; } if(curpos < 0) break; if(pos[sort[0]] + generation[sort[0]] > pos[sort[1]] + generation[sort[1]]){ sort[0] => int temp; sort[1] => sort[0]; temp => sort[1]; } if(pos[sort[0]] + generation[sort[0]] > pos[sort[2]] + generation[sort[2]]){ sort[0] => int temp; sort[2] => sort[0]; temp => sort[2]; } if(pos[sort[1]] + generation[sort[1]] > pos[sort[2]] + generation[sort[2]]){ sort[1] => int temp; sort[2] => sort[1]; temp => sort[2]; } for(0 => int j; j < 3; j++){ velo[sort[j]] => inst[sort[j]].noteOn; // start note duration1 => now; } duration2 => now; for(0 => int j; j < 3; j++){ 0.1 => inst[sort[j]].noteOff; // start note (duration2 / 3) => now; } for(0 => int j; j < 3; j++){ (i + j) % inst.cap() => int k; pos[k]--; if(pos[k] < 0){ pos[k] + 7 => pos[k]; generation[k]++; if(n > 84 && (generation[k]%5 == 0 || generation[k]%5 == 2)) generation[k] - 7 => generation[k]; } } // advance time by tempo and calculate the next tempo i++; // increment note and instrument (i % inst.cap()) => i; // cycle instrument n++; n % 42 => int m; m - 21 => m; if(m < 0) -m => m; ((150 * (m+5) / 26)) :: ms => duration1; (150 * (26-m) / 26) :: ms => duration2; if(n > 84){ duration1 * ((n / 21.0) - 3.0) => duration1; duration2 * ((n / 21.0) - 3.0) => duration2; (1 + 0.7 - (n / 84.0)) => pluck; } }