summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/processors/add-offset.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/processors/add-offset.js')
-rw-r--r--testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/processors/add-offset.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/processors/add-offset.js b/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/processors/add-offset.js
new file mode 100644
index 0000000000..d05056bd84
--- /dev/null
+++ b/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/processors/add-offset.js
@@ -0,0 +1,34 @@
+/*
+ * @class AddOffsetProcessor
+ * @extends AudioWorkletProcessor
+ *
+ * Just adds a fixed value to the input
+ */
+class AddOffsetProcessor extends AudioWorkletProcessor {
+ constructor(options) {
+ super();
+
+ this._offset = options.processorOptions.offset;
+ }
+
+ process(inputs, outputs) {
+ // This processor assumes the node has at least 1 input and 1 output.
+ let input = inputs[0];
+ let output = outputs[0];
+ let outputChannel = output[0];
+
+ if (input.length > 0) {
+ let inputChannel = input[0];
+ for (let k = 0; k < outputChannel.length; ++k)
+ outputChannel[k] = inputChannel[k] + this._offset;
+ } else {
+ // No input connected, so pretend it's silence and just fill the
+ // output with the offset value.
+ outputChannel.fill(this._offset);
+ }
+
+ return true;
+ }
+}
+
+registerProcessor('add-offset-processor', AddOffsetProcessor);