fix audio device hot-plug - #3
Open
leonardo-spy wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to fix audio device hot-plug handling by wiring SDL audio-device events into the host and adding OpenAL device reconnect logic in the audio mixer loop.
Changes:
- Initialize SDL’s audio subsystem alongside the game controller subsystem so audio device add/remove events are emitted.
- Dispatch SDL audio device add/remove events to the Audio subsystem.
- Add periodic reconnect logic in
Audio(including optionalALC_SOFT_reopen_devicesupport and a manual reopen fallback).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| RecompOne.Runtime/Host/InputManager.cs | Initializes SDL audio subsystem and forwards SDL audio device hot-plug events to Audio. |
| RecompOne.Runtime/Host/Audio.cs | Adds device-change flagging and reconnect/reopen logic in the mixer loop. |
Suppressed comments (2)
RecompOne.Runtime/Host/Audio.cs:127
- IsDeviceConnected() currently returns true when _device is null (preventing retries after a failed reopen) and queries ALC_CONNECTED unconditionally. If ALC_EXT_disconnect isn't supported, the invalid enum likely leaves 'connected' at 0, causing a forced reopen every second on platforms/backends without that extension.
static bool IsDeviceConnected()
{
if (_alc == null || _device == null) return true;
int connected = 0;
_alc.GetContextProperty(_device, (GetContextInteger)AlcConnected, 1, &connected);
return connected != 0;
}
RecompOne.Runtime/Host/Audio.cs:145
- ReopenDevice() deletes the source/buffers but leaves _source and _buffers populated. If OpenDevice() fails, subsequent reopen attempts will operate on stale/deleted IDs (and with _device left null), which can lead to repeated errors and prevent recovery.
_al.DeleteSource(_source);
fixed (uint* ptr = _buffers)
_al.DeleteBuffers(NumBuffers, ptr);
if (_context != null) { _alc.DestroyContext(_context); _context = null; }
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
No description provided.