Commit 8c8ea9ab authored by Daniel Clarke's avatar Daniel Clarke

maxiAudio is refactored.

parent c52a542b
......@@ -5,7 +5,7 @@ EMSCR=../../em++
# Maximilian base stuff
# POST_JS is all the external js stuff that handles web audio etc
POST_JS_webAudio_all=src/js/maxi_webAudio_Complete.js
POST_JS_webAudio_all=src/js/maxi_webAudio.js
# POST_JS_extras=src/js/maxi_extras.js
#the .cpp file that is used
......
......@@ -33332,65 +33332,74 @@ maximJs.maxiTools.loadSample = (function(url, samplePlayer, contextIn) {
});
request.send();
});
maximJs.maxiAudio = (function() {});
maximJs.maxiAudio.output = 0;
maximJs.maxiAudio.numChannels = 2;
maximJs.maxiAudio.context = null;
maximJs.maxiAudio.source = null;
maximJs.maxiAudio.analyser = null;
maximJs.maxiAudio.jsProcessor = null;
maximJs.maxiAudio.play = (function() {});
maximJs.maxiAudio.setup = (function() {
console.log("non-overrided setup");
});
maximJs.maxiAudio.setNumChannels = (function(isArray, numChannels_) {
this.numChannels = numChannels_;
this.outputIsArray(isArray, numChannels_);
this.resetAudio();
});
maximJs.maxiAudio.outputIsArray = (function(isArray, numChannels_) {
if (isArray) {
maximJs.maxiAudio.output = new Array(numChannels_);
for (var i = 0; i < numChannels_; i++) {
maximJs.maxiAudio.output[i] = 0;
}
} else {
maximJs.maxiAudio.output = 0;
}
});
maximJs.maxiAudio.process = (function(event) {
var numChannels = event.outputBuffer.numberOfChannels;
var outputLength = event.outputBuffer.getChannelData(0).length;
for (var i = 0; i < outputLength; ++i) {
maximJs.maxiAudio.play();
if (maximJs.maxiAudio.output instanceof Array) {
for (var channel = 0; channel < numChannels; channel++) {
event.outputBuffer.getChannelData(channel)[i] = maximJs.maxiAudio.output[channel];
maximJs.maxiAudio = (function() {
var numChannels = 2;
var output = 0;
this.context = null;
this.source = null;
this.analyser = null;
this.jsProcessor = null;
var initDone = false;
this.play = (function() {});
this.setup = (function() {
console.log("non-overrided setup");
});
this.getNumChannels = (function() {
return numChannels;
});
this.setNumChannels = (function(isArray, numChannels_) {
numChannels = numChannels_;
this.outputIsArray(isArray, numChannels_);
this.resetAudio();
});
this.outputIsArray = (function(isArray) {
if (isArray) {
maximJs.maxiAudio.output = new Array(numChannels);
for (var i = 0; i < numChannels; i++) {
maximJs.maxiAudio.output[i] = 0;
}
} else {
for (var channel = 0; channel < numChannels; channel++) {
event.outputBuffer.getChannelData(channel)[i] = maximJs.maxiAudio.output;
maximJs.maxiAudio.output = 0;
}
});
var process = (function(event) {
var numChannels = event.outputBuffer.numberOfChannels;
var outputLength = event.outputBuffer.getChannelData(0).length;
for (var i = 0; i < outputLength; ++i) {
maximJs.maxiAudio.play();
if (maximJs.maxiAudio.output instanceof Array) {
for (var channel = 0; channel < numChannels; channel++) {
event.outputBuffer.getChannelData(channel)[i] = maximJs.maxiAudio.output[channel];
}
} else {
for (var channel = 0; channel < numChannels; channel++) {
event.outputBuffer.getChannelData(channel)[i] = maximJs.maxiAudio.output;
}
}
}
}
});
maximJs.maxiAudio.resetAudio = (function() {
this.source.disconnect();
this.jsProcessor.disconnect();
this.analyser.disconnect();
this.init();
});
maximJs.maxiAudio.init = (function() {
this.context = new (window.AudioContext || window.webkitAudioContext);
this.source = this.context.createBufferSource();
this.jsProcessor = this.context.createScriptProcessor(4096, this.numChannels, this.numChannels);
this.jsProcessor.onaudioprocess = this.process;
this.analyser = this.context.createAnalyser();
this.analyser.fftSize = 2048;
this.source.connect(this.jsProcessor);
this.jsProcessor.connect(this.analyser);
this.analyser.connect(this.context.destination);
});
});
this.resetAudio = (function() {
if (initDone) {
this.source.disconnect();
this.jsProcessor.disconnect();
this.analyser.disconnect();
}
this.init();
});
this.init = (function() {
this.context = new (window.AudioContext || window.webkitAudioContext);
this.source = this.context.createBufferSource();
this.jsProcessor = this.context.createScriptProcessor(4096, numChannels, numChannels);
this.jsProcessor.onaudioprocess = process;
this.analyser = this.context.createAnalyser();
this.analyser.fftSize = 2048;
this.source.connect(this.jsProcessor);
this.jsProcessor.connect(this.analyser);
this.analyser.connect(this.context.destination);
initDone = true;
});
return this;
})();
......@@ -85,7 +85,7 @@ maximJs.maxiAudio.play = function(){
// The last input is the resonance.
myFilteredOutput=myFilter.lores(myOscOutput,myCurrentVolume*1000,10);
this.output=myFilteredOutput;//left speaker
output=myFilteredOutput;//left speaker
}
......@@ -141,7 +141,7 @@ maximJs.maxiAudio.play = function(){
// The last input is the resonance.
myFilteredOutput=myFilter.lores(myOscOutput,myCurrentVolume*1000,10);
this.output=myFilteredOutput;//left speaker
output=myFilteredOutput;//left speaker
}
</pre>
</body></html>
......@@ -44,7 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
maximJs.maxiAudio.init();
// change this.output to an array
// change output to an array
maximJs.maxiAudio.outputIsArray(true, 2);
var myOsc = new maximJs.maxiOsc();
......@@ -55,9 +55,9 @@ var myOutputs = new maximJs.maxiMix();//this is the stereo mixer channel.
maximJs.maxiAudio.play = function(){
myOutputs.stereo(myOsc.noise(),myStereoOutput,(myAutoPanner.sinewave(1)+1)/2);//Stereo, Quad or 8 Channel. Specify the input to be mixed, the this.output[numberofchannels], and the pan (0-1,equal power).
this.output[0]=myStereoOutput.get(0);//When working with mixing, you need to specify the this.outputs explicitly
this.output[1]=myStereoOutput.get(1);//
myOutputs.stereo(myOsc.noise(),myStereoOutput,(myAutoPanner.sinewave(1)+1)/2);//Stereo, Quad or 8 Channel. Specify the input to be mixed, the output[numberofchannels], and the pan (0-1,equal power).
output[0]=myStereoOutput.get(0);//When working with mixing, you need to specify the outputs explicitly
output[1]=myStereoOutput.get(1);//
}
</script>
......@@ -80,7 +80,7 @@ maximJs.maxiAudio.play = function(){
function setup(){
// change this.output to an array
// change output to an array
// setNumOutputChannels(2);
OutputIsArray(true, 2);
}
......@@ -88,9 +88,9 @@ maximJs.maxiAudio.play = function(){
maximJs.maxiAudio.play = function(){
myOutputs.stereo(myOsc.noise(),myStereoOutput,(myAutoPanner.sinewave(1)+1)/2);//Stereo, Quad or 8 Channel. Specify the input to be mixed, the this.output[numberofchannels], and the pan (0-1,equal power).
this.output[0]=myStereoOutput.get(0);//When working with mixing, you need to specify the this.outputs explicitly
this.output[1]=myStereoOutput.get(1);//
myOutputs.stereo(myOsc.noise(),myStereoOutput,(myAutoPanner.sinewave(1)+1)/2);//Stereo, Quad or 8 Channel. Specify the input to be mixed, the output[numberofchannels], and the pan (0-1,equal power).
output[0]=myStereoOutput.get(0);//When working with mixing, you need to specify the outputs explicitly
output[1]=myStereoOutput.get(1);//
}
</pre>
</body></html>
......@@ -55,10 +55,10 @@ maximJs.maxiTools.loadSample("audio/beat2.wav", samplePlayer);
maximJs.maxiAudio.play = function(){
// this is necessary as file loading may not complete in setup
if(samplePlayer.isReady()){
this.output = samplePlayer.play();//just play the file. Looping is default for all play functions.
// this.output=samplePlayer.play(0.69) ;//play the file with a speed setting. 1. is normal speed.
// this.output=samplePlayer.play(0.5,0,44100);//linear interpolationplay with a frequency input, start point and end point. Useful for syncing.
// this.output=samplePlayer.play4(0.5,0,44100);//cubic interpolation play with a frequency input, start point and end point. Useful for syncing.
output = samplePlayer.play();//just play the file. Looping is default for all play functions.
// output=samplePlayer.play(0.69) ;//play the file with a speed setting. 1. is normal speed.
// output=samplePlayer.play(0.5,0,44100);//linear interpolationplay with a frequency input, start point and end point. Useful for syncing.
// output=samplePlayer.play4(0.5,0,44100);//cubic interpolation play with a frequency input, start point and end point. Useful for syncing.
}
}
......@@ -86,10 +86,10 @@ loadSample("./beat2.wav", samplePlayer);
maximJs.maxiAudio.play = function(){
// this is necessary as file loading may not complete in setup
if(samplePlayer.isReady()){
this.output = samplePlayer.play();//just play the file. Looping is default for all play functions.
// this.output=samplePlayer.play(0.69) ;//play the file with a speed setting. 1. is normal speed.
// this.output=samplePlayer.play(0.5,0,44100);//linear interpolationplay with a frequency input, start point and end point. Useful for syncing.
// this.output=samplePlayer.play4(0.5,0,44100);//cubic interpolation play with a frequency input, start point and end point. Useful for syncing.
output = samplePlayer.play();//just play the file. Looping is default for all play functions.
// output=samplePlayer.play(0.69) ;//play the file with a speed setting. 1. is normal speed.
// output=samplePlayer.play(0.5,0,44100);//linear interpolationplay with a frequency input, start point and end point. Useful for syncing.
// output=samplePlayer.play4(0.5,0,44100);//cubic interpolation play with a frequency input, start point and end point. Useful for syncing.
}
}
</pre>
......
......@@ -88,7 +88,7 @@ maximJs.maxiAudio.play = function() {//this is where the magic happens. Very slo
ys[0] = (b0/a0)*xs[0] + (b1/a0)*xs[1] + (b2/a0)*xs[2]
- (a1/a0)*ys[1] - (a2/a0)*ys[2];
this.output = ys[0];
output = ys[0];
ys[2] = ys[1]; ys[1] = ys[0];
xs[2] = xs[1]; xs[1] = xs[0];
......@@ -153,7 +153,7 @@ maximJs.maxiAudio.play = function() {//this is where the magic happens. Very slo
ys[0] = (b0/a0)*xs[0] + (b1/a0)*xs[1] + (b2/a0)*xs[2]
- (a1/a0)*ys[1] - (a2/a0)*ys[2];
this.output = ys[0];
output = ys[0];
ys[2] = ys[1]; ys[1] = ys[0];
xs[2] = xs[1]; xs[1] = xs[0];
......
......@@ -96,7 +96,7 @@ maximJs.maxiAudio.play = function(){
var finalSound=VCFout*ADSRout;//finally we add the ADSR as an amplitude modulator
ADSR.trigger=0;
this.output=finalSound;
output=finalSound;
}
</script>
......@@ -164,7 +164,7 @@ maximJs.maxiAudio.play = function(){
var finalSound=VCFout*ADSRout;//finally we add the ADSR as an amplitude modulator
ADSR.trigger=0;
this.output=finalSound;
output=finalSound;
}
</pre>
</body></html>
......@@ -45,7 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
maximJs.maxiAudio.init();
// change this.output to an array
// change output to an array
maximJs.maxiAudio.outputIsArray(true, 2);
//This shows how to use maximilian to build a polyphonic synth.
......@@ -131,8 +131,8 @@ maximJs.maxiAudio.play = function(){
}
this.output[0]=mix*0.5;//left channel
this.output[1]=mix*0.5;//right channel
output[0]=mix*0.5;//left channel
output[1]=mix*0.5;//right channel
// This just sends note-off messages.
for (var i=0; i<6; i++) {
......@@ -155,7 +155,7 @@ maximJs.maxiAudio.play = function(){
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
maximJs.maxiAudio.init();
// change this.output to an array
// change output to an array
maximJs.maxiAudio.outputIsArray(true, 2);
//This shows how to use maximilian to build a polyphonic synth.
......@@ -240,8 +240,8 @@ maximJs.maxiAudio.play = function(){
}
this.output[0]=mix*0.5;//left channel
this.output[1]=mix*0.5;//right channel
output[0]=mix*0.5;//left channel
output[1]=mix*0.5;//right channel
// This just sends note-off messages.
for (var i=0; i<6; i++) {
......
......@@ -107,8 +107,8 @@ maximJs.maxiAudio.play = function(){
if(trigger!=0)trigger=0;//set the trigger to off if you want it to trigger immediately next time.
this.output[0]=(bassout + delayout)/2;//sum this.output
this.output[1]=(bassout + delayout)/2;
output[0]=(bassout + delayout)/2;//sum output
output[1]=(bassout + delayout)/2;
}
......@@ -190,8 +190,8 @@ maximJs.maxiAudio.play = function(){
if(trigger!=0)trigger=0;//set the trigger to off if you want it to trigger immediately next time.
this.output[0]=(bassout + delayout)/2;//sum this.output
this.output[1]=(bassout + delayout)/2;
output[0]=(bassout + delayout)/2;//sum output
output[1]=(bassout + delayout)/2;
}
</pre>
</body></html>
......@@ -70,8 +70,8 @@ maximJs.maxiAudio.play = function(){
}
this.output[0]=out;
this.output[1]=out;
output[0]=out;
output[1]=out;
}
......@@ -112,8 +112,8 @@ maximJs.maxiAudio.play = function(){
}
this.output[0]=out;
this.output[1]=out;
output[0]=out;
output[1]=out;
}
</pre>
</body></html>
......@@ -97,10 +97,10 @@ maximJs.maxiAudio.play = function(){
sampleOut=hat.playOnce()*0.2+kick.playOnce()+snare.playOnce();//just play the files. No looping.
this.output=sampleOut;//left channel
output=sampleOut;//left channel
// this.output[0]=sampleOut;//left channel
// this.output[1]=sampleOut;//right channel
// output[0]=sampleOut;//left channel
// output[1]=sampleOut;//right channel
kicktrigger = 0;//set trigger to 0 at the end of each sample to guarantee retriggering.
snaretrigger = 0;
......@@ -174,10 +174,10 @@ maximJs.maxiAudio.play = function(){
sampleOut=hat.playOnce()*0.2+kick.playOnce()+snare.playOnce();//just play the files. No looping.
this.output=sampleOut;//left channel
output=sampleOut;//left channel
// this.output[0]=sampleOut;//left channel
// this.output[1]=sampleOut;//right channel
// output[0]=sampleOut;//left channel
// output[1]=sampleOut;//right channel
kicktrigger = 0;//set trigger to 0 at the end of each sample to guarantee retriggering.
snaretrigger = 0;
......
......@@ -85,8 +85,8 @@ maximJs.maxiAudio.play = function(){
//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); //
this.output[0]=sampleOut;//left channel
this.output[1]=sampleOut;//right channel
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.
}
......@@ -145,8 +145,8 @@ maximJs.maxiAudio.play = function(){
//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); //
this.output[0]=sampleOut;//left channel
this.output[1]=sampleOut;//right channel
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.
}
......
......@@ -51,7 +51,7 @@ maximJs.maxiAudio.init();
var mySine = new maximJs.maxiOsc();
maximJs.maxiAudio.play = function(){
this.output = mySine.sinewave(440);
output = mySine.sinewave(440);
}
......@@ -74,7 +74,7 @@ maximJs.maxiAudio.init();
var mySine = new maximJs.maxiOsc();
maximJs.maxiAudio.play = function(){
this.output = mySine.sinewave(440);
output = mySine.sinewave(440);
}
</pre>
</body>
......
......@@ -62,7 +62,7 @@ maximJs.maxiAudio.play = function(){
wave = wave + thisSine;
}
wave *= 0.1;
this.output = wave;//simple as that!
output = wave;//simple as that!
}
......@@ -99,7 +99,7 @@ maximJs.maxiAudio.play = function(){
wave = wave + thisSine;
}
wave *= 0.1;
this.output = wave;//simple as that!
output = wave;//simple as that!
}
</pre>
</body></html>
......@@ -114,7 +114,7 @@ maximJs.maxiAudio.play = function(){
count++; // increment counter
}
this.output = wave;
output = wave;
}
......@@ -189,7 +189,7 @@ maximJs.maxiAudio.play = function(){
count++; // increment counter
}
this.output = wave;
output = wave;
}
......
......@@ -67,7 +67,7 @@ if(!grainsSet){
grainsSet = true;
}
this.output = stretch.play(1, 2,0.1, 2, 0);
output = stretch.play(1, 2,0.1, 2, 0);
// ouptut = grains.play2(pos, 0.1, 4);
}
}
......@@ -108,7 +108,7 @@ if(!grainsSet){
grainsSet = true;
}
this.output = stretch.play(1, 2,0.1, 2, 0);
output = stretch.play(1, 2,0.1, 2, 0);
// ouptut = grains.play2(pos, 0.1, 4);
}
}
......
......@@ -54,7 +54,7 @@ var myOtherSine = new maximJs.maxiOsc();
maximJs.maxiAudio.play = function(){
// these two sines will beat together. They're now a bit too loud though..
this.output = mySine.sinewave(440) + myOtherSine.sinewave(441);
output = mySine.sinewave(440) + myOtherSine.sinewave(441);
}
</script>
......@@ -78,7 +78,7 @@ var myOtherSine = new maximJs.maxiOsc();
maximJs.maxiAudio.play = function(){
// these two sines will beat together. They're now a bit too loud though..
this.output = mySine.sinewave(440) + myOtherSine.sinewave(441);
output = mySine.sinewave(440) + myOtherSine.sinewave(441);
}
</pre>
</body></html>
......@@ -54,7 +54,7 @@ var myOtherSine = new maximJs.maxiOsc();
maximJs.maxiAudio.play = function(){
// these two sines will beat together. They're now a bit too loud though..
this.output = mySine.sinewave(440)*myOtherSine.sinewave(1);
output = mySine.sinewave(440)*myOtherSine.sinewave(1);
}
......@@ -80,7 +80,7 @@ var myOtherSine = new maximJs.maxiOsc();
maximJs.maxiAudio.play = function(){
// these two sines will beat together. They're now a bit too loud though..
this.output = mySine.sinewave(440)*myOtherSine.sinewave(1);
output = mySine.sinewave(440)*myOtherSine.sinewave(1);
}
......
......@@ -55,7 +55,7 @@ var myPhasor = new maximJs.maxiOsc();
maximJs.maxiAudio.play = function(){
// these two sines will beat together. They're now a bit too loud though..
this.output = mySine.sinewave(440)*myOtherSine.sinewave(myPhasor.phasor(0.1,0,440));
output = mySine.sinewave(440)*myOtherSine.sinewave(myPhasor.phasor(0.1,0,440));
}
......@@ -82,7 +82,7 @@ var myPhasor = new maximJs.maxiOsc();
maximJs.maxiAudio.play = function(){
// these two sines will beat together. They're now a bit too loud though..
this.output = mySine.sinewave(440)*myOtherSine.sinewave(myPhasor.phasor(0.1,0,440));
output = mySine.sinewave(440)*myOtherSine.sinewave(myPhasor.phasor(0.1,0,440));
}
</pre>
</body></html>
......@@ -54,7 +54,7 @@ var myOtherSine = new maximJs.maxiOsc();
maximJs.maxiAudio.play = function(){
// these two sines will beat together. They're now a bit too loud though.
this.output = mySine.sinewave(440+(myOtherSine.sinewave(1)*100));
output = mySine.sinewave(440+(myOtherSine.sinewave(1)*100));
}
......
......@@ -53,7 +53,7 @@ var myLastSine = new maximJs.maxiOsc();
var myPhasor = new maximJs.maxiOsc();
maximJs.maxiAudio.play = function(){
this.output=mySine.sinewave(myOtherSine.sinewave(myLastSine.sinewave(0.1)*30)*440);//awesome bassline
output=mySine.sinewave(myOtherSine.sinewave(myLastSine.sinewave(0.1)*30)*440);//awesome bassline
}
......@@ -77,7 +77,7 @@ var myLastSine = new maximJs.maxiOsc();
var myPhasor = new maximJs.maxiOsc();
maximJs.maxiAudio.play = function(){
this.output=mySine.sinewave(myOtherSine.sinewave(myLastSine.sinewave(0.1)*30)*440);//awesome bassline
output=mySine.sinewave(myOtherSine.sinewave(myLastSine.sinewave(0.1)*30)*440);//awesome bassline
}
</pre>
</body></html>
......@@ -66,7 +66,7 @@ maximJs.maxiAudio.play = function(){
} // The curly braces close the conditional
this.output=mySine.sinewave(freq);//simple as that!
output=mySine.sinewave(freq);//simple as that!
}
......@@ -105,7 +105,7 @@ maximJs.maxiAudio.play = function(){
} // The curly braces close the conditional
this.output=mySine.sinewave(freq);//simple as that!
output=mySine.sinewave(freq);//simple as that!
}
</pre>
</body></html>
......@@ -53,7 +53,7 @@ var currentCount;
maximJs.maxiAudio.play = function(){
CurrentCount = Math.floor(myCounter.phasor(1, 1, 9));//phasor can take three arguments; frequency, start value and end value
this.output=mySquare.square(CurrentCount*100);
output=mySquare.square(CurrentCount*100);
}
......@@ -78,7 +78,7 @@ var currentCount;
maximJs.maxiAudio.play = function(){
CurrentCount = Math.floor(myCounter.phasor(1, 1, 9));//phasor can take three arguments; frequency, start value and end value
this.output=mySquare.square(CurrentCount*100);
output=mySquare.square(CurrentCount*100);
}
</pre>
</body></html>
......@@ -49,7 +49,7 @@ maximJs.maxiAudio.init();
var myCounter = new maximJs.maxiOsc();
var mySwitchableOsc = new maximJs.maxiOsc();//these oscillators will help us count and make sound.
var CurrentCount;//we're going to put the current count in this variable so that we can use it more easily.
var myOscOutput;//we're going to stick the this.output here to make it easier to mess with stuff.
var myOscOutput;//we're going to stick the output here to make it easier to mess with stuff.
maximJs.maxiAudio.play = function(){
CurrentCount=Math.floor(myCounter.phasor(1, 1, 9));//phasor can take three arguments; frequency, start value and end value.
......@@ -60,7 +60,7 @@ maximJs.maxiAudio.play = function(){
else if (CurrentCount>=5){//and the 'else' bit.
myOscOutput=mySwitchableOsc.sinewave(CurrentCount*50);//one osc object can produce whichever waveform you want.
}
this.output=myOscOutput;//point me at your speakers and fire.
output=myOscOutput;//point me at your speakers and fire.
}
......
......@@ -52,7 +52,7 @@ var mySwitchableOsc = new maximJs.maxiOsc();
var another = new maximJs.maxiOsc();
var CurrentCount;//we're going to put the current count in this variable so that we can use it more easily.
var myOscOutput;//we're going to stick the this.output here to make it easier to mess with stuff.
var myOscOutput;//we're going to stick the output here to make it easier to mess with stuff.
var myArray=[100,200,300,400,300,200,100,240,640,360];
maximJs.maxiAudio.play = function(){
......@@ -66,7 +66,7 @@ maximJs.maxiAudio.play = function(){
myOscOutput=mySwitchableOsc.sawn(myArray[CurrentCount]);//one osc object can produce whichever waveform you want.
}
this.output=myOscOutput;//point me at your speakers and fire.
output=myOscOutput;//point me at your speakers and fire.
}
......@@ -87,7 +87,7 @@ maximJs.maxiAudio.play = function(){
var myCounter = new maximJs.maxiOsc();
var mySwitchableOsc = new maximJs.maxiOsc();//these oscillators will help us count and make sound.
var CurrentCount;//we're going to put the current count in this variable so that we can use it more easily.
var myOscOutput;//we're going to stick the this.output here to make it easier to mess with stuff.
var myOscOutput;//we're going to stick the output here to make it easier to mess with stuff.
maximJs.maxiAudio.play = function(){
CurrentCount=Math.floor(myCounter.phasor(1, 1, 9));//phasor can take three arguments; frequency, start value and end value.
......@@ -98,7 +98,7 @@ maximJs.maxiAudio.play = function(){
else if (CurrentCount>=5){//and the 'else' bit.
myOscOutput=mySwitchableOsc.sinewave(CurrentCount*50);//one osc object can produce whichever waveform you want.
}
this.output=myOscOutput;//point me at your speakers and fire.
output=myOscOutput;//point me at your speakers and fire.
}
</pre>
</body></html>
......@@ -88,7 +88,7 @@ if (CurrentCount<5){
myOscOutput=mySwitchableOsc.sinewave(CurrentCount*50);//one osc object can produce whichever waveform you want.
}
this.output=myOscOutput*myCurrentVolume;//left speaker
output=myOscOutput*myCurrentVolume;//left speaker
}
......@@ -148,7 +148,7 @@ if (CurrentCount<5){
myOscOutput=mySwitchableOsc.sinewave(CurrentCount*50);//one osc object can produce whichever waveform you want.
}
this.output=myOscOutput*myCurrentVolume;//left speaker
output=myOscOutput*myCurrentVolume;//left speaker
}
</pre>
</body></html>
......@@ -139,7 +139,83 @@ function play(){
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
// An example of jsMaxim with manual implementation of webAudio
var context = new (window.AudioContext || window.webkitAudioContext)();
var source;
var jsProcessor = 0;
var analyser;
var output = 0;
var bufferLoader;
// function handling audio processing
// called byjsProcessor
function process(event) {
var numChannels = event.outputBuffer.numberOfChannels;
var outputLength = event.outputBuffer.getChannelData(0).length;
for (var i = 0; i < outputLength; ++i) {
play();
if(output instanceof Array){ // check if we're using arrays
for (var channel = 0; channel < numChannels; channel++) {
event.outputBuffer.getChannelData(channel)[i] = output[channel];
}
}
else
{
for (var channel = 0; channel < numChannels; channel++) {
event.outputBuffer.getChannelData(channel)[i] = output;
}
}
}
}
function initAudio(numChannels) {
source = context.createBufferSource();
jsProcessor = context.createScriptProcessor(4096, numChannels, numChannels);
jsProcessor.onaudioprocess = process;
analyser = context.createAnalyser();
analyser.fftSize = 2048;
// Connect the processing graph: source -> jsProcessor -> analyser -> destination
source.connect(jsProcessor);
jsProcessor.connect(analyser);
analyser.connect(context.destination);
}
function init() {
initAudio(2);
setup();
}
window.onload = init;
// ----------------------------------------------------------------------
// The code
var mySine = new maximJs.maxiOsc();
var mySamp = new maximJs.maxiSample();