Commit fc26f9bb authored by Daniel Clarke's avatar Daniel Clarke

Replicant example working

parent 0160af9d
......@@ -415,7 +415,6 @@ double *maxiMix::ambisonic(double input,double eight[8],double x,double y,double
void maxiMix::stereo(double input,vector<double>& two,double x) {
if (x>1) x=1;
if (x<0) x=0;
// two.clear();
two[0]=input*sqrt(1.0-x);
two[1]=input*sqrt(x);
......@@ -423,7 +422,7 @@ void maxiMix::stereo(double input,vector<double>& two,double x) {
}
//quad bus
vector<double> maxiMix::quad(double input,vector<double> four, double x,double y) {
void maxiMix::quad(double input,vector<double>& four, double x,double y) {
if (x>1) x=1;
if (x<0) x=0;
if (y>1) y=1;
......@@ -432,11 +431,11 @@ vector<double> maxiMix::quad(double input,vector<double> four, double x,double y
four[1]=input*sqrt((1.0-x)*(1.0-y));
four[2]=input*sqrt(x*y);
four[3]=input*sqrt(x*(1.0-y));
return(four);
// return(four);
}
//ambisonic bus
vector<double> maxiMix::ambisonic(double input,vector<double> eight,double x,double y,double z) {
void maxiMix::ambisonic(double input,vector<double>& eight,double x,double y,double z) {
if (x>1) x=1;
if (x<0) x=0;
if (y>1) y=1;
......@@ -451,7 +450,7 @@ vector<double> maxiMix::ambisonic(double input,vector<double> eight,double x,dou
eight[5]=input*(sqrt((1.0-x)*(1.0-y))*z);
eight[6]=input*sqrt((x*y)*z);
eight[7]=input*sqrt((x*(1.0-y))*z);
return(eight);
// return(eight);
}
// --------------------------------------------------------------------------------
......
......@@ -68,7 +68,7 @@ var outputErrorLogged = false;
function process(event) {
var numChannels = event.outputBuffer.numberOfChannels;
var outputLength = event.outputBuffer.getChannelData(0).length;
console.log(numChannels);
// console.log(numChannels);
for (var i = 0; i < outputLength; ++i) {
play();
......
<!--
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">
//Bizarelly, this sounds a little bit like Kraftwerk's 'Metropolis', although it isn't. Funny that.
var sound = new Module.maxiOsc();
var bass = new Module.maxiOsc();
var timer = new Module.maxiOsc();
var mod = new Module.maxiOsc();
var lead = new Module.maxiOsc();
var lead2 = new Module.maxiOsc();
var leadmod = new Module.maxiOsc();
var envelope = new Module.maxiEnv();
var leadenvelope = new Module.maxiEnv();
var filter = new Module.maxiFilter();
var filter2 = new Module.maxiFilter();
var delay = new Module.maxiDelayline();
var mtof = new Module.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];
function setup(){
OutputIsArray(true, 2);
}
function play(){
// currentCount=timer.phasor(9);//this sets up a metronome that ticks every so often
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
// FIX!!!
leadPitch=mtof.mtof(leadLinePitch[newnote]);//get the next pitch val
newnote++;//and iterate
if (newnote>14) {
newnote=0;//make sure we don't go over the edge of the array
}
}
currentPitch=mtof.mtof(pitch[(playHead%4)]+chord[currentChord%8]);//write the frequency val into currentPitch
playHead++;//iterate the playhead
if (playHead%32==0) {//wrap every 4 bars
currentChord++;//change the chord
}
//cout << "tick\n";//the clock ticks
lastCount=0;//set lastCount to 0
}
bassout=filter2.lores(envelope.adsr(bass.saw(currentPitch*0.5)+sound.pulse(currentPitch*0.5,mod.phasor(1)),1,0.9995, 0.25, 0.9995, 1, trigger),9250,2);//new, simple ADSR.
leadout=filter.lores(leadenvelope.ar(lead2.saw(leadPitch*4)+lead.pulse(leadPitch+(leadmod.sinebuf(1.9)*1.5), 0.6), 0.00005, 0.999975, 50000, trigger2),5900,10);//leadline
delayout=(leadout+(delay.dl(leadout, 14000, 0.8)*0.5))/2;//add some delay
if(trigger!=0)trigger=0;//set the trigger to off if you want it to trigger immediately next time.
output[0]=(bassout+delayout)/2;//sum output
output[1]=(bassout+delayout)/2;
}
</script>
</head>
<body>
<h1> Sample Example </h1>
<p>
</p>
</body></html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment