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

Improve audio latency #93

Merged
merged 3 commits into from
Jul 4, 2024
Merged

Conversation

mawe42
Copy link
Contributor

@mawe42 mawe42 commented Jul 2, 2024

This PR makes two improvements to the SnapWeb audio stream latency handling.

As the standardized-audio-context doesn't expose the outputLatency property, the first commits adds a getter that tries to fetch the AudioContext.outputLatency from the native AudioContext, if it exists. It improves the sync between SnapWeb and other (non-web) Snapcast clients dramatically.

The second commit sets the latencyHint of the AudioContext to "interactive". This not only reduces the output latency on most systems, but seems to make the output latency also more stable. On some platforms, the output latency varies over time depending on system load and other factors. Using "interactive" seems to make this a little less likely.

Tested on recent Chrome and Firefox on Linux. More tests would probably be a good idea.

mawe42 added 2 commits July 2, 2024 16:06
As standardized-audio-context doesn't export the
outputLatency property, attempt to fetch it from
the native AudioContext, if exists.

Resolves large playback differences between SnapWeb
and other SnapCast clients.
With "playback" latency, the outputLatency might vary
quite extensively on some platforms and sound servers.
Using interactive reduces the overall latency and also
seems to increase the output latency stability.
@badaix
Copy link
Owner

badaix commented Jul 3, 2024

Thanks, testing is always a problem without a QA team, most users avoid versions that are tagged as beta...
Can you please check what went wrong in the CI?

Property '_nativeAudioContext' does not exist on type 'AudioContextPatched'.

@mawe42
Copy link
Contributor Author

mawe42 commented Jul 3, 2024

The TS error should be resolved by the latest commit.

@badaix badaix merged commit c2860af into badaix:develop Jul 4, 2024
1 check passed
@badaix
Copy link
Owner

badaix commented Jul 4, 2024

Thanks

@mawe42 mawe42 deleted the improve-audio-latency branch July 4, 2024 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants