dac.chan(0) => WvOut out0 => blackhole; //left channel sends audio called physmodOut out to blackhole (the sample sucker) dac.chan(1) => WvOut out1 => blackhole; //right channel sends audio called samplerOut out to blackhole (the sample sucker) dac.chan(2) => WvOut out2 => blackhole; //left channel sends audio called physmodOut out to blackhole (the sample sucker) dac.chan(3) => WvOut out3 => blackhole; //right channel sends audio called samplerOut out to blackhole (the sample sucker) me.sourceDir() + "/0.wav" => string _capture0; //creating the string names for later reference me.sourceDir() + "/1.wav" => string _capture1; //" me.sourceDir() + "/2.wav" => string _capture2; //creating the string names for later reference me.sourceDir() + "/3.wav" => string _capture3; //" _capture0 => out0.wavFilename; //puts that sting into this file name _capture1 => out1.wavFilename; //puts that sting into this file name _capture2 => out2.wavFilename; //puts that sting into this file name _capture3 => out3.wavFilename; //puts that sting into this file name 4 => int nPitches; // array to hold midi pitches (key numbers) int keyn[nPitches]; [65, 60, 62, 64] @=> keyn; // @ is sytax specific for initializing arrays // ------------------------------------------------------------- // against a cycle of a different length which varies instrument // parameters 3 => int nInsts; // arrays to hold loudnesses, pitch register transpositions, // channels, fm instrument parameters //section 1 parameters // loudness contour (100dB = loudest) [80.0, 80.0, 80.0] @=> float loud[]; // pitch register contour // e.g., 2.0 for octave higher, 4.0 for two octaves, etc. [1.0, 2.0, 4.0] @=> float tran[]; // fmIndex contour // fm modulation index [1.0, 1.0, 1.0] @=> float fmIndex[]; // fmRatio contour [1.0, 1.0, 1.0] @=> float fmRatio[]; // skew contour [0.1, 0.1, 0.1] @=> float skew[]; // instantiate UGens FMFS fm[3]; //[x, y, z] 1 array named fm with 3 instances of FMFS; do not need => for initializing objects, do need for primitives for (int i; i < 3; ++i) { // start with instruments muted 0.0 => fm[i].out.gain; // fm[0].out.gain(0.0); calls the FMFS object at that index location as opposed to the array itself // fm[i].out => dac; } // ------------------------------------------------------------- // global parameters // set a common note duration 200::ms => dur duration; // starting inter-onset interval (inverse of tempo) 100::ms => dur ioi; // accelerate to this smallest ioi 5::ms => dur minIoi; // which pitch is next 0 => int p; // which instrument is next 0 => int i; // ----------------------------------------------------------- // section 1 // section 1 pitches [ 36, 40, 45, 47] @=> keyn; [80.0, 70.0, 80.0] @=> loud; [2.0, 3.0, 1.0] @=> tran; [0.0, 0.5, 7.0] @=> fmIndex; //changed this ratio [0.0, 0.75, 1.0] @=> fmRatio; [1.0, 0.1, 0.1] @=> skew; // channel contour [0, 1, 2, 3] @=> int fmchan[]; //each pitch gets a different chanel // when to change 20::second + now => time endOfSection1; while (now < endOfSection1) { chout <= "PITCH = " <= p <= "\t\t"; // chout means print; arrow faces direction of dataflow; tab char chout <= "INST. = " <= i <= "\t\t"; chout <= "CHAN. = " <= fmchan[p] <= "\t\t" <= IO.newline(); Std.mtof(keyn[p]) * tran[i] => float tmp; //keyn[0] = 65, etc // assign pitch fm[i].setPitch(tmp); // assign loudness after converting to amplitude fm[i].out.gain(Math.dbtorms(loud[i])); // assign modulator index fm[i].setIndex(fmIndex[i]); // assign modulator / carrier frequency ratio fm[i].setRatio(fmRatio[i]); // assign pitch skew fm[i].setSkew(skew[i]); // start note fm[i].attack(100::ms); // wait fm[i].out =< dac; fm[i].out => dac.chan(fmchan[p]); //calls pitch instead of instrument duration => now; // stop note fm[i].release(10::ms); // increment note and instrument p++; i++; // cycle pitch through full array nPitches %=> p; // cycle instrument through full array nInsts %=> i; // advance time by interval and calculate the next time interval ioi => now; // accelerate ioi * 0.8 => ioi; // can't go faster than minIoi if (ioi < minIoi) { minIoi => ioi; } } // ----------------------------------------------------------- // section 2 // section 2 pitches [ 36, 40, 36, 40 ] @=> keyn; [80.0, 70.0, 90.0] @=> loud; [2.0, 2.0, 1.0] @=> tran; [0, 1, 2, 3] @=> fmchan; [7.5, 1.0, 7.5] @=> fmIndex; //changed this ratio [0.5, 0.75, 1.0] @=> fmRatio; [0.1, 0.1, 0.1] @=> skew; // set a common note duration 100::ms => duration; // starting inter-onset interval (inverse of tempo) 1000::ms => ioi; // accelerate to this smallest ioi 1::ms => minIoi; // which pitch is next 0 => p; // which instrument is next 0 => i; 20::second + now => time endOfSection2; while (now < endOfSection2) { chout <= "PITCH = " <= p <= "\t\t"; // chout means print; arrow faces direction of dataflow; tab char chout <= "INST. = " <= i <= IO.newline(); Std.mtof(keyn[p]) * tran[i] => float tmp; //keyn[0] = 65, etc // assign pitch fm[i].setPitch(tmp); // assign loudness after converting to amplitude fm[i].out.gain(Math.dbtorms(loud[i])); // assign modulator index fm[i].setIndex(fmIndex[i]); // assign modulator / carrier frequency ratio fm[i].setRatio(fmRatio[i]); // assign pitch skew fm[i].setSkew(skew[i]); // start note fm[i].attack(100::ms); // wait duration => now; // stop note fm[i].release(10::ms); // increment note and instrument p++; i++; // cycle pitch through full array nPitches %=> p; // cycle instrument through full array nInsts %=> i; // advance time by interval and calculate the next time interval ioi => now; // accelerate ioi * 0.8 => ioi; // can't go faster than minIoi if (ioi < minIoi) { minIoi => ioi; } } // ------------------------------------------------------------- // @class FMFS fm implementation from scratch with envelopes // @author Chris Chafe (cc@ccrma) class FMFS { // modulator with index envelope and carrier with // amplitude envelope SinOsc mod => Gain ind => ADSR indEnv => SinOsc car; car => ADSR ampEnv => Gain out => blackhole; // generate detailed pitch contour with skew, periodic // vibrato and random jitter // unity constant for center pitch of event Step unity => Gain pit; // add in skew offset controlled by simple Envelope Step skew => Envelope skewEnv => pit; // add in vibrato controlled by ADSR Envelope SinOsc perVib => ADSR vibEnv => pit; // add in some low-frequency randomness Noise ranVib => ResonZ lpf => pit; // apply pitch everywhere that depends on it pit => car; pit => Gain rat => mod; pit => ind; // configure modes of above UG's // config oscillator for fm input (see SinOsc class) 2 => car.sync; // freq is controlled by input only 0.0 => car.freq; // config oscillator for fm input 2 => mod.sync; // freq is controlled by input only 0.0 => mod.freq; // config gain to multiply inputs (see UG class) 3 => ind.op; // initial values setPitch(440.0); setIndex(1.0); setRatio(1.0); // set A, D, S, and R all at once ampEnv.set (10::ms, 10::ms, 0.5, 100::ms); indEnv.set (50::ms, 50::ms, 1, 100::ms); skewEnv.duration (100::ms); vibEnv.set (50::ms, 500::ms, 0.4, 100::ms); // skew in semitones setSkew(1.0); // vibrato frequency, excursion in semitones setVib(6.5, 1.0); // randomness frequency, excursion in semitones setJit(6.5, 1.0); // setPitch() fun void setPitch(float pitch) { pit.gain(pitch); } // setIndex() fun void setIndex(float index) { mod.gain(index); } // setRatio() fun void setRatio(float ratio) { rat.gain(ratio); } // setSkew() fun void setSkew(float semitones) { // units are equal-tempered semitones (Math.pow(2.0, semitones/12.0) - 1.0) => float skewAmt; skew.next( skewAmt ); } // setVib() fun void setVib(float f, float semitones) { perVib.freq(f); // scale it to equal-tempered quartertones // in each direction Math.pow(2.0, semitones/24.0) - 1.0 => float jitAmt; perVib.gain( jitAmt ); } // setJit() fun void setJit(float f, float semitones) { lpf.freq(f); // bandwidth of low-frequency filter resonance, // ok as a constant lpf.Q(1.0); // scale it to equal-tempered quartertones // in each direction Math.pow(2.0, semitones/24.0) - 1.0 => float jitAmt; // empirically scaled up to where it's noticeable 12.0 *=> jitAmt; ranVib.gain(jitAmt); } // attack(): sculpt a note using envelopes fun void attack(dur attack) { // rise time of ADSR ampEnv.attackTime(attack); indEnv.attackTime(attack); vibEnv.attackTime(attack); // duration of simple Envelope skewEnv.duration(attack); // trigger ADSR ampEnv.keyOn(); indEnv.keyOn(); vibEnv.keyOn(); // kind of counterintuitive, but skew from skewAmt // to 0 for attack skewEnv.keyOff(); } // release() fun void release(dur release) { // release time of ADSR ampEnv.releaseTime(release); indEnv.releaseTime(release); vibEnv.releaseTime(release); // duration of simple Envelope skewEnv.duration(release); // trigger ADSR release ampEnv.keyOff(); indEnv.keyOff(); vibEnv.keyOff(); // also counterintuitive, but skew from 0 // to skewAmt during note off skewEnv.keyOn(); } } // END OF CLASS: FMFS