Re: [w3ctag/design-reviews] Web Audio API: RenderCapacity API (Issue #843)

There is a way to estimate render capacity that works today. To do this, capture timestamps before and after processing on the audio thread. There are a couple of challenges to overcome: timestamps can only be captured with 1ms precision (thanks Spectre) and the audio chunk rate may beat with the 1kHz timestamp clock. So aggregation/estimation requires a period of the order of 1 second to stabilise although this could possibly be improved with better designed signal processing.

See it in action: https://bungee.parabolaresearch.com/bungee-web-demo. 

There may be a further challenge with adapting processing complexity according to render capacity. Occasionally something (browser or OS) seems to detect a lightly used thread and either move it to an efficient or low-clocked core. So, paradoxically, faster render code can sometimes result in increased render capacity. This is a "denominator problem" that needs more study.

Simple sample below.
```JS
class NoiseGenerator extends AudioWorkletProcessor {
  constructor() {
    super();
    this.active = this.idle= 0;
  }

  process(inputs, outputs, parameters) {
    const start = Date.now();
    this.active -= start;
    if (this.idle) {
        this.idle += start;
        console.log("Render capacity: " + 100 * this.active / (this.active + this.idle) + "%");
    }

    // generate some noise
    const output = outputs[0];
    for (let channel = 0; channel < outputs[0].length; ++channel)
      for (let i = 0; i < outputs[0][channel].length; ++i)
        outputs[0][channel][i] = Math.random() * 2 - 1;

    const finish = Date.now();
    this.active += finish;
    this.idle -= finish;

    return true;
  }
}

registerProcessor('noise-generator', NoiseGenerator);
```

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3ctag/design-reviews/issues/843#issuecomment-1956258818
You are receiving this because you are subscribed to this thread.

Message ID: <w3ctag/design-reviews/issues/843/1956258818@github.com>

Received on Wednesday, 21 February 2024 09:44:56 UTC