Commit b2abc4ff authored by mzed's avatar mzed
Browse files

Filter, envelope, and mixing

parent 3301a541
<!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://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?lang=js&amp;skin=sunburst"></script>
<!-- show all line numbers-->
<style type="text/css">.prettyprint ol.linenums > li { list-style-type: decimal }</style>
<script src="maxiLib.js"></script>
<!-- Our javascript code -->
<script type="text/javascript">
var maxiLib = MaxiLib();
var audio = new maxiLib.maxiAudio();
audio.init();
var myCounter = new maxiLib.maxiOsc(); //these oscillators will help us count and play sound
var mySwitchableOsc = new maxiLib.maxiOsc();//
var CurrentCount;//
var myCurrentVolume;
var myOscOutput,myFilteredOutput;//
var myEnvelope = new maxiLib.maxiEnv();
var myFilter = new maxiLib.maxiFilter();
//Timing is in ms
myEnvelope.setAttack(0);
myEnvelope.setDecay(1); // Needs to be at least 1
myEnvelope.setSustain(1);
myEnvelope.setRelease(1000);
audio.play = function(){
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);
this.output=myFilteredOutput;//left speaker
}
</script>
</head>
<body>
<h1> Filter Example </h1>
<p>
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var maxiLib = window.MaxiLib();
var audio = new maxiLib.maxiAudio();
audio.init();
var myCounter = new maxiLib.maxiOsc(); //these oscillators will help us count and play sound
var mySwitchableOsc = new maxiLib.maxiOsc();//
var CurrentCount;//
var myCurrentVolume;
var myOscOutput,myFilteredOutput;//
var myEnvelope = new maxiLib.maxiEnv();
var myFilter = new maxiLib.maxiFilter();
//Timing is in ms
myEnvelope.setAttack(0);
myEnvelope.setDecay(1); // Needs to be at least 1
myEnvelope.setSustain(1);
myEnvelope.setRelease(1000);
audio.play = function(){
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);
this.output=myFilteredOutput;//left speaker
}
</pre>
</body></html>
<!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://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?lang=js&amp;skin=sunburst"></script>
<!-- show all line numbers-->
<style type="text/css">.prettyprint ol.linenums > li { list-style-type: decimal }</style>
<script src="maxiLib.js"></script>
<!-- Our javascript code -->
<script type="text/javascript">
var maxiLib = window.MaxiLib();
var audio = new maxiLib.maxiAudio();
audio.init();
var myCounter = new maxiLib.maxiOsc(); //these oscillators will help us count and play sound
var mySwitchableOsc = new maxiLib.maxiOsc();//
var CurrentCount;//
var myCurrentEnv;
var myOscOutput,myFilteredOutput = 0.0;//
var myEnvelope = new maxiLib.maxiEnv();
var SVF = new maxiLib.maxiSVF();
//Timing is in ms
myEnvelope.setAttack(1.5);
myEnvelope.setDecay(1); // Needs to be at least 1
myEnvelope.setSustain(1);
myEnvelope.setRelease(200);
SVF.setCutoff(400);
SVF.setResonance(1);
audio.play = function(){
myCurrentEnv=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(50) * mySwitchableOsc.sinewave(1);
// run output through this filter, and get a mixture of lowpass, bandpass, highpass and notch outputs
myFilteredOutput = SVF.play(myOscOutput, 0.8, 0, 0.1, myCurrentEnv);
this.output=myFilteredOutput;
}
</script>
</head>
<body>
<h1> Filter Example </h1>
<p>
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var maxiLib = window.MaxiLib();
var audio = new maxiLib.maxiAudio();
audio.init();
var myCounter = new maxiLib.maxiOsc(); //these oscillators will help us count and play sound
var mySwitchableOsc = new maxiLib.maxiOsc();//
var CurrentCount;//
var myCurrentVolume;
var myOscOutput,myFilteredOutput;//
var myEnvelope = new maxiLib.maxiEnv();
var myFilter = new maxiLib.maxiFilter();
//Timing is in ms
myEnvelope.setAttack(0);
myEnvelope.setDecay(1); // Needs to be at least 1
myEnvelope.setSustain(1);
myEnvelope.setRelease(1000);
audio.play = function(){
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);
this.output=myFilteredOutput;//left speaker
}
</pre>
</body></html>
<!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://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?lang=js&amp;skin=sunburst"></script>
<!-- show all line numbers-->
<style type="text/css">.prettyprint ol.linenums > li { list-style-type: decimal }</style>
<script src="maxiLib.js"></script>
<!-- Our javascript code -->
<script type="text/javascript">
var maxiLib = window.MaxiLib();
var audio = new maxiLib.maxiAudio();
audio.init();
// change output to an array
audio.outputIsArray(true, 2);
var myOsc = new maxiLib.maxiOsc();
var myAutoPanner = new maxiLib.maxiOsc();
var myStereoOutput = maxiLib.maxiTools.getArrayAsVectorDbl([0,0]);
var myOutputs = new maxiLib.maxiMix();//this is the stereo mixer channel.
audio.play = function(){
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).
this.output[0]=myStereoOutput.get(0);//When working with mixing, you need to specify the outputs explicitly
this.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 maxiLib = window.maxiLib();
var audio = new maxiLib.maxiAudio();
audio.init();
// change output to an array
audio.outputIsArray(true, 2);
var myOsc = new maxiLib.maxiOsc();
var myAutoPanner = new maxiLib.maxiOsc();
var myStereoOutput = maxiLib.maxiTools.getArrayAsVectorDbl([0,0]);
var myOutputs = new maxiLib.maxiMix();//this is the stereo mixer channel.
audio.play = function(){
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).
this.output[0]=myStereoOutput.get(0);//When working with mixing, you need to specify the outputs explicitly
this.output[1]=myStereoOutput.get(1);//
}
</pre>
</body></html>
<!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://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?lang=js&amp;skin=sunburst"></script>
<!-- show all line numbers-->
<style type="text/css">.prettyprint ol.linenums > li { list-style-type: decimal }</style>
<script src="maxiLib.js"></script>
<!-- Our javascript code -->
<script type="text/javascript">
var maxiLib = window.MaxiLib();
var audio = new maxiLib.maxiAudio();
audio.init();
var myCounter = new maxiLib.maxiOsc(); //these oscillators will help us count and play sound
var mySwitchableOsc = new maxiLib.maxiOsc();//
var CurrentCount;//
var myOscOutput,myCurrentVolume;//
var myEnvelope = new maxiLib.maxiEnv();
//Timing is in ms
myEnvelope.setAttack(0);
myEnvelope.setDecay(1); // Needs to be at least 1
myEnvelope.setSustain(1);
myEnvelope.setRelease(1000);
audio.play = function(){
//notice that we feed in a value of 1. to create an envelope shape we can apply later.
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
}
if (CurrentCount<5){
myOscOutput=mySwitchableOsc.sawn(CurrentCount*100);
}
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*myCurrentVolume;//left speaker
}
</script>
</head>
<body>
<h1> Envelope Example </h1>
<p>
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var maxiLib = window.MaxiLib();
var audio = new maxiLib.maxiAudio();
audio.init();
var myCounter = new maxiLib.maxiOsc(); //these oscillators will help us count and play sound
var mySwitchableOsc = new maxiLib.maxiOsc();//
var CurrentCount;//
var myOscOutput,myCurrentVolume;//
var myEnvelope = new maxiLib.maxiEnv();
//Timing is in ms
myEnvelope.setAttack(0);
myEnvelope.setDecay(1); // Needs to be at least 1
myEnvelope.setSustain(1);
myEnvelope.setRelease(1000);
audio.play = function(){
//notice that we feed in a value of 1. to create an envelope shape we can apply later.
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
}
if (CurrentCount<5){
myOscOutput=mySwitchableOsc.sawn(CurrentCount*100);
}
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*myCurrentVolume;//left speaker
}
</pre>
</body></html>
Markdown is supported
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