Skip to content

Fix audio loss when switching devices and support live audio device changes - #5314

Open
TheCrazy17 wants to merge 9 commits into
multitheftauto:masterfrom
TheCrazy17:fix/audio-hotplug
Open

Fix audio loss when switching devices and support live audio device changes#5314
TheCrazy17 wants to merge 9 commits into
multitheftauto:masterfrom
TheCrazy17:fix/audio-hotplug

Conversation

@TheCrazy17

@TheCrazy17 TheCrazy17 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

This is both a bugfix and an enhancement at the same time. For as long as I can remember, if you unplug an audio device or connect a new one, MTA would become completely silent because it only detected the audio output device once, when the game started.

Now the game detects when the current audio output or input device changes (unplugged, replugged, plugged for first time, or the OS default changes) and reacts live, no restart needed. Also adds explicit output and input device pickers to Settings > Audio, so you can pick a specific device directly instead of only following the OS default; picking one there applies immediately across all three audio paths: MTA's own BASS-based sounds (playSound, internet radio), the native GTA:SA engine (weapons, footsteps, engines, ambience, ped chatter, vehicle radio), and voice chat.

Grand Theft Auto San Andreas Screenshot 2026 09 03 - 22 16 11 36 Grand Theft Auto San Andreas Screenshot 2026 09 03 - 22 16 14 70

Motivation

Fixes #1146

I also wanted to add per-device audio settings, but I feel like that would’ve made the PR way too complicated.

Test plan

Tested manually in-game over many sessions:

  • Switched the output device repeatedly (10+ times in a row, including forcing switches under 1 second apart) and confirmed native SFX, vehicle radio, and MTA sounds all kept working indefinitely, with no silent/muted state.
  • Unplugged and replugged both output and input devices and confirmed the pickers refresh and the active device follows without a restart.
  • Confirmed an unrelated joystick or microphone hotplug no longer triggers a native audio restart (only an actual output/input device change does).

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

BASS_Init only binds to whatever was the OS default at startup, so unplugging that device leaves MTA silent until a restart; BASS_CONFIG_DEV_DEFAULT keeps it following the OS default automatically.
Adds device enumeration and BASS_ChannelSetDevice plumbing so picking a specific output device moves currently playing sounds and voice chat over immediately, instead of only affecting whatever plays next.
Listens for the same Windows device notifications as the joystick fix and rescans on a background thread, so a plugged or unplugged sound device gets picked up right away instead of stalling the game for the scan.
Mirrors the joypad device combo box, listing every enabled BASS device by name and switching to whichever one the player picks.
Lets the player pick a specific capture device in the Audio tab, keeps it in sync with the same background rescan as the output device, and shows a plain message instead of an empty list when nothing is plugged in.
EAXDirectSoundCreate8 always got a null device GUID, so the native engine only ever opened on whatever Windows considered default; hooking that call to substitute a real device GUID lets it honor the same pick as the output device combo, taking effect the next time the audio hardware initialises.
Exposes CAEAudioHardware::Terminate/Initialise so the native engine can be torn down and rebuilt on demand, then wires that into both the output device picker and the hotplug detector; a disconnected preferred device now falls back to the system default instead of retrying a dead GUID.
Terminate()/Initialise() leaked CdStream pak handles and both worker thread handles on every switch, filling a fixed 32-slot table within a couple of tries and muting every sound bank with no crash. Switching device now only rebuilds what is actually device-dependent (the DirectSound device, the 3D listener, the channels and their two threads) instead of tearing down the whole engine each time, with the old full teardown kept as a fallback. Also makes BASS streams and the voice recorder follow the selected device correctly, and stops an unrelated joystick or microphone hotplug from restarting the native audio hardware.
@TheCrazy17 TheCrazy17 changed the title Fix/audio hotplug Switch audio devices live, without restarting the game Sep 4, 2026
@Fernando-A-Rocha

Copy link
Copy Markdown
Contributor

Nice!

How about refactoring "Voice volume"? Afaik it's the Volume of other people's voices, so it should be renamed accordingly, and there should be a setting for controlling your Microphone volume (input)?

@TheCrazy17

Copy link
Copy Markdown
Contributor Author

Nice!

How about refactoring "Voice volume"? Afaik it's the Volume of other people's voices, so it should be renamed accordingly, and there should be a setting for controlling your Microphone volume (input)?

It can be done, but I think it would be better as a separate PR. This one is already pretty long.

@TheCrazy17 TheCrazy17 changed the title Switch audio devices live, without restarting the game Fix audio loss when switching devices and support live audio device changes Sep 4, 2026
@FileEX FileEX added bugfix Solution to a bug of any kind enhancement New feature or request labels Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Solution to a bug of any kind enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change/Select Voice/Sound Device

3 participants