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

Only add gain node and AudioContext when normalization enabled #6142

Merged

Conversation

gnattu
Copy link
Member

@gnattu gnattu commented Oct 1, 2024

Currently, we create a Web Audio session and connect to it regardless of the normalization status, hoping it will work. However, it turns out that some devices exhibit buggy behavior when the Web Audio session is connected to a gain node, causing distorted audio playback. This PR makes that the gain element is only created when normalization is not off. The downside is that users must manually stop the currently playing song and start a new one to apply the state change between on and off. By doing this, users experiencing bugged playback can turn off the normalization so that the playback behavior would be the same as 10.8 which should be fine.

We do need this workaround because:

  • Device and/or OS vendors are less concerned about this issue than we are, meaning it might take a long time to be fixed upstream.
  • Not all devices have the option to update to the latest software. We need to provide users with such devices a workaround so that they can at least have a normal playback, even if it means losing a feature.

Changes

  • Only create gain element when normalization is not off.

Issues

See jellyfin/jellyfin#11614, hopefully will workaround that.

@gnattu gnattu requested a review from a team as a code owner October 1, 2024 09:13
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESLint doesn't pass. Please fix all ESLint issues.

src/plugins/htmlAudioPlayer/plugin.js Outdated Show resolved Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Dmitry Lyzo <56478732+dmitrylyzo@users.noreply.github.com>
Copy link

sonarqubecloud bot commented Oct 1, 2024

@jellyfin-bot
Copy link
Collaborator

Cloudflare Pages deployment

Latest commit 24c30dc96d577610cd4650f397c995bd6b2116c7
Status ✅ Deployed!
Preview URL https://825f5573.jellyfin-web.pages.dev
Type 🔀 Preview

Copy link
Member

@ferferga ferferga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to comment this yesterday, but wanted to actually verify it, and I can confirm now that this doesn't fix the issue.

The problem start as soon as the AudioContext is connected to the media element, no other nodes are necessary. In Vue for instance, we use WebAudio for analyzing the audio waveform, but we don't apply any gain (or any other node that modifies the output), yet the error still happens.

In order to fix the underlying issue, WebAudio must be completely suspended.

@gnattu
Copy link
Member Author

gnattu commented Oct 2, 2024

But what this PR actually does is not to crate the AudioContext at all when normalization is off? So it makes me quite confused why that did not fix your problem.

@gnattu gnattu changed the title Only add gain node when normalization enabled Only add gain node and AudioContext when normalization enabled Oct 2, 2024
Copy link
Member

@ferferga ferferga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gnattu My fault: I assumed audio normalization was off by default, but actually after checking the settings it is on by default. I also just checked the PR's diff and not the entire file, thinking an audio context was attached somewhere else and that the addGainElement just added the gain node.

Actually, shall we turn off audio normalization by default? This issue affects all Android devices with Chromium-based browsers (so also the app).
Although that's probably for another PR.

@thornbill thornbill merged commit ef7642a into jellyfin:master Oct 2, 2024
12 checks passed
@gnattu gnattu deleted the only-add-node-when-enabled-normalization branch October 2, 2024 16:38
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.

5 participants