// class to generate sounds for Acoustic Interloper's chess program // by Les Hall (Inventor) // This software is freeware, use as you wish // instantiate the oscillator class oscillators Osc; // hook up the oscillator class Osc.out_left => dac.left; Osc.out_right => dac.right; // call some test functions with time delays between them Osc.voice (0, 0, 247.5, 0, 0.275, 0.125); 3::second => now; Osc.voice (1, 0, 196.0, 0, 0.125, 0.275); 3::second => now; Osc.voice (0, 1, 329.0, 0, 0.275, 0.125); 3::second => now; Osc.voice (1, 1, 440.0, 0, 0.125, 0.275); 3::second => now; Osc.quiet (); 3::second => now; // The oscillator class class oscillators { // parameters 23 => int num_osc; // number of oscillators // the patch SinOsc sine_wave[num_osc]; Gain sine_left[num_osc]; Gain sine_right[num_osc]; TriOsc tri_wave[num_osc]; Gain tri_left[num_osc]; Gain tri_right[num_osc]; Gain out_left; Gain out_right; for (0 => int i; i < num_osc; i++) { sine_wave[i] => sine_left[i] => out_left; sine_wave[i] => sine_right[i] => out_right; tri_wave[i] => tri_left[i] => out_left; tri_wave[i] => tri_right[i] => out_right; } // initialize oscillators as quiet for (0 => int i; i < num_osc; i++) { 1 => sine_wave[i].gain; 1 => tri_wave[i].gain; 0 => sine_left[i].gain; 0 => sine_right[i].gain; 0 => tri_left[i].gain; 0 => tri_right[i].gain; } 1 => out_left.gain; 1 => out_right.gain; // the sine wave function fun void voice (int bank, int osc, float freq, float phase, float left, float right) { if (bank == 0) { freq => sine_wave[osc].freq; phase => sine_wave[osc].phase; left => sine_left[osc].gain; right => sine_right[osc].gain; } else { freq => tri_wave[osc].freq; phase => tri_wave[osc].phase; left => tri_left[osc].gain; right => tri_right[osc].gain; } } // quiet all oscillators fun void quiet () { for (0 => int i; i < num_osc; i++) { 0 => sine_left[i].gain; 0 => sine_right[i].gain; 0 => tri_left[i].gain; 0 => tri_right[i].gain; } } }