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 (30)
Showing
with 23176 additions and 45273 deletions
Maxi_Emscripten/
src/cpp/Maximilian-master/
Recordings/
\ No newline at end of file
Recordings/
maxiLib/maximilian_examples_web/load_sample_test.html
maxiLib/sed_addText.sh
maxiLib/sed_replace.sh
maxiLib/sed_text_stuff/
maximilian_examples_cpp/
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
# change '../../em++' to path to em++ in emscriten folder
# change '../../em++' to path to em++ in emscripten folder
EMSCR=../../em++
# ----------------------------------------
# Maximilian base stuff
# POST_JS is all the external js stuff that handles web audio etc
POST_JS=src/js/maxi_webAudio.js
POST_JS_webAudio_all=src/js/maxi_webAudio.js
# POST_JS_extras=src/js/maxi_extras.js
#the .cpp file that is used
SOURCE_MAXI=src/cpp/maxi_emscr_new.cpp
# destination .js file
OUTPUT_MAXI=maxiLib/maxiLib.js
# OUTPUT_MAXI_noAudio=maxiLib/maxiLib_noWebAudio.js
# ----------------------------------------
# extra libs stuff
SOURCE_maxiFFT=src/cpp/libs/maxiFFT.cpp
SOURCE_maxiMFCC=src/cpp/libs/maxiMFCC.cpp
SOURCE_maxiGrains=src/cpp/libs/maxiGrains.cpp
# destination for maxiFFT from when I didn't know better
# OUTPUT_maxiFFT=maxiLib/libs/maxiLib_maxiFFT.js
SOURCES_LIBS = $(SOURCE_maxiFFT) $(SOURCE_maxiMFCC) $(SOURCE_maxiGrains)
# ----------------------------------------
......@@ -30,7 +33,11 @@ CFLAGS=-O3 -s DISABLE_EXCEPTION_CATCHING=0 -s ALLOW_MEMORY_GROWTH=1 -s ASSERTION
# ----------------------------------------
# Final paths
maxi:
$(EMSCR) $(CFLAGS) --post-js $(POST_JS) --bind -o $(OUTPUT_MAXI) $(SOURCE_MAXI) $(SOURCE_maxiFFT)
full:
$(EMSCR) $(CFLAGS) --post-js $(POST_JS_webAudio_all) --bind -o $(OUTPUT_MAXI) $(SOURCE_MAXI) $(SOURCES_LIBS)
all: maxi
\ No newline at end of file
# without webAudio stuff
# basic:
# $(EMSCR) $(CFLAGS) --post-js $(POST_JS_extras) --bind -o $(OUTPUT_MAXI_noAudio) $(SOURCE_MAXI) $(SOURCES_LIBS)
all: full
\ No newline at end of file
An implementation of maximilian in javascript using emscripten to compile code from C++ to javascript.
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.
Makefile!! - Can now use ‘make’ command to compile. You will probably need to change the location of em++ in the Makefile though.
- to just make base maximilian (without libs [fft etc]) use ‘make maxi’
File structure:
src: Contains all files (.cpp/.js) for use with emscripten.
- cpp/* : all maximilian files and emscripten bindings
- js/maxi_webAudio.js : some stuff for interacting with AudioContext and loading files (plus some other bits) which is appended to the end of emscripten’s output automatically.
maxiLib: files for the js implementation of maximilian.
- maxiLib.js is the output from emscripten.
- libs will contain all extra maximilian libraries when completed.
old stuff : the initial files from the beginning. Not of much use anymore.
To use: move the maxiLib.js file from the maxiLib folder to an appropriate location and include using the <script> tag right now.
Examples are in maxiLib/maximilian_examples_web.
\ No newline at end of file
This diff is collapsed.
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -44,6 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- 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();//
......@@ -55,15 +57,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);
function play(){
audio.play = function(){
myCurrentVolume=myEnvelope.adsr(1.,myEnvelope.trigger);
......@@ -84,7 +86,7 @@ function play(){
// The last input is the resonance.
myFilteredOutput=myFilter.lores(myOscOutput,myCurrentVolume*1000,10);
output=myFilteredOutput;//left speaker
this.output=myFilteredOutput;//left speaker
}
......@@ -99,4 +101,51 @@ function play(){
<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>
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -44,93 +44,49 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- 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
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;
}
......@@ -140,10 +96,56 @@ function play(){
<body>
<h1> polysynth </h1>
<h1> Filter Example </h1>
<p>
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" >
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>
<!--
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">
var myCounter = new maximJs.maxiOsc();
var mySwitchableOsc = new maximJs.maxiOsc();
var myAutoPanner = new maximJs.maxiOsc();
var currentCount;
var myOscOutput, myFilteredOutput, myPanPosition;
var myStereoOutput = new Module.VectorDouble();// we need an output for each channel.
// var myEnvelopeData = [500,0,1000,500,0,500];//this data will be used to make an envelope. Value and time to value in ms.
var myEnvelopeData = new Module.VectorDouble();//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(){
myEnvelopeData.push_back(500);
myEnvelopeData.push_back(0);
myEnvelopeData.push_back(1000);
myEnvelopeData.push_back(500);
myEnvelopeData.push_back(0);
myEnvelopeData.push_back(500);
myStereoOutput.push_back(0);
myStereoOutput.push_back(0);
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);//
}
// window.onbeforeunload = function () {
// alert('unload');
// }
</script>
</head>
<body>
<h1> Mixing Example </h1>
<p>
</p>
</body></html>
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -43,33 +43,25 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
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 = GetArrayAsVectorDbl([0,0]);
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);
}
function play(){
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);//
}
// window.onbeforeunload = function () {
// alert('unload');
// }
this.output[0]=myStereoOutput.get(0);//When working with mixing, you need to specify the outputs explicitly
this.output[1]=myStereoOutput.get(1);//
}
</script>
</script>
</head>
......@@ -80,4 +72,25 @@ function play(){
<p>
</p>
<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
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.
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>
<!--
Copyright 2010, Google Inc.
All rights reserved.
......@@ -35,7 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -43,25 +42,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
var audio = new maximJs.maxiAudio();
audio.init();
var samplePlayer = new maximJs.maxiSample();
var mySine = new maximJs.maxiOsc();
function setup(){
// console.log(samplePlayer.load("Macintosh HD/Users/Dan/Documents/Programming/Emscripten/emsdk_portable/emscripten/tag-1.34.11/tests/maximilian/web/maximilian_examples_web/beat2.wav", 1));
loadSample("./beat2.wav", samplePlayer);
}
// load sample to 'samplePlayer' using 'audio' object
audio.loadSample("audio/beat2.wav", samplePlayer);
function play(){
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.
}
}
......@@ -74,6 +71,27 @@ function play(){
<h1> Sample Example </h1>
<p>
</p>
</body></html>
<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();
// load sample using 'audio' object
audio.loadSample("audio/beat2.wav", samplePlayer);
audio.play = function(){
// this is necessary as file loading may not complete in setup
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>
\ No newline at end of file
......@@ -34,7 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -43,60 +43,68 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
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();
function setup() {//some inits
var cos = Math.cos;
var cos = Math.cos;
// Band-pass reson:
// b0 = alpha;
// b1 = 0;
// b2 = -1 * alpha;
// a0 = 1 + alpha;
// a1 = -2*cos(w0);
// a2 = 1 - alpha;
//Notch:
// b0 = 1;
// b1 = -2*cos(w0);
// b2 = 1;
// a0 = 1 + alpha;
// a1 = -2*cos(w0);
// a2 = 1 - alpha;
//LPF:
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);
//Band-pass reson:
// b0 = alpha;
// b1 = 0;
// b2 = -1 * alpha;
// a0 = 1 + alpha;
// a1 = -2*cos(w0);
// a2 = 1 - alpha;
//Notch:
b0 = 1;
b1 = -2*cos(w0);
b2 = 1;
a0 = 1 + alpha;
a1 = -2*cos(w0);
a2 = 1 - alpha;
//LPF:
// b0 = (1 - cos(w0))/2;
// b1 = 1 - cos(w0);
// b2 = (1 - cos(w0))/2;
// a0 = 1 + alpha;
// a1 = -2*cos(w0);
// a2 = 1 - alpha;
}
function play() {//this is where the magic happens. Very slow magic.
xs[0] = mySwitchableOsc.sawn(400);
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;
}
// window.onbeforeunload = function () {
// alert('unload');
// }
</script>
</script>
</head>
......@@ -105,6 +113,62 @@ function play() {//this is where the magic happens. Very slow magic.
<h1> Advanced Filters </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 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;
// b2 = -1 * alpha;
// a0 = 1 + alpha;
// a1 = -2*cos(w0);
// a2 = 1 - alpha;
//Notch:
b0 = 1;
b1 = -2*cos(w0);
b2 = 1;
a0 = 1 + alpha;
a1 = -2*cos(w0);
a2 = 1 - alpha;
//LPF:
// b0 = (1 - cos(w0))/2;
// b1 = 1 - cos(w0);
// b2 = (1 - cos(w0))/2;
// a0 = 1 + alpha;
// a1 = -2*cos(w0);
// a2 = 1 - alpha;
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>
<!--
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">
// 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);
}
}
// window.onbeforeunload = function () {
// alert('unload');
// }
</script>
</head>
<body>
<h1> Sequencing Example </h1>
<p>
</p>
</body></html>
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -44,6 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
var audio = new maximJs.maxiAudio();
audio.init();
//This shows how to use maximilian to build a monophonic synth
//These are the synthesiser bits
......@@ -53,27 +55,23 @@ var LFO1 = new maximJs.maxiOsc();
var LFO2 = new maximJs.maxiOsc();
var VCF = new maximJs.maxiFilter();
var ADSR = new maximJs.maxiEnv();
//This is a bunch of control signals so that we can hear something
var timer = new maximJs.maxiOsc();//this is the metronome
var currentCount,lastCount;//these values are used to check if we have a new beat this sample
//and these are some variables we can use to pass stuff around
var VCO1out,VCO2out,LFO1out,LFO2out,VCFout,ADSRout;
function setup(){
ADSR.setAttack(1000);
ADSR.setDecay(1);
ADSR.setSustain(1);
ADSR.setRelease(1000);
}
ADSR.setAttack(1000);
ADSR.setDecay(1);
ADSR.setSustain(1);
ADSR.setRelease(1000);
function play(){
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
if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound
......@@ -99,10 +97,8 @@ function play(){
var finalSound=VCFout*ADSRout;//finally we add the ADSR as an amplitude modulator
ADSR.trigger=0;
output=finalSound;
this.output=finalSound;
}
</script>
</head>
......@@ -115,4 +111,60 @@ function play(){
This shows how to use maximilian to build a monophonic synth
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
audio.init();
//This shows how to use maximilian to build a monophonic synth
//These are the synthesiser bits
var VCO1 = new maximJs.maxiOsc();
var VCO2 = new maximJs.maxiOsc();
var LFO1 = new maximJs.maxiOsc();
var LFO2 = new maximJs.maxiOsc();
var VCF = new maximJs.maxiFilter();
var ADSR = new maximJs.maxiEnv();
//This is a bunch of control signals so that we can hear something
var timer = new maximJs.maxiOsc();//this is the metronome
var currentCount,lastCount;//these values are used to check if we have a new beat this sample
//and these are some variables we can use to pass stuff around
var VCO1out,VCO2out,LFO1out,LFO2out,VCFout,ADSRout;
ADSR.setAttack(1000);
ADSR.setDecay(1);
ADSR.setSustain(1);
ADSR.setRelease(1000);
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
if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound
ADSR.trigger = 1;//trigger the envelope from the start
// console.log("tick\n");//the clock ticks
lastCount=0;//set lastCount to 0
}
//and this is where we build the synth
ADSRout=ADSR.adsr(1.0,ADSR.trigger);
LFO1out=LFO1.sinebuf(0.2);//this lfo is a sinewave at 0.2 hz
VCO1out=VCO1.pulse(55,0.6);//here's VCO1. it's a pulse wave at 55 hz, with a pulse width of 0.6
VCO2out=VCO2.pulse(110+LFO1out,0.2);//here's VCO2. it's a pulse wave at 110hz with LFO modulation on the frequency, and width of 0.2
VCFout=VCF.lores((VCO1out+VCO2out)*0.5, ADSRout*10000, 10);//now we stick the VCO's into the VCF, using the ADSR as the filter cutoff
var finalSound=VCFout*ADSRout;//finally we add the ADSR as an amplitude modulator
ADSR.trigger=0;
this.output=finalSound;
}
</pre>
</body></html>
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -44,28 +44,52 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
var audio = new maximJs.maxiAudio();
audio.init();
// change output to an array
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;
// for some reason, chrome doesn't like this example?
//These are the synthesiser bits
var VCO1 = [];
for(var i = 0; i < VCO_ArraySize; ++i){
VCO1.push(new maximJs.maxiOsc());
}
// maximTools will make it quicker to fill arrays with maxim objects
var maximTools = new maximJs.maximTools();
var VCO2 = [];
for(var i = 0; i < VCO_ArraySize; ++i){
VCO2.push(new maximJs.maxiOsc());
}
var VCO_ArraySize = 6;
//These are the synthesiser bits
var VCO1 = maximTools.ArrayOfObj(maximJs.maxiOsc, VCO_ArraySize);
var VCO2 = maximTools.ArrayOfObj(maximJs.maxiOsc, VCO_ArraySize);
var LFO1 = maximTools.ArrayOfObj(maximJs.maxiOsc, VCO_ArraySize);
var LFO2 = maximTools.ArrayOfObj(maximJs.maxiOsc, VCO_ArraySize);
var 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 = maximTools.ArrayOfObj(maximJs.maxiFilter, VCO_ArraySize);
var ADSR = maximTools.ArrayOfObj(maximJs.maxiEnv, VCO_ArraySize);
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);
......@@ -82,20 +106,16 @@ var currentCount = 0,lastCount = 0, voice = 0;//these values are used to check i
var mix;
for (var i=0;i<VCO_ArraySize;i++) {
function setup(){
for (var i=0;i<VCO_ArraySize;i++) {
ADSR[i].setAttack(0);
ADSR[i].setDecay(200);
ADSR[i].setSustain(0.2);
ADSR[i].setRelease(2000);
ADSR[i].setAttack(0);
ADSR[i].setDecay(200);
ADSR[i].setSustain(0.2);
ADSR[i].setRelease(2000);
}
OutputIsArray(true, 2);
}
function play(){
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.
......@@ -104,7 +124,7 @@ function play(){
if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound
if (voice>=6) {
if (voice>=VCO_ArraySize) {
voice=0;
}
......@@ -115,8 +135,7 @@ function play(){
}
//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.
......@@ -129,16 +148,16 @@ function play(){
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;
}
}
......@@ -156,4 +175,124 @@ function play(){
This shows how to use maximilian to build a polyphonic synth.
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var audio = new maximJs.maxiAudio();
audio.init();
// change output to an array
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
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 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);
LFO1out.push(0);
LFO2out.push(0);
VCFout.push(0);
ADSRout.push(0);
pitch.push(0);
}
//This is a bunch of control signals so that we can hear something
var timer = new maximJs.maxiOsc();//this is the metronome
var currentCount = 0,lastCount = 0, voice = 0;//these values are used to check if we have a new beat this sample
var mix;
for (var i=0;i<VCO_ArraySize;i++) {
ADSR[i].setAttack(0);
ADSR[i].setDecay(200);
ADSR[i].setSustain(0.2);
ADSR[i].setRelease(2000);
}
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.
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>=VCO_ArraySize) {
voice=0;
}
ADSR[voice].trigger=1;//trigger the envelope from the start
pitch[voice]=voice+1;
voice++;
// lastCount = 0;
}
//and this is where we build the synth
for (var i=0; i<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.
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]/VCO_ArraySize;//finally we add the ADSR as an amplitude modulator
}
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<VCO_ArraySize; i++) {
ADSR[i].trigger=0;
}
}
</pre>
</body></html>
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -43,9 +43,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
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();
......@@ -76,12 +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];
function setup(){
OutputIsArray(true, 2);
}
function play(){
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
......@@ -111,11 +108,9 @@ function play(){
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>
......@@ -127,4 +122,75 @@ function play(){
<p>
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
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();
var mod = new maximJs.maxiOsc();
var lead = new maximJs.maxiOsc();
var lead2 = new maximJs.maxiOsc();
var leadmod = new maximJs.maxiOsc();
var envelope = new maximJs.maxiEnv();
var leadenvelope = new maximJs.maxiEnv();
var filter = new maximJs.maxiFilter();
var filter2 = new maximJs.maxiFilter();
var delay = new maximJs.maxiDelayline();
var mtof = new maximJs.convert();
var bassout,leadout, delayout;//some variables to hold the data and pass it around
var trigger, trigger2, newnote = 0;//some control variables
var currentCount,lastCount,playHead=0, currentChord=0;//some other control variables
var pitch = [57,57,59,60];//the bassline for the arpeggio
var chord = [0,0,7,2,5,5,0,0];//the root chords for the arpeggio
var currentPitch,leadPitch;//the final pitch variables
//here's the lead line trigger array, followed by the pitches
var leadLineTrigger=[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var leadLinePitch=[69,67,65,64,67,66,64,62,65,64,62,57,55,60,57];
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
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.
audio.output[0]=(bassout + delayout)/2;//sum output
audio.output[1]=(bassout + delayout)/2;
}
</pre>
</body></html>
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -44,33 +44,34 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
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;
function setup(){
OutputIsArray(true, 2);
compressor.setAttack(100);
compressor.setRelease(300);
compressor.setThreshold(0.25);
compressor.setRatio(5);
audio.outputIsArray(true, 2);
loadSample('./beat2.wav', beats);
}
compressor.setAttack(100);
compressor.setRelease(300);
compressor.setThreshold(0.25);
compressor.setRatio(5);
audio.loadSample('audio/beat2.wav', beats);
function play(){
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;
}
......@@ -86,4 +87,36 @@ output[1]=out;
compressing a file in real-time
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var 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;
audio.outputIsArray(true, 2);
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));
}
this.output[0]=out;
this.output[1]=out;
}
</pre>
</body></html>
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -44,6 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
var audio = new maximJs.maxiAudio();
audio.init();
var kick = new maximJs.maxiSample();
var snare = new maximJs.maxiSample();
......@@ -57,18 +59,14 @@ var snarehit=[0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0];//This is the sequence for the sn
var hathit=[0,0,1,0, 0,0,1,0, 0,0,1,0, 0,0,1,1];//This is the sequence for the snare
var kicktrigger,snaretrigger, hattrigger;
var sampleOut;
function setup(){
// OutputIsArray(true, 2);
loadSample('./kick1.wav', kick);
loadSample('./snare1.wav', snare);
loadSample('./hat12.wav', hat);
audio.loadSample('audio/kick1.wav', kick);
audio.loadSample('audio/snare1.wav', snare);
audio.loadSample('audio/hat12.wav', hat);
}
function play(){
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
......@@ -84,33 +82,26 @@ function play(){
}
if (kicktrigger==1) {//if the sequence has a 1 in it
// console.log("K");
kick.trigger();//reset the playback position of the sample to 0 (the beginning)
}
if (snaretrigger==1) {
// console.log("S");
snare.trigger();//likewise for the snare
}
if (hattrigger==1) {
// console.log("S");
hat.trigger();//likewise for the snare
}
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;
// }
}
......@@ -126,4 +117,65 @@ function play(){
using samples to make a drum machine
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var audio = new maximJs.maxiAudio();
audio.init();
var kick = new maximJs.maxiSample();
var snare = new maximJs.maxiSample();
var hat = new maximJs.maxiSample();
var timer = new maximJs.maxiOsc();
var currentCount,lastCount,playHead = 0;
var kickhit = [1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1]; //This is the sequence for the kick
var snarehit=[0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0];//This is the sequence for the snare
var hathit=[0,0,1,0, 0,0,1,0, 0,0,1,0, 0,0,1,1];//This is the sequence for the snare
var kicktrigger,snaretrigger, hattrigger;
var sampleOut;
audio.loadSample('audio/kick1.wav', kick);
audio.loadSample('audio/snare1.wav', snare);
audio.loadSample('audio/hat12.wav', hat);
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
if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound
kicktrigger=kickhit[playHead%16];//get the value out of the array for the kick
snaretrigger=snarehit[playHead%16];//same for the snare
hattrigger=hathit[playHead%16];
playHead++;//iterate the playhead
lastCount=0;//reset the metrotest
}
if (kicktrigger==1) {//if the sequence has a 1 in it
kick.trigger();//reset the playback position of the sample to 0 (the beginning)
}
if (snaretrigger==1) {
snare.trigger();//likewise for the snare
}
if (hattrigger==1) {
hat.trigger();//likewise for the snare
}
sampleOut=hat.playOnce()*0.2+kick.playOnce()+snare.playOnce();//just play the files. No looping.
this.output=sampleOut;//left channel
kicktrigger = 0;//set trigger to 0 at the end of each sample to guarantee retriggering.
snaretrigger = 0;
hattrigger = 0;
}
</pre>
</body></html>
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -44,6 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
var audio = new maximJs.maxiAudio();
audio.init();
var sound1 = new maximJs.maxiSample();
......@@ -59,12 +61,12 @@ var sequence = [1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0]; //This is the sequence for the
var sampleTrigger = 0;
var sampleOut = 0;
function setup(){
OutputIsArray(true, 2);
loadSample('./beat2.wav', sound1);
}
function play(){
audio.outputIsArray(true, 2);
audio.loadSample('audio/kick1.wav', sound1);
audio.play = function(){
if(sound1.isReady()){
currentCount=Math.floor(timer.phasor(8));//this sets up a metronome that ticks 8 times a second
......@@ -84,8 +86,8 @@ function play(){
//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.
}
......@@ -104,4 +106,54 @@ function play(){
this tutorial explains how to use the maxiEnv
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var audio = new maximJs.maxiAudio();
audio.init();
var sound1 = new maximJs.maxiSample();
var snarePhase = new maximJs.maxiOsc();
var timer = new maximJs.maxiOsc();
var envelope = new maximJs.maxiEnv();
var currentCount = 0,lastCount = 0,playHead = 0;
var sequence = [1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0]; //This is the sequence for the kick
var sampleTrigger = 0;
var sampleOut = 0;
audio.outputIsArray(true, 2);
audio.loadSample('audio/kick1.wav', sound1);
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
}
//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); //
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>
</body></html>
......@@ -33,33 +33,55 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>
Javascript Audio Processing
Javascript Audio Processing
</title>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></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">
// create audio handler
var audio = new maximJs.maxiAudio();
// initialise audio
audio.init();
// create oscillator
var mySine = new maximJs.maxiOsc();
function play(){
output = mySine.sinewave(440);
}
audio.play = function(){
// direct value to output
this.output = mySine.sinewave(440);
}
</script>
</head>
<body>
<h1> Test Tone </h1>
<h1> Test Tone </h1>
<p id="funcs"></p>
<p>
A simple 440Hz sinewave.
</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
audio.init();
// create oscillator
var mySine = new maximJs.maxiOsc();
<p>
A simple 440Hz sinewave.
</p>
audio.play = function(){
// direct value to output
this.output = mySine.sinewave(440);
}
</pre>
</body>
</body></html>
</html>
......@@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<title>
Javascript Audio Processing
</title>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?autoload=true&amp;skin=sunburst&amp;lang=css" defer="defer"></script>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
......@@ -44,6 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<!-- Our javascript code -->
<script type="text/javascript">
var audio = new maximJs.maxiAudio();
audio.init();
var sineBank = [];
......@@ -51,11 +53,7 @@ for(var i = 0; i < 10; i++){
sineBank.push(new maximJs.maxiOsc());
}
function setup(){ //some inits
//nothing to go here this time
}
function play(){
audio.play = function(){
var wave=0;
var f0 = 100;
for(var i=0; i < 10; i++) {
......@@ -65,7 +63,7 @@ function play(){
wave = wave + thisSine;
}
wave *= 0.1;
output = wave;//simple as that!
this.output = wave;//simple as that!
}
......@@ -81,4 +79,27 @@ function play(){
using samples to make a drum machine
</p>
<pre class="prettyprint lang-js linenums:true" id="quine" style="border:4px solid #88c" >
var audio = new maximJs.maxiAudio();
audio.init();
var sineBank = [];
for(var i = 0; i < 10; i++){
sineBank.push(new maximJs.maxiOsc());
}
audio.play = function(){
var wave=0;
var f0 = 100;
for(var i=0; i < 10; i++) {
var thisSine = wave + sineBank[i].sinewave(f0 + (i * f0));
var multiplier = 1.0 / (i+1.0);
thisSine = thisSine * multiplier;
wave = wave + thisSine;
}
wave *= 0.1;
this.output = wave;//simple as that!
}
</pre>
</body></html>