summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/processors/add-offset.js
blob: d05056bd8491d8b5f290b28910fcb657c6ac4e83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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);