Filter Example

var myCounter = new maximJs.maxiOsc(); //these oscillators will help us count and play sound
var mySwitchableOsc = new maximJs.maxiOsc();//

var CurrentCount;//
var myCurrentVolume;
var myOscOutput,myFilteredOutput;//

var myEnvelope = new maximJs.maxiEnv();
var myFilter = new maximJs.maxiFilter();

function setup(){
    //Timing is in ms
    myEnvelope.setDecay(1);  // Needs to be at least 1
} = function(){
    CurrentCount=Math.round(myCounter.phasor(1, 1, 9));//phasor can take three arguments; frequency, start value and end value.
    // You'll notice that these 'if' statements don't require curly braces "{}".
    // This is because there is only one outcome if the statement is true.
    if (CurrentCount==1) myEnvelope.trigger=1; //trigger the envelope
    else myEnvelope.trigger=0;//release the envelope to make it fade out only if it's been triggered
    // Below, the oscilator signals are being passed through a low pass filter.
    // The middle input is the filter cutoff. It is being controlled by the envelope.
    // Notice that the envelope is being amplified so that it scales between 0 and 1000.
    // The last input is the resonance.
    this.output=myFilteredOutput;//left speaker