tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

add-offset.js (893B)


      1 /*
      2 * @class AddOffsetProcessor
      3 * @extends AudioWorkletProcessor
      4 *
      5 * Just adds a fixed value to the input
      6 */
      7 class AddOffsetProcessor extends AudioWorkletProcessor {
      8  constructor(options) {
      9    super();
     10 
     11    this._offset = options.processorOptions.offset;
     12  }
     13 
     14  process(inputs, outputs) {
     15    // This processor assumes the node has at least 1 input and 1 output.
     16    let input = inputs[0];
     17    let output = outputs[0];
     18    let outputChannel = output[0];
     19 
     20    if (input.length > 0) {
     21      let inputChannel = input[0];
     22      for (let k = 0; k < outputChannel.length; ++k)
     23        outputChannel[k] = inputChannel[k] + this._offset;
     24    } else {
     25      // No input connected, so pretend it's silence and just fill the
     26      // output with the offset value.
     27      outputChannel.fill(this._offset);
     28    }
     29 
     30    return true;
     31  }
     32 }
     33 
     34 registerProcessor('add-offset-processor', AddOffsetProcessor);