// @title hw3-exampleScore.ck // @author Chris Chafe (cc@ccrma), Hongchan Choi (hongchan@ccrma) // @desc An example score file for homework 3, Music220a-2012 // @version chuck-1.3.2.0 // @revision 2 // pick a physical model synth, send to left chan (0) Brass physmod => dac.left; // bring in a mono .wav file from which to play sample // pass through Envelope to avoid clicks from SndBuf // to right chan (1) SndBuf sampler => Envelope samplerEnv => dac.right; me.sourceDir() + "/sample.wav" => string _file; _file => sampler.read; cherr <= "[score] SndBuf: " <= _file <= IO.newline(); 10::ms => samplerEnv.duration; // write signals to file dac => WvOut2 out => blackhole; me.sourceDir() + "/exampleScore.wav" => string _capture; _capture => out.wavFilename; // ------------------------------------------------------------ // three algorithms which generate numbers in range -1.0 to 1.0 // see 1) logisticMapNotes.ck 2) logisticMapNotesOSC.ck for // more info fun float logistic(float x, float r) { return r * x * (1.0 - x); } // see 1) psuedoRandomNotes.ck 2) psuedoRandomNotesOSC.ck for // more info fun float random(float r) { if (r > 1.0) { 1.0 => r; } // get a random value return Math.random2f(-r, r); } // see 1) sinNotes.ck 2) sinNotesOSC.ck fun float sinusoid(float r) { // rate in radians at 1 sec period 2 * pi => float sinScale; // convert to desired rate in radians if (r > 0.0) r /=> sinScale; // current time in seconds now / second => float nowInSeconds; // convert to phase angle using rate in radians nowInSeconds * sinScale => float currentPhase; // or could be another trig function return Math.sin(currentPhase); } // ------------------------------------------------------------ // tick the chosen algorithm to get a new value fun float algorithm(float state, string type, float r) { if (type == "logistic") { // choose me to iterate the map and hear logistic map "tune" return logistic(state, r); } else if (type == "random") { // choose me for random "tune" return random(r); } else if (type == "sinusoid") { // choose me for sin function "tune" return sinusoid(r); } else { cherr <= "[score] Unknown algorithm type.\n"; } } // sporkable function that plays physical model notes forever fun void pLoop(string type, float r, float vibGain, float volume) { 0.1 => float state; physmod.vibratoGain(vibGain); physmod.volume(volume); while (true) { // note off in case it's already on physmod.stopBlowing(0.4); // a short rest 50::ms => now; algorithm(state, type, r) => state; // use state as a frequency 440.0 + (state * 110.0) => float f; // to brass physmod.freq(f); // note on physmod.startBlowing(0.4); 100::ms => now; } } // sporkable function that plays sampler notes forever fun void sLoop(string type, float r) { 0.1 => float state; while (true) { // turn off envelope in case it's already on samplerEnv.target(0.0); // a short rest 50::ms => now; algorithm(state, type, r) => state; sampler.length() => dur totalFile; // time in file to start playing sample from ((state + 1.0) * 0.5) * totalFile * r => dur start; // sample duration 100::ms => dur duration; // end time of sample start + duration => dur end; if (end > totalFile) { end - duration => start; } // start position in file in actual samples sampler.pos((start / samp) $ int); // ramp up the envelope samplerEnv.target(1.0); duration => now; } } // ------------------------------------------------------------ // prepare the show Shred pShred; Shred sShred; // needed to stop both shreds gracefully fun void killShreds() { pShred.exit(); sShred.exit(); me.yield(); // note off physmod.stopBlowing(1.0); // turn off envelope samplerEnv.target(0.0); 10::ms => now; } 50::ms => now; // ------------------------------------------------------------ //fun void pLoop(string type, float r, float vibGain, float volume) // start the show, this is just and example score with changing sections spork ~pLoop("logistic", 3.9, .01, 1) @=> pShred; 4::second => now; killShreds(); .01::second => now; spork ~pLoop("sinusoid", .5, .1, .66) @=> pShred; 4::second => now; killShreds(); .01::second => now; spork ~pLoop("random", 3.9, 0, .33) @=> pShred; 4::second => now; killShreds(); .01::second => now; spork ~pLoop("sinusoid", 2.5, .5, .66) @=> pShred;; 4::second => now; killShreds(); .01::second => now; spork ~pLoop ("logistic", 3.4, .01, 1) @=> pShred; 4:: second => now; killShreds(); 1:: second => now; spork ~sLoop("random", 2.1) @=> sShred; 4::second => now; killShreds(); .01::second => now; spork ~sLoop("sinusoid", 1.8) @=> sShred; 4::second => now; killShreds(); .01::second => now; spork ~sLoop("logistic", 4.2) @=> sShred; 4::second => now; killShreds(); .01::second => now; spork ~sLoop("sinusoid", 2.1) @=> sShred; 4::second => now; killShreds(); .01::second => now; spork ~sLoop("random", 3.2) @=> sShred; 4::second => now; killShreds(); 1::second => now; spork ~pLoop("sinusoid", 1.2, .01, 1) @=> pShred; spork ~sLoop("random", 3.4) @=> sShred; 5::second => now; killShreds(); .01::second => now; spork ~pLoop("logistic", 3.4, .01, 1) @=> pShred; spork ~sLoop("sinusoid", 1.2) @=> sShred; 5::second => now; killShreds(); .01::second => now; spork ~pLoop("sinusoid", 1.2, .05, 1) @=> pShred; spork ~sLoop("sinusoid", 1.2) @=> sShred; 5::second => now; killShreds(); .01::second => now; spork ~pLoop("random", 2.1, .05, 1) @=> pShred; spork ~sLoop("random", 2.1) @=> sShred; 5::second => now; killShreds(); .01::second => now; spork ~pLoop("random", 1.8, .2, .5) @=> pShred; spork ~sLoop("sinusoid", 1.5) @=> sShred; 5::second => now; killShreds(); .01::second => now; spork ~pLoop("sinusoid", 4.8, 0, .5) @=> pShred; spork ~sLoop("sinusoid", 4.8) @=> sShred; 5::second => now; killShreds(); .01::second => now; spork ~pLoop("logistic", 3.3, 0, .5) @=> pShred; spork ~sLoop("random", 3.3) @=> sShred; 5::second => now; killShreds(); .01::second => now; // ------------------------------------------------------------ // finish the show out.closeFile(); // print message in terminal for sox command cherr <= "[score] Finished.\n"; cherr <= me.sourceDir() + "/exampleScore.wav";