// @title m220a-Player.ck // @desc a sample sound player goes with DataReader class // @author Chris Chafe (cc@ccrma) //=== TODO: modify this path and name for your system ===// "/Users/briangurewitz/Desktop/Sleep/" => string dataDir; "emg_sleep.dat" => string dataFile; dac => WvOut2 out => blackhole; me.sourceDir() + "/emg_sleep.wav" => string _capture; _capture => out.wavFilename; // update rate in ms 10.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 { Noise n => TwoPole s => dac; 1 => s.norm; 0.1 => s.gain; 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 emg_sleep; emg_sleep.setDataSource(dataDir + dataFile); emg_sleep.start(); Player p; while (!emg_sleep.isFinished()) { // next data point, scaled in 0.0 - 1.0 range emg_sleep.scaledVal() => float w; p.amp.target(0.5 * Math.pow(w,4.5)); p.freq.target(Std.mtof(60 + w*10)); update::ms => now; }