-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Web Audio API: RenderCapacity API #843
Comments
How are you defining "load" (as exposed in |
Audio systems, when rendering an audio stream, typically work with a synchronous audio callback (called in the spec a This callback, called continuously during the lifetime of the audio stream, returns to the system with audio samples, and then hands it off to the rest of the OS. This audio might be post-processed and is usually output on an audio output device, such as headphones or speakers. Let
The load for this render quantum is:
In a nominal scenario, the load is below 1.0: it took less time to render the audio than it takes to play it out. In an overload scenario (called under-run in the audio programming jargon), the load can be greater than 1.0. At this point, it is expected that the user will hear audio dropouts. This provokes discontinuities in the audio output and is very noticeable. Because the time it takes to render the audio is usually directly controllable by authors (for example, by deciding to reduce the quality of some parts of the audio processing graph, that are less essential than others for the application), authors would like to be able to observe this load. A real-life example that could benefit from this new API would be the excellent https://learningsynths.ableton.com/. If you open the menu by clicking the icon on the top left (on desktop), and scroll down this panel, you see that the render quality is controllable. Similarly, it's not uncommon for digital audio workstations or other professional audio software to display a load indicator in their user interface, to warn the user that there's too much processing for the system in its current configuration. In the Web Audio API spec, this is defined in the section Rendering an audio graph. |
This, compute pressure, and the worker QoS proposal seems to be all somewhat connected in terms of serving this kind of compute time guarantee needs (or lack of guarantee thereof) - would it make sense to distill some common patterns out of this for consistency? |
Sorry for the long delay. We've discussed this during our F2F, and having some level of consistency/interoperability between this proposal and compute pressure would be a better architectural direction. (Setting aside QoS and how to make that proposal consistent, as it seems much earlier stages) Some questions for you:
With all of these questions, we think the use cases are valid so no questions there. |
There is a way to estimate render capacity that works today: capture timestamps before and after processing on the audio thread. This method isn't without challenges: 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 probably be improved with more sophisticated timestamp 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 (simpler averaging than link above). class NoiseGenerator extends AudioWorkletProcessor {
constructor() {
super();
this.active = this.idle = 0;
}
process(inputs, outputs, parameters) {
const start = Date.now();
if (this.idle) {
this.idle += start;
console.log("Render capacity: " + 100 * this.active / (this.active + this.idle + 1e-10) + "%");
}
this.active -= start;
// generate some noise
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); |
Hello there! We looked at this today during a breakout. Other TAG members will comment with other components of the review, but we had some questions wrt API design. We need to better understand how this API fits in to the general use cases where it will be used. Currently, the explainer includes a snippet of code showing this in isolation, where it is modifying parameters in the abstract. What is the scope of starting and stopping this kind of monitoring for the use cases listed? Are authors expected to listen continuously or sample short periods of time (because monitoring is expensive)? If they are expected to listen continuously, then what is the purpose of the We were also unsure what the update interval does exactly. Does it essentially throttle the event so you can never get more than one event per that period? Does it set the period over which the load is aggregated? Both? Can you get multiple Lastly, as a very minor point, We were also wondering how this relates to #939 ? |
An addendum on security... We think that the general approach to managing side-channel risk is acceptable. Overall, fewer buckets would be preferable; at most 10, though preferably 5. Though surveys indicate that some number of sites would be unhappy with fewer than 10 buckets, there is an opportunity to revise the number of buckets over time based on feedback on use. Increasing the number of buckets should be feasible without affecting site compatibility. Starting with a more private default is the conservative option. Increasing resolution carries a small risk in that change events are more likely to occur more often (see API design feedback). More detail is ultimately necessary to understand the design:
|
This is somewhat in pause for now at the Audio WG level, implementors aren't exactly sure how to ship this. |
I'm requesting a TAG review of RenderCapacity API.
Generally, the Web Audio renderer’s performance is affected by the machine speed and the computational load of an audio graph. However, Web Audio API does not expose a way to monitor the computational load, and it leaves developers no options to detect glitches that are the essential part of UX in audio applications. Providing developers with a “glitch indicator” is getting more important because the scale of audio applications grows larger and more complex. (Developers have been asking for this feature since 2018.)
Further details:
We'd prefer the TAG provide feedback as (please delete all but the desired option):
💬 leave review feedback as a comment in this issue and @hoch @padenot
The text was updated successfully, but these errors were encountered: