//------------------------------------------------ // //Setup and function definition // //------------------------------------------------ Event trigger; //declares an Event object named trigger //define a function that takes a bunch of arguments as parameters for an individual partial fun void partial( Event e, float amp, float freq, float dura, float a, float d, float sustain, float r ) { //tells chuck to wait for a signal from this event object e => now; //the code that follows will only execute if it gets signaled SinOsc s => ADSR adsr => dac; //create our patch amp => s.gain; //passes the amp argument to the gain parameter of the sine wave freq => s.freq; //passes the freq argument to the frequency parameter of the sine wave //attack, decay, and release are defined as ratios of the total duration dura * a => float attack; dura * d => float decay; dura * r => float release; adsr.set( attack::ms, decay::ms, sustain, release::ms ); //starts the attack and decay adsr.keyOn(); //advance time by the total duration minus the release duration dura::ms - release::ms => now; //starts the release adsr.keyOff(); //advance time by the release duration so that the release doesn't get cut off //also by using this with the above we make sure to only advance time by the total duration release::ms => now; } //------------------------------------------------ // //Now the part of the program that uses the above resources to make sound // //------------------------------------------------ //Assign values to the following variables to use interchangeably 0.16 => float amp; //over all amplitude 150 => float ff; //fundamental frequency 7000 => float duration; //total duration //Spork our partials as individual shreds in the chuck virtual machine-- //By using ff*n we define a harmonic timbre spork ~ partial( trigger, amp, ff*1, duration, 0.2, 0.01, 0.8, 0.5 ); spork ~ partial( trigger, amp, ff*3.24, duration, 0.02, 0.4, 0.3, 0.4 ); spork ~ partial( trigger, amp, ff*3.12, duration, 0.2, 0.23, 0.2, 0.4 ); spork ~ partial( trigger, amp, ff*7.5, duration, 0.01, 0.24, 0.1, 0.3 ); spork ~ partial( trigger, amp, ff*17, duration, 0.02, 0.25, 0.05, 0.2 ); spork ~ partial( trigger, amp, ff*18.0045, duration, 0.3, 0.25, 0.0035, 0.01 ); //we need to yeild the execution of this (the current shred) to let the shreds sporked above //to execute me.yield(); //broadcast a signal to the functions to begin their execution (exactly synchronized) trigger.broadcast(); //we have to put a time loop in at the bottom to keep the current shred in the virtual machine //otherwise the child shreds (our individual partials) sporked above won't make any sound while ( true ) { 1::ms => now; }