Fix audio loss when switching devices and support live audio device changes - #5314
Open
TheCrazy17 wants to merge 9 commits into
Open
Fix audio loss when switching devices and support live audio device changes#5314TheCrazy17 wants to merge 9 commits into
TheCrazy17 wants to merge 9 commits into
Conversation
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.
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)? |
Contributor
Author
It can be done, but I think it would be better as a separate PR. This one is already pretty long. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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:
Checklist