polysynth

This shows how to use maximilian to build a polyphonic synth.

var audio = new maximJs.maxiAudio();
audio.init();
  // change output to an array
  audio.outputIsArray(true, 2);

//This shows how to use maximilian to build a polyphonic synth.
// Chrome doesn't like this one for some reason
var VCO_ArraySize = 6;

//These are the synthesiser bits
var VCO1 = [];
for(var i = 0; i < VCO_ArraySize; ++i){
VCO1.push(new maximJs.maxiOsc());
}

var VCO2 = [];
for(var i = 0; i < VCO_ArraySize; ++i){
VCO2.push(new maximJs.maxiOsc());
}

var LFO1 = [];
for(var i = 0; i < VCO_ArraySize; ++i){
LFO1.push(new maximJs.maxiOsc());
}

var LFO2 = [];
for(var i = 0; i < VCO_ArraySize; ++i){
LFO2.push(new maximJs.maxiOsc());
}

var VCF = [];
for(var i = 0; i < VCO_ArraySize; ++i){
VCF.push(new maximJs.maxiFilter());
}

var ADSR = [];
for(var i = 0; i < VCO_ArraySize; ++i){
ADSR.push(new maximJs.maxiEnv());
}

//and these are some variables we can use to pass stuff around
var VCO1out = [], VCO2out = [], LFO1out = [],LFO2out = [], VCFout = [], ADSRout = [];

var pitch = [];

// fill arrays with 0s
for(var i = 0; i < VCO_ArraySize; i++){
    VCO1out.push(0);
    VCO2out.push(0);
    LFO1out.push(0);
    LFO2out.push(0);
    VCFout.push(0);
    ADSRout.push(0);
    pitch.push(0);
}

//This is a bunch of control signals so that we can hear something
var timer = new maximJs.maxiOsc();//this is the metronome
var currentCount = 0,lastCount = 0, voice = 0;//these values are used to check if we have a new beat this sample

var mix;

for (var i=0;i=VCO_ArraySize) {
            voice=0;
        }

        ADSR[voice].trigger=1;//trigger the envelope from the start
        pitch[voice]=voice+1;
        voice++;
        // lastCount = 0;
    }

    //and this is where we build the synth
    for (var i=0; i