16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 19:49:19 +02:00

feat: follow audio output device changes (reopen on disconnect)

OpenAL does not re-route on its own, so unplugging the active output device
(e.g. headphones) mid-game left the sim silent until restart. Poll ALC_CONNECTED
(ALC_EXT_disconnect) at ~1 Hz and, when the device is lost, reopen playback on
the current default output via alcReopenDeviceSOFT, preserving the context and
all sources. Tokens are declared locally since the bundled AL headers ship no
alext.h; the entry point is resolved at runtime, so this is a no-op (with a log
warning) on OpenAL Soft builds too old to provide ALC_SOFT_reopen_device.
This commit is contained in:
maj00r
2026-07-03 22:12:55 +02:00
parent 2ffff9193f
commit 7fd98374e9
2 changed files with 45 additions and 0 deletions

View File

@@ -176,6 +176,12 @@ private:
void (*alProcessUpdatesSOFT)() = nullptr;
void (*alcDevicePauseSOFT)(ALCdevice*) = nullptr;
void (*alcDeviceResumeSOFT)(ALCdevice*) = nullptr;
// ALC_SOFT_reopen_device: move playback to the current default output when the active
// device disappears (e.g. headphones unplugged mid-game), keeping context and sources
ALCboolean (*alcReopenDeviceSOFT)(ALCdevice*, ALCchar const*, ALCint const*) = nullptr;
bool m_candetectdisconnect{ false }; // ALC_EXT_disconnect present, ALC_CONNECTED is queryable
ALCint m_contextattributes[3]{ 0, 0, 0 }; // cached context attribs, reused when reopening the device
double m_devicechecktime{ 0.0 }; // accumulates dt to throttle the ALC_CONNECTED poll to ~1 Hz
};
extern openal_renderer renderer;