Skip to content
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

Closed
rtoy opened this issue May 14, 2014 · 11 comments
Closed

WaveShaperNode oversampling latency? #322

rtoy opened this issue May 14, 2014 · 11 comments

Comments

@rtoy
Copy link
Member

rtoy commented May 14, 2014

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.

@karlt
Copy link
Contributor

karlt commented May 14, 2014

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.

@rtoy
Copy link
Member Author

rtoy commented May 15, 2014

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.

@karlt
Copy link
Contributor

karlt commented May 16, 2014

You may be right that another WaveShaperNode could be overly expensive.

@cwilso
Copy link
Contributor

cwilso commented Oct 29, 2014

Why does this oversampling cause latency?

@cwilso cwilso added this to the Web Audio Last Call 1 milestone Oct 29, 2014
@karlt
Copy link
Contributor

karlt commented Oct 29, 2014

Knowing future sample values helps the resampler interpolate. The resampler needs to wait for the future sample values.

@cwilso
Copy link
Contributor

cwilso commented Oct 29, 2014

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.

@karlt
Copy link
Contributor

karlt commented Oct 29, 2014

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.

@rtoy
Copy link
Member Author

rtoy commented Oct 30, 2014

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.

@joeberkovitz
Copy link
Contributor

F2F resolution: as per #469 and #414 capture information about WaveShaperNode's tailTime and latency being coupled to use of oversampling.

@joeberkovitz
Copy link
Contributor

Currently WaveShaperNode says there is no tail-time. We need to fix this.

@padenot
Copy link
Member

padenot commented Sep 29, 2016

This has been fixed, closing.

@padenot padenot closed this as completed Sep 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants