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
WaveShaperNode oversampling latency? #322
Comments
I wonder whether it would be sufficient to just mention that oversampling can introduce latency. Allowing the client to specify the latency would be requiring implementations to provide a range of resampling algorithms and implement corrections to match the latency precisely. Better I think would be to expose the latency introduced by the implementation in a readonly parameter, but I'm not sure that is necessary. A client can align signals by using a WaveShaperNode on each path. I guess the only advantage of exposing the latency would be if a client could use a more efficient means of aligning signals. |
I wasn't thinking of allowing the client to specify the latency. I was thinking of an attribute on the WaveShaperNode that specified the latency. Yes, I guess another WaveShaperNode would work, but that seems expensive. A simple delay node could provide the alignment if the latency were known. |
You may be right that another WaveShaperNode could be overly expensive. |
Why does this oversampling cause latency? |
Knowing future sample values helps the resampler interpolate. The resampler needs to wait for the future sample values. |
Ah, of course. That will only add one block of latency regardless of oversampling factor, correct? Seems like we could just mention that and not expose it. |
The latency is of the order of one block for a symmetric resampling filter, but is typically less and could be more if using a larger filter for higher quality. There is a performance/quality tradeoff. Looking at numbers in speex resampler, > 90% of bandwidth can be retained with total of up and downsampling latencies at one block or less, regardless of oversampling factor. |
In Chrome, the latency for 2x processing is one block; 4x sampling is two blocks. It looks like a 128-point sinc filter is used for upsampling. A 128-point sinc is used for downsampling, so you get a total delay of 128 for 2x processing. 4x processing does the 2x sampling twice, presumably for simplicity. Without telling the user, I think karlt's solution of two WaveShaperNodes is a good solution. An alternative would be to use an offline context to measure the latency and use that to create a delay node with the correct latency. Measuring the latency can be a bit difficult if the sampling is not using a linear phase filter. |
Currently WaveShaperNode says there is no tail-time. We need to fix this. |
This has been fixed, closing. |
The WaveShaperNode allows for oversampling by 2 or 4 using some appropriate algorithm. Depending on the algorithm used for oversampling, this can introduce some latency in the output.
Should the user be able to determine the latency that was introduced (if any)? This would be needed if you need to align some signals precisely in time.
The text was updated successfully, but these errors were encountered: