// @title m220a-Player.ck // @desc a sample sound player goes with DataReader class // @author Chris Chafe (cc@ccrma) "/Users/Keaton/Desktop/music220a/" => string dataDir; "ibm-stock-prices.dat" => string dataFile; // update rate in ms 150.00 => 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 { SinOsc s => NRev rev => dac; 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 } DataReader ibm; ibm.setDataSource(dataDir + dataFile); ibm.start(); Player p; while (!ibm.isFinished()) { // next data point, scaled in 0.0 - 1.0 range ibm.scaledVal() => float w; p.amp.target(Math.pow(w, 2.0)); p.freq.target(Std.mtof(55.0 + w*20.0)); update::ms => now; }