Skip to content

Support overriding the number of channels in the AudioDriverPulseAudio buffer #105682

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

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

Conversation

goatchurchprime
Copy link
Contributor

This PR (replacing #103655 ) adds the option audio/driver/override_channels to force Godot to create up to 8 channels internally even when your output hardware has only the stereo two.

image

This feature makes it possible for godot developers without the necessary surround sound peripheral to reproduce bugs and review fixes to issues that are the result of an unanticipated number of channels, such as: #92532

It also enables game developers who do not have the hardware to test if their sound system code works okay with multiple channel surround sound.

Screenshot from 2025-03-05 20-48-05

Cons: This only works when running the PulseAudio system, though it could be extended to the other platforms one at a time.

Also, I have heard that it is theoretically possible to achieve this feature by temporarily reconfiguring PulseAudio at the operating system level. However, it's difficult and I haven't worked out how to do it in a way that doesn't mute all the sound. If someone knows the command to do it, please put it here, otherwise I believe this change is a reasonable option.

@BuzzLord
Copy link

I love the idea, but this PR seems a bit too ad hoc/hack-y. As you mention, its only for PulseAudio, and is pretty limited in its function (e.g. only applies if the PA driver is stereo to begin with). I think something similar, but in the AudioServer class would be a more robust solution. Being able to override the number of channels Godot uses, then mix and match which channels are copied to the driver. It would be driver/OS independent that way.

I'll take a crack at it this weekend, or early next week.

@goatchurchprime
Copy link
Contributor Author

Great, as long as you know what you are doing. Given how difficult it is to get consensus on the most reasoned changes to the audio system, I was trying to make this the most minimal thing possible. Once this was in, then it would be easier to make the case to extend it to other platforms.

This feature is only useful for testing, so ought to be in the Editor settings. A much more useful Project setting feature for production environments would be the opposite: Force Godot to only use Stereo Busses.

Almost all flat screen developers will have only ever tested and designed for the stereo case, and the whole Godot surround sound system will likely be (a) unknown to them, (b) untested, and (c) of no interest except as a source of bugs they can't reproduce at home. If I had my way I'd make this setting force the output only to the front two speakers no matter what the underlying configuration -- and set it true by default!

@BuzzLord
Copy link

BuzzLord commented Apr 26, 2025

Take a look at: https://github.com/BuzzLord/godot/tree/audio-server-override-channels

I think it does everything we want. It overrides the internal speaker_mode to adjust the number of channels used in the AudioServer (while leaving the audio driver channels alone), and lets you redirect any channel to any other channel.

Edit: Spoke too soon. I just noticed your use case is not working... Setting override to 7.1 on a stereo device, then redirecting an upper channel to the stereo channel. I thought I tested that. Fixed. I'll make a PR for it soon.

@goatchurchprime
Copy link
Contributor Author

Take a look at: https://github.com/BuzzLord/godot/tree/audio-server-override-channels

So you did know what you were doing! I can't see how I got it into my head that you needed to hack the individual drivers for each platform.

Can this also force surround sound back to stereo sound? I'll have to find someone with a surround sound setup who can confirm this.

A few thoughts:

When you run Godot with --verbose there is the following debug message:

print_verbose("PulseAudio: detected " + itos(pa_map.channels) + " output channels");

Maybe there should be some print_verbose("AudioServer: ...") messages reporting these configurations (overridden or not) to add additional context.

We need to help people out with the fact that Godot calls a pair of PulseAudio channels a "channel". Maybe we should call ours "stereo channels"?

I was looking forward to testing this by flipping the left-right speakers, but sadly this isn't an option.

@BuzzLord
Copy link

Can this also force surround sound back to stereo sound? I'll have to find someone with a surround sound setup who can confirm this.

Yep. I can use this to hear the different stereo volume mixing on my surround setup. It's pretty nice.

A few thoughts:

When you run Godot with --verbose there is the following debug message:

print_verbose("PulseAudio: detected " + itos(pa_map.channels) + " output channels");

Maybe there should be some print_verbose("AudioServer: ...") messages reporting these configurations (overridden or not) to add additional context.

Good idea. I'll add something to print out the config details. Also, if you haven't played with it (not sure if you built it, or just looked at the code), I made it so you can just change the settings without restarting the editor, and you can see the channels changing in the Audio tab as you change the speaker mode override.

We need to help people out with the fact that Godot calls a pair of PulseAudio channels a "channel". Maybe we should call ours "stereo channels"?

I've struggled with how to phrase things clearly with the channels. I've used "stereo channels", "channel pair", and "stereo channel pair" in the past, but wasn't confident they actually conveyed what I wanted. I think "stereo channels" is probably best, so I'll update my docs to use that.

I was looking forward to testing this by flipping the left-right speakers, but sadly this isn't an option.

Yeah, that would be kinda fun, but would take a bit more in-depth configuration and buffer indexing/management to get it working. Not too hard, but I didn't think it would be worth it (at least for now).

@goatchurchprime
Copy link
Contributor Author

Yes, I compiled and ran it. Make your pull request already, so I can kill this one off and point to it.

@BuzzLord
Copy link

BuzzLord commented May 1, 2025

Pull request made: #105934

The build checks seem to be failing due to an old dependency in the build system missing, so hopefully that gets fixed soon.

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.

3 participants