From 3d6c45cd00572937825cab5411466cbae5609552 Mon Sep 17 00:00:00 2001 From: maj00r Date: Sat, 4 Jul 2026 15:33:32 +0200 Subject: [PATCH] audio: use native OpenAL Soft typedefs, drop local token fallbacks Now that ref/openal ships a current alext.h, include it and use the real LPALC*SOFT / ALCEVENTPROCTYPESOFT typedefs instead of hand-rolled function pointer types and #define'd ALC_* tokens. The event callback is marked ALC_APIENTRY + noexcept to match ALCEVENTPROCTYPESOFT. No behaviour change. --- audio/audio.h | 1 + audio/audiorenderer.cpp | 35 +++++++++-------------------------- audio/audiorenderer.h | 19 +++++++++---------- 3 files changed, 19 insertions(+), 36 deletions(-) diff --git a/audio/audio.h b/audio/audio.h index 9d6285ec..5e306d25 100644 --- a/audio/audio.h +++ b/audio/audio.h @@ -15,6 +15,7 @@ http://mozilla.org/MPL/2.0/. #else #include #include +#include #endif namespace audio { diff --git a/audio/audiorenderer.cpp b/audio/audiorenderer.cpp index d2bd83b7..81f81570 100644 --- a/audio/audiorenderer.cpp +++ b/audio/audiorenderer.cpp @@ -17,23 +17,6 @@ http://mozilla.org/MPL/2.0/. #include "simulation/simulation.h" #include "vehicle/Train.h" -// ALC_EXT_disconnect / ALC_SOFT_reopen_device tokens; the bundled AL headers ship no alext.h, -// but OpenAL Soft provides these at runtime (resolved via alcGetProcAddress). -#ifndef ALC_CONNECTED -#define ALC_CONNECTED 0x313 -#endif -// ALC_ENUMERATE_ALL_EXT token; identifies the system's current default output device -#ifndef ALC_DEFAULT_ALL_DEVICES_SPECIFIER -#define ALC_DEFAULT_ALL_DEVICES_SPECIFIER 0x1012 -#endif -// ALC_SOFT_system_events tokens (bundled headers may predate them); functions resolved at runtime -#ifndef ALC_EVENT_TYPE_DEFAULT_DEVICE_CHANGED_SOFT -#define ALC_PLAYBACK_DEVICE_SOFT 0x19D4 -#define ALC_CAPTURE_DEVICE_SOFT 0x19D5 -#define ALC_EVENT_TYPE_DEFAULT_DEVICE_CHANGED_SOFT 0x19D6 -#define ALC_EVENT_TYPE_DEVICE_REMOVED_SOFT 0x19D8 -#endif - namespace audio { openal_renderer renderer; @@ -299,8 +282,8 @@ openal_renderer::~openal_renderer() { // 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 -openal_renderer::device_event_callback( ALCenum eventtype, ALCenum devicetype, ALCdevice */*device*/, ALCsizei /*length*/, ALCchar const */*message*/, void *userparam ) { +void ALC_APIENTRY +openal_renderer::device_event_callback( ALCenum eventtype, ALCenum devicetype, ALCdevice */*device*/, ALCsizei /*length*/, ALCchar const */*message*/, void *userparam ) noexcept { if( userparam == nullptr ) { return; } if( devicetype == ALC_CAPTURE_DEVICE_SOFT ) { return; } // only care about playback output @@ -639,23 +622,23 @@ openal_renderer::init_caps() { // Initialize all extension function pointers if (alIsExtensionPresent("AL_SOFT_deferred_updates")) { - m_alDeferUpdatesSOFT = (void(*)())alGetProcAddress("alDeferUpdatesSOFT"); - m_alProcessUpdatesSOFT = (void(*)())alGetProcAddress("alProcessUpdatesSOFT"); + m_alDeferUpdatesSOFT = (LPALDEFERUPDATESSOFT)alGetProcAddress("alDeferUpdatesSOFT"); + m_alProcessUpdatesSOFT = (LPALPROCESSUPDATESSOFT)alGetProcAddress("alProcessUpdatesSOFT"); } if (!m_alDeferUpdatesSOFT || !m_alProcessUpdatesSOFT) WriteLog("sound: warning: extension AL_SOFT_deferred_updates not found"); if (alcIsExtensionPresent(m_device, "ALC_SOFT_pause_device")) { - m_alcDevicePauseSOFT = (void(*)(ALCdevice*))alcGetProcAddress(m_device, "alcDevicePauseSOFT"); - m_alcDeviceResumeSOFT = (void(*)(ALCdevice*))alcGetProcAddress(m_device, "alcDeviceResumeSOFT"); + m_alcDevicePauseSOFT = (LPALCDEVICEPAUSESOFT)alcGetProcAddress(m_device, "alcDevicePauseSOFT"); + m_alcDeviceResumeSOFT = (LPALCDEVICERESUMESOFT)alcGetProcAddress(m_device, "alcDeviceResumeSOFT"); } if (!m_alcDevicePauseSOFT || !m_alcDeviceResumeSOFT) WriteLog("sound: warning: extension ALC_SOFT_pause_device not found"); m_candetectdisconnect = ( alcIsExtensionPresent( m_device, "ALC_EXT_disconnect" ) == ALC_TRUE ); if( alcIsExtensionPresent( m_device, "ALC_SOFT_reopen_device" ) == ALC_TRUE ) - m_alcReopenDeviceSOFT = (ALCboolean(*)(ALCdevice*, ALCchar const*, ALCint const*))alcGetProcAddress( m_device, "alcReopenDeviceSOFT" ); + m_alcReopenDeviceSOFT = (LPALCREOPENDEVICESOFT)alcGetProcAddress( m_device, "alcReopenDeviceSOFT" ); if( !m_alcReopenDeviceSOFT ) WriteLog( "sound: warning: extension ALC_SOFT_reopen_device not found; audio output device changes won't be followed" ); @@ -663,8 +646,8 @@ openal_renderer::init_caps() { // catches both device removal and default-output changes, incl. re-plugging headphones if( m_alcReopenDeviceSOFT != nullptr && alcIsExtensionPresent( m_device, "ALC_SOFT_system_events" ) == ALC_TRUE ) { - m_alcEventControlSOFT = (ALCboolean(*)(ALCsizei, ALCenum const*, ALCboolean))alcGetProcAddress( m_device, "alcEventControlSOFT" ); - m_alcEventCallbackSOFT = (void(*)(alc_event_proc, void*))alcGetProcAddress( m_device, "alcEventCallbackSOFT" ); + m_alcEventControlSOFT = (LPALCEVENTCONTROLSOFT)alcGetProcAddress( m_device, "alcEventControlSOFT" ); + m_alcEventCallbackSOFT = (LPALCEVENTCALLBACKSOFT)alcGetProcAddress( m_device, "alcEventCallbackSOFT" ); if( m_alcEventControlSOFT != nullptr && m_alcEventCallbackSOFT != nullptr ) { m_alcEventCallbackSOFT( &openal_renderer::device_event_callback, this ); ALCenum const events[]{ ALC_EVENT_TYPE_DEFAULT_DEVICE_CHANGED_SOFT, ALC_EVENT_TYPE_DEVICE_REMOVED_SOFT }; diff --git a/audio/audiorenderer.h b/audio/audiorenderer.h index 22a1b5e4..ec26ec82 100644 --- a/audio/audiorenderer.h +++ b/audio/audiorenderer.h @@ -141,12 +141,12 @@ private: source_list m_sources; source_sequence m_sourcespares; - // Poprawione deklaracje dla OpenAL 1.25 - void (*m_alDeferUpdatesSOFT)(void) { nullptr }; - void (*m_alProcessUpdatesSOFT)(void) { nullptr }; - void (*m_alcDevicePauseSOFT)(ALCdevice*) { nullptr }; - void (*m_alcDeviceResumeSOFT)(ALCdevice*) { nullptr }; - ALCboolean (*m_alcReopenDeviceSOFT)(ALCdevice*, ALCchar const*, ALCint const*) { nullptr }; + // OpenAL Soft extension entry points, resolved at runtime via al(c)GetProcAddress + LPALDEFERUPDATESSOFT m_alDeferUpdatesSOFT { nullptr }; + LPALPROCESSUPDATESSOFT m_alProcessUpdatesSOFT { nullptr }; + LPALCDEVICEPAUSESOFT m_alcDevicePauseSOFT { nullptr }; + LPALCDEVICERESUMESOFT m_alcDeviceResumeSOFT { nullptr }; + LPALCREOPENDEVICESOFT m_alcReopenDeviceSOFT { nullptr }; bool m_candetectdisconnect { false }; ALCint m_contextattributes[3] { 0, 0, 0 }; @@ -155,12 +155,11 @@ private: // 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. - using alc_event_proc = void (*)( ALCenum, ALCenum, ALCdevice*, ALCsizei, ALCchar const*, void* ); - ALCboolean (*m_alcEventControlSOFT)( ALCsizei, ALCenum const*, ALCboolean ) { nullptr }; - void (*m_alcEventCallbackSOFT)( alc_event_proc, void* ) { nullptr }; + LPALCEVENTCONTROLSOFT m_alcEventControlSOFT { nullptr }; + LPALCEVENTCALLBACKSOFT m_alcEventCallbackSOFT { nullptr }; bool m_usedeviceevents { false }; std::atomic m_outputchanged { false }; // set from the (possibly off-thread) event callback - static void device_event_callback( ALCenum eventtype, ALCenum devicetype, ALCdevice *device, ALCsizei length, ALCchar const *message, void *userparam ); + static void ALC_APIENTRY device_event_callback( ALCenum eventtype, ALCenum devicetype, ALCdevice *device, ALCsizei length, ALCchar const *message, void *userparam ) noexcept; }; extern openal_renderer renderer;