Commit f822c970 authored by Daniel Clarke's avatar Daniel Clarke

added code display to example pages

parent b125d4a5
Maxi_Emscripten/
src/cpp/Maximilian-master/
Recordings/
maxiLib/maximilian_examples_web/load_sample_test.html
\ No newline at end of file
maxiLib/maximilian_examples_web/load_sample_test.html
maxiLib/sed_addText.sh
maxiLib/sed_text_stuff/
\ No newline at end of file
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -99,4 +99,48 @@ function play(){
<p>
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
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.setAttack(0);
myEnvelope.setDecay(1); // Needs to be at least 1
myEnvelope.setSustain(1);
myEnvelope.setRelease(1000);
}
function play(){
myCurrentVolume=myEnvelope.adsr(1.,myEnvelope.trigger);
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
myOscOutput=mySwitchableOsc.sawn(100);
// 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.
myFilteredOutput=myFilter.lores(myOscOutput,myCurrentVolume*1000,10);
output=myFilteredOutput;//left speaker
}
</pre>
</body></html>
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -53,23 +53,18 @@ var myOutputs = new maximJs.maxiMix();//this is the stereo mixer channel.
function setup(){
// change output to an array
// setNumOutputChannels(2);
OutputIsArray(true, 2);
}
function play(){
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);//
}
// window.onbeforeunload = function () {
// alert('unload');
// }
}
</script>
</script>
</head>
......@@ -80,4 +75,26 @@ function play(){
<p>
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var myOsc = new maximJs.maxiOsc();
var myAutoPanner = new maximJs.maxiOsc();
var myStereoOutput = GetArrayAsVectorDbl([0,0]);
var myOutputs = new maximJs.maxiMix();//this is the stereo mixer channel.
function setup(){
// change output to an array
// setNumOutputChannels(2);
OutputIsArray(true, 2);
}
function play(){
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>
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -48,10 +48,7 @@ var samplePlayer = new maximJs.maxiSample();
var mySine = new maximJs.maxiOsc();
function setup(){
// console.log(samplePlayer.load("Macintosh HD/Users/Dan/Documents/Programming/Emscripten/emsdk_portable/emscripten/tag-1.34.11/tests/maximilian/web/maximilian_examples_web/beat2.wav", 1));
loadSample("./beat2.wav", samplePlayer);
}
function play(){
......@@ -76,4 +73,23 @@ function play(){
<p>
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var samplePlayer = new maximJs.maxiSample();
var mySine = new maximJs.maxiOsc();
function setup(){
loadSample("./beat2.wav", samplePlayer);
}
function play(){
// this is necessary as file loading may not complete in setup
if(samplePlayer.isReady()){
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>
</body></html>
......@@ -34,7 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -92,9 +92,6 @@ function play() {//this is where the magic happens. Very slow magic.
xs[2] = xs[1]; xs[1] = xs[0];
}
// window.onbeforeunload = function () {
// alert('unload');
// }
</script>
......@@ -107,4 +104,54 @@ function play() {//this is where the magic happens. Very slow magic.
<p>
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var a = new maximJs.maxiOsc();
var xs = [0,0,0], ys = [0,0,0];
var a0, a1, a2, b0, b1, b2;
var f0 = 400; //THE FREQUENCY
var Q = 1.0;
var mySwitchableOsc = new maximJs.maxiOsc();
function setup() {//some inits
var cos = Math.cos;
var w0 = 2*Math.PI*f0/44100;
var alpha = Math.sin(w0)/(2*Q);
//Band-pass reson:
// b0 = alpha;
// b1 = 0;
// b2 = -1 * alpha;
// a0 = 1 + alpha;
// a1 = -2*cos(w0);
// a2 = 1 - alpha;
//Notch:
b0 = 1;
b1 = -2*cos(w0);
b2 = 1;
a0 = 1 + alpha;
a1 = -2*cos(w0);
a2 = 1 - alpha;
//LPF:
// b0 = (1 - cos(w0))/2;
// b1 = 1 - cos(w0);
// b2 = (1 - cos(w0))/2;
// a0 = 1 + alpha;
// a1 = -2*cos(w0);
// a2 = 1 - alpha;
}
function play() {//this is where the magic happens. Very slow magic.
xs[0] = mySwitchableOsc.sawn(400);
ys[0] = (b0/a0)*xs[0] + (b1/a0)*xs[1] + (b2/a0)*xs[2]
- (a1/a0)*ys[1] - (a2/a0)*ys[2];
output = ys[0];
ys[2] = ys[1]; ys[1] = ys[0];
xs[2] = xs[1]; xs[1] = xs[0];
}
</pre>
</body></html>
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -57,7 +57,6 @@ var VCF = new maximJs.maxiFilter();
var ADSR = new maximJs.maxiEnv();
//This is a bunch of control signals so that we can hear something
var timer = new maximJs.maxiOsc();//this is the metronome
var currentCount,lastCount;//these values are used to check if we have a new beat this sample
......@@ -115,4 +114,62 @@ function play(){
This shows how to use maximilian to build a monophonic synth
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
//This shows how to use maximilian to build a monophonic synth
//These are the synthesiser bits
var VCO1 = new maximJs.maxiOsc();
var VCO2 = new maximJs.maxiOsc();
var LFO1 = new maximJs.maxiOsc();
var LFO2 = new maximJs.maxiOsc();
var VCF = new maximJs.maxiFilter();
var ADSR = new maximJs.maxiEnv();
//This is a bunch of control signals so that we can hear something
var timer = new maximJs.maxiOsc();//this is the metronome
var currentCount,lastCount;//these values are used to check if we have a new beat this sample
//and these are some variables we can use to pass stuff around
var VCO1out,VCO2out,LFO1out,LFO2out,VCFout,ADSRout;
function setup(){
ADSR.setAttack(1000);
ADSR.setDecay(1);
ADSR.setSustain(1);
ADSR.setRelease(1000);
}
function play(){
//so this first bit is just a basic metronome so we can hear what we're doing.
currentCount=Math.round(timer.phasor(0.5));//this sets up a metronome that ticks every 2 seconds
if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound
ADSR.trigger = 1;//trigger the envelope from the start
// console.log("tick\n");//the clock ticks
lastCount=0;//set lastCount to 0
}
//and this is where we build the synth
ADSRout=ADSR.adsr(1.0,ADSR.trigger);
LFO1out=LFO1.sinebuf(0.2);//this lfo is a sinewave at 0.2 hz
VCO1out=VCO1.pulse(55,0.6);//here's VCO1. it's a pulse wave at 55 hz, with a pulse width of 0.6
VCO2out=VCO2.pulse(110+LFO1out,0.2);//here's VCO2. it's a pulse wave at 110hz with LFO modulation on the frequency, and width of 0.2
VCFout=VCF.lores((VCO1out+VCO2out)*0.5, ADSRout*10000, 10);//now we stick the VCO's into the VCF, using the ADSR as the filter cutoff
var finalSound=VCFout*ADSRout;//finally we add the ADSR as an amplitude modulator
ADSR.trigger=0;
output=finalSound;
}
</pre>
</body></html>
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -156,4 +156,104 @@ function play(){
This shows how to use maximilian to build a polyphonic synth.
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
//This shows how to use maximilian to build a polyphonic synth.
// for some reason, chrome doesn't like this example?
// maximTools will make it quicker to fill arrays with maxim objects
var maximTools = new maximJs.maximTools();
var VCO_ArraySize = 6;
//These are the synthesiser bits
var VCO1 = maximTools.ArrayOfObj(maximJs.maxiOsc, VCO_ArraySize);
var VCO2 = maximTools.ArrayOfObj(maximJs.maxiOsc, VCO_ArraySize);
var LFO1 = maximTools.ArrayOfObj(maximJs.maxiOsc, VCO_ArraySize);
var LFO2 = maximTools.ArrayOfObj(maximJs.maxiOsc, VCO_ArraySize);
var VCF = maximTools.ArrayOfObj(maximJs.maxiFilter, VCO_ArraySize);
var ADSR = maximTools.ArrayOfObj(maximJs.maxiEnv, VCO_ArraySize);
//and these are some variables we can use to pass stuff around
var VCO1out = [], VCO2out = [], LFO1out = [],LFO2out = [], VCFout = [], ADSRout = [];
var pitch = [];
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;
function setup(){
for (var i=0;i<VCO_ArraySize;i++) {
ADSR[i].setAttack(0);
ADSR[i].setDecay(200);
ADSR[i].setSustain(0.2);
ADSR[i].setRelease(2000);
}
OutputIsArray(true, 2);
}
function play(){
mix=0;//we're adding up the samples each update and it makes sense to clear them each time first.
//so this first bit is just a basic metronome so we can hear what we're doing.
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
if (voice>=6) {
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<6; i++) {
ADSRout[i]=ADSR[i].adsr(1.,ADSR[i].trigger);//our ADSR env is passed a constant signal of 1 to generate the transient.
LFO1out[i]=LFO1[i].sinebuf(0.2);//this lfo is a sinewave at 0.2 hz
VCO1out[i]=VCO1[i].pulse(55*pitch[i],0.6);//here's VCO1. it's a pulse wave at 55 hz, with a pulse width of 0.6
VCO2out[i]=VCO2[i].pulse((110*pitch[i])+LFO1out[i],0.2);//here's VCO2. it's a pulse wave at 110hz with LFO modulation on the frequency, and width of 0.2
VCFout[i]=VCF[i].lores((VCO1out[i]+VCO2out[i])*0.5, 250+((pitch[i]+LFO1out[i])*1000), 10);//now we stick the VCO's into the VCF, using the ADSR as the filter cutoff
mix+=VCFout[i]*ADSRout[i]/6;//finally we add the ADSR as an amplitude modulator
}
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++) {
ADSR[i].trigger=0;
}
}
</pre>
</body></html>
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -127,4 +127,77 @@ function play(){
<p>
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
//Bizarelly, this sounds a little bit like Kraftwerk's 'Metropolis', although it isn't. Funny that.
var sound = new maximJs.maxiOsc();
var bass = new maximJs.maxiOsc();
var timer = new maximJs.maxiOsc();
var mod = new maximJs.maxiOsc();
var lead = new maximJs.maxiOsc();
var lead2 = new maximJs.maxiOsc();
var leadmod = new maximJs.maxiOsc();
var envelope = new maximJs.maxiEnv();
var leadenvelope = new maximJs.maxiEnv();
var filter = new maximJs.maxiFilter();
var filter2 = new maximJs.maxiFilter();
var delay = new maximJs.maxiDelayline();
var mtof = new maximJs.convert();
var bassout,leadout, delayout;//some variables to hold the data and pass it around
var trigger, trigger2, newnote = 0;//some control variables
var currentCount,lastCount,playHead=0, currentChord=0;//some other control variables
var pitch = [57,57,59,60];//the bassline for the arpeggio
var chord = [0,0,7,2,5,5,0,0];//the root chords for the arpeggio
var currentPitch,leadPitch;//the final pitch variables
//here's the lead line trigger array, followed by the pitches
var leadLineTrigger=[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var leadLinePitch=[69,67,65,64,67,66,64,62,65,64,62,57,55,60,57];
function setup(){
OutputIsArray(true, 2);
}
function play(){
currentCount=Math.floor(timer.phasor(9));//this sets up a metronome that ticks every so often
if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound
trigger=1;//play the arpeggiator line
trigger2=leadLineTrigger[playHead%256];//play the lead line
if (trigger2==1) {//if we are going to play a note
leadPitch=mtof.mtof(leadLinePitch[newnote]);//get the next pitch val
newnote++;//and iterate
if (newnote>14) {
newnote=0;//make sure we don't go over the edge of the array
}
}
currentPitch=mtof.mtof(pitch[(playHead%4)]+chord[currentChord%8]);//write the frequency val into currentPitch
playHead++;//iterate the playhead
if (playHead%32==0) {//wrap every 4 bars
currentChord++;//change the chord
}
//cout << "tick\n";//the clock ticks
lastCount=0;//set lastCount to 0
}
bassout=filter2.lores(envelope.adsr(bass.saw(currentPitch*0.5)+sound.pulse(currentPitch*0.5,mod.phasor(1)),1,0.9995, 0.25, 0.9995, 1, trigger),9250,2);//new, simple ADSR.
leadout=filter.lores(leadenvelope.ar(lead2.saw(leadPitch*4)+lead.pulse(leadPitch+(leadmod.sinebuf(1.9)*1.5), 0.6), 0.00005, 0.999975, 50000, trigger2),5900,10);//leadline
delayout=(leadout+(delay.dl(leadout, 14000, 0.8)*0.5))/2;//add some delay
if(trigger!=0)trigger=0;//set the trigger to off if you want it to trigger immediately next time.
output[0]=(bassout + delayout)/2;//sum output
output[1]=(bassout + delayout)/2;
}
</pre>
</body></html>
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -50,7 +50,7 @@ var compressor = new maximJs.maxiDyn(); //this is a compressor
var out = 0;
function setup(){
OutputIsArray(true, 2);
OutputIsArray(true, 2);
compressor.setAttack(100);
compressor.setRelease(300);
......@@ -67,10 +67,10 @@ function play(){
out=compressor.compress(beats.play());
// out=compressor.compress(beats.play(0.66));
}
}
output[0]=out;
output[1]=out;
output[0]=out;
output[1]=out;
}
......@@ -86,4 +86,33 @@ output[1]=out;
compressing a file in real-time
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var beats = new maximJs.maxiSample(); //We give our sample a name. It's called beats this time. We could have loads of them, but they have to have different names.
var compressor = new maximJs.maxiDyn(); //this is a compressor
var out = 0;
function setup(){
OutputIsArray(true, 2);
compressor.setAttack(100);
compressor.setRelease(300);
compressor.setThreshold(0.25);
compressor.setRatio(5);
loadSample('./beat2.wav', beats);
}
function play(){
if(beats.isReady()){
//here, we're just compressing the file in real-time
//arguments are input,ratio,threshold,attack,release
out=compressor.compress(beats.play());
// out=compressor.compress(beats.play(0.66));
}
output[0]=out;
output[1]=out;
}
</pre>
</body></html>
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -84,19 +84,16 @@ function play(){
}
if (kicktrigger==1) {//if the sequence has a 1 in it
// console.log("K");
kick.trigger();//reset the playback position of the sample to 0 (the beginning)
}
if (snaretrigger==1) {
// console.log("S");
snare.trigger();//likewise for the snare
}
if (hattrigger==1) {
// console.log("S");
hat.trigger();//likewise for the snare
}
......@@ -110,7 +107,6 @@ function play(){
kicktrigger = 0;//set trigger to 0 at the end of each sample to guarantee retriggering.
snaretrigger = 0;
hattrigger = 0;
// }
}
......@@ -126,4 +122,69 @@ function play(){
using samples to make a drum machine
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var kick = new maximJs.maxiSample();
var snare = new maximJs.maxiSample();
var hat = new maximJs.maxiSample();
var timer = new maximJs.maxiOsc();
var currentCount,lastCount,playHead = 0;
var kickhit = [1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1]; //This is the sequence for the kick
var snarehit=[0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0];//This is the sequence for the snare
var hathit=[0,0,1,0, 0,0,1,0, 0,0,1,0, 0,0,1,1];//This is the sequence for the snare
var kicktrigger,snaretrigger, hattrigger;
var sampleOut;
function setup(){
// OutputIsArray(true, 2);
loadSample('./kick1.wav', kick);
loadSample('./snare1.wav', snare);
loadSample('./hat12.wav', hat);
}
function play(){
// if(kick.isReady() && snare.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
kicktrigger=kickhit[playHead%16];//get the value out of the array for the kick
snaretrigger=snarehit[playHead%16];//same for the snare
hattrigger=hathit[playHead%16];
playHead++;//iterate the playhead
lastCount=0;//reset the metrotest
}
if (kicktrigger==1) {//if the sequence has a 1 in it
kick.trigger();//reset the playback position of the sample to 0 (the beginning)
}
if (snaretrigger==1) {
snare.trigger();//likewise for the snare
}
if (hattrigger==1) {
hat.trigger();//likewise for the snare
}
sampleOut=hat.playOnce()*0.2+kick.playOnce()+snare.playOnce();//just play the files. No looping.
output=sampleOut;//left 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;
hattrigger = 0;
}
</pre>
</body></html>
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -104,4 +104,51 @@ function play(){
this tutorial explains how to use the maxiEnv
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
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;