Skip to content

Conversation

@Fangal-Airbag
Copy link

This PR adds in support for separate Gamepad and TV SDL Devices while retaining support for mirroring the audio on both at the same time.

These audio devices can be created as follows:

// Gamepad
SDL_AudioDeviceID drcAudio = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_WIIU_GAMEPAD, 0, &desiredSpec, &obtainedSpec1, 0);

// TV
SDL_AudioDeviceID tvAudio = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_WIIU_TV, 0, &desiredSpec, &obtainedSpec2, 0);

// Both
SDL_AudioDeviceID bothAudio = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_WIIU_MIRRORED, 0, &desiredSpec, &obtainedSpec3, 0);

When setting up SDL_Audio and creating an audio device, if not specified, the audio device will default to SDL_AUDIO_DEVICE_WIIU_MIRRORED.

sorry for the second PR, had to fix some git stuff

Copy link

@GaryOderNichts GaryOderNichts left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Hmm, this code seems somewhat fragile at the moment.
Closing a single audio device will uninitialize AX, even if other devices are still running. wiiuDevices is also not updated when closing a device, causing potential issues in the frame callback.
Ideally it should be possible to close and reopen audio devices. I think separating the AX initialization from opening and closing audio devices might be a good idea.

@Fangal-Airbag
Copy link
Author

So with this commit AX will only deinitialize if its the last audio device being closed. wiiuDevices is also now updated with both the open and close device functions. AX will also not initialize if its already been initialized, this was already the case before this PR but this case should only really happen now. Let me know if I missed anything!

Copy link

@GaryOderNichts GaryOderNichts left a comment

Choose a reason for hiding this comment

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

Looks better now. There is still an issue if the first initialized device is closed before the last initialized device though.

}

static void WIIUAUDIO_CloseDevice(_THIS) {
if (AXIsInit()) {
Copy link

@GaryOderNichts GaryOderNichts Nov 26, 2025

Choose a reason for hiding this comment

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

I'd probably make AX (de-)initialization completely independent from opening and closing devices, by moving it into WIIUAUDIO_Init and the Deinitialize callback.

Comment on lines +298 to +300
SDL_AddAudioDevice(SDL_FALSE, SDL_AUDIO_DEVICE_WIIU_MIRRORED, &spec, &mirrorHandle);
SDL_AddAudioDevice(SDL_FALSE, SDL_AUDIO_DEVICE_WIIU_TV, &spec, &tvHandle);
SDL_AddAudioDevice(SDL_FALSE, SDL_AUDIO_DEVICE_WIIU_GAMEPAD, &spec, &drcHandle);
Copy link

@GaryOderNichts GaryOderNichts Nov 26, 2025

Choose a reason for hiding this comment

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

The "handles" here are supposed to be unique identifiers/pointers which can be retried using device->handle. In this case you could do something similar to the SNDIO driver, and use your device IDs here:

static void SNDIO_DetectDevices(SDL_AudioDevice **default_playback, SDL_AudioDevice **default_recording)
{
*default_playback = SDL_AddAudioDevice(false, DEFAULT_PLAYBACK_DEVNAME, NULL, (void *)0x1);
*default_recording = SDL_AddAudioDevice(true, DEFAULT_RECORDING_DEVNAME, NULL, (void *)0x2);
}

Then you can check this handle in WIIUAUDIO_OpenDevice and avoid comparing against the device name.

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