summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/processors/input-length-processor.js
blob: be485f03e8b323ff55c98697a267b77a3803af73 (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
/**
 * @class InputLengthProcessor
 * @extends AudioWorkletProcessor
 *
 * This processor class just sets the output to the length of the
 * input array for verifying that the input length changes when the
 * input is disconnected.
 */
class InputLengthProcessor extends AudioWorkletProcessor {
  constructor() {
    super();
  }

  process(inputs, outputs, parameters) {
    let input = inputs[0];
    let output = outputs[0];

    // Set output channel to the length of the input channel array.
    // If the input is unconnected, set the value to zero.
    const fillValue = input.length > 0 ? input[0].length : 0;
    output[0].fill(fillValue);

    return true;
  }
}

registerProcessor('input-length-processor', InputLengthProcessor);