mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-17 10:18:28 +00:00
Added an example of setting PS5 controller audio routing
Closes https://github.com/libsdl-org/SDL/pull/9661
This commit is contained in:
parent
a9a51cebde
commit
8aa7910184
1 changed files with 49 additions and 4 deletions
|
@ -60,6 +60,7 @@ typedef struct
|
||||||
char *mapping;
|
char *mapping;
|
||||||
SDL_bool has_bindings;
|
SDL_bool has_bindings;
|
||||||
|
|
||||||
|
int audio_route;
|
||||||
int trigger_effect;
|
int trigger_effect;
|
||||||
} Controller;
|
} Controller;
|
||||||
|
|
||||||
|
@ -191,6 +192,44 @@ typedef struct
|
||||||
Uint8 ucLedBlue; /* 46 */
|
Uint8 ucLedBlue; /* 46 */
|
||||||
} DS5EffectsState_t;
|
} DS5EffectsState_t;
|
||||||
|
|
||||||
|
static void CyclePS5AudioRoute(Controller *device)
|
||||||
|
{
|
||||||
|
DS5EffectsState_t state;
|
||||||
|
|
||||||
|
device->audio_route = (device->audio_route + 1) % 4;
|
||||||
|
|
||||||
|
SDL_zero(state);
|
||||||
|
switch (device->audio_route) {
|
||||||
|
case 0:
|
||||||
|
/* Audio disabled */
|
||||||
|
state.ucEnableBits1 |= (0x80 | 0x20 | 0x10); /* Modify audio route and speaker / headphone volume */
|
||||||
|
state.ucSpeakerVolume = 0; /* Maximum volume */
|
||||||
|
state.ucHeadphoneVolume = 0; /* Maximum volume */
|
||||||
|
state.ucAudioEnableBits = 0x00; /* Output to headphones */
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
/* Headphones */
|
||||||
|
state.ucEnableBits1 |= (0x80 | 0x10); /* Modify audio route and headphone volume */
|
||||||
|
state.ucHeadphoneVolume = 100; /* Maximum volume */
|
||||||
|
state.ucAudioEnableBits = 0x00; /* Output to headphones */
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
/* Speaker */
|
||||||
|
state.ucEnableBits1 |= (0x80 | 0x20); /* Modify audio route and speaker volume */
|
||||||
|
state.ucSpeakerVolume = 100; /* Maximum volume */
|
||||||
|
state.ucAudioEnableBits = 0x30; /* Output to headphones */
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
/* Both */
|
||||||
|
state.ucEnableBits1 |= (0x80 | 0x20 | 0x10); /* Modify audio route and speaker / headphone volume */
|
||||||
|
state.ucSpeakerVolume = 100; /* Maximum volume */
|
||||||
|
state.ucHeadphoneVolume = 100; /* Maximum volume */
|
||||||
|
state.ucAudioEnableBits = 0x20; /* Output to both speaker and headphones */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
SDL_SendGamepadEffect(device->gamepad, &state, sizeof(state));
|
||||||
|
}
|
||||||
|
|
||||||
static void CyclePS5TriggerEffect(Controller *device)
|
static void CyclePS5TriggerEffect(Controller *device)
|
||||||
{
|
{
|
||||||
DS5EffectsState_t state;
|
DS5EffectsState_t state;
|
||||||
|
@ -1715,11 +1754,17 @@ static void loop(void *arg)
|
||||||
#endif /* VERBOSE_BUTTONS */
|
#endif /* VERBOSE_BUTTONS */
|
||||||
|
|
||||||
if (display_mode == CONTROLLER_MODE_TESTING) {
|
if (display_mode == CONTROLLER_MODE_TESTING) {
|
||||||
/* Cycle PS5 trigger effects when the microphone button is pressed */
|
|
||||||
if (event.type == SDL_EVENT_GAMEPAD_BUTTON_DOWN &&
|
if (event.type == SDL_EVENT_GAMEPAD_BUTTON_DOWN &&
|
||||||
controller && SDL_GetGamepadType(controller->gamepad) == SDL_GAMEPAD_TYPE_PS5 &&
|
controller && SDL_GetGamepadType(controller->gamepad) == SDL_GAMEPAD_TYPE_PS5) {
|
||||||
event.gbutton.button == SDL_GAMEPAD_BUTTON_MISC1) {
|
/* Cycle PS5 audio routing when the microphone button is pressed */
|
||||||
CyclePS5TriggerEffect(controller);
|
if (event.gbutton.button == SDL_GAMEPAD_BUTTON_MISC1) {
|
||||||
|
CyclePS5AudioRoute(controller);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cycle PS5 trigger effects when the triangle button is pressed */
|
||||||
|
if (event.gbutton.button == SDL_GAMEPAD_BUTTON_NORTH) {
|
||||||
|
CyclePS5TriggerEffect(controller);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue