Skip to content
Browse files

Update operators for single-sample ticking

  • Loading branch information...
1 parent 3e58250 commit e7620ccf13a1bdc8a0dd082f8a8469b1570bbf78 @oampo committed Feb 13, 2012
View
36 src/operators/Add.js
@@ -32,40 +32,16 @@ extend(Add, AudioletNode);
/**
* Process a block of samples
- *
- * @param {AudioletBuffer[]} inputBuffers Samples received from the inputs.
- * @param {AudioletBuffer[]} outputBuffers Samples to be sent to the outputs.
*/
-Add.prototype.generate = function(inputBuffers, outputBuffers) {
- var inputBuffer = inputBuffers[0];
- var outputBuffer = outputBuffers[0];
-
- if (inputBuffer.isEmpty) {
- outputBuffer.isEmpty = true;
- return;
- }
+Add.prototype.generate = function() {
+ var input = this.inputs[0];
+ var output = this.outputs[0];
- // Local processing variables
- var valueParameter = this.value;
- var value, valueChannel;
- if (valueParameter.isStatic()) {
- value = valueParameter.getValue();
- }
- else {
- valueChannel = valueParameter.getChannel();
- }
+ var value = this.value.getValue();
- var numberOfChannels = inputBuffer.numberOfChannels;
+ var numberOfChannels = input.samples.length;
for (var i = 0; i < numberOfChannels; i++) {
- var inputChannel = inputBuffer.getChannelData(i);
- var outputChannel = outputBuffer.getChannelData(i);
- var bufferLength = inputBuffer.length;
- for (var j = 0; j < bufferLength; j++) {
- if (valueChannel) {
- value = valueChannel[j];
- }
- outputChannel[j] = inputChannel[j] + value;
- }
+ output.samples[i] = input.samples[i] + value;
}
};
View
36 src/operators/Divide.js
@@ -32,40 +32,16 @@ extend(Divide, AudioletNode);
/**
* Process a block of samples
- *
- * @param {AudioletBuffer[]} inputBuffers Samples received from the inputs.
- * @param {AudioletBuffer[]} outputBuffers Samples to be sent to the outputs.
*/
-Divide.prototype.generate = function(inputBuffers, outputBuffers) {
- var inputBuffer = inputBuffers[0];
- var outputBuffer = outputBuffers[0];
-
- if (inputBuffer.isEmpty) {
- outputBuffer.isEmpty = true;
- return;
- }
+Divide.prototype.generate = function() {
+ var input = this.inputs[0];
+ var output = this.outputs[0];
- // Local processing variables
- var valueParameter = this.value;
- var value, valueChannel;
- if (valueParameter.isStatic()) {
- value = valueParameter.getValue();
- }
- else {
- valueChannel = valueParameter.getChannel();
- }
+ var value = this.value.getValue();
- var numberOfChannels = inputBuffer.numberOfChannels;
+ var numberOfChannels = input.samples.length;
for (var i = 0; i < numberOfChannels; i++) {
- var inputChannel = inputBuffer.getChannelData(i);
- var outputChannel = outputBuffer.getChannelData(i);
- var bufferLength = inputBuffer.length;
- for (var j = 0; j < bufferLength; j++) {
- if (valueChannel) {
- value = valueChannel[j];
- }
- outputChannel[j] = inputChannel[j] / value;
- }
+ output.samples[i] = input.samples[i] / value;
}
};
View
36 src/operators/Modulo.js
@@ -32,40 +32,16 @@ extend(Modulo, AudioletNode);
/**
* Process a block of samples
- *
- * @param {AudioletBuffer[]} inputBuffers Samples received from the inputs.
- * @param {AudioletBuffer[]} outputBuffers Samples to be sent to the outputs.
*/
-Modulo.prototype.generate = function(inputBuffers, outputBuffers) {
- var inputBuffer = inputBuffers[0];
- var outputBuffer = outputBuffers[0];
-
- if (inputBuffer.isEmpty) {
- outputBuffer.isEmpty = true;
- return;
- }
+Modulo.prototype.generate = function() {
+ var input = this.inputs[0];
+ var output = this.outputs[0];
- // Local processing variables
- var valueParameter = this.value;
- var value, valueChannel;
- if (valueParameter.isStatic()) {
- value = valueParameter.getValue();
- }
- else {
- valueChannel = valueParameter.getChannel();
- }
+ var value = this.value.getValue();
- var numberOfChannels = inputBuffer.numberOfChannels;
+ var numberOfChannels = input.samples.length;
for (var i = 0; i < numberOfChannels; i++) {
- var inputChannel = inputBuffer.getChannelData(i);
- var outputChannel = outputBuffer.getChannelData(i);
- var bufferLength = inputBuffer.length;
- for (var j = 0; j < bufferLength; j++) {
- if (valueChannel) {
- value = valueChannel[j];
- }
- outputChannel[j] = inputChannel[j] % value;
- }
+ output.samples[i] = input.samples[i] % value;
}
};
View
44 src/operators/MulAdd.js
@@ -41,47 +41,15 @@ extend(MulAdd, AudioletNode);
* @param {AudioletBuffer[]} outputBuffers Samples to be sent to the outputs.
*/
MulAdd.prototype.generate = function(inputBuffers, outputBuffers) {
- var inputBuffer = inputBuffers[0];
- var outputBuffer = outputBuffers[0];
+ var input = this.inputs[0];
+ var output = this.outputs[0];
- if (inputBuffer.isEmpty) {
- outputBuffer.isEmpty = true;
- return;
- }
-
- // Local processing variables
- var mulParameter = this.mul;
- var mul, mulChannel;
- if (mulParameter.isStatic()) {
- mul = mulParameter.getValue();
- }
- else {
- mulChannel = mulParameter.getChannel();
- }
-
- var addParameter = this.add;
- var add, addChannel;
- if (addParameter.isStatic()) {
- add = addParameter.getValue();
- }
- else {
- addChannel = addParameter.getChannel();
- }
+ var mul = this.mul.getValue();
+ var add = this.add.getValue();
- var numberOfChannels = inputBuffer.numberOfChannels;
+ var numberOfChannels = input.samples.length;
for (var i = 0; i < numberOfChannels; i++) {
- var inputChannel = inputBuffer.getChannelData(i);
- var outputChannel = outputBuffer.getChannelData(i);
- var bufferLength = inputBuffer.length;
- for (var j = 0; j < bufferLength; j++) {
- if (mulChannel) {
- mul = mulChannel[j];
- }
- if (addChannel) {
- add = addChannel[j];
- }
- outputChannel[j] = inputChannel[j] * mul + add;
- }
+ output.samples[i] = input.samples[i] * mul + add;
}
};
View
23 src/operators/Reciprocal.js
@@ -25,27 +25,14 @@ extend(Reciprocal, AudioletNode);
/**
* Process a block of samples
- *
- * @param {AudioletBuffer[]} inputBuffers Samples received from the inputs.
- * @param {AudioletBuffer[]} outputBuffers Samples to be sent to the outputs.
*/
-Reciprocal.prototype.generate = function(inputBuffers, outputBuffers) {
- var inputBuffer = inputBuffers[0];
- var outputBuffer = outputBuffers[0];
-
- if (inputBuffer.isEmpty) {
- outputBuffer.isEmpty = true;
- return;
- }
+Reciprocal.prototype.generate = function() {
+ var input = this.inputs[0];
+ var output = this.outputs[0];
- var numberOfChannels = inputBuffer.numberOfChannels;
+ var numberOfChannels = input.samples.length;
for (var i = 0; i < numberOfChannels; i++) {
- var inputChannel = inputBuffer.getChannelData(i);
- var outputChannel = outputBuffer.getChannelData(i);
- var bufferLength = inputBuffer.length;
- for (var j = 0; j < bufferLength; j++) {
- outputChannel[j] = 1 / inputChannel[j];
- }
+ output.samples[i] = 1 / input.samples[i];
}
};
View
31 src/operators/Subtract.js
@@ -37,35 +37,14 @@ extend(Subtract, AudioletNode);
* @param {AudioletBuffer[]} outputBuffers Samples to be sent to the outputs.
*/
Subtract.prototype.generate = function(inputBuffers, outputBuffers) {
- var inputBuffer = inputBuffers[0];
- var outputBuffer = outputBuffers[0];
+ var input = this.inputs[0];
+ var output = this.outputs[0];
- if (inputBuffer.isEmpty) {
- outputBuffer.isEmpty = true;
- return;
- }
-
- // Local processing variables
- var valueParameter = this.value;
- var value, valueChannel;
- if (valueParameter.isStatic()) {
- value = valueParameter.getValue();
- }
- else {
- valueChannel = valueParameter.getChannel();
- }
+ var value = this.value.getValue();
- var numberOfChannels = inputBuffer.numberOfChannels;
+ var numberOfChannels = input.samples.length;
for (var i = 0; i < numberOfChannels; i++) {
- var inputChannel = inputBuffer.getChannelData(i);
- var outputChannel = outputBuffer.getChannelData(i);
- var bufferLength = inputBuffer.length;
- for (var j = 0; j < bufferLength; j++) {
- if (valueChannel) {
- value = valueChannel[j];
- }
- outputChannel[j] = inputChannel[j] - value;
- }
+ output.samples[i] = input.samples[i] - value;
}
};
View
27 src/operators/Tanh.js
@@ -26,30 +26,17 @@ extend(Tanh, AudioletNode);
/**
* Process a block of samples
- *
- * @param {AudioletBuffer[]} inputBuffers Samples received from the inputs.
- * @param {AudioletBuffer[]} outputBuffers Samples to be sent to the outputs.
*/
Tanh.prototype.generate = function(inputBuffers, outputBuffers) {
- var inputBuffer = inputBuffers[0];
- var outputBuffer = outputBuffers[0];
-
- if (inputBuffer.isEmpty) {
- outputBuffer.isEmpty = true;
- return;
- }
+ var input = this.inputs[0];
+ var output = this.outputs[0];
- var numberOfChannels = inputBuffer.numberOfChannels;
+ var numberOfChannels = input.samples.length;
for (var i = 0; i < numberOfChannels; i++) {
- var inputChannel = inputBuffer.getChannelData(i);
- var outputChannel = outputBuffer.getChannelData(i);
- var bufferLength = inputBuffer.length;
- for (var j = 0; j < bufferLength; j++) {
- var value = inputChannel[j];
- outputChannel[j] = (Math.exp(value) - Math.exp(-value)) /
- (Math.exp(value) + Math.exp(-value));
- }
- }
+ var value = input.samples[i];
+ output.samples[i] = (Math.exp(value) - Math.exp(-value)) /
+ (Math.exp(value) + Math.exp(-value));
+ }
};
/**

0 comments on commit e7620cc

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