16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-09-01 06:59:18 +02:00

audio: guard ALC_SOFT_system_events behind #ifdef for OpenAL < 1.24

This commit is contained in:
maj00r
2026-08-16 14:38:34 +02:00
parent 1454d150e2
commit 38fc9e3c00
2 changed files with 11 additions and 2 deletions

View File

@@ -272,7 +272,9 @@ openal_source::clear() {
openal_renderer::~openal_renderer() {
#ifdef ALC_SOFT_system_events
if( m_alcEventCallbackSOFT != nullptr ) { m_alcEventCallbackSOFT( nullptr, nullptr ); } // stop callbacks before teardown
#endif
::alcMakeContextCurrent( nullptr );
@@ -280,6 +282,7 @@ openal_renderer::~openal_renderer() {
if( m_device != nullptr ) { ::alcCloseDevice( m_device ); }
}
#ifdef ALC_SOFT_system_events
// invoked by OpenAL (possibly on an internal thread) on device events; only flags the change,
// the actual reopen is done on the main thread in update()
void ALC_APIENTRY
@@ -291,6 +294,7 @@ openal_renderer::device_event_callback( ALCenum eventtype, ALCenum devicetype, A
&& eventtype != ALC_EVENT_TYPE_DEVICE_REMOVED_SOFT ) { return; }
static_cast<openal_renderer*>( userparam )->m_outputchanged.store( true );
}
#endif
audio::buffer_handle
openal_renderer::fetch_buffer( std::string const &Filename ) {
@@ -642,6 +646,7 @@ openal_renderer::init_caps() {
if( !m_alcReopenDeviceSOFT )
WriteLog( "sound: warning: extension ALC_SOFT_reopen_device not found; audio output device changes won't be followed" );
#ifdef ALC_SOFT_system_events
// prefer event-driven output following (ALC_SOFT_system_events) over polling: it reliably
// catches both device removal and default-output changes, incl. re-plugging headphones
if( m_alcReopenDeviceSOFT != nullptr
@@ -656,6 +661,7 @@ openal_renderer::init_caps() {
WriteLog( "sound: following audio output device changes via ALC_SOFT_system_events" );
}
}
#endif
return true;
}

View File

@@ -152,14 +152,17 @@ private:
ALCint m_contextattributes[3] { 0, 0, 0 };
double m_devicechecktime { 0.0 };
bool m_usedeviceevents { false };
std::atomic<bool> m_outputchanged { false }; // set from the (possibly off-thread) event callback
#ifdef ALC_SOFT_system_events
// ALC_SOFT_system_events: event-driven following of output-device / default-output changes.
// Preferred over polling because it reliably catches both device removal and default changes
// (e.g. re-plugging headphones), which alcGetString(DEFAULT_ALL_DEVICES) does not report live.
// Requires OpenAL Soft >= 1.24; on older headers this is compiled out and we poll instead.
LPALCEVENTCONTROLSOFT m_alcEventControlSOFT { nullptr };
LPALCEVENTCALLBACKSOFT m_alcEventCallbackSOFT { nullptr };
bool m_usedeviceevents { false };
std::atomic<bool> m_outputchanged { false }; // set from the (possibly off-thread) event callback
static void ALC_APIENTRY device_event_callback( ALCenum eventtype, ALCenum devicetype, ALCdevice *device, ALCsizei length, ALCchar const *message, void *userparam ) noexcept;
#endif
};
extern openal_renderer renderer;