Commit 3301a541 authored by mzed's avatar mzed
Browse files

fm and counting examples

parent 19397a7e
......@@ -45,7 +45,7 @@ var audio = new maxiLib.maxiAudio();
audio.init();
// create oscillator
var mySine = new maximJs.maxiOsc();
var mySine = new maxiLib.maxiOsc();
audio.play = function(){
// direct value to output
......
<!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();
//This shows how to use maximilian to do basic frequency modulation
var mySine = new maxiLib.maxiOsc();
var myOtherSine = new maxiLib.maxiOsc();
var myLastSine = new maxiLib.maxiOsc();
var myPhasor = new maxiLib.maxiOsc();
audio.play = function(){
this.output=mySine.sinewave(myOtherSine.sinewave(myLastSine.sinewave(0.1)*30)*440);//awesome bassline
}
</script>
</head>
<body>
<h1> FM </h1>
<p>
More basic frequency modulation
</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();
//This shows how to use maximilian to do basic frequency modulation
var mySine = new maxiLib.maxiOsc();
var myOtherSine = new maxiLib.maxiOsc();
var myLastSine = new maxiLib.maxiOsc();
var myPhasor = new maxiLib.maxiOsc();
audio.play = function(){
this.output=mySine.sinewave(myOtherSine.sinewave(myLastSine.sinewave(0.1)*30)*440);//awesome bassline
}
</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 mySine = new maxiLib.maxiOsc(); // This is the oscillator we will use to generate the test tone
var myClock = new maxiLib.maxiClock(); // This will allow us to generate a clock signal and do things at specific times
var freq; // This is a variable that we will use to hold and set the current frequency of the oscillator
myClock.setTicksPerBeat(1);//This sets the number of ticks per beat
myClock.setTempo(120);// This sets the tempo in Beats Per Minute
freq=20; // Here we initialise the variable
audio.play = function(){
myClock.ticker(); // This makes the clock object count at the current samplerate
//This is a 'conditional'. It does a test and then does something if the test is true
// console.log(myClock.isTick());
if (myClock.tick) { // If there is an actual tick at this time, this will be true.
freq+=100; // DO SOMETHING
} // The curly braces close the conditional
this.output=mySine.sinewave(freq);//simple as that!
}
</script>
</head>
<body>
<h1> Counting </h1>
<p>
Using phasor to count
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var maxiLib = window.MaxiLib();
var audio = new maxiLibs.maxiAudio();
audio.init();
var mySine = new maxiLib.maxiOsc(); // This is the oscillator we will use to generate the test tone
var myClock = new maxiLib.maxiClock(); // This will allow us to generate a clock signal and do things at specific times
var freq; // This is a variable that we will use to hold and set the current frequency of the oscillator
myClock.setTicksPerBeat(1);//This sets the number of ticks per beat
myClock.setTempo(120);// This sets the tempo in Beats Per Minute
freq=20; // Here we initialise the variable
audio.play = function(){
myClock.ticker(); // This makes the clock object count at the current samplerate
//This is a 'conditional'. It does a test and then does something if the test is true
// console.log(myClock.isTick());
if (myClock.tick) { // If there is an actual tick at this time, this will be true.
freq+=100; // DO SOMETHING
} // The curly braces close the conditional
this.output=mySine.sinewave(freq);//simple as that!
}
</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 mySquare = new maxiLib.maxiOsc();
//we're going to put the current count in this variable so that we can use it more easily.
var currentCount;
audio.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);
}
</script>
</head>
<body>
<h1> Counting 2 </h1>
<p>
Using phasor to count
</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 mySquare = new maxiLib.maxiOsc();
//we're going to put the current count in this variable so that we can use it more easily.
var currentCount;
audio.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);
}
</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();
var mySwitchableOsc = new maxiLib.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 output here to make it easier to mess with stuff.
audio.play = function(){
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.sinewave(CurrentCount*50);//one osc object can produce whichever waveform you want.
}
this.output=myOscOutput;//point me at your speakers and fire.
}
</script>
</head>
<body>
<h1> Counting </h1>
<p>
Using phasor to count
</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();
var mySwitchableOsc = new maxiLib.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 output here to make it easier to mess with stuff.
audio.play = function(){
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.sinewave(CurrentCount*50);//one osc object can produce whichever waveform you want.
}
this.output=myOscOutput;//point me at your speakers and fire.
}
</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();
//these oscillators will help us count and make sound.
var myCounter = new maxiLib.maxiOsc();
var mySwitchableOsc = new maxiLib.maxiOsc();
var another = new maxiLib.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 output here to make it easier to mess with stuff.
var myArray=[100,200,300,400,300,200,100,240,640,360];
audio.play = function(){
CurrentCount=Math.round(myCounter.phasor(1*((another.sawn(0.1)+1)/2), 1, 9));//phasor can take three arguments; frequency, start value and end value.
if (CurrentCount<5) {//simple if statement
myOscOutput=mySwitchableOsc.square(myArray[CurrentCount]);
}
else if (CurrentCount>=5) {//and the 'else' bit.
myOscOutput=mySwitchableOsc.sawn(myArray[CurrentCount]);//one osc object can produce whichever waveform you want.
}
this.output=myOscOutput;//point me at your speakers and fire.
}
</script>
</head>
<body>
<h1> Counting 4 </h1>
<p>
Using phasor to count
</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();
//these oscillators will help us count and make sound.
var myCounter = new maxiLib.maxiOsc();
var mySwitchableOsc = new maxiLib.maxiOsc();
var another = new maxiLib.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 output here to make it easier to mess with stuff.
var myArray=[100,200,300,400,300,200,100,240,640,360];
audio.play = function(){
CurrentCount=Math.round(myCounter.phasor(1*((another.sawn(0.1)+1)/2), 1, 9));//phasor can take three arguments; frequency, start value and end value.
if (CurrentCount<5) {//simple if statement
myOscOutput=mySwitchableOsc.square(myArray[CurrentCount]);
}
else if (CurrentCount>=5) {//and the 'else' bit.
myOscOutput=mySwitchableOsc.sawn(myArray[CurrentCount]);//one osc object can produce whichever waveform you want.
}
this.output=myOscOutput;//point me at your speakers and fire.
}
</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