Enveloping

this tutorial explains how to use the maxiEnv

		var sound1 = new maximJs.maxiSample();

		var snarePhase = new maximJs.maxiOsc();
		var timer = new maximJs.maxiOsc();

		var envelope = new maximJs.maxiEnv();
		var currentCount = 0,lastCount = 0,playHead = 0;

		var sequence = [1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0]; //This is the sequence for the kick


		var sampleTrigger = 0;
		var sampleOut = 0;

		function setup(){
		OutputIsArray(true, 2);
		loadSample('audio/beat2.wav', sound1);
	}

	maximJs.maxiAudio.play = function(){
	if(sound1.isReady()){
	currentCount=Math.floor(timer.phasor(8));//this sets up a metronome that ticks 8 times a second
	
	
	if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound

	sampleTrigger=sequence[playHead%16];
	playHead++;//iterate the playhead
	lastCount=0;//reset the metrotest

}

//the envelope we're using here is an AR envelope.
//It has an input (which in this case is a sound)
//It has an attack coefficient, a hold val (in samples)
//and a release coefficient. Finally, it has a trigger input.
//If you stick a 1 in the trigger input, it retriggers the envelope
sampleOut=envelope.ar(sound1.play(1.), 0.1, 0.9999, 1, sampleTrigger); //

output[0]=sampleOut;//left channel
output[1]=sampleOut;//right channel

sampleTrigger = 0;//set trigger to 0 at the end of each sample to guarantee retriggering.
}
}