Skip to content
Browse files

Remove unused timestampt from AudioletNode, and rebuild.

  • Loading branch information...
1 parent 88f22cd commit 7fd55424534345d7ff1cdaba321b75139e167fda @oampo committed Feb 10, 2012
Showing with 61 additions and 137 deletions.
  1. +58 −130 src/audiolet/Audiolet.js
  2. +3 −3 src/audiolet/Audiolet.min.js
  3. +0 −4 src/core/AudioletNode.js
View
188 src/audiolet/Audiolet.js
@@ -473,8 +473,6 @@ var AudioletNode = function(audiolet, numberOfInputs, numberOfOutputs,
if (generate) {
this.generate = generate;
}
-
- this.timestamp = null;
};
/**
@@ -565,8 +563,6 @@ AudioletNode.prototype.traverse = function(nodes) {
/**
* Call the tick function on nodes which are connected to the inputs. This
* function should not be called manually by users.
- *
- * @param {Number} timestamp A timestamp for the block of samples.
*/
AudioletNode.prototype.traverseParents = function(nodes) {
var numberOfInputs = this.inputs.length;
@@ -1103,7 +1099,19 @@ PassThroughNode.prototype.createOutputSamples = function(length) {
output.samples = input.samples;
}
else {
- output.samples = new Array(output.getNumberOfChannels());
+ // Create the correct number of output samples
+ var numberOfChannels = output.getNumberOfChannels();
+ if (output.samples.length == numberOfChannels) {
+ continue;
+ }
+ else if (output.samples.length > numberOfChannels) {
+ output.samples = output.samples.slice(0, numberOfChannels);
+ continue;
+ }
+
+ for (var j = output.samples.length; j < numberOfChannels; j++) {
+ output.samples[j] = 0;
+ }
}
}
};
@@ -1803,42 +1811,19 @@ BiquadFilter.prototype.calculateCoefficients = function(frequency) {
* @param {AudioletBuffer[]} inputBuffers Samples received from the inputs.
* @param {AudioletBuffer[]} outputBuffers Samples to be sent to the outputs.
*/
-BiquadFilter.prototype.generate = function(inputBuffers, outputBuffers) {
- var inputBuffer = inputBuffers[0];
- var outputBuffer = outputBuffers[0];
-
- if (inputBuffer.isEmpty) {
- outputBuffer.isEmpty = true;
- return;
- }
-
+BiquadFilter.prototype.generate = function() {
+ var input = this.inputs[0];
+ var output = this.outputs[0]
var xValueArray = this.xValues;
var yValueArray = this.yValues;
- var inputChannels = [];
- var outputChannels = [];
- var numberOfChannels = inputBuffer.numberOfChannels;
- for (var i = 0; i < numberOfChannels; i++) {
- inputChannels.push(inputBuffer.getChannelData(i));
- outputChannels.push(outputBuffer.getChannelData(i));
- if (i >= xValueArray.length) {
- xValueArray.push([0, 0]);
- yValueArray.push([0, 0]);
- }
- }
+ var frequency = this.frequency.getValue();
- // Local processing variables
- var frequencyParameter = this.frequency;
- var frequency, frequencyChannel;
- if (frequencyParameter.isStatic()) {
- frequency = frequencyParameter.getValue();
+ if (frequency != this.lastFrequency) {
+ // Recalculate the coefficients
+ this.calculateCoefficients(frequency);
+ this.lastFrequency = frequency;
}
- else {
- frequencyChannel = frequencyParameter.getChannel();
- }
-
-
- var lastFrequency = this.lastFrequency;
var a0 = this.a0;
var a1 = this.a1;
@@ -1847,52 +1832,34 @@ BiquadFilter.prototype.generate = function(inputBuffers, outputBuffers) {
var b1 = this.b1;
var b2 = this.b2;
- var bufferLength = outputBuffer.length;
- for (var i = 0; i < bufferLength; i++) {
- if (frequencyChannel) {
- var frequency = frequencyChannel[i];
- }
-
- if (frequency != lastFrequency) {
- // Recalculate and make the coefficients local
- this.calculateCoefficients(frequency);
- lastFrequency = frequency;
- a0 = this.a0;
- a1 = this.a1;
- a2 = this.a2;
- b0 = this.b0;
- b1 = this.b1;
- b2 = this.b2;
+ var numberOfChannels = input.samples.length;
+ for (var i = 0; i < numberOfChannels; i++) {
+ if (i >= xValueArray.length) {
+ xValueArray.push([0, 0]);
+ yValueArray.push([0, 0]);
}
- for (var j = 0; j < numberOfChannels; j++) {
- var inputChannel = inputChannels[j];
- var outputChannel = outputChannels[j];
-
- var xValues = xValueArray[j];
- var x1 = xValues[0];
- var x2 = xValues[1];
- var yValues = yValueArray[j];
- var y1 = yValues[0];
- var y2 = yValues[1];
-
- var x0 = inputChannel[i];
- var y0 = (b0 / a0) * x0 +
- (b1 / a0) * x1 +
- (b2 / a0) * x2 -
- (a1 / a0) * y1 -
- (a2 / a0) * y2;
+ var xValues = xValueArray[i];
+ var x1 = xValues[0];
+ var x2 = xValues[1];
+ var yValues = yValueArray[i];
+ var y1 = yValues[0];
+ var y2 = yValues[1];
- outputChannel[i] = y0;
+ var x0 = input.samples[i];
+ var y0 = (b0 / a0) * x0 +
+ (b1 / a0) * x1 +
+ (b2 / a0) * x2 -
+ (a1 / a0) * y1 -
+ (a2 / a0) * y2;
+ output.samples[i] = y0;
- xValues[0] = x0;
- xValues[1] = x1;
- yValues[0] = y0;
- yValues[1] = y1;
- }
+ xValues[0] = x0;
+ xValues[1] = x1;
+ yValues[0] = y0;
+ yValues[1] = y1;
}
- this.lastFrequency = lastFrequency;
};
/**
@@ -1998,84 +1965,45 @@ var Amplitude = function(audiolet, attack, release) {
this.linkNumberOfOutputChannels(0, 0);
this.followers = [];
- var sampleRate = this.audiolet.device.sampleRate;
- // attack = Math.pow(0.01, 1 / (attack * sampleRate));
this.attack = new AudioletParameter(this, 1, attack || 0.01);
-
- // release = Math.pow(0.01, 1 / (release * sampleRate));
this.release = new AudioletParameter(this, 2, release || 0.01);
};
extend(Amplitude, AudioletNode);
/**
* Process a block of samples
- *
- * @param {AudioletBuffer[]} inputBuffers Samples received from the inputs.
- * @param {AudioletBuffer[]} outputBuffers Samples to be sent to the outputs.
*/
-Amplitude.prototype.generate = function(inputBuffers, outputBuffers) {
- var inputBuffer = inputBuffers[0];
- var outputBuffer = outputBuffers[0];
-
- if (inputBuffer.isEmpty) {
- outputBuffer.isEmpty = true;
- return;
- }
+Amplitude.prototype.generate = function() {
+ var input = this.inputs[0];
+ var output = this.outputs[0];
var followers = this.followers;
var numberOfFollowers = followers.length;
var sampleRate = this.audiolet.device.sampleRate;
// Local processing variables
- var attackParameter = this.attack;
- var attack, attackChannel;
- if (attackParameter.isStatic()) {
- attack = Math.pow(0.01, 1 / (attackParameter.getValue() *
- sampleRate));
- }
- else {
- attackChannel = attackParameter.getChannel();
- }
-
- // Local processing variables
- var releaseParameter = this.release;
- var release, releaseChannel;
- if (releaseParameter.isStatic()) {
- release = Math.pow(0.01, 1 / (releaseParameter.getValue() *
- sampleRate));
- }
- else {
- releaseChannel = releaseParameter.getChannel();
- }
+ var attack = this.attack.getValue();
+ attack = Math.pow(0.01, 1 / (attack * sampleRate));
+ var release = this.release.getValue();
+ release = Math.pow(0.01, 1 / (release * sampleRate));
- var numberOfChannels = inputBuffer.numberOfChannels;
+ var numberOfChannels = input.samples.length;
for (var i = 0; i < numberOfChannels; i++) {
if (i >= numberOfFollowers) {
followers.push(0);
}
var follower = followers[i];
- var inputChannel = inputBuffer.getChannelData(i);
- var outputChannel = outputBuffer.getChannelData(i);
- var bufferLength = inputBuffer.length;
- for (var j = 0; j < bufferLength; j++) {
- var value = Math.abs(inputChannel[j]);
- if (attackChannel) {
- attack = Math.pow(0.01, 1 / (attackChannel[j] * sampleRate));
- }
- if (releaseChannel) {
- release = Math.pow(0.01, 1 / (releaseChannel[j] * sampleRate));
- }
- if (value > follower) {
- follower = attack * (follower - value) + value;
- }
- else {
- follower = release * (follower - value) + value;
- }
- outputChannel[j] = follower;
+ var value = Math.abs(input.samples[i]);
+ if (value > follower) {
+ follower = attack * (follower - value) + value;
+ }
+ else {
+ follower = release * (follower - value) + value;
}
+ output.samples[i] = follower;
followers[i] = follower;
}
};
View
6 src/audiolet/Audiolet.min.js
@@ -11,7 +11,7 @@ a.set(h)}};AudioletBuffer.prototype.add=function(b){var f=this.length;var d=b.nu
/*!
* @depends AudioletGroup.js
*/
-var AudioletDestination=function(c,b,a,d){AudioletGroup.call(this,c,1,0);this.device=new AudioletDevice(c,b,a,d);c.device=this.device;this.scheduler=new Scheduler(c);c.scheduler=this.scheduler;this.upMixer=new UpMixer(c,this.device.numberOfChannels);this.inputs[0].connect(this.scheduler);this.scheduler.connect(this.upMixer);this.upMixer.connect(this.device)};extend(AudioletDestination,AudioletGroup);AudioletDestination.prototype.toString=function(){return"Destination"};var AudioletNode=function(c,b,e,a){this.audiolet=c;this.inputs=[];for(var d=0;d<b;d++){this.inputs.push(new AudioletInput(this,d))}this.outputs=[];for(var d=0;d<e;d++){this.outputs.push(new AudioletOutput(this,d))}if(a){this.generate=a}this.timestamp=null};AudioletNode.prototype.connect=function(d,c,b){if(d instanceof AudioletGroup){d=d.inputs[b||0];b=0}var a=this.outputs[c||0];var e=d.inputs[b||0];a.connect(e);e.connect(a);this.audiolet.device.needTraverse=true};AudioletNode.prototype.disconnect=function(d,c,b){if(d instanceof AudioletGroup){d=d.inputs[b||0];b=0}var a=this.outputs[c||0];var e=d.inputs[b||0];e.disconnect(a);a.disconnect(e);this.audiolet.device.needTraverse=true};AudioletNode.prototype.setNumberOfOutputChannels=function(a,b){this.outputs[a].numberOfChannels=b};AudioletNode.prototype.linkNumberOfOutputChannels=function(b,a){this.outputs[b].linkNumberOfChannels(this.inputs[a])};AudioletNode.prototype.tick=function(){this.createInputSamples();this.createOutputSamples();this.generate()};AudioletNode.prototype.traverse=function(a){a=this.traverseParents(a);if(a.indexOf(this)==-1){a.push(this)}return a};AudioletNode.prototype.traverseParents=function(c){var a=this.inputs.length;for(var e=0;e<a;e++){var b=this.inputs[e];var f=b.connectedFrom.length;for(var d=0;d<f;d++){c=b.connectedFrom[d].node.traverse(c)}}return c};AudioletNode.prototype.generate=function(){};AudioletNode.prototype.createInputSamples=function(){var a=this.inputs.length;for(var f=0;f<a;f++){var d=this.inputs[f];if(!d.connectedFrom.length){continue}var h=0;for(var e=0;e<d.connectedFrom.length;e++){var c=d.connectedFrom[e];for(var b=0;b<c.samples.length;b++){var g=c.samples[b];if(b<h){d.samples[b]+=g}else{d.samples[b]=g;h+=1}}}if(d.samples.length>h){d.samples=d.samples.slice(0,h)}}};AudioletNode.prototype.createOutputSamples=function(){var e=this.outputs.length;for(var d=0;d<e;d++){var a=this.outputs[d];var c=a.getNumberOfChannels();if(a.samples.length==c){continue}else{if(a.samples.length>c){a.samples=a.samples.slice(0,c);continue}}for(var b=a.samples.length;b<c;b++){a.samples[b]=0}}};AudioletNode.prototype.remove=function(){var g=this.inputs.length;for(var e=0;e<g;e++){var h=this.inputs[e];var c=h.connectedFrom.length;for(var d=0;d<c;d++){var a=h.connectedFrom[d];var b=a.node;b.disconnect(this,a.index,e)}}var f=this.outputs.length;for(var e=0;e<f;e++){var b=this.outputs[e];var c=b.connectedTo.length;for(var d=0;d<c;d++){var k=b.connectedTo[d];var h=k.node;this.disconnect(h,e,k.index)}}};
+var AudioletDestination=function(c,b,a,d){AudioletGroup.call(this,c,1,0);this.device=new AudioletDevice(c,b,a,d);c.device=this.device;this.scheduler=new Scheduler(c);c.scheduler=this.scheduler;this.upMixer=new UpMixer(c,this.device.numberOfChannels);this.inputs[0].connect(this.scheduler);this.scheduler.connect(this.upMixer);this.upMixer.connect(this.device)};extend(AudioletDestination,AudioletGroup);AudioletDestination.prototype.toString=function(){return"Destination"};var AudioletNode=function(c,b,e,a){this.audiolet=c;this.inputs=[];for(var d=0;d<b;d++){this.inputs.push(new AudioletInput(this,d))}this.outputs=[];for(var d=0;d<e;d++){this.outputs.push(new AudioletOutput(this,d))}if(a){this.generate=a}};AudioletNode.prototype.connect=function(d,c,b){if(d instanceof AudioletGroup){d=d.inputs[b||0];b=0}var a=this.outputs[c||0];var e=d.inputs[b||0];a.connect(e);e.connect(a);this.audiolet.device.needTraverse=true};AudioletNode.prototype.disconnect=function(d,c,b){if(d instanceof AudioletGroup){d=d.inputs[b||0];b=0}var a=this.outputs[c||0];var e=d.inputs[b||0];e.disconnect(a);a.disconnect(e);this.audiolet.device.needTraverse=true};AudioletNode.prototype.setNumberOfOutputChannels=function(a,b){this.outputs[a].numberOfChannels=b};AudioletNode.prototype.linkNumberOfOutputChannels=function(b,a){this.outputs[b].linkNumberOfChannels(this.inputs[a])};AudioletNode.prototype.tick=function(){this.createInputSamples();this.createOutputSamples();this.generate()};AudioletNode.prototype.traverse=function(a){a=this.traverseParents(a);if(a.indexOf(this)==-1){a.push(this)}return a};AudioletNode.prototype.traverseParents=function(c){var a=this.inputs.length;for(var e=0;e<a;e++){var b=this.inputs[e];var f=b.connectedFrom.length;for(var d=0;d<f;d++){c=b.connectedFrom[d].node.traverse(c)}}return c};AudioletNode.prototype.generate=function(){};AudioletNode.prototype.createInputSamples=function(){var a=this.inputs.length;for(var f=0;f<a;f++){var d=this.inputs[f];if(!d.connectedFrom.length){continue}var h=0;for(var e=0;e<d.connectedFrom.length;e++){var c=d.connectedFrom[e];for(var b=0;b<c.samples.length;b++){var g=c.samples[b];if(b<h){d.samples[b]+=g}else{d.samples[b]=g;h+=1}}}if(d.samples.length>h){d.samples=d.samples.slice(0,h)}}};AudioletNode.prototype.createOutputSamples=function(){var e=this.outputs.length;for(var d=0;d<e;d++){var a=this.outputs[d];var c=a.getNumberOfChannels();if(a.samples.length==c){continue}else{if(a.samples.length>c){a.samples=a.samples.slice(0,c);continue}}for(var b=a.samples.length;b<c;b++){a.samples[b]=0}}};AudioletNode.prototype.remove=function(){var g=this.inputs.length;for(var e=0;e<g;e++){var h=this.inputs[e];var c=h.connectedFrom.length;for(var d=0;d<c;d++){var a=h.connectedFrom[d];var b=a.node;b.disconnect(this,a.index,e)}}var f=this.outputs.length;for(var e=0;e<f;e++){var b=this.outputs[e];var c=b.connectedTo.length;for(var d=0;d<c;d++){var k=b.connectedTo[d];var h=k.node;this.disconnect(h,e,k.index)}}};
/*!
* @depends AudioletNode.js
*/
@@ -23,7 +23,7 @@ var ParameterNode=function(a,b){AudioletNode.call(this,a,1,1);this.parameter=new
/*!
* @depends AudioletNode.js
*/
-var PassThroughNode=function(b,a,c){AudioletNode.call(this,b,a,c)};extend(PassThroughNode,AudioletNode);PassThroughNode.prototype.createOutputSamples=function(e){var f=this.outputs.length;var a=this.inputs.length;for(var d=0;d<f;d++){var c=this.outputs[d];if(d<a){var b=this.inputs[d];c.samples=b.samples}else{c.samples=new Array(c.getNumberOfChannels())}}};PassThroughNode.prototype.toString=function(){return"Pass Through Node"};var PriorityQueue=function(c,b){if(b){this.compare=b}if(c){this.heap=c;for(var a=0;a<Math.floor(this.heap.length/2);a++){this.siftUp(a)}}else{this.heap=[]}};PriorityQueue.prototype.push=function(a){this.heap.push(a);this.siftDown(0,this.heap.length-1)};PriorityQueue.prototype.pop=function(){var b,a;b=this.heap.pop();if(this.heap.length){var a=this.heap[0];this.heap[0]=b;this.siftUp(0)}else{a=b}return(a)};PriorityQueue.prototype.peek=function(){return(this.heap[0])};PriorityQueue.prototype.isEmpty=function(){return(this.heap.length==0)};PriorityQueue.prototype.siftDown=function(d,a){var b=this.heap[a];while(a>d){var e=(a-1)>>1;var c=this.heap[e];if(this.compare(b,c)){this.heap[a]=c;a=e;continue}break}this.heap[a]=b};PriorityQueue.prototype.siftUp=function(a){var e=this.heap.length;var d=a;var c=this.heap[a];var b=2*a+1;while(b<e){var f=b+1;if(f<e&&!this.compare(this.heap[b],this.heap[f])){b=f}this.heap[a]=this.heap[b];a=b;b=2*a+1}this.heap[a]=c;this.siftDown(d,a)};PriorityQueue.prototype.compare=function(d,c){return(d<c)};
+var PassThroughNode=function(b,a,c){AudioletNode.call(this,b,a,c)};extend(PassThroughNode,AudioletNode);PassThroughNode.prototype.createOutputSamples=function(g){var h=this.outputs.length;var a=this.inputs.length;for(var f=0;f<h;f++){var c=this.outputs[f];if(f<a){var b=this.inputs[f];c.samples=b.samples}else{var e=c.getNumberOfChannels();if(c.samples.length==e){continue}else{if(c.samples.length>e){c.samples=c.samples.slice(0,e);continue}}for(var d=c.samples.length;d<e;d++){c.samples[d]=0}}}};PassThroughNode.prototype.toString=function(){return"Pass Through Node"};var PriorityQueue=function(c,b){if(b){this.compare=b}if(c){this.heap=c;for(var a=0;a<Math.floor(this.heap.length/2);a++){this.siftUp(a)}}else{this.heap=[]}};PriorityQueue.prototype.push=function(a){this.heap.push(a);this.siftDown(0,this.heap.length-1)};PriorityQueue.prototype.pop=function(){var b,a;b=this.heap.pop();if(this.heap.length){var a=this.heap[0];this.heap[0]=b;this.siftUp(0)}else{a=b}return(a)};PriorityQueue.prototype.peek=function(){return(this.heap[0])};PriorityQueue.prototype.isEmpty=function(){return(this.heap.length==0)};PriorityQueue.prototype.siftDown=function(d,a){var b=this.heap[a];while(a>d){var e=(a-1)>>1;var c=this.heap[e];if(this.compare(b,c)){this.heap[a]=c;a=e;continue}break}this.heap[a]=b};PriorityQueue.prototype.siftUp=function(a){var e=this.heap.length;var d=a;var c=this.heap[a];var b=2*a+1;while(b<e){var f=b+1;if(f<e&&!this.compare(this.heap[b],this.heap[f])){b=f}this.heap[a]=this.heap[b];a=b;b=2*a+1}this.heap[a]=c;this.siftDown(d,a)};PriorityQueue.prototype.compare=function(d,c){return(d<c)};
/*!
* @depends PassThroughNode.js
*/
@@ -75,7 +75,7 @@ var AllPassFilter=function(a,b){BiquadFilter.call(this,a,b)};extend(AllPassFilte
/*!
* @depends ../core/AudioletNode.js
*/
-var Amplitude=function(c,d,a){AudioletNode.call(this,c,3,1);this.linkNumberOfOutputChannels(0,0);this.followers=[];var b=this.audiolet.device.sampleRate;this.attack=new AudioletParameter(this,1,d||0.01);this.release=new AudioletParameter(this,2,a||0.01)};extend(Amplitude,AudioletNode);Amplitude.prototype.generate=function(b,h){var p=b[0];var v=h[0];if(p.isEmpty){v.isEmpty=true;return}var d=this.followers;var e=d.length;var a=this.audiolet.device.sampleRate;var w=this.attack;var r,m;if(w.isStatic()){r=Math.pow(0.01,1/(w.getValue()*a))}else{m=w.getChannel()}var t=this.release;var u,n;if(t.isStatic()){u=Math.pow(0.01,1/(t.getValue()*a))}else{n=t.getChannel()}var c=p.numberOfChannels;for(var s=0;s<c;s++){if(s>=e){d.push(0)}var k=d[s];var f=p.getChannelData(s);var l=v.getChannelData(s);var g=p.length;for(var q=0;q<g;q++){var o=Math.abs(f[q]);if(m){r=Math.pow(0.01,1/(m[q]*a))}if(n){u=Math.pow(0.01,1/(n[q]*a))}if(o>k){k=r*(k-o)+o}else{k=u*(k-o)+o}l[q]=k}d[s]=k}};Amplitude.prototype.toString=function(){return("Amplitude")};
+var Amplitude=function(b,c,a){AudioletNode.call(this,b,3,1);this.linkNumberOfOutputChannels(0,0);this.followers=[];this.attack=new AudioletParameter(this,1,c||0.01);this.release=new AudioletParameter(this,2,a||0.01)};extend(Amplitude,AudioletNode);Amplitude.prototype.generate=function(){var h=this.inputs[0];var a=this.outputs[0];var f=this.followers;var b=f.length;var l=this.audiolet.device.sampleRate;var d=this.attack.getValue();d=Math.pow(0.01,1/(d*l));var j=this.release.getValue();j=Math.pow(0.01,1/(j*l));var g=h.samples.length;for(var c=0;c<g;c++){if(c>=b){f.push(0)}var e=f[c];var k=Math.abs(h.samples[c]);if(k>e){e=d*(e-k)+k}else{e=j*(e-k)+k}a.samples[c]=e;f[c]=e}};Amplitude.prototype.toString=function(){return("Amplitude")};
/*!
* @depends ../core/PassThroughNode.js
*/
View
4 src/core/AudioletNode.js
@@ -29,8 +29,6 @@ var AudioletNode = function(audiolet, numberOfInputs, numberOfOutputs,
if (generate) {
this.generate = generate;
}
-
- this.timestamp = null;
};
/**
@@ -121,8 +119,6 @@ AudioletNode.prototype.traverse = function(nodes) {
/**
* Call the tick function on nodes which are connected to the inputs. This
* function should not be called manually by users.
- *
- * @param {Number} timestamp A timestamp for the block of samples.
*/
AudioletNode.prototype.traverseParents = function(nodes) {
var numberOfInputs = this.inputs.length;

0 comments on commit 7fd5542

Please sign in to comment.
Something went wrong with that request. Please try again.