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

DS5 speaker initialization #9661

Open
wants to merge 1 commit into
base: SDL2
Choose a base branch
from
Open

Conversation

igor725
Copy link

@igor725 igor725 commented May 1, 2024

Description

This PR makes SDL2 initialize DualSense audio output when enhanced mode is set. Initialization bits are educated guesses based on DualSense behavior. Developer now can easily write audio data to gamepad speaker using SDL_AUDIO subsystem. Probably I need to add some checks for compatible gamepads, but I don't have that information.

@icculus
Copy link
Collaborator

icculus commented May 1, 2024

This change needs a better log message than "initial commit," if you could change that. Run git commit --amend to edit the log, followed by a git push -f to replace the current commit.

Does this bit just make the gamepad speaker start reporting itself as some sort of standard USB/Bluetooth audio device? And if so, does it take some time before the OS realizes it's available?

@igor725
Copy link
Author

igor725 commented May 1, 2024

Does this bit just make the gamepad speaker start reporting itself as some sort of standard USB/Bluetooth audio device?

The operating system is already aware about the audio device, but it won't play anything without this internal initialization. When you connect gamepad to PC with USB cable, the audio device appears there automatically.

image

@igor725
Copy link
Author

igor725 commented May 1, 2024

Gamepad reports itself as 4 channel audio device. First channel seems to be unsed, the second one is for said pad speaker. The rest of channels used for HD Rumble feature.

@igor725
Copy link
Author

igor725 commented May 1, 2024

In my commit I made sure to initialize audio speaker only. If you unset any of those bits, the pad stops playing any sound again.

@igor725
Copy link
Author

igor725 commented May 1, 2024

Does this bit just make the gamepad speaker start reporting itself as some sort of standard USB/Bluetooth audio device?

The operating system is already aware about the audio device, but it won't play anything without this internal initialization. When you connect gamepad to PC with USB cable, the audio device appears there automatically.

image

This screenshot may confuse a little, but I have two gamepads connected right now, so Windows reports two audio devices.

@igor725
Copy link
Author

igor725 commented May 1, 2024

It would be nice to have a way to identify gamepad's audio sources, it will simplify speaker useage, but I haven't found any good solution to this problem yet. SDL_GameControllerGetNumAudioDevices(...), SDL_GameControllerGetAudioDeviceName(...) functions may need to be implemented, they should iterate all the audio devices that have a gamepad as a USB parent device and store them.

@slouken
Copy link
Collaborator

slouken commented May 1, 2024

Does this enable the headphone jack or is there some external speaker built into the controller?

@igor725
Copy link
Author

igor725 commented May 1, 2024

Does this enable the headphone jack or is there some external speaker built into the controller?

I think jack should be initialized by some of the audioEnableBits. I'm not sure, haven't tested it yet. But I do know there is possibility, to forward sound to both of them or to particular device (internal speaker, or headphones).

@igor725
Copy link
Author

igor725 commented May 1, 2024

But they def can't play the different audio at the same time since DualSense creates only one audio device.

@igor725
Copy link
Author

igor725 commented May 1, 2024

I have no 3.5 headphones on me, but I can connect my subwoofer and find out how gamepad's jack works, but it will take some time. And probably we should add some API to select the audio output in that case.

@igor725
Copy link
Author

igor725 commented May 1, 2024

ucAudioEnableBits values:

  • 8th bit set (0x80) - Sound forwards to 3.5 jack only
  • 7th bit set (0x40) - The same behavior as above
  • 6th bit set (0x20) - Sound forwards to internal speaker and 3.5 jack
  • The rest of them seems to be ignored, they produces the same behavior as 8th and 7th bits.
    It doesn't look like bit mask, behavior changes with one bit installed.

@igor725
Copy link
Author

igor725 commented May 1, 2024

With no bits set happens the same thing as if any bit except 6th is set, so I think they all ignored and gamepad checks only 6th bit. So it's more like:

  • 6th bit (0x20) - Forward 3.5 jack sound to internal speaker
    And.. that's all.

@igor725
Copy link
Author

igor725 commented May 1, 2024

I tried to disconnect 3.5 from my gamepad every test too, just to see if there's a bit that controls hot plug. Well, I haven't found it.

@igor725
Copy link
Author

igor725 commented May 1, 2024

Probably a bit mask after all. Installed 6th and 5th bits and sound forwards to internal speaker only now.

@igor725
Copy link
Author

igor725 commented May 1, 2024

Configuration 0b10100000 ignores jack 3.5 at all, sound forwards to internal speaker only again.

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.

None yet

3 participants