-
Notifications
You must be signed in to change notification settings - Fork 168
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
ConvolverNode's "buffer" attribute doesn't actually define the setter steps #1862
Comments
Yes, we need to define the steps. But I think it's not necessary to acquire the contents. At least Chrome and Safari basically convert the buffer into a bunch of FFTs (except for maybe the first 128 frames of the response), and doesn't refer to the original data anymore. (I'll have to check the exact details on when this conversion is done.) So, maybe it's enough to just say that the data is copied and the convolver doesn't have to acquire the contents? |
https://webaudio.github.io/web-audio-api/#acquire-the-content
Gecko doesn't have the "connected to an output node" condition. I don't know the reasoning behind this condition. It's theoretically possible to delay some of the FFT calculation work when the impulse response is long enough that FFTs of the tail are not required immediately. Gecko doesn't yet do this, but is performing the FFTs on the rendering thread (which is not so good without the mentioned optimization). Impulse responses buffers can be moderately large, but I haven't quantified the cost of a main thread copy. Perhaps an advantage of keeping the acquire-the-content for ConvolverNode would be so that, for all similar APIs, these steps are consistently "invoked when the contents of an AudioBuffer are needed by some API implementation." |
Chrome doesn't acquire the contents and, even worse, potentially modifies the given impulse response when computing the normalization factor. IIUC, acquiring the contents would mean two convolvers couldn't use the same impulse response array and would need to have separate copies. Given the size of some responses, this would be bad for low-memory mobile devices. |
The acquire the content operation is designed in a way that is not observably different from a copy-on-write implementation, and so using two ConvolverNodes with a single AudioBuffer does not require a copy. Step 4 "Attach ArrayBuffers containing copies of the data to the AudioBuffer, to be returned by the next call to getChannelData()." is not observable until getChannelData() is called and so copying of the data is not required unless and until the AudioBuffer is modified or getChannelData() makes it available to JS for modification. |
Oops. I always forget that nothing happens unless someone wants to write to the AudioBuffer. |
FWIW, I checked Chrome's code. While constructing the convolver, it computes all the required FFTs. The iniitial part of the impulse response uses a direct convolution instead of an FFT, but Chrome makes a copy of the initial part of the response. Chrome's webaudio impl is fairly careful not to allocate memory on the rendering thread, so delaying the tail FFT setup would not be good for Chrome. So, effectively, it's as if an internal copy were made. |
Teleconf: @padenot to investigate how FireFox behaves when using the same buffer for two convolvers, but the buffer is modified before being given to the second convolver. Generally, we might say the UA may acquire the contents but isn't required to. (But maybe it should behave as if it were copied. Both Chrome and Firefox basically do this by computing FFTs and not using the buffer values any more.) |
Here's a little test of the convolver and buffers, as mentioned in #1862 (comment). If you hear something, then it means that the modified With Chrome beta and Firefox nightly, I hear a tone. |
@padenot to look at writing the spec text for this to be compatible with what Chrome and Firefox do today. |
In both Firefox and Chrome, printing out All UAs are compatible here, and do the right thing and we "just" need to make the prose reflect this. |
It's fine to |
Just wanted to mention here that at the F2F when printing out the convolver buffer value (using Not sure what do to here about this. |
I don't know if we can do anything here. Having to keep the buffer set around is a bit costly for an edge case like this. |
Fixed in PR #1962 |
https://webaudio.github.io/web-audio-api/#dom-convolvernode-buffer does not clearly define the setter steps. This is bad, because the actual implementation at least in Gecko seems to do https://webaudio.github.io/web-audio-api/#acquire-the-content as part of those steps, which is obviously an observable side-effect that needs to be clearly specified.
The text was updated successfully, but these errors were encountered: