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

Fix playback volume of mono sounds in the lwjgl3 backend #7365

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Hangman
Copy link
Contributor

@Hangman Hangman commented Mar 13, 2024

Might fix #6784

The position of sound sources was set to (0,0,1) in 3D space, resulting in sounds not playing at full volume. This led to varying levels of audio output volume compared to other backends (stereo sounds weren't affected).

This PR sets the position to (0,0,0). In order to not break panning, I had to change the way how 2D panning works.
If pan is set to 0 (center), sound output shouldn't differ from playing an unpanned sound. This was the case with the original panning calculation and a default source position of (0,0,1).

The new panning calculation is based on this comment by kcat, the author of OpenAL Soft. If you read the comment, you'll notice a mention of a second variant in the last block. I've chosen this method because the sound output closely matches the output prior to this PR.

Visual comparison:
play(volume, pitch, pan)
The red line indicates the maximum level of output.
pr

@Frosty-J
Copy link
Contributor

Frosty-J commented Mar 13, 2024

It's different but sadly still not quite right, in terms of both amplitude and frequency response.

Three-way comparison of a mono sound in this branch, a mono sound in 1.12.1, a stereo sound in this branch - in that order:

booms.mp4

(FLAC in MP4 container due to GitHub file restrictions - player is muted by default for some reason)

The files I'm using for testing (mono version is louder than each stereo channel): boom-oggs.zip

Edit: I think we're on the right track, though. By removing where AL_DIRECT_CHANNELS_SOFT is set, or setting it to the default AL_FALSE, I can get stereo sounds to sound bad like mono ones. Unfortunately, nothing I've done has made mono sounds sound good.

@Hangman
Copy link
Contributor Author

Hangman commented Mar 13, 2024

I also notice a slight difference. But for me it's minimal, barely audible, barely visible in the waveform. The difference in your mp4 is brutal. I honestly don't know what's going on.

Well, even if it doesn't completely solve the problem for you, this PR is also a prerequisite for panning stereo sources, as stereo channels only remain separated at position (0,0,0) (if not panned). If we want to enable that in the future.

@Frosty-J
Copy link
Contributor

Stereo panning would be nice, and I think this makes mono sounds slightly better. Doesn't make them any worse, at least, so I'm not against this. I'm sure panning stereo sources works on GWT; don't see any reason why it shouldn't work for Android either since it just adjusts the volume of the left and right channels independently. iOS I'm not so sure on, but it's sorta the ugly duckling anyway and not a reason to hold desktop back. I'll repeat the experiment if you get stereo panning working, to see if that screws it up as well or if mono sources are a special case.

@crykn crykn added this to the 1.12.3 milestone Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Audio sounds muffled when using LWJGL3 backend
4 participants