Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (18)
Showing
with 4524 additions and 2550 deletions
......@@ -6,4 +6,5 @@ maxiLib/sed_addText.sh
maxiLib/sed_replace.sh
maxiLib/sed_text_stuff/
maximilian_examples_cpp/
old_stuff/
\ No newline at end of file
old_stuff/
.DS_Store
### maxiAudio ###
This the audio context. You must always have one to produce sound with maxiLib
#### methods ####
##### .init() #####
initialise the audio engine
##### .outputIsArray( isArray, numChannels) #####
for multi channel sound
- isArray = true or false
- numChannels = 2, 4, or 8
##### .loadSample(sampleUrl, maxiSample) #####
load a sample into a maxiSample object
#### properties ####
##### .play #####
the function which is the play loop
##### .output #####
the current value of the audio output
<br><br>
### maxiSample ###
Stores and plays an audio sample
#### methods ####
##### .play() #####
plays the sample at normal speed
##### .play(playRate) #####
plays the sample at the specified play rate
##### .playOnce() #####
plays the sample once at normal speed
##### .playOnce(playRate) #####
plays the sample once at specified play rate
##### .trigger() #####
set the playhead to zero (use in conjunction with playOnce)
##### .isReady() #####
returns true if sample is loaded
<br><br>
### maxiTimestretch ###
plays a sample at different rates leaving pitch unchanged
#### methods ####
##### .setSample(maxiSample) #####
sets the sample play for timestretch to use
##### .play(rate, grainLength, overlaps, startPos) #####
- rate (eg. 0.5 = half speed)
- grainLength (a time in seconds)
- overlaps (normally 2 is good)
- startPos (where to start playing in the sample - in seconds)
##### .setPosition(startPos) #####
useful for resetting a sound
##### .getPosition() #####
returns position in ???
##### .getNormalisedPosition() #####
Useful for ending sample play back
<br><br>
### maxiPitchShift ###
plays a sample at different pitches leaving the speed unchanged
#### methods ####
##### .setSample(maxiSample) #####
sets the sample play for pitchShift to use
##### .play(pitch, grainLength, overlaps, startPos) #####
- pitch (eg. 0.5 = half pitch)
- grainLength (a time in seconds)
- overlaps (normally 2 is good)
- startPos (where to start playing in the sample - in seconds)
##### .setPosition(startPos) #####
useful for resetting a sound
##### .getPosition() #####
returns position in ???
##### .getNormalisedPosition() #####
Useful for ending sample play back
<br><br>
### maxiPitchStretch ###
plays a sample with independent control of pitch and speed
#### methods ####
##### .setSample(maxiSample) #####
sets the sample play for timestretch to use
##### .play(pitch, rate, grainLength, overlaps, startPos) #####
- pitch (eg. 0.5 = half pitch)
- rate (eg. 0.5 = half speed)
- grainLength (a time in seconds)
- overlaps (normally 2 is good)
- startPos (where to start playing in the sample - in seconds)
##### .getPosition() #####
returns position in ???
##### .getNormalisedPosition() #####
Useful for ending sample play back
##### .setPosition(startPos) #####
useful for resetting a sound
<br><br>
### maxiDelay ###
A simple delay line
#### methods ####
##### .dl(inputSignal, delayTime, foldback) #####
process a signal with delay
- inputSignal (any signal eg. output from an oscillator
- delayTime (a value in milliseconds)
- foldback (how much of the signal to feedback into the delay buffer - determines how long echos last)
<br><br>
### maxiOsc ###
An oscillator with methods for a number of waveforms
#### methods ####
##### .sinewave(frequency) #####
outputs a sine wave at the given frequency between -1.0 & 1.0
##### .triangle(frequency) #####
outputs a triangle wave at the given frequency between -1.0 & 1.0
##### .saw(frequency) #####
outputs a sawtooth wave at the given frequency between -1.0 & 1.0
##### .square(frequency) #####
outputs a square wave at the given frequency between 0.0 & 1.0
##### .phasor(frequency) #####
outputs a linear ramp at the given frequency between 0.0 & 1.0
##### .phaseReset(phase) #####
reset the phase to a specific value
- phase (a value between 0 & 1)
<br><br>
### maxiEnv ###
An adsr envelope.
#### methods ####
##### .setAttack(time) #####
- time = milliseconds
##### .setDecay(time) #####
- time = milliseconds
##### .setSustain(level) #####
- level = a value between 0.0 and 1.0
##### .setRelease(time) #####
- time = milliseconds
##### .adsr(level, trigger) #####
- level (the overall level of the envelope; everything will be scaled by this value)
- trigger (envelope will begin attack when set to 1.0 and release when set to 0.0)
<br><br>
### maxiFilter ###
A bunch of useful filter methods
#### methods ####
##### .lores(input, cutoff, resonance) #####
A lowpass resonant filter. Returns the filtered frequency.
- input = input signal
- cutoff = cutoff frequency in Hz
- resonance = a value between 0.0 & 10.0
##### .hires(input, cutoff, resonance) #####
A highpass resonant filter. Returns the filtered frequency.
- input = input signal
- cutoff = cutoff frequency in Hz
- resonance = a value between 0.0 & 10.0
### maxiFFT ###
#### methods ####
##### .setup(fftSize, windowSize, hopSize) #####
must be called before using the FFT
- fftSize = (A power of two, 1024, 512 .. etc)
- windowSize = half the fftSize
- hopSize = half the windowSize
##### .process(sig) #####
returns true if successful
- sig = signal in
##### .getMagnitude(index) #####
get the magnitude of a particular bin
- index = A number between 0 and the fftSize/2
##### .getMagnitudeDB(index) #####
get the decibels of a particular bin
##### .magsToDb() #####
perform the conversion on all bins
<br><br>
### convert ###
A collection of conversion functions. Currently numbering one !
#### methods ####
##### .mtof(midi) #####
pass a midi value and its frequency is returned
<br><br>
### maxiMix ###
A multichannel mixer.
#### methods ####
##### .stereo(sig, outputArray, pan) #####
Makes a stereo mix.
- sig = inputsignal
- outputArray = VectorDbl array (see maxiTools)
- pan = a value between 0 & 1
<br><br>
### maxiTools ###
#### methods ####
##### .getArrayAsVectorDbl(inputArray) #####
Returns the array as a VectorDbl object. (Needed for maxiMix).
### Undocumented classes ###
- maxiArray
- maxiChorus
- maxiClock
- maxiDCBlocker
- maxiDistortion
- maxiDyn
- maxiEnvelope
- maxiEnvelopeFollower (undefined)
- maxiFFTOctaveAnalyzer
- maxiFlanger
- maxiHats
- maxiIFFT
- maxiKick
- maxiLagExp
- maxiMFCC
- maxiMap
- maxiSVF
- maxiSettings
- maxiSnare
- maxiTools
This diff is collapsed.
......@@ -44,7 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
maximJs.maxiAudio.init();
var audio = new maximJs.maxiAudio();
audio.init();
var myCounter = new maximJs.maxiOsc(); //these oscillators will help us count and play sound
var mySwitchableOsc = new maximJs.maxiOsc();//
......@@ -64,7 +65,7 @@ myEnvelope.setSustain(1);
myEnvelope.setRelease(1000);
maximJs.maxiAudio.play = function(){
audio.play = function(){
myCurrentVolume=myEnvelope.adsr(1.,myEnvelope.trigger);
......@@ -85,7 +86,7 @@ maximJs.maxiAudio.play = function(){
// The last input is the resonance.
myFilteredOutput=myFilter.lores(myOscOutput,myCurrentVolume*1000,10);
output=myFilteredOutput;//left speaker
this.output=myFilteredOutput;//left speaker
}
......@@ -102,6 +103,9 @@ maximJs.maxiAudio.play = function(){
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var audio = new maximJs.maxiAudio();
audio.init();
var myCounter = new maximJs.maxiOsc(); //these oscillators will help us count and play sound
var mySwitchableOsc = new maximJs.maxiOsc();//
......@@ -112,15 +116,15 @@ 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);
}
myEnvelope.setAttack(0);
myEnvelope.setDecay(1); // Needs to be at least 1
myEnvelope.setSustain(1);
myEnvelope.setRelease(1000);
maximJs.maxiAudio.play = function(){
audio.play = function(){
myCurrentVolume=myEnvelope.adsr(1.,myEnvelope.trigger);
......@@ -141,7 +145,7 @@ maximJs.maxiAudio.play = function(){
// The last input is the resonance.
myFilteredOutput=myFilter.lores(myOscOutput,myCurrentVolume*1000,10);
output=myFilteredOutput;//left speaker
this.output=myFilteredOutput;//left speaker
}
</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 audio = new maximJs.maxiAudio();
audio.init();
var myCounter = new maximJs.maxiOsc(); //these oscillators will help us count and play sound
var mySwitchableOsc = new maximJs.maxiOsc();//
var CurrentCount;//
var myCurrentEnv;
var myOscOutput,myFilteredOutput = 0.0;//
var myEnvelope = new maximJs.maxiEnv();
var SVF = new maximJs.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 audio = new maximJs.maxiAudio();
audio.init();
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();
//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>
......@@ -43,9 +43,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
maximJs.maxiAudio.init();
var audio = new maximJs.maxiAudio();
audio.init();
// change output to an array
maximJs.maxiAudio.outputIsArray(true, 2);
audio.outputIsArray(true, 2);
var myOsc = new maximJs.maxiOsc();
var myAutoPanner = new maximJs.maxiOsc();
......@@ -54,10 +55,10 @@ var myOutputs = new maximJs.maxiMix();//this is the stereo mixer channel.
maximJs.maxiAudio.play = function(){
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).
output[0]=myStereoOutput.get(0);//When working with mixing, you need to specify the outputs explicitly
output[1]=myStereoOutput.get(1);//
this.output[0]=myStereoOutput.get(0);//When working with mixing, you need to specify the outputs explicitly
this.output[1]=myStereoOutput.get(1);//
}
</script>
......@@ -73,24 +74,23 @@ maximJs.maxiAudio.play = function(){
</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.
var audio = new maximJs.maxiAudio();
audio.init();
// change output to an array
audio.outputIsArray(true, 2);
var myOsc = new maximJs.maxiOsc();
var myAutoPanner = new maximJs.maxiOsc();
var myStereoOutput = maximJs.maxiTools.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);
}
maximJs.maxiAudio.play = function(){
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);//
}
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>
<!--
Copyright 2010, Google Inc.
All rights reserved.
......@@ -43,22 +42,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
maximJs.maxiAudio.init();
var audio = new maximJs.maxiAudio();
audio.init();
var samplePlayer = new maximJs.maxiSample();
var mySine = new maximJs.maxiOsc();
maximJs.maxiAudio.loadSample("audio/beat2.wav", samplePlayer);
// maximJs.maxiTools.loadSample("audio/beat2.wav", samplePlayer, maximJs.maxiAudio.context);
// load sample to 'samplePlayer' using 'audio' object
audio.loadSample("audio/beat2.wav", samplePlayer);
maximJs.maxiAudio.play = function(){
audio.play = function(){
// 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.
}
if(samplePlayer.isReady()){
this.output = samplePlayer.play();//just play the file. Looping is default for all play functions.
// this.output=samplePlayer.play(0.69) ;//play the file with a speed setting. 1. is normal speed.
// this.output=samplePlayer.play(0.5,0,44100);//linear interpolationplay with a frequency input, start point and end point. Useful for syncing.
// this.output=samplePlayer.play4(0.5,0,44100);//cubic interpolation play with a frequency input, start point and end point. Useful for syncing.
}
}
......@@ -71,25 +71,27 @@ maximJs.maxiAudio.play = function(){
<h1> Sample Example </h1>
<p>
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var audio = new maximJs.maxiAudio();
audio.init();
var samplePlayer = new maximJs.maxiSample();
var mySine = new maximJs.maxiOsc();
function setup(){
loadSample("./beat2.wav", samplePlayer);
}
// load sample using 'audio' object
audio.loadSample("audio/beat2.wav", samplePlayer);
maximJs.maxiAudio.play = function(){
audio.play = function(){
// 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.
}
if(samplePlayer.isReady()){
this.output = samplePlayer.play();//just play the file. Looping is default for all play functions.
// this.output=samplePlayer.play(0.69) ;//play the file with a speed setting. 1. is normal speed.
// this.output=samplePlayer.play(0.5,0,44100);//linear interpolationplay with a frequency input, start point and end point. Useful for syncing.
// this.output=samplePlayer.play4(0.5,0,44100);//cubic interpolation play with a frequency input, start point and end point. Useful for syncing.
}
}
</pre>
</body></html>
</body></html>
\ No newline at end of file
......@@ -43,20 +43,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
maximJs.maxiAudio.init();
var audio = new maximJs.maxiAudio();
audio.init();
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();
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;
......@@ -66,32 +66,41 @@ var alpha = Math.sin(w0)/(2*Q);
// 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;
// b0 = 1;
// b1 = -2*cos(w0);
// b2 = 1;
// a0 = 1 + alpha;
// a1 = -2*cos(w0);
// a2 = 1 - alpha;
//LPF:
maximJs.maxiAudio.play = function() {//this is where the magic happens. Very slow magic.
xs[0] = mySwitchableOsc.sawn(400);
var f0 = 20;
audio.play = function() {//this is where the magic happens. Very slow magic.
f0 = (f0 + 0.001)%8000; //THE FREQUENCY
var w0 = 2*Math.PI*f0/44100;
var alpha = Math.sin(w0)/(2*Q);
b0 = (1 - cos(w0))/2;
b1 = 1 - cos(w0);
b2 = (1 - cos(w0))/2;
a0 = 1 + alpha;
a1 = -2*cos(w0);
a2 = 1 - alpha;
xs[0] = Math.random();
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];
var out = ys[0];
ys[2] = ys[1]; ys[1] = ys[0];
xs[2] = xs[1]; xs[1] = xs[0];
this.output = out;
}
......@@ -104,11 +113,12 @@ maximJs.maxiAudio.play = function() {//this is where the magic happens. Very slo
<h1> Advanced Filters </h1>
<p>
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
maximJs.maxiAudio.init();
var audio = new maximJs.maxiAudio();
audio.init();
var a = new maximJs.maxiOsc();
var xs = [0,0,0], ys = [0,0,0];
......@@ -148,15 +158,17 @@ a2 = 1 - alpha;
maximJs.maxiAudio.play = function() {//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];
audio.play = function() {//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];
this.output = ys[0];
ys[2] = ys[1]; ys[1] = ys[0];
xs[2] = xs[1]; xs[1] = xs[0];
}
</pre>
</body></html>
......@@ -44,7 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
maximJs.maxiAudio.init();
var audio = new maximJs.maxiAudio();
audio.init();
//This shows how to use maximilian to build a monophonic synth
//These are the synthesiser bits
......@@ -69,7 +70,7 @@ ADSR.setSustain(1);
ADSR.setRelease(1000);
maximJs.maxiAudio.play = function(){
audio.play = function(){
//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
......@@ -96,7 +97,7 @@ maximJs.maxiAudio.play = function(){
var finalSound=VCFout*ADSRout;//finally we add the ADSR as an amplitude modulator
ADSR.trigger=0;
output=finalSound;
this.output=finalSound;
}
</script>
......@@ -111,7 +112,7 @@ maximJs.maxiAudio.play = function(){
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
maximJs.maxiAudio.init();
audio.init();
//This shows how to use maximilian to build a monophonic synth
//These are the synthesiser bits
......@@ -121,7 +122,6 @@ 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
......@@ -137,7 +137,7 @@ ADSR.setSustain(1);
ADSR.setRelease(1000);
maximJs.maxiAudio.play = function(){
audio.play = function(){
//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
......@@ -164,7 +164,7 @@ maximJs.maxiAudio.play = function(){
var finalSound=VCFout*ADSRout;//finally we add the ADSR as an amplitude modulator
ADSR.trigger=0;
output=finalSound;
this.output=finalSound;
}
</pre>
</body></html>
......@@ -44,23 +44,45 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
maximJs.maxiAudio.init();
var audio = new maximJs.maxiAudio();
audio.init();
// change output to an array
maximJs.maxiAudio.outputIsArray(true, 2);
audio.outputIsArray(true, 2);
//This shows how to use maximilian to build a polyphonic synth.
// Chrome doesn't like this one for some reason
var VCO_ArraySize = 6;
//These are the synthesiser bits
// maxiTools makes it quicker to fill arrays with maxim objects
var VCO1 = maximJs. maxiTools.arrayOfObj(maximJs.maxiOsc, VCO_ArraySize);
var VCO2 = maximJs. maxiTools.arrayOfObj(maximJs.maxiOsc, VCO_ArraySize);
var LFO1 = maximJs. maxiTools.arrayOfObj(maximJs.maxiOsc, VCO_ArraySize);
var LFO2 = maximJs. maxiTools.arrayOfObj(maximJs.maxiOsc, VCO_ArraySize);
var VCO1 = [];
for(var i = 0; i < VCO_ArraySize; ++i){
VCO1.push(new maximJs.maxiOsc());
}
var VCO2 = [];
for(var i = 0; i < VCO_ArraySize; ++i){
VCO2.push(new maximJs.maxiOsc());
}
var VCF = maximJs. maxiTools.arrayOfObj(maximJs.maxiFilter, VCO_ArraySize);
var ADSR = maximJs. maxiTools.arrayOfObj(maximJs.maxiEnv, VCO_ArraySize);
var LFO1 = [];
for(var i = 0; i < VCO_ArraySize; ++i){
LFO1.push(new maximJs.maxiOsc());
}
var LFO2 = [];
for(var i = 0; i < VCO_ArraySize; ++i){
LFO2.push(new maximJs.maxiOsc());
}
var VCF = [];
for(var i = 0; i < VCO_ArraySize; ++i){
VCF.push(new maximJs.maxiFilter());
}
var ADSR = [];
for(var i = 0; i < VCO_ArraySize; ++i){
ADSR.push(new maximJs.maxiEnv());
}
//and these are some variables we can use to pass stuff around
var VCO1out = [], VCO2out = [], LFO1out = [],LFO2out = [], VCFout = [], ADSRout = [];
......@@ -93,7 +115,7 @@ for (var i=0;i<VCO_ArraySize;i++) {
}
maximJs.maxiAudio.play = function(){
audio.play = function(){
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.
......@@ -102,7 +124,7 @@ maximJs.maxiAudio.play = function(){
if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound
if (voice>=6) {
if (voice>=VCO_ArraySize) {
voice=0;
}
......@@ -113,7 +135,7 @@ maximJs.maxiAudio.play = function(){
}
//and this is where we build the synth
for (var i=0; i<6; i++) {
for (var i=0; i<VCO_ArraySize; i++) {
ADSRout[i]=ADSR[i].adsr(1.,ADSR[i].trigger);//our ADSR env is passed a constant signal of 1 to generate the transient.
......@@ -126,16 +148,16 @@ maximJs.maxiAudio.play = function(){
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
mix+=VCFout[i]*ADSRout[i]/VCO_ArraySize;//finally we add the ADSR as an amplitude modulator
}
output[0]=mix*0.5;//left channel
output[1]=mix*0.5;//right channel
this.output[0]=mix*0.5;//left channel
this.output[1]=mix*0.5;//right channel
// This just sends note-off messages.
for (var i=0; i<6; i++) {
for (var i=0; i<VCO_ArraySize; i++) {
ADSR[i].trigger=0;
}
}
......@@ -153,30 +175,53 @@ maximJs.maxiAudio.play = function(){
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" >
maximJs.maxiAudio.init();
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var audio = new maximJs.maxiAudio();
audio.init();
// change output to an array
maximJs.maxiAudio.outputIsArray(true, 2);
audio.outputIsArray(true, 2);
//This shows how to use maximilian to build a polyphonic synth.
// Chrome doesn't like this one for some reason
var VCO_ArraySize = 6;
//These are the synthesiser bits
// maxiTools makes it quicker to fill arrays with maxim objects
var VCO1 = maximJs. maxiTools.arrayOfObj(maximJs.maxiOsc, VCO_ArraySize);
var VCO2 = maximJs. maxiTools.arrayOfObj(maximJs.maxiOsc, VCO_ArraySize);
var LFO1 = maximJs. maxiTools.arrayOfObj(maximJs.maxiOsc, VCO_ArraySize);
var LFO2 = maximJs. maxiTools.arrayOfObj(maximJs.maxiOsc, VCO_ArraySize);
var VCO1 = [];
for(var i = 0; i < VCO_ArraySize; ++i){
VCO1.push(new maximJs.maxiOsc());
}
var VCF = maximJs. maxiTools.arrayOfObj(maximJs.maxiFilter, VCO_ArraySize);
var ADSR = maximJs. maxiTools.arrayOfObj(maximJs.maxiEnv, VCO_ArraySize);
var VCO2 = [];
for(var i = 0; i < VCO_ArraySize; ++i){
VCO2.push(new maximJs.maxiOsc());
}
var LFO1 = [];
for(var i = 0; i < VCO_ArraySize; ++i){
LFO1.push(new maximJs.maxiOsc());
}
var LFO2 = [];
for(var i = 0; i < VCO_ArraySize; ++i){
LFO2.push(new maximJs.maxiOsc());
}
var VCF = [];
for(var i = 0; i < VCO_ArraySize; ++i){
VCF.push(new maximJs.maxiFilter());
}
var ADSR = [];
for(var i = 0; i < VCO_ArraySize; ++i){
ADSR.push(new maximJs.maxiEnv());
}
//and these are some variables we can use to pass stuff around
var VCO1out = [], VCO2out = [], LFO1out = [],LFO2out = [], VCFout = [], ADSRout = [];
var pitch = [];
// fill arrays with 0s
for(var i = 0; i < VCO_ArraySize; i++){
VCO1out.push(0);
VCO2out.push(0);
......@@ -202,7 +247,7 @@ for (var i=0;i<VCO_ArraySize;i++) {
}
maximJs.maxiAudio.play = function(){
audio.play = function(){
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.
......@@ -211,7 +256,7 @@ maximJs.maxiAudio.play = function(){
if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound
if (voice>=6) {
if (voice>=VCO_ArraySize) {
voice=0;
}
......@@ -222,7 +267,7 @@ maximJs.maxiAudio.play = function(){
}
//and this is where we build the synth
for (var i=0; i<6; i++) {
for (var i=0; i<VCO_ArraySize; i++) {
ADSRout[i]=ADSR[i].adsr(1.,ADSR[i].trigger);//our ADSR env is passed a constant signal of 1 to generate the transient.
......@@ -235,18 +280,19 @@ maximJs.maxiAudio.play = function(){
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
mix+=VCFout[i]*ADSRout[i]/VCO_ArraySize;//finally we add the ADSR as an amplitude modulator
}
output[0]=mix*0.5;//left channel
output[1]=mix*0.5;//right channel
this.output[0]=mix*0.5;//left channel
this.output[1]=mix*0.5;//right channel
// This just sends note-off messages.
for (var i=0; i<6; i++) {
for (var i=0; i<VCO_ArraySize; i++) {
ADSR[i].trigger=0;
}
}
</pre>
</body></html>
......@@ -43,8 +43,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
maximJs.maxiAudio.init();
maximJs.maxiAudio.outputIsArray(true, 2);
var audio = new maximJs.maxiAudio();
audio.init();
audio.outputIsArray(true, 2);
//Bizarelly, this sounds a little bit like Kraftwerk's 'Metropolis', although it isn't. Funny that.
var sound = new maximJs.maxiOsc();
......@@ -77,7 +78,7 @@ 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
var leadLinePitch=[69,67,65,64,67,66,64,62,65,64,62,57,55,60,57];
maximJs.maxiAudio.play = function(){
audio.play = function(){
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
......@@ -107,11 +108,9 @@ maximJs.maxiAudio.play = function(){
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;
audio.output[0]=(bassout + delayout)/2;//sum output
audio.output[1]=(bassout + delayout)/2;
}
</script>
</head>
......@@ -125,11 +124,11 @@ maximJs.maxiAudio.play = function(){
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
maximJs.maxiAudio.init();
maximJs.maxiAudio.outputIsArray(true, 2);
var audio = new maximJs.maxiAudio();
audio.init();
audio.outputIsArray(true, 2);
//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();
......@@ -160,7 +159,7 @@ 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
var leadLinePitch=[69,67,65,64,67,66,64,62,65,64,62,57,55,60,57];
maximJs.maxiAudio.play = function(){
audio.play = function(){
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
......@@ -190,8 +189,8 @@ maximJs.maxiAudio.play = function(){
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;
audio.output[0]=(bassout + delayout)/2;//sum output
audio.output[1]=(bassout + delayout)/2;
}
</pre>
</body></html>
......@@ -44,34 +44,34 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
maximJs.maxiAudio.init();
var audio = new maximJs.maxiAudio();
audio.init();
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;
maximJs.maxiAudio.outputIsArray(true, 2);
audio.outputIsArray(true, 2);
compressor.setAttack(100);
compressor.setRelease(300);
compressor.setThreshold(0.25);
compressor.setRatio(5);
maximJs.maxiTools.loadSample('audio/beat2.wav', beats);
audio.loadSample('audio/beat2.wav', beats);
maximJs.maxiAudio.play = function(){
audio.play = function(){
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;
this.output[0]=out;
this.output[1]=out;
}
......@@ -88,32 +88,35 @@ maximJs.maxiAudio.play = function(){
</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;
var audio = new maximJs.maxiAudio();
audio.init();
function setup(){
OutputIsArray(true, 2);
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;
compressor.setAttack(100);
compressor.setRelease(300);
compressor.setThreshold(0.25);
compressor.setRatio(5);
loadSample('./beat2.wav', beats);
}
audio.outputIsArray(true, 2);
maximJs.maxiAudio.play = function(){
compressor.setAttack(100);
compressor.setRelease(300);
compressor.setThreshold(0.25);
compressor.setRatio(5);
audio.loadSample('audio/beat2.wav', beats);
audio.play = function(){
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));
// out=compressor.compress(beats.play(0.66));
}
this.output[0]=out;
this.output[1]=out;
}
output[0]=out;
output[1]=out;
}
</pre>
</body></html>
......@@ -44,8 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
maximJs.maxiAudio.init();
// maximJs.maxiAudio.utputIsArray(true, 2);
var audio = new maximJs.maxiAudio();
audio.init();
var kick = new maximJs.maxiSample();
var snare = new maximJs.maxiSample();
......@@ -61,12 +61,12 @@ var hathit=[0,0,1,0, 0,0,1,0, 0,0,1,0, 0,0,1,1];//This is the sequence for the s
var kicktrigger,snaretrigger, hattrigger;
var sampleOut;
maximJs.maxiTools.loadSample('audio/kick1.wav', kick);
maximJs.maxiTools.loadSample('audio/snare1.wav', snare);
maximJs.maxiTools.loadSample('audio/hat12.wav', hat);
audio.loadSample('audio/kick1.wav', kick);
audio.loadSample('audio/snare1.wav', snare);
audio.loadSample('audio/hat12.wav', hat);
maximJs.maxiAudio.play = function(){
audio.play = function(){
// if(kick.isReady() && snare.isReady()){
currentCount=Math.floor(timer.phasor(8));//this sets up a metronome that ticks 8 times a second
......@@ -97,11 +97,8 @@ maximJs.maxiAudio.play = function(){
sampleOut=hat.playOnce()*0.2+kick.playOnce()+snare.playOnce();//just play the files. No looping.
output=sampleOut;//left channel
this.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;
......@@ -121,8 +118,8 @@ maximJs.maxiAudio.play = function(){
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
maximJs.maxiAudio.init();
// maximJs.maxiAudio.utputIsArray(true, 2);
var audio = new maximJs.maxiAudio();
audio.init();
var kick = new maximJs.maxiSample();
var snare = new maximJs.maxiSample();
......@@ -138,12 +135,12 @@ var hathit=[0,0,1,0, 0,0,1,0, 0,0,1,0, 0,0,1,1];//This is the sequence for the s
var kicktrigger,snaretrigger, hattrigger;
var sampleOut;
maximJs.maxiTools.loadSample('audio/kick1.wav', kick);
maximJs.maxiTools.loadSample('audio/snare1.wav', snare);
maximJs.maxiTools.loadSample('audio/hat12.wav', hat);
audio.loadSample('audio/kick1.wav', kick);
audio.loadSample('audio/snare1.wav', snare);
audio.loadSample('audio/hat12.wav', hat);
maximJs.maxiAudio.play = function(){
audio.play = function(){
// if(kick.isReady() && snare.isReady()){
currentCount=Math.floor(timer.phasor(8));//this sets up a metronome that ticks 8 times a second
......@@ -174,11 +171,8 @@ maximJs.maxiAudio.play = function(){
sampleOut=hat.playOnce()*0.2+kick.playOnce()+snare.playOnce();//just play the files. No looping.
output=sampleOut;//left channel
this.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;
......
......@@ -44,7 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
maximJs.maxiAudio.init();
var audio = new maximJs.maxiAudio();
audio.init();
var sound1 = new maximJs.maxiSample();
......@@ -61,11 +62,11 @@ var sampleTrigger = 0;
var sampleOut = 0;
maximJs.maxiAudio.outputIsArray(true, 2);
maximJs.maxiTools.loadSample('audio/kick1.wav', sound1);
audio.outputIsArray(true, 2);
audio.loadSample('audio/kick1.wav', sound1);
maximJs.maxiAudio.play = function(){
audio.play = function(){
if(sound1.isReady()){
currentCount=Math.floor(timer.phasor(8));//this sets up a metronome that ticks 8 times a second
......@@ -85,8 +86,8 @@ maximJs.maxiAudio.play = function(){
//If you stick a 1 in the trigger input, it retriggers the envelope
sampleOut=envelope.ar(sound1.play(1.), 0.1, 0.9999, 1, sampleTrigger); //
output[0]=sampleOut;//left channel
output[1]=sampleOut;//right channel
this.output[0]=sampleOut;//left channel
this.output[1]=sampleOut;//right channel
sampleTrigger = 0;//set trigger to 0 at the end of each sample to guarantee retriggering.
}
......@@ -106,49 +107,52 @@ maximJs.maxiAudio.play = function(){
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var sound1 = new maximJs.maxiSample();
var audio = new maximJs.maxiAudio();
audio.init();
var snarePhase = new maximJs.maxiOsc();
var timer = new maximJs.maxiOsc();
var sound1 = new maximJs.maxiSample();
var envelope = new maximJs.maxiEnv();
var currentCount = 0,lastCount = 0,playHead = 0;
var snarePhase = new maximJs.maxiOsc();
var timer = new maximJs.maxiOsc();
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 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;
var sampleOut = 0;
function setup(){
OutputIsArray(true, 2);
loadSample('audio/beat2.wav', sound1);
}
var sampleTrigger = 0;
var sampleOut = 0;
audio.outputIsArray(true, 2);
audio.loadSample('audio/kick1.wav', sound1);
maximJs.maxiAudio.play = function(){
audio.play = function(){
if(sound1.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
sampleTrigger=sequence[playHead%16];
playHead++;//iterate the playhead
lastCount=0;//reset the metrotest
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
}
//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); //
sampleTrigger = 0;//set trigger to 0 at the end of each sample to guarantee retriggering.
this.output[0]=sampleOut;//left channel
this.output[1]=sampleOut;//right channel
sampleTrigger = 0;//set trigger to 0 at the end of each sample to guarantee retriggering.
}
}
</pre>
......
......@@ -44,17 +44,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
// create audio handler
var audio = new maximJs.maxiAudio();
// initialise audio
audio.init();
// create oscillator
var mySine = new maximJs.maxiOsc();
audio.play = function(){
// direct value to output
this.output = mySine.sinewave(440);
}
</script>
</head>
......@@ -68,13 +69,17 @@ audio.play = function(){
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
// create audio handler
var audio = new maximJs.maxiAudio();
// initialise audio
maximJs.maxiAudio.init();
audio.init();
// create oscillator
var mySine = new maximJs.maxiOsc();
maximJs.maxiAudio.play = function(){
output = mySine.sinewave(440);
audio.play = function(){
// direct value to output
this.output = mySine.sinewave(440);
}
</pre>
</body>
......
......@@ -44,7 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
maximJs.maxiAudio.init();
var audio = new maximJs.maxiAudio();
audio.init();
var sineBank = [];
......@@ -52,7 +53,7 @@ for(var i = 0; i < 10; i++){
sineBank.push(new maximJs.maxiOsc());
}
maximJs.maxiAudio.play = function(){
audio.play = function(){
var wave=0;
var f0 = 100;
for(var i=0; i < 10; i++) {
......@@ -62,7 +63,7 @@ maximJs.maxiAudio.play = function(){
wave = wave + thisSine;
}
wave *= 0.1;
output = wave;//simple as that!
this.output = wave;//simple as that!
}
......@@ -79,17 +80,16 @@ maximJs.maxiAudio.play = function(){
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var audio = new maximJs.maxiAudio();
audio.init();
var sineBank = [];
for(var i = 0; i < 10; i++){
sineBank.push(new maximJs.maxiOsc());
}
function setup(){ //some inits
//nothing to go here this time
}
maximJs.maxiAudio.play = function(){
audio.play = function(){
var wave=0;
var f0 = 100;
for(var i=0; i < 10; i++) {
......@@ -99,7 +99,7 @@ maximJs.maxiAudio.play = function(){
wave = wave + thisSine;
}
wave *= 0.1;
output = wave;//simple as that!
this.output = wave;//simple as that!
}
</pre>
</body></html>
......@@ -40,8 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
<!-- <script src="../libs/maxiLib_maxiFFT.js"></script> -->
<script src="../maxiLib.js"></script>
<!-- Our javascript code -->
......@@ -65,32 +63,81 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</body>
<script type="text/javascript">
maximJs.maxiAudio.init();
var audio = new maximJs.maxiAudio();
audio.init();
var fftSize = 1024;
var sampleRate = 44100;
var fft = new maximJs.maxiFFT();
// var ifft = new maximJs.maxiIFFT();
// var mffc = new maximJs.maxiMFFC();
var mfcc = new maximJs.maxiMFCC();
var oct = new maximJs.maxiFFTOctaveAnalyzer();
var nAverages = 12;
fft.setup(fftSize, 512, 256);
mfcc.setup(512, 42, 13, 20, 20000, sampleRate);
oct.setup(sampleRate, fftSize/2, nAverages);
// for storing fft values
/*
required as passing a vector from one class
to another isn't currently working
*/
var magnitudes = new Module.VectorFloat();
var magnitudesDB = new Module.VectorFloat();
// will store mfcc output
var mfccs = new Module.VectorDouble();
for(var i = 0; i < 13; ++i){
mfccs.push_back(0);
}
for(var i = 0; i < fftSize/2; ++i){
magnitudes.push_back(0);
}
var osc = new maximJs.maxiOsc();
var fftSize = 1024;
var sampleRate = 44100;
// if you want to play a sample...
var samplePlayer = new maximJs.maxiSample();
audio.loadSample("./audio/beat2.wav", samplePlayer);
var magMult = 6;
var count = 0;
var updateIncr = 50;
var ignoreCount = false;
var bars = [];
var barsBottom = 600;
var barsLeft = 50;
var magMult = 6;
var fftDraw = {
barsBottom: 600,
barsLeft: 50,
barsSize:1,
magMult: 6
};
var mfccDraw = {
barsBottom: 350,
barsLeft: 350,
barsSize:10,
magMult: 24
};
var octDraw = {
barsBottom: 150,
barsLeft: 350,
barsSize:10,
magMult: 0.5
};
var amtAvgs = 15;
var pitchHist = [];
window.onload = setup;
function setup(){
fft.setup(fftSize, 512, 256);
// ifft.setup(fftSize, 512, 256);
// mfcc.setup(512, 42, 13, 20, 20000, sampleRate);
// This gets the window in the browser
var canvas=document.getElementById("myCanvas");
......@@ -103,110 +150,276 @@ function setup(){
return setInterval(draw, 40);
}
maximJs.maxiAudio.play = function(){
audio.play = function(){
// create wave for fft
var wave = osc.square(220);
// or use a sample
// var wave = samplePlayer.isReady() ? samplePlayer.play() : 0.0;
// process wave
if(fft.process(wave)){
fft.magsToDB();
count++; // increment counter
// // sorry, this is not nice
Module.vectorTools.clearVectorFloat(magnitudes);
Module.vectorTools.clearVectorFloat(magnitudesDB);
for(var i = 0; i < fftSize/2; ++i){
magnitudes.push_back(fft.getMagnitude(i));
magnitudesDB.push_back(fft.getMagnitudeDB(i));
}
output = wave;
// // pass magnitudes to mfcc and store in mfccs vector
mfcc.mfcc(magnitudes, mfccs);
oct.calculate(magnitudesDB);
}
this.output = wave;
}
//The stuff inside the script tag is very similar to processing code.
function draw() {
//This is basically the same as any other 2D processing draw routine.
//clear the screen
context.clearRect(0,0,700,700);
// fft
context.fillStyle="#FF0000";
context.font = "30px Arial";
context.fillText("FFT",70,200);
for(var i=0; i < fftSize / 2; i++) {
context.beginPath();
context.fillStyle="#FF0000";
context.rect(barsLeft + i, barsBottom, 1, -(fft.getMagnitude(i) * magMult));
context.rect(
fftDraw.barsLeft + i,
fftDraw.barsBottom,
fftDraw.barsSize,
-(fft.getMagnitude(i) * fftDraw.magMult));
context.fill();
// context.stroke();
context.closePath();
}
// mfcc
context.fillStyle="rgba(0, 220, 0, 0.5)"
context.font = "30px Arial";
context.fillText("MFCC",350,250);
for(var i=0; i < 13; i++) {
context.beginPath();
context.rect(
mfccDraw.barsLeft + i*mfccDraw.barsSize,
mfccDraw.barsBottom,
mfccDraw.barsSize,
(mfccs.get(i) * mfccDraw.magMult));
context.fill();
context.closePath();
}
// octave analyser
var j = 0;
for(var i=0; i < amtAvgs; ++i) {
pitchHist[i] = 0;
}
for (var i = 0; i < oct.nAverages; ++i) {
pitchHist[j] += oct.getAverage(i);
j++;
j = j % amtAvgs;
}
context.fillStyle="rgba(0, 0, 255, 0.5)"
context.font = "30px Arial";
context.fillText("OCT",350,50);
for(var i=0; i < amtAvgs; i++) {
context.beginPath();
context.rect(
octDraw.barsLeft + i*(octDraw.barsSize*1.5),
octDraw.barsBottom,
octDraw.barsSize,
-(pitchHist[i] * octDraw.magMult));
context.fill();
context.closePath();
}
}
</script>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
maximJs.maxiAudio.init();
var audio = new maximJs.maxiAudio();
audio.init();
var fft = new maximJs.maxiFFT();
// var ifft = new maximJs.maxiIFFT();
// var mffc = new maximJs.maxiMFFC();
var fft = new maximJs.maxiFFT();
var mfcc = new maximJs.maxiMFCC();
var oct = new maximJs.maxiFFTOctaveAnalyzer();
var osc = new maximJs.maxiOsc();
var nAverages = 12;
var fftSize = 1024;
var sampleRate = 44100;
// for storing fft values
/*
required as passing a vector from one class
to another isn't currently working
*/
var magnitudes = new Module.VectorFloat();
var magnitudesDB = new Module.VectorFloat();
var magMult = 6;
// will store mfcc output
var mfccs = new Module.VectorDouble();
var osc = new maximJs.maxiOsc();
// if you want to play a sample...
// var samplePlayer = new maximJs.maxiSample();
// audio.loadSample("./audio/beat2.wav", samplePlayer);
var fftSize = 1024;
var sampleRate = 44100;
var count = 0;
var updateIncr = 50;
var ignoreCount = false;
var magMult = 6;
var bars = [];
var barsBottom = 600;
var barsLeft = 50;
var fftDraw = {
barsBottom: 600,
barsLeft: 50,
barsSize:1,
magMult: 6
};
var mfccDraw = {
barsBottom: 350,
barsLeft: 350,
barsSize:10,
magMult: 24
};
var octDraw = {
barsBottom: 150,
barsLeft: 350,
barsSize:10,
magMult: 0.5
};
var amtAvgs = 15;
var pitchHist = [];
window.onload = setup;
function setup(){
fft.setup(fftSize, 512, 256);
// ifft.setup(fftSize, 512, 256);
// mfcc.setup(512, 42, 13, 20, 20000, sampleRate);
fft.setup(fftSize, 512, 256);
mfcc.setup(512, 42, 13, 20, 20000, sampleRate);
oct.setup(sampleRate, fftSize/2, nAverages);
// This gets the window in the browser
var canvas=document.getElementById("myCanvas");
for(var i = 0; i < 13; ++i){
mfccs.push_back(0);
}
// This creates a 2d drawing context in it.
context=canvas.getContext("2d");
for(var i = 0; i < fftSize/2; ++i){
magnitudes.push_back(0);
}
//finally, we return setInterval, which wants a function to call,
//and a period in milliseconds to wait between calling it.
return setInterval(draw, 40);
// This gets the window in the browser
var canvas=document.getElementById("myCanvas");
// This creates a 2d drawing context in it.
context=canvas.getContext("2d");
//finally, we return setInterval, which wants a function to call,
//and a period in milliseconds to wait between calling it.
return setInterval(draw, 40);
}
audio.play = function(){
// create wave for fft
var wave = osc.square(220);
maximJs.maxiAudio.play = function(){
// create wave for fft
var wave = osc.square(220);
// or use a sample
// var wave = samplePlayer.isReady() ? samplePlayer.play() : 0.0;
// process wave
if(fft.process(wave)){
fft.magsToDB();
count++; // increment counter
}
// process wave
if(fft.process(wave)){
fft.magsToDB();
output = wave;
// // sorry, this is not nice
Module.vectorTools.clearVectorFloat(magnitudes);
Module.vectorTools.clearVectorFloat(magnitudesDB);
for(var i = 0; i < fftSize/2; ++i){
magnitudes.push_back(fft.getMagnitude(i));
magnitudesDB.push_back(fft.getMagnitudeDB(i));
}
// // pass magnitudes to mfcc and store in mfccs vector
mfcc.mfcc(magnitudes, mfccs);
oct.calculate(magnitudesDB);
}
this.output = wave;
}
//The stuff inside the script tag is very similar to processing code.
function draw() {
//This is basically the same as any other 2D processing draw routine.
//clear the screen
context.clearRect(0,0,700,700);
// fft
context.fillStyle="#FF0000";
context.font = "30px Arial";
context.fillText("FFT",70,200);
for(var i=0; i < fftSize / 2; i++) {
context.beginPath();
context.fillStyle="#FF0000";
context.rect(barsLeft + i, barsBottom, 1, -(fft.getMagnitude(i) * magMult));
context.fill();
// context.stroke();
context.closePath();
context.beginPath();
context.rect(
fftDraw.barsLeft + i,
fftDraw.barsBottom,
fftDraw.barsSize,
-(fft.getMagnitude(i) * fftDraw.magMult));
context.fill();
context.closePath();
}
// mfcc
context.fillStyle="rgba(0, 220, 0, 0.5)"
context.font = "30px Arial";
context.fillText("MFCC",350,250);
for(var i=0; i < 13; i++) {
context.beginPath();
context.rect(
mfccDraw.barsLeft + i*mfccDraw.barsSize,
mfccDraw.barsBottom,
mfccDraw.barsSize,
(mfccs.get(i) * mfccDraw.magMult));
context.fill();
context.closePath();
}
// octave analyser
var j = 0;
for(var i=0; i < amtAvgs; ++i) {
pitchHist[i] = 0;
}
for (var i = 0; i < oct.nAverages; ++i) {
pitchHist[j] += oct.getAverage(i);
j++;
j = j % amtAvgs;
}
context.fillStyle="rgba(0, 0, 255, 0.5)"
context.font = "30px Arial";
context.fillText("OCT",350,50);
for(var i=0; i < amtAvgs; i++) {
context.beginPath();
context.rect(
octDraw.barsLeft + i*(octDraw.barsSize*1.5),
octDraw.barsBottom,
octDraw.barsSize,
-(pitchHist[i] * octDraw.magMult));
context.fill();
context.closePath();
}
}
</pre>
......
......@@ -43,7 +43,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
maximJs.maxiAudio.init();
var audio = new maximJs.maxiAudio();
audio.init();
var samplePlayer = new maximJs.maxiSample();
......@@ -53,10 +54,10 @@ var stretch = new Module.maxiPitchStretch();
var speed = 0.5;
maximJs.maxiTools.loadSample("audio/beat2.wav", samplePlayer);
audio.loadSample("audio/beat2.wav", samplePlayer);
var grainsSet = false;
maximJs.maxiAudio.play = function(){
audio.play = function(){
// this is necessary as file loading may not complete in setup
if(samplePlayer.isReady()){
......@@ -67,8 +68,8 @@ if(!grainsSet){
grainsSet = true;
}
output = stretch.play(1, 2,0.1, 2, 0);
// ouptut = grains.play2(pos, 0.1, 4);
this.output = stretch.play(1, 2,0.1, 2, 0);
// this.ouptut = grains.play2(pos, 0.1, 4);
}
}
</script>
......@@ -84,7 +85,8 @@ output = stretch.play(1, 2,0.1, 2, 0);
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
maximJs.maxiAudio.init();
var audio = new maximJs.maxiAudio();
audio.init();
var samplePlayer = new maximJs.maxiSample();
......@@ -94,10 +96,10 @@ var stretch = new Module.maxiPitchStretch();
var speed = 0.5;
maximJs.maxiTools.loadSample("audio/beat2.wav", samplePlayer);
audio.loadSample("audio/beat2.wav", samplePlayer);
var grainsSet = false;
maximJs.maxiAudio.play = function(){
audio.play = function(){
// this is necessary as file loading may not complete in setup
if(samplePlayer.isReady()){
......@@ -108,8 +110,8 @@ if(!grainsSet){
grainsSet = true;
}
output = stretch.play(1, 2,0.1, 2, 0);
// ouptut = grains.play2(pos, 0.1, 4);
this.output = stretch.play(1, 2,0.1, 2, 0);
// this.ouptut = grains.play2(pos, 0.1, 4);
}
}
</pre>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -43,83 +43,41 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<script src="../maxiLib.js"></script>
<!-- <script src="../maxi_webAudio.js"></script> -->
</head>
<body>
<h1> Two Tones </h1>
<canvas id="myCanvas" width="700" height="700" style="border:1px solid #c3c3c3;">
<!-- It's a good idea to warn people whose browsers don't support the tag -->
Your browser does not support the canvas element.
</canvas>
<script type="text/javascript">
var context;
window.onload = setup;
function setup(){
// fft.setup(fftSize, 512, 256);
// ifft.setup(fftSize, 512, 256);
// mfcc.setup(512, 42, 13, 20, 20000, sampleRate);
// This gets the window in the browser
var canvas=document.getElementById("myCanvas");
// This creates a 2d drawing context in it.
context=canvas.getContext("2d");
//finally, we return setInterval, which wants a function to call,
//and a period in milliseconds to wait between calling it.
return setInterval(draw, 40);
}
//The stuff inside the script tag is very similar to processing code.
function draw() {
//This is basically the same as any other 2D processing draw routine.
//clear the screen
context.clearRect(0,0,700,700);
context.beginPath();
context.fillStyle="#FF0000";
context.rect(0,0,50,50);
context.fill();
// context.stroke();
context.closePath();
}
// initialise audio
maximJs.maxiAudio.init();
<!-- Our javascript code -->
<script type="text/javascript">
var audio = new maximJs.maxiAudio();
audio.init();
var mySine = new maximJs.maxiOsc();
var myOtherSine = new maximJs.maxiOsc();
maximJs.maxiAudio.play = function(){
audio.play = function(){
// these two sines will beat together. They're now a bit too loud though..
output = mySine.sinewave(440) + myOtherSine.sinewave(441);
this.output = mySine.sinewave(440) + myOtherSine.sinewave(441);
}
</script>
</head>
<body>
<h1> Two Tones </h1>
<p>
These sines are taking a beating...
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
// initialise audio
maximJs.maxiAudio.init();
var audio = new maximJs.maxiAudio();
audio.init();
var mySine = new maximJs.maxiOsc();
var myOtherSine = new maximJs.maxiOsc();
maximJs.maxiAudio.play = function(){
// these two sines will beat together. They're now a bit too loud though..
output = mySine.sinewave(440) + myOtherSine.sinewave(441);
audio.play = function(){
// these two sines will beat together. They're now a bit too loud though..
this.output = mySine.sinewave(440) + myOtherSine.sinewave(441);
}
</pre>
</body></html>