// @title m220a-Duo_so2_at_Kilauea_Multi_Inst.ck // @desc a sound player with polyphony for DataReader class // @author HANNAH CHOI (hchoi20@ccrma) //=== TODO: modify this path and name for your system ===// // "/home/cc/220a/hw1/" => string dataDir; // linux template "/user/h/hchoi20/Library/Web/220a/hw1/" => string dataDir; // osx template // update rate in ms //100.0 => float update; //200.0 => float update; 210.0 => float update; //215.0 => float update; //300.0 => float update; // new class to manage envelopes class Env { Step s => Envelope e => blackhole; // feed constant into env update::ms => e.duration; // set ramp time fun void target (float val) { e.target(val); } } class Player { //For Sinewave //SinOsc s => NRev rev; // //For Clarinet SqrOsc s => NRev rev; fun void setChan(int c) { rev => dac.chan(c); } rev.mix(0.05); Env amp, freq; fun void run() // sample loop to smoothly update gain { while (true) { s.gain(amp.e.last()); s.freq(freq.e.last()); 1::samp => now; } } spork ~ run(); // run 'run' function as a new shred } // sporking multiple shreds programmatically spork ~ go("data-so2_at_kilauea_org.dat", 0); spork ~ go("data-so2_at_kilauea_org.dat", 1); //spork ~ go("data-so2_at_kilauea_org.dat", 2); //spork ~ go("data-so2_at_kilauea_org.dat", 3); //For multiple instruments Moog inst => dac; Flute inst1 => dac; BlowHole inst2 => dac; // function for shredding fun void go(string file, int chan) { DataReader reader; reader.setDataSource(dataDir + file); reader.start(); Player p; p.setChan(chan); while (!reader.isFinished()) { // next data point, scaled in 0.0 - 1.0 range reader.scaledVal() => float w; //p.amp.target(0.5 * Math.pow(w, 2.0)); //p.freq.target(Std.mtof(80.0 + w*20.0)); // //Change amp and freq p.amp.target(0.9 * Math.pow(w, 2.0)); p.freq.target(Std.mtof(40.0 + w*40.0)); //Background notes - G/F# std.mtof( 31 ) => inst.freq; //set the note to G inst.noteOn( 0.2 ); std.mtof( 54 ) => inst1.freq; //set the note to F# inst1.noteOn( 0.2 ); update::ms => now; } //Note for final stage - A# std.mtof( 70 ) => inst2.freq; //set the note to A# inst2.noteOn( 0.5 ); //play a note at half volume 5::second => now; //compute audio for 5 seconds } // to make the main shred alive 1::day => now;