WebAudio / web-audio-api

The Web Audio API v1.0, developed by the W3C Audio WG
https://webaudio.github.io/web-audio-api/
Other
1.05k stars 167 forks source link

Type of input when nothing is connected to an AudioWorkletProcessor process. #2177

Closed rtoy closed 4 years ago

rtoy commented 4 years ago

Describe the issue The spec currently says when the m'th input to an AudioWorklet has no connections then inputs[m] is an empty array. Chrome implements this a bit differently and inputs[m] is a Float32Array of length 0.

My very vague memory was that this was the intent, but I'm not sure any more.

Since the input is a sequence<sequence<Float32Array>, the inputs[m] should be a sequence<Float32Array>. As spec'ed, I think we get sequence of length 0. I think it makes more sense to be a sequence<Float32Array>.

Where Is It https://webaudio.github.io/web-audio-api/#dom-audioworkletprocessor-process-inputs-outputs-parameters-inputs

rtoy commented 4 years ago

On second thought, I think an empty sequence is probably the right thing. There is no connection, so a sequence of a single Float32Array with no elements kind of indicates an input with a single channel with no elements. Might as well not create the empty Float32Array.

I guess the question is if sequence with no elements is a subtype of sequence<Float32Array>. It would seem not to be, but maybe that doesn't matter?

karlt commented 4 years ago

I assume a sequence can have zero elements, but once https://github.com/WebAudio/web-audio-api/issues/1933 is resolved, these won't be sequences anyway.

padenot commented 4 years ago

I'm using abstract terms here because we don't know yet what #1933's outcome will be.

There are three layers at play:

  1. inputs
  2. channels
  3. frames

The first layer tells you how many input there are, the second how many channels there are (length is variable depending on mixing rules), for each input (length is variable depending on the number of channels of the input), and the third one is, for now, always 128 and has the actua data.

The spec in its current form, to me, is clear, useful, and implementable, probably regardless of what we do in #1933.

A zero-length inner-most Float32Array could indicate that the input is known silent, but we haven't spec-ced this. The value for this is also clear, a stateless AudioWorkletNode that receives silence can simply return (this is a trick that is used quite a lot in Gecko's implementation of native nodes). It would be wrong if the node has nothing connected to it however.

rtoy commented 4 years ago

Yes, I think we've talked about providing a silent hint by using a 0-length Float32Array. (Or maybe a length-1 array with a value of 0?) Chrome, like Firefox, uses this a lot. I think we decided not to do this.

rtoy commented 4 years ago

Teleconf: Silent hint is for v2. Let's resolve #1933 first and revisit this then.

padenot commented 4 years ago

Closing, nothing to do now that #1933 has been agreed on. Silent hint for v2, probably as part of the BYOB-API.