You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Need to provide hints to increase buffering for power consumption reasons #348
Needs EditsDecision has been made, the issue can be fixed. https://speced.github.io/spec-maintenance/about/
It's been requested that we enable a batching mechanism to let users of the API tell us to process a batch of frames at a time (rather than the lowest latency we can support on a given system), trading off higher latency for applications that would rather minimize power (e.g. a simple background-music-playback app).
I've also had people requesting something like this to me as
well.
I was thinking that it could be part of some some of Audio
Channel API [0], but that's still not specced properly
(although I remember talking to Google people about it, and
Microsoft has something similar).
In general, I'd prefer to spec this in terms of use case or
developer intent than explicitly latency.
Why is this not up to the UA? For example, the WebAudio API on iOS will already switch to a larger buffer size when the system goes into a low-power mode.
padenot:
In general, I'd prefer to spec this in terms of use case or developer intent than explicitly latency.
I agree, and this could tie into other API feature requests as well. An author could mark an AudioSession as "media playback", which would both trigger a lower buffer size, and would interrupt other media playback on the device.
It should be, ultimately, and I wouldn't want to take away the ability of a
system to up the buffer size because it decides to go into a low-power mode.
However, apps should be specifically able to say "I'm cool with having a
larger buffer size". I don't think this is just media playback, per se -
it's any less-interactive audio scenario. It's finer grained (or perhaps
just orthogonal) to the audio channel specification types.
On Mon, Aug 25, 2014 at 10:10 AM, Jer Noble [email protected]
wrote:
Why is this not up to the UA? For example, the WebAudio API on iOS will
already switch to a larger buffer size when the system goes into a
low-power mode.
padenot:
In general, I'd prefer to spec this in terms of use case or developer
intent than explicitly latency.
I agree, and this could tie into other API feature requests as well. An
author could mark an AudioSession as "media playback", which would both
trigger a lower buffer size, and would interrupt other media playback on
the device.
—
Reply to this email directly or view it on GitHub #348 (comment)
.
A UA could decide to set the hardware buffer size to 128 for "interactive" playback, to 4096 for "non-interactive", and to 44,100 for "media" playback.
A UA could decide to set the hardware buffer size to 128 for
"interactive" playback, to 4096 for "non-interactive", and
to 44,100 for "media" playback.
—
Reply to this email directly or [1]view it on GitHub.
In Gecko, we put that in the AudioContext ctor to make it clear that it can't be changed.
Is there some reason why it can't be changed? Maybe that's reasonable, but for iOS and OS X it's certainly possible to change the hardware buffer size dynamically.
We implemented a whatwg proposal where you give an audio channel (roughly corresponding to use cases, see the link to the interface in the second comment) to a context, or media element, etc, and this gets decided on construction. It is possible to change the latency while everything is running, but that's not exposed yet to the web (and in fact, AudioChannel stuff is only available to system apps, iirc, it's not really exposed to the web).
In short, the constructor for AudioContext becomes:
AudioContext AudioContext (optional float buffering = 0);
A user may choose to ask the system to process blocks of audio in batches, in order to reduce power consumption (while increasing latency). This parameter is specified as the number of seconds of desired buffering latency. This is a hint to the system about the minimum requested buffering; underlying constraints may forcer larger buffers (higher latency) than requested for system reasons. This buffer request will also be increased to the nearest larger duration that equals an integral number of 128-sample processing blocks.
There are a couple of problems with this proposal:
It is extreme overkill for the use case in question. Instead of indicating to the UA that the author would like the UA to prioritize power consumption over latency, this API requires the author to pick a specific buffer size in order to do so. The control (preferred buffer size) is two levels removed from its intended goal (power consumption, by way of increasing CPU idle periods, presumably). And setting the buffer size to a high value could conceivably be counterproductive (to power consumption) on certain UAs.
It takes a very specific parameter, which is almost always ignored. The buffering parameter will be rounded to the nearest 128 / sampleRate. It will be ignored if the hardware minimum buffer size exceeds it, or basically whenever the UA decides to. The parameter feels like an inherently broken promise.
If the UA is going to generally ignore this parameter, and if the UA knows how to best tune the buffer size (among other things) to achieve low power consumption at the expense of latency, it would be better to have the hint be something both less precise and more descriptive: e.g., "low", "medium", and "high". (To be clear, I prefer the "interactive", "non-interactive", "media" proposal, but for reasons unrelated to power use.)
I'd argue it's not overkill. It's not a binary "prioritize power over latency", it's a "here's the level of latency I'm happy with."
Happy to change the semantic there - number of blocks? And of course, the hardware can up it - the same has always been true of buffersize in ScriptProcessor.
The UA doesn't know best how to tune the buffer size without being told what level of latency a particular app is comfortable with. I think this is beyond low/medium/high. "Interactive" is different for a live audio mixer vs a DJ scratching, e.g.
I'd argue it's not overkill. It's not a binary "prioritize power over latency", it's a "here's the level of latency I'm happy with."
But that’s not the use case you’re trying to solve. You specifically brought up “power consumption” as the driving use case for this change, which is not what this API actually fixes. If you want a generic latency control mechanism, this use case doesn't justify it.
I'd argue it's not overkill. It's not a binary "prioritize power over
latency", it's a "here's the level of latency I'm happy with."
But that’s not the use case you’re trying to solve. You specifically
brought up “power consumption” as the driving use case for this change,
which is not what this API actually fixes. If you want a generic latency
control mechanism, this use case doesn't justify it.
—
Reply to this email directly or view it on GitHub #348 (comment)
.
Needs EditsDecision has been made, the issue can be fixed. https://speced.github.io/spec-maintenance/about/
Question. If the user specified "interactive" (or some other enum), what should baseLatency return? Should it be the actual latency or "interactive"? As currently spec'ed in #775, we need to return a double, but should it also support enums? A double is nice, though.
Finally, it's the time in sec. A value in msec would be more natural, but does make it different from all other time values in WebAudio.
Having baseLatency always be a double would make sense to me. Otherwise there's presumably no way of knowing what "interactive" mapped to, and if knowing baseLatency is ever useful it ought to be potentially useful in that case as well.
Agree that double would be useful even if it's best effort.
On Thu, Apr 14, 2016, 11:21 Philip Jägenstedt [email protected]
wrote:
Having baseLatency always be a double would make sense to me. Otherwise
there's presumably no way of knowing what "interactive" mapped to, and if
knowing baseLatency is ever useful it ought to be potentially useful in
that case as well.
—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub #348 (comment)
Needs EditsDecision has been made, the issue can be fixed. https://speced.github.io/spec-maintenance/about/
Activity
padenot commentedon Aug 25, 2014
I've also had people requesting something like this to me as
well.
I was thinking that it could be part of some some of Audio
Channel API [0], but that's still not specced properly
(although I remember talking to Google people about it, and
Microsoft has something similar).
In general, I'd prefer to spec this in terms of use case or
developer intent than explicitly latency.
[0]http://dxr.mozilla.org/mozilla-central/source/dom/interfaces
/html/nsIDOMHTMLMediaElement.idl#98
jernoble commentedon Aug 25, 2014
Why is this not up to the UA? For example, the WebAudio API on iOS will already switch to a larger buffer size when the system goes into a low-power mode.
padenot:
I agree, and this could tie into other API feature requests as well. An author could mark an AudioSession as "media playback", which would both trigger a lower buffer size, and would interrupt other media playback on the device.
cwilso commentedon Aug 25, 2014
It should be, ultimately, and I wouldn't want to take away the ability of a
system to up the buffer size because it decides to go into a low-power mode.
However, apps should be specifically able to say "I'm cool with having a
larger buffer size". I don't think this is just media playback, per se -
it's any less-interactive audio scenario. It's finer grained (or perhaps
just orthogonal) to the audio channel specification types.
On Mon, Aug 25, 2014 at 10:10 AM, Jer Noble [email protected]
wrote:
jernoble commentedon Aug 28, 2014
I didn't see a specific API proposal here, so here's a strawman:
A UA could decide to set the hardware buffer size to 128 for "interactive" playback, to 4096 for "non-interactive", and to 44,100 for "media" playback.
padenot commentedon Aug 28, 2014
In Gecko, we put that in the AudioContext ctor to make it clear
that it can't be changed.
On Thu, Aug 28, 2014, at 07:09 PM, Jer Noble wrote:
I didn't see a specific API proposal here, so here's a
strawman:
enum AudioContextPlaybackCategory { "interactive", "non-interactive", "m
edia"};
partial interface AudioContext {
// defaults to "interactive"
attribute AudioContextPlaybackCategory playbackCategory;
}
A UA could decide to set the hardware buffer size to 128 for
"interactive" playback, to 4096 for "non-interactive", and
to 44,100 for "media" playback.
—
Reply to this email directly or [1]view it on GitHub.
References
jernoble commentedon Aug 28, 2014
padenot:
Is there some reason why it can't be changed? Maybe that's reasonable, but for iOS and OS X it's certainly possible to change the hardware buffer size dynamically.
padenot commentedon Aug 28, 2014
Sorry, I was unclear.
We implemented a whatwg proposal where you give an audio channel (roughly corresponding to use cases, see the link to the interface in the second comment) to a context, or media element, etc, and this gets decided on construction. It is possible to change the latency while everything is running, but that's not exposed yet to the web (and in fact, AudioChannel stuff is only available to system apps, iirc, it's not really exposed to the web).
cwilso commentedon Aug 29, 2014
ROC: Sorry, the specific proposal I'd made was here: http://cwilso.github.io/web-audio-api/proposals.html#widl-AudioContext-AudioContext-AudioContext-float-buffering.
In short, the constructor for AudioContext becomes:
AudioContext AudioContext (optional float buffering = 0);
A user may choose to ask the system to process blocks of audio in batches, in order to reduce power consumption (while increasing latency). This parameter is specified as the number of seconds of desired buffering latency. This is a hint to the system about the minimum requested buffering; underlying constraints may forcer larger buffers (higher latency) than requested for system reasons. This buffer request will also be increased to the nearest larger duration that equals an integral number of 128-sample processing blocks.
jernoble commentedon Aug 29, 2014
cwilso:
There are a couple of problems with this proposal:
It is extreme overkill for the use case in question. Instead of indicating to the UA that the author would like the UA to prioritize power consumption over latency, this API requires the author to pick a specific buffer size in order to do so. The control (preferred buffer size) is two levels removed from its intended goal (power consumption, by way of increasing CPU idle periods, presumably). And setting the buffer size to a high value could conceivably be counterproductive (to power consumption) on certain UAs.
It takes a very specific parameter, which is almost always ignored. The
bufferingparameter will be rounded to the nearest 128 / sampleRate. It will be ignored if the hardware minimum buffer size exceeds it, or basically whenever the UA decides to. The parameter feels like an inherently broken promise.If the UA is going to generally ignore this parameter, and if the UA knows how to best tune the buffer size (among other things) to achieve low power consumption at the expense of latency, it would be better to have the hint be something both less precise and more descriptive: e.g., "low", "medium", and "high". (To be clear, I prefer the "interactive", "non-interactive", "media" proposal, but for reasons unrelated to power use.)
cwilso commentedon Sep 4, 2014
I'd argue it's not overkill. It's not a binary "prioritize power over latency", it's a "here's the level of latency I'm happy with."
Happy to change the semantic there - number of blocks? And of course, the hardware can up it - the same has always been true of buffersize in ScriptProcessor.
The UA doesn't know best how to tune the buffer size without being told what level of latency a particular app is comfortable with. I think this is beyond low/medium/high. "Interactive" is different for a live audio mixer vs a DJ scratching, e.g.
jernoble commentedon Sep 4, 2014
@cwilso
But that’s not the use case you’re trying to solve. You specifically brought up “power consumption” as the driving use case for this change, which is not what this API actually fixes. If you want a generic latency control mechanism, this use case doesn't justify it.
cwilso commentedon Sep 4, 2014
Sorry, I should have expanded. "I want to minimize power. Here's a level
of latency I'm willing to trade for it."
On Thu, Sep 4, 2014 at 11:11 AM, Jer Noble [email protected] wrote:
65 remaining items
mdjp commentedon Apr 7, 2016
Change processingLatency to baseLatency to avoid confusion. Otherwise accept revision to add numeric value.
hoch commentedon Apr 7, 2016
Note: this constructor option and the latency property are only valid for real-time audio context.
alvestrand commentedon Apr 11, 2016
/sub
The latency constraint (a request to getUserMedia) is already in that spec.
rtoy commentedon Apr 14, 2016
Question. If the user specified "interactive" (or some other enum), what should
baseLatencyreturn? Should it be the actual latency or "interactive"? As currently spec'ed in #775, we need to return a double, but should it also support enums? A double is nice, though.Finally, it's the time in sec. A value in msec would be more natural, but does make it different from all other time values in WebAudio.
foolip commentedon Apr 14, 2016
Having
baseLatencyalways be a double would make sense to me. Otherwise there's presumably no way of knowing what "interactive" mapped to, and if knowingbaseLatencyis ever useful it ought to be potentially useful in that case as well.tomasgunn commentedon Apr 14, 2016
Agree that double would be useful even if it's best effort.
On Thu, Apr 14, 2016, 11:21 Philip Jägenstedt [email protected]
wrote:
rtoy commentedon Apr 14, 2016
I actually like a numeric value for all cases too. I'm going to leave it as double, then.
Merge pull request #775 from rtoy/348-processing-latency
Fix WebAudio#348: Add latencyHint