Skip to content
Snippets Groups Projects
Commit d80bb324 authored by Dr-Dan's avatar Dr-Dan
Browse files

ignoring old_stuff folder. Updated readme yet again

parent 7669964b
Branches
No related merge requests found
Showing
with 4 additions and 1326 deletions
......@@ -4,4 +4,5 @@ Recordings/
maxiLib/maximilian_examples_web/load_sample_test.html
maxiLib/sed_addText.sh
maxiLib/sed_text_stuff/
maximilian_examples_cpp/
\ No newline at end of file
maximilian_examples_cpp/
old_stuff/
\ No newline at end of file
An implementation of maximilian in javascript using emscripten to compile code from C++ to javascript/asm.js.
To use: move the maxiLib.js file from the maxiLib folder to an appropriate location and include using the <script> tag.
To use: move the maxiLib.js file from the maxiLib folder to an appropriate location and include using the <script> tag right now.
If you want to use without webAudio API setup for you, include maxiLib_noWebAudio.js. You can still include the maxi_webAudio file (from the src/js folder) after this and all will function as usual.
Examples of usage are contained in maxiLib/maximilian_examples_web.
\ No newline at end of file
Examples are in maxiLib/maximilian_examples_web.
\ No newline at end of file
<!--
Copyright 2010, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<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"> -->
<script src="../maxiLib.js"></script>
<!-- Our javascript code -->
<script type="text/javascript">
var myCounter = new maximJs.maxiOsc();
var mySwitchableOsc = new maximJs.maxiOsc();
var myAutoPanner = new maximJs.maxiOsc();
var currentCount;
var myOscOutput, myFilteredOutput, myPanPosition;
var myStereoOutput = GetArrayAsVectorDbl([0,0]);// we need an output for each channel.
var myEnvelopeData = GetArrayAsVectorDbl([500,0,1000,500,0,500]);//this data will be used to make an envelope. Value and time to value in ms.
var myEnvelope = new maximJs.maxiEnvelope();
var myFilter = new maximJs.maxiFilter();
var myOutputs = new maximJs.maxiMix();
function setup(){
myEnvelope.amplitude=myEnvelopeData.get(0); //initialise the envelope
// change output to an array
// setNumOutputChannels(2);
OutputIsArray(true, 2);
}
function play(){
CurrentCount=Math.floor(myCounter.phasor(1, 1, 9));//phasor can take three arguments; frequency, start value and end value.
if (CurrentCount<5){//simple if statement
myOscOutput=mySwitchableOsc.square(CurrentCount*100);
}
else if (CurrentCount>=5){//and the 'else' bit.
myOscOutput=mySwitchableOsc.saw(CurrentCount*50);//one osc object can produce whichever waveform you want.
}
if (CurrentCount==1) {
myEnvelope.trigger(0,myEnvelopeData.get(0)); //trigger the envelope
}
myFilteredOutput=myFilter.lores(myOscOutput,(myEnvelope.line(6, myEnvelopeData)),10);//lores takes an audio input, a frequency and a resonance factor (1-100)
myPanPosition=myAutoPanner.sinewave(1);
myOutputs.stereo(myFilteredOutput,myStereoOutput,myPanPosition);//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 explicityly
output[1]=myStereoOutput.get(1);//
}
</script>
</head>
<body>
<h1> Mixing Example </h1>
<p>
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var myCounter = new maximJs.maxiOsc();
var mySwitchableOsc = new maximJs.maxiOsc();
var myAutoPanner = new maximJs.maxiOsc();
var currentCount;
var myOscOutput, myFilteredOutput, myPanPosition;
var myStereoOutput = GetArrayAsVectorDbl([0,0]);// we need an output for each channel.
var myEnvelopeData = GetArrayAsVectorDbl([500,0,1000,500,0,500]);//this data will be used to make an envelope. Value and time to value in ms.
var myEnvelope = new maximJs.maxiEnvelope();
var myFilter = new maximJs.maxiFilter();
var myOutputs = new maximJs.maxiMix();
function setup(){
myEnvelope.amplitude=myEnvelopeData.get(0); //initialise the envelope
// change output to an array
// setNumOutputChannels(2);
OutputIsArray(true, 2);
}
function play(){
CurrentCount=Math.floor(myCounter.phasor(1, 1, 9));//phasor can take three arguments; frequency, start value and end value.
if (CurrentCount<5){//simple if statement
myOscOutput=mySwitchableOsc.square(CurrentCount*100);
}
else if (CurrentCount>=5){//and the 'else' bit.
myOscOutput=mySwitchableOsc.saw(CurrentCount*50);//one osc object can produce whichever waveform you want.
}
if (CurrentCount==1) {
myEnvelope.trigger(0,myEnvelopeData.get(0)); //trigger the envelope
}
myFilteredOutput=myFilter.lores(myOscOutput,(myEnvelope.line(6, myEnvelopeData)),10);//lores takes an audio input, a frequency and a resonance factor (1-100)
myPanPosition=myAutoPanner.sinewave(1);
myOutputs.stereo(myFilteredOutput,myStereoOutput,myPanPosition);//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 explicityly
output[1]=myStereoOutput.get(1);//
}
</pre>
</body></html>
<!--
Copyright 2010, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<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"> -->
<script src="../maxiLib.js"></script>
<!-- <script src="../maxi_webAudio.js"></script> -->
<!-- Our javascript code -->
<script type="text/javascript">
// var outputs = new Array(2);
// var moreoutputs = new Array(2); //some track outputs
var outputs = new Module.VectorDouble();
var moreoutputs = new Module.VectorDouble();//this data will be used to make an envelope. Value and time to value in ms.
var filtered,patch1,patch2,tune,delayed,mixed,ramp,filtered2,noise,pan,more;//a bunch of patch cables
var beat,lastbeat, morebeats, morebeats2,lastmorebeats;//some rhythmic elemts
// var env = [200,0,0,50];//the kick drum pitch envelope data
var env = GetArrayAsVectorDbl([200,0,0,50]);
// var env2 = [10000,0,9000,5,0,5];//the hi hat pitch envelope dat
var env2 = GetArrayAsVectorDbl([10000,0,9000,5,0,5]);
var melody = [600,0,0,650,0,0,400,0,0,425,0,300,0,315,0,315, 0];//the melody data
var rhythm1 = [1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0];//another way of doing a rhythm
var a = new maximJs.maxiOsc();
var c = new maximJs.maxiOsc();
var d = new maximJs.maxiOsc();
var e = new maximJs.maxiOsc();
var g = new maximJs.maxiOsc();
var h = new maximJs.maxiOsc();
var i = new maximJs.maxiOsc();
var j = new maximJs.maxiOsc();
var squarewave = new maximJs.maxiOsc();//some oscillators maxiOsc...
var b = new maximJs.maxiEnvelope();
var f = new maximJs.maxiEnvelope();//two envelopers
var delay = new maximJs.maxiDelayline();//a delay line
var myfilter = new maximJs.maxiFilter();
var antia = new maximJs.maxiFilter();// a FAT filter
var mymix = new maximJs.maxiMix();
var bobbins = new maximJs.maxiMix();//some panning busses
var beats = new maximJs.maxiSample();
function setup() {//some inits
outputs.push_back(0);
outputs.push_back(0);
moreoutputs.push_back(0);
moreoutputs.push_back(0);
b.amplitude=env.get(0);//starting value for envelope b
f.amplitude=env2.get(0);//same for f
// beats.load("/Users/chris/src/Maximilian/beat2.wav");//put a path to a soundfile here. Wav format only.
loadSample("./beat2.wav", beats);
// printf("Summary:\n%s", beats.getSummary());//get info on samples if you like
OutputIsArray(true, 2);
}
function play() {//this is where the magic happens. Very slow magic.
if(beats.isReady()){
beat = Math.floor(c.phasor(8));//this oscillator is now a counter
morebeats = Math.floor(e.phasor(0.5,0,16));//so is this one
patch1 = b.line(4,env);//here's envelope b
patch2 = f.line(6,env2);//here's envelop f
tune=g.saw(melody[morebeats]*0.25);
if (lastbeat!=beat) {//this is a nice sample and hold routine for the kick drum
f.trigger(0, env2.get(0));//it runs off the hi hat.
if (rhythm1[morebeats]==1) {
b.trigger(0, env.get(0));//and gets played when it's time.
// console.log("B: " + morebeats);
}
}
lastbeat=beat;//let's start again. It's a loop
ramp=i.phasor(0.5,1,2048);//create a basic ramp
pan=j.phasor(0.25);//some panning from a phasor (object is equal power)
delayed=delay.dl(tune, ramp, 0.9)*0.125;//the delay line
//then it all gets mixed.
mixed=((a.sinewave(patch1)*0.5)+((d.saw(patch2))*0.125)+(delayed*0.3)*0.5);
//add some noise
noise=i.noise()*0.25;
filtered2=beats.play(1*(1.0/16.0),0,beats.getLength());
// filtered2=beats.play(-1);
more=squarewave.pulse(melody[morebeats],pan)*0.05;
//filter the noise! this lores takes values between 1 and 100 for res, and freq for cutoff.
filtered=myfilter.lores(filtered2, 1+(pan*10000), 10)*0.4;
//now we send the sounds to some stereo busses.
mymix.stereo(more+mixed+delayed, outputs, 1-pan);
bobbins.stereo(filtered, moreoutputs, pan);//invert the pan
// mixing
output[0]=outputs.get(0)+moreoutputs.get(0);//stick it in the out!!
output[1]=outputs.get(1)+moreoutputs.get(1);
}
}
</script>
</head>
<body>
<h1> Sequencing Example </h1>
<p>
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var outputs = new Module.VectorDouble();
var moreoutputs = new Module.VectorDouble();//this data will be used to make an envelope. Value and time to value in ms.
var filtered,patch1,patch2,tune,delayed,mixed,ramp,filtered2,noise,pan,more;//a bunch of patch cables
var beat,lastbeat, morebeats, morebeats2,lastmorebeats;//some rhythmic elemts
// var env = [200,0,0,50];//the kick drum pitch envelope data
var env = GetArrayAsVectorDbl([200,0,0,50]);
// var env2 = [10000,0,9000,5,0,5];//the hi hat pitch envelope dat
var env2 = GetArrayAsVectorDbl([10000,0,9000,5,0,5]);
var melody = [600,0,0,650,0,0,400,0,0,425,0,300,0,315,0,315, 0];//the melody data
var rhythm1 = [1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0];//another way of doing a rhythm
var a = new maximJs.maxiOsc();
var c = new maximJs.maxiOsc();
var d = new maximJs.maxiOsc();
var e = new maximJs.maxiOsc();
var g = new maximJs.maxiOsc();
var h = new maximJs.maxiOsc();
var i = new maximJs.maxiOsc();
var j = new maximJs.maxiOsc();
var squarewave = new maximJs.maxiOsc();//some oscillators maxiOsc...
var b = new maximJs.maxiEnvelope();
var f = new maximJs.maxiEnvelope();//two envelopers
var delay = new maximJs.maxiDelayline();//a delay line
var myfilter = new maximJs.maxiFilter();
var antia = new maximJs.maxiFilter();// a FAT filter
var mymix = new maximJs.maxiMix();
var bobbins = new maximJs.maxiMix();//some panning busses
var beats = new maximJs.maxiSample();
function setup() {//some inits
outputs.push_back(0);
outputs.push_back(0);
moreoutputs.push_back(0);
moreoutputs.push_back(0);
b.amplitude=env.get(0);//starting value for envelope b
f.amplitude=env2.get(0);//same for f
// beats.load("/Users/chris/src/Maximilian/beat2.wav");//put a path to a soundfile here. Wav format only.
loadSample("./beat2.wav", beats);
// printf("Summary:\n%s", beats.getSummary());//get info on samples if you like
OutputIsArray(true, 2);
}
function play() {//this is where the magic happens. Very slow magic.
if(beats.isReady()){
beat = Math.floor(c.phasor(8));//this oscillator is now a counter
morebeats = Math.floor(e.phasor(0.5,0,16));//so is this one
patch1 = b.line(4,env);//here's envelope b
patch2 = f.line(6,env2);//here's envelop f
tune=g.saw(melody[morebeats]*0.25);
if (lastbeat!=beat) {//this is a nice sample and hold routine for the kick drum
f.trigger(0, env2.get(0));//it runs off the hi hat.
if (rhythm1[morebeats]==1) {
b.trigger(0, env.get(0));//and gets played when it's time.
// console.log("B: " + morebeats);
}
}
lastbeat=beat;//let's start again. It's a loop
ramp=i.phasor(0.5,1,2048);//create a basic ramp
pan=j.phasor(0.25);//some panning from a phasor (object is equal power)
delayed=delay.dl(tune, ramp, 0.9)*0.125;//the delay line
//then it all gets mixed.
mixed=((a.sinewave(patch1)*0.5)+((d.saw(patch2))*0.125)+(delayed*0.3)*0.5);
//add some noise
noise=i.noise()*0.25;
filtered2=beats.play(1*(1.0/16.0),0,beats.getLength());
// filtered2=beats.play(-1);
more=squarewave.pulse(melody[morebeats],pan)*0.05;
//filter the noise! this lores takes values between 1 and 100 for res, and freq for cutoff.
filtered=myfilter.lores(filtered2, 1+(pan*10000), 10)*0.4;
//now we send the sounds to some stereo busses.
mymix.stereo(more+mixed+delayed, outputs, 1-pan);
bobbins.stereo(filtered, moreoutputs, pan);//invert the pan
// mixing
output[0]=outputs.get(0)+moreoutputs.get(0);//stick it in the out!!
output[1]=outputs.get(1)+moreoutputs.get(1);
}
}
</pre>
</body></html>
<!--
Copyright 2010, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>
Javascript Audio Processing
</title>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
<script src="../maxiLib.js"></script>
<!-- <script src="../maxi_webAudio.js"></script> -->
<!-- Our javascript code -->
<script type="text/javascript">
//This shows how to use maximilian to build a polyphonic synth.
var VCO_ArraySize = 6;
//These are the synthesiser bits
var VCO1 = [], VCO2 = [], LFO1 = [], LFO2 = [];
var VCF = [];
var ADSR = [];
//and these are some variables we can use to pass stuff around
var VCO1out = [], VCO2out = [], LFO1out = [],LFO2out = [], VCFout = [], ADSRout = [];
for(var i = 0; i < VCO_ArraySize; i++){
VCO1.push(new maximJs.maxiOsc());
VCO2.push(new maximJs.maxiOsc());
LFO1.push(new maximJs.maxiOsc());
LFO2.push(new maximJs.maxiOsc());
VCF.push(new maximJs.maxiFilter());
ADSR.push(new maximJs.maxiEnvelope());
VCO1out.push(0);
VCO2out.push(0);
LFO1out.push(0);
LFO2out.push(0);
VCFout.push(0);
ADSRout.push(0);
}
//These are the control values for the envelope
// var adsrEnvArray = [1,5,0.125,100,0.125,200,0,1000];
var adsrEnv = GetArrayAsVectorDbl([1,5,0.125,100,0.125,200,0,1000]);
//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, voice = 0;//these values are used to check if we have a new beat this sample
var mix;
var pitch = [1,2,3,4,5,6];
function setup(){
setNumChannels(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(0, adsrEnv.get(0));//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].line(8,adsrEnv);//our ADSR env has 8 value/time pairs.
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
// some kind of NaN problem here !!!
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
}
</script>
</head>
<body>
<h1> polysynth </h1>
<p>
This shows how to use maximilian to build a polyphonic synth.
</p>
</body></html>
<!--
Copyright 2010, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>
Javascript Audio Processing
</title>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
<script src="maxiLib.js"></script>
<!-- Our javascript code -->
<script type="text/javascript">
// Temporary patch until all browsers support unprefixed context.
AudioContext = AudioContext || webkitAudioContext;
// init() once the page has finished loading.
window.onload = init;
var context;
var source = 0;
var jsProcessor = 0;
var analyser;
var analyserView1;
var phaseL = 0.0;
var phaseR = 0.0;
var kBaseFrequency = 440.0;
var phaseIncrL = 2.0 * Math.PI * 440.0 / 44100.0;
var phaseIncrR = 2.0 * Math.PI * (kBaseFrequency * 1.1) / 44100.0; // modulate slightly different on right channel
var kTwoPi = 2.0 * Math.PI;
var pitchRate = 1.0;
var mySine = new Module.maxiOsc();
var osc2 = new Module.maxiOsc();
var osc3 = new Module.maxiOsc();
// var filt = new Module.maxiFilter();
var passFreq = 880;
var m = 10;
function process(event) {
// Get left/right input and output arrays
// var inputArrayL = event.inputBuffer.getChannelData(0);
// var inputArrayR = event.inputBuffer.getChannelData(1);
var outputArrayL = event.outputBuffer.getChannelData(0);
var outputArrayR = event.outputBuffer.getChannelData(1);
var n = outputArrayL.length;
if(passFreq < 220 || passFreq > 1020){
m = -m;
}
passFreq-=m;
for (var i = 0; i < n; ++i) {
// var sampleL = Math.sin(phaseL);
// var sampleR = Math.sin(phaseR);
// phaseL += pitchRate * phaseIncrL;
// phaseR += pitchRate * phaseIncrR;
// if (phaseL > kTwoPi) phaseL -= kTwoPi;
// if (phaseR > kTwoPi) phaseR -= kTwoPi;
// Amplitude modulation effect
// outputArrayL[i] = inputArrayL[i] * sampleL;
// outputArrayR[i] = inputArrayR[i] * sampleR;
var output = mySine.sinewave(440);
// outputArrayL[i] = Math.random();
// outputArrayR[i] = Math.random();
outputArrayL[i] = output;
outputArrayR[i] = output;
}
}
// function loadSample(url) {
// // Load asynchronously
// var request = new XMLHttpRequest();
// request.open("GET", url, true);
// request.responseType = "arraybuffer";
// request.onload = function() {
// context.decodeAudioData(
// request.response,
// function(buffer) {
// source.buffer = buffer;
// source.loop = true;
// source.start(0);
// draw();
// },
// function(buffer) {
// console.log("Error decoding source!");
// }
// );
// }
// request.send();
// }
// if ( !window.requestAnimationFrame ) {
// window.requestAnimationFrame = ( function() {
// return window.webkitRequestAnimationFrame ||
// window.mozRequestAnimationFrame || // comment out if FF4 is slow (it caps framerate at ~30fps: https://bugzilla.mozilla.org/show_bug.cgi?id=630127)
// window.oRequestAnimationFrame ||
// window.msRequestAnimationFrame ||
// function( /* function FrameRequestCallback */ callback, /* DOMElement Element */ element ) {
// window.setTimeout( callback, 1000 / 60 );
// };
// } )();
// }
function initAudio() {
context = new AudioContext();
source = context.createBufferSource();
// This AudioNode will do the amplitude modulation effect directly in JavaScript
jsProcessor = context.createScriptProcessor(4096);
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() {
//analyserView1 = new AnalyserView("view1");
initAudio();
//analyserView1.initByteBuffer();
}
</script>
</head>
<body>
<h1> JavaScript Processing </h1>
<p>
This example illustrates a simple amplitude modulation effect processed directly in JavaScript.
</p>
<!-- Real-time visualizer view -->
<!--<canvas id="view1" width="800px" height="600px"></canvas>-->
</body></html>
#include "maximilian.h"
maxiOsc mySine;//let's create an oscillator and give it a name.
void setup() {//some inits
//nothing to go here this time
}
void play(double *output) {//this is where the magic happens. Very slow magic.
*output=mySine.sinewave(440);//simple as that!
}
#include "maximilian.h"
maxiOsc myCounter,mySwitchableOsc;//
int CurrentCount;//
double myOscOutput,myFilteredOutput;//
double myEnvelopeData[6] = {500,0,1000,500,0,500};//this data will be used to make an envelope. Value and time to value in ms.
maxiEnvelope myEnvelope;
maxiFilter myFilter;
void setup() {//some inits
myEnvelope.amplitude=myEnvelopeData[0]; //initialise the envelope
}
void play(double *output) {
CurrentCount=myCounter.phasor(1, 1, 9);//phasor can take three arguments; frequency, start value and end value.
if (CurrentCount<5)//simple if statement
myOscOutput=mySwitchableOsc.square(CurrentCount*100);
else if (CurrentCount>=5)//and the 'else' bit.
myOscOutput=mySwitchableOsc.saw(CurrentCount*50);//one osc object can produce whichever waveform you want.
if (CurrentCount==1)
myEnvelope.trigger(0,myEnvelopeData[0]); //trigger the envelope
myFilteredOutput=myFilter.lores(myOscOutput,(myEnvelope.line(6, myEnvelopeData)),10);//lores takes an audio input, a frequency and a resonance factor (1-100)
*output=myFilteredOutput;//point me at your speakers and fire.
}
#include "maximilian.h"
maxiOsc myCounter,mySwitchableOsc,myAutoPanner;//
int CurrentCount;//
double myOscOutput,myFilteredOutput,myPanPosition;//
double myStereoOutput[2];// we need an output for each channel.
double myEnvelopeData[6] = {500,0,1000,500,0,500};//this data will be used to make an envelope. Value and time to value in ms.
maxiEnvelope myEnvelope;
maxiFilter myFilter;
maxiMix myOutputs;//this is the stereo mixer channel.
void setup() {//some inits
myEnvelope.amplitude=myEnvelopeData[0]; //initialise the envelope
}
void play(double *output) {
CurrentCount=myCounter.phasor(1, 1, 9);//phasor can take three arguments; frequency, start value and end value.
if (CurrentCount<5)//simple if statement
myOscOutput=mySwitchableOsc.square(CurrentCount*100);
else if (CurrentCount>=5)//and the 'else' bit.
myOscOutput=mySwitchableOsc.saw(CurrentCount*50);//one osc object can produce whichever waveform you want.
if (CurrentCount==1)
myEnvelope.trigger(0,myEnvelopeData[0]); //trigger the envelope
myFilteredOutput=myFilter.lores(myOscOutput,(myEnvelope.line(6, myEnvelopeData)),10);//lores takes an audio input, a frequency and a resonance factor (1-100)
myPanPosition=myAutoPanner.sinewave(1);
myOutputs.stereo(myFilteredOutput,myStereoOutput,myPanPosition);//Stereo, Quad or 8 Channel. Specify the input to be mixed, the output[numberofchannels], and the pan (0-1,equal power).
output[0]=myStereoOutput[0];//When working with mixing, you need to specify the outputs explicityly
output[1]=myStereoOutput[1];//
}
#include "maximilian.h"
maxiSample beats; //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.
void setup() {//some inits
beats.load("/Users/username/somewhere/Maximilian/beat2.wav");//load in your samples. Provide the full path to a wav file.
printf("Summary:\n%s", beats.getSummary());//get info on samples if you like.
}
void play(double *output) {//this is where the magic happens. Very slow magic.
*output=beats.play();//just play the file. Looping is default for all play functions.
// *output=beats.play(0.69);//play the file with a speed setting. 1. is normal speed.
// *output=beats.play(0.5,0,44100);//linear interpolationplay with a frequency input, start point and end point. Useful for syncing.
// *output=beats.play4(0.5,0,44100);//cubic interpolation play with a frequency input, start point and end point. Useful for syncing.
}
#include "maximilian.h"
double outputs[2],moreoutputs[2]; //some track outputs
double filtered,patch1,patch2,tune,delayed,
mixed,ramp,filtered2,noise,pan,more;//a bunch of patch cables
int beat,lastbeat,morebeats,lastmorebeats;//some rhythmic elemts
double env[4]={200,0,0,50};//the kick drum pitch envelope data
double env2[6]={10000,0,9000,5,0,5};//the hi hat pitch envelope dat
double melody[14]={600,0,0,650,0,0,400,0,0,425,0,300,0,315};//the melody data
int rhythm1[16]={1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0};//another way of doing a rhythm
maxiOsc a,c,d,e,g,h,i,j,squarewave;//some oscillators
maxiEnvelope b,f;//two envelopers
maxiDelayline delay;//a delay line
maxiFilter myfilter,antia;// a FAT filter
maxiMix mymix,bobbins;//some panning busses
maxiSample beats;
void setup() {//some inits
b.amplitude=env[0];//starting value for envelope b
f.amplitude=env2[0];//same for f
beats.load("/Users/chris/src/Maximilian/beat2.wav");//put a path to a soundfile here. Wav format only.
printf("Summary:\n%s", beats.getSummary());//get info on samples if you like
}
void play(double *output) {//this is where the magic happens. Very slow magic.
beat=((int) c.phasor(8));//this oscillator is now a counter
morebeats=((int) e.phasor(0.5,0,16));//so is this one
patch1=b.line(4,env);//here's envelope b
patch2=f.line(6,env2);//here's envelop f
tune=g.saw(melody[morebeats]*0.25);//here's the melody, which occurs at certain times
if (lastbeat!=beat) {//this is a nice sample and hold routine for the kick drum
f.trigger(0, env2[0]);//it runs off the hi hat.
if (rhythm1[morebeats]==1) {
b.trigger(0, env[0]);//and gets played when it's time.
}
}
lastbeat=beat;//let's start again. It's a loop
ramp=i.phasor(0.5,1,2048);//create a basic ramp
pan=j.phasor(0.25);//some panning from a phasor (object is equal power)
delayed=delay.dl(tune, ramp, 0.9)*0.125;//the delay line
//then it all gets mixed.
mixed=((a.sinewave(patch1)*0.5)+((d.saw(patch2))*0.125)+(delayed*0.3)*0.5);
//add some noise
noise=i.noise()*0.25;
filtered2=beats.play(1*(1./16.),0,beats.length);
// filtered2=beats.play(-1);
more=squarewave.pulse(melody[morebeats],pan)*0.05;
//filter the noise! this lores takes values between 1 and 100 for res, and freq for cutoff.
filtered=myfilter.lores(filtered2, 1+(pan*10000), 10)*0.4;
//now we send the sounds to some stereo busses.
mymix.stereo(more+mixed+delayed, outputs, 1-pan);
bobbins.stereo(filtered, moreoutputs, pan);//invert the pan
//mixing
output[0]=outputs[0]+moreoutputs[0];//stick it in the out!!
output[1]=outputs[1]+moreoutputs[1];
}
#include "maximilian.h"
//This shows how to use maximilian to build a monophonic synth
//These are the synthesiser bits
maxiOsc VCO1,VCO2,LFO1,LFO2;
maxiFilter VCF;
maxiEnvelope ADSR;
//These are the control values for the envelope
double adsrEnv[8]={1,5,0.125,250,0.125,125,0,500};
//This is a bunch of control signals so that we can hear something
maxiOsc timer;//this is the metronome
int 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
double VCO1out,VCO2out,LFO1out,LFO2out,VCFout,ADSRout;
void setup() {//some inits
}
void play(double *output) {
//so this first bit is just a basic metronome so we can hear what we're doing.
currentCount=(int)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(0, adsrEnv[0]);//trigger the envelope from the start
cout << "tick\n";//the clock ticks
lastCount=0;//set lastCount to 0
}
//and this is where we build the synth
ADSRout=ADSR.line(8,adsrEnv);//our ADSR env has 8 value/time pairs.
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, 250+(ADSRout*15000), 10);//now we stick the VCO's into the VCF, using the ADSR as the filter cutoff
*output=VCFout*ADSRout;//finally we add the ADSR as an amplitude modulator
}
#include "maximilian.h"
//This shows how to use maximilian to build a polyphonic synth.
//These are the synthesiser bits
maxiOsc VCO1[6],VCO2[6],LFO1[6],LFO2[6];
maxiFilter VCF[6];
maxiEnvelope ADSR[6];
//These are the control values for the envelope
double adsrEnv[8]={1,5,0.125,100,0.125,200,0,1000};
//This is a bunch of control signals so that we can hear something
maxiOsc timer;//this is the metronome
int currentCount,lastCount,voice=0;//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
double VCO1out[6],VCO2out[6],LFO1out[6],LFO2out[6],VCFout[6],ADSRout[6],mix,pitch[6];
void setup() {//some inits
}
void play(double *output) {
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=(int)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(0, adsrEnv[0]);//trigger the envelope from the start
pitch[voice]=voice+1;
voice++;
lastCount=0;
}
//and this is where we build the synth
for (int i=0; i<6; i++) {
ADSRout[i]=ADSR[i].line(8,adsrEnv);//our ADSR env has 8 value/time pairs.
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
}
#include "maximilian.h"
//Bizarelly, this sounds a little bit like Kraftwerk's 'Metropolis', although it isn't. Funny that.
maxiOsc sound,bass,timer,mod,lead,lead2,leadmod;//here are the synth bits
maxiEnv envelope, leadenvelope;//some envelopes
maxiFilter filter, filter2;//some filters
maxiDelayline delay;//a delay
convert mtof;//a method for converting midi notes to frequency
double bassout,leadout, delayout;//some variables to hold the data and pass it around
int trigger, trigger2, newnote;//some control variables
int currentCount,lastCount,playHead=0, currentChord=0;//some other control variables
int pitch[8]={57,57,59,60};//the bassline for the arpeggio
int chord[8]={0,0,7,2,5,5,0,0};//the root chords for the arpeggio
float currentPitch,leadPitch;//the final pitch variables
//here's the lead line trigger array, followed by the pitches
int leadLineTrigger[256]={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};
int leadLinePitch[15]={69,67,65,64,67,66,64,62,65,64,62,57,55,60,57};
void setup() {//some inits
}
void play(double *output) {//this is where the magic happens. Very slow magic.
currentCount=(int)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;
}
\ No newline at end of file
#include "maximilian.h"
maxiSample beats; //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.
maxiDyn compressor; //this is a compressor
double out;
void setup() {//some inits
beats.load("/Users/yourusername/somewhere/schub.wav");//load in your samples. Provide the full path to a wav file.
printf("Summary:\n%s", beats.getSummary());//get info on samples if you like.
}
void play(double *output) {//this is where the magic happens. Very slow magic.
//here, we're just compressing the file in real-time
//arguments are input,ratio,threshold,attack,release
out=compressor.compressor(beats.play(),5,0.25,0.0001,0.9999);
output[0]=out;
output[1]=out;
// *output=beats.play(0.69);//play the file with a speed setting. 1. is normal speed.
// *output=beats.play(0.5,0,44100);//linear interpolationplay with a frequency input, start point and end point. Useful for syncing.
// *output=beats.play4(0.5,0,44100);//cubic interpolation play with a frequency input, start point and end point. Useful for syncing.
}
#include "maximilian.h"
maxiSample kick,snare; //we've got two sampleplayers
maxiOsc timer; //and a timer
int currentCount,lastCount,playHead,hit[16]={1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1}; //This is the sequence for the kick
int snarehit[16]={0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0};//This is the sequence for the snare
int kicktrigger,snaretrigger;
double sampleOut;
void setup() {//some inits
//YOU HAVE TO PROVIDE THE SAMPLES....
kick.load("/Users/yourusername/somewhere/kick.wav");//load in your samples. Provide the full path to a wav file.
snare.load("/Users/yourusername/somewhere/snare.wav");//load in your samples. Provide the full path to a wav file.
printf("Summary:\n%s", kick.getSummary());//get info on samples if you like.
//beats.getLength();
}
void play(double *output) {//this is where the magic happens. Very slow magic.
currentCount=(int)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=hit[playHead%16];//get the value out of the array for the kick
snaretrigger=snarehit[playHead%16];//same for the snare
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
}
sampleOut=kick.playOnce()+snare.playOnce();//just play the file. No looping.
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;
}
\ No newline at end of file
#include "maximilian.h"
//this tutorial explains how to use the maxiEnv
maxiSample sound1;
maxiOsc timer,snarePhase; //and a timer
maxiEnv envelope;//this is going to be an envelope
int currentCount,lastCount,playHead,
sequence[16]={1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0}; //This is the sequence for the kick
int sampleTrigger;
double sampleOut;
void setup() {//some inits
//YOU HAVE TO PROVIDE THE SAMPLES....
sound1.load("/Users/mickgrierson/Documents/audio/68373__juskiddink__Cello_open_string_bowed.wav");//load in your samples. Provide the full path to a wav file.
printf("Summary:\n%s", sound1.getSummary());//get info on samples if you like.
//beats.getLength();
}
void play(double *output) {//this is where the magic happens. Very slow magic.
currentCount=(int)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.
}
\ No newline at end of file
#include "maximilian.h"
maxiOsc mySine,myOtherSine;//Two oscillators with names.
void setup() {//some inits
//nothing to go here this time
}
void play(double *output) {//this is where the magic happens. Very slow magic.
*output=mySine.sinewave(440)+myOtherSine.sinewave(441);//these two sines will beat together. They're now a bit too loud though..
}
#include "maximilian.h"
maxiOsc sineBank[10];//let's create an oscillator and give it a name.
void setup() {//some inits
//nothing to go here this time
}
void play(double *output) {//this is where the magic happens. Very slow magic.
double wave=0;
double f0 = 100;
for(int i=0; i < 10; i++) {
double thisSine = wave + sineBank[i].sinewave(f0 + (i * f0));
double multiplier = 1.0 / (i+1.0);
thisSine = thisSine * multiplier;
wave = wave + thisSine;
}
wave *= 0.1;
*output = wave;//simple as that!
}
#include "maximilian.h"
//This shows how to use maximilian to do basic amplitude modulation
maxiOsc mySine,myOtherSine;//Two oscillators. They can be called anything. They can be any of the available waveforms. These ones will be sinewaves
void setup() {//some inits
//nothing to go here this time
}
void play(double *output) {
*output=mySine.sinewave(440)*myOtherSine.sinewave(10);
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment