mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 00:49:19 +02:00
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.
This commit is contained in:
@@ -15,6 +15,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#else
|
#else
|
||||||
#include <AL/al.h>
|
#include <AL/al.h>
|
||||||
#include <AL/alc.h>
|
#include <AL/alc.h>
|
||||||
|
#include <AL/alext.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace audio {
|
namespace audio {
|
||||||
|
|||||||
@@ -17,23 +17,6 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "simulation/simulation.h"
|
#include "simulation/simulation.h"
|
||||||
#include "vehicle/Train.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 {
|
namespace audio {
|
||||||
|
|
||||||
openal_renderer renderer;
|
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,
|
// 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()
|
// the actual reopen is done on the main thread in update()
|
||||||
void
|
void ALC_APIENTRY
|
||||||
openal_renderer::device_event_callback( ALCenum eventtype, ALCenum devicetype, ALCdevice */*device*/, ALCsizei /*length*/, ALCchar const */*message*/, void *userparam ) {
|
openal_renderer::device_event_callback( ALCenum eventtype, ALCenum devicetype, ALCdevice */*device*/, ALCsizei /*length*/, ALCchar const */*message*/, void *userparam ) noexcept {
|
||||||
|
|
||||||
if( userparam == nullptr ) { return; }
|
if( userparam == nullptr ) { return; }
|
||||||
if( devicetype == ALC_CAPTURE_DEVICE_SOFT ) { return; } // only care about playback output
|
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
|
// Initialize all extension function pointers
|
||||||
if (alIsExtensionPresent("AL_SOFT_deferred_updates"))
|
if (alIsExtensionPresent("AL_SOFT_deferred_updates"))
|
||||||
{
|
{
|
||||||
m_alDeferUpdatesSOFT = (void(*)())alGetProcAddress("alDeferUpdatesSOFT");
|
m_alDeferUpdatesSOFT = (LPALDEFERUPDATESSOFT)alGetProcAddress("alDeferUpdatesSOFT");
|
||||||
m_alProcessUpdatesSOFT = (void(*)())alGetProcAddress("alProcessUpdatesSOFT");
|
m_alProcessUpdatesSOFT = (LPALPROCESSUPDATESSOFT)alGetProcAddress("alProcessUpdatesSOFT");
|
||||||
}
|
}
|
||||||
if (!m_alDeferUpdatesSOFT || !m_alProcessUpdatesSOFT)
|
if (!m_alDeferUpdatesSOFT || !m_alProcessUpdatesSOFT)
|
||||||
WriteLog("sound: warning: extension AL_SOFT_deferred_updates not found");
|
WriteLog("sound: warning: extension AL_SOFT_deferred_updates not found");
|
||||||
|
|
||||||
if (alcIsExtensionPresent(m_device, "ALC_SOFT_pause_device"))
|
if (alcIsExtensionPresent(m_device, "ALC_SOFT_pause_device"))
|
||||||
{
|
{
|
||||||
m_alcDevicePauseSOFT = (void(*)(ALCdevice*))alcGetProcAddress(m_device, "alcDevicePauseSOFT");
|
m_alcDevicePauseSOFT = (LPALCDEVICEPAUSESOFT)alcGetProcAddress(m_device, "alcDevicePauseSOFT");
|
||||||
m_alcDeviceResumeSOFT = (void(*)(ALCdevice*))alcGetProcAddress(m_device, "alcDeviceResumeSOFT");
|
m_alcDeviceResumeSOFT = (LPALCDEVICERESUMESOFT)alcGetProcAddress(m_device, "alcDeviceResumeSOFT");
|
||||||
}
|
}
|
||||||
if (!m_alcDevicePauseSOFT || !m_alcDeviceResumeSOFT)
|
if (!m_alcDevicePauseSOFT || !m_alcDeviceResumeSOFT)
|
||||||
WriteLog("sound: warning: extension ALC_SOFT_pause_device not found");
|
WriteLog("sound: warning: extension ALC_SOFT_pause_device not found");
|
||||||
|
|
||||||
m_candetectdisconnect = ( alcIsExtensionPresent( m_device, "ALC_EXT_disconnect" ) == ALC_TRUE );
|
m_candetectdisconnect = ( alcIsExtensionPresent( m_device, "ALC_EXT_disconnect" ) == ALC_TRUE );
|
||||||
if( alcIsExtensionPresent( m_device, "ALC_SOFT_reopen_device" ) == 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 )
|
if( !m_alcReopenDeviceSOFT )
|
||||||
WriteLog( "sound: warning: extension ALC_SOFT_reopen_device not found; audio output device changes won't be followed" );
|
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
|
// catches both device removal and default-output changes, incl. re-plugging headphones
|
||||||
if( m_alcReopenDeviceSOFT != nullptr
|
if( m_alcReopenDeviceSOFT != nullptr
|
||||||
&& alcIsExtensionPresent( m_device, "ALC_SOFT_system_events" ) == ALC_TRUE ) {
|
&& alcIsExtensionPresent( m_device, "ALC_SOFT_system_events" ) == ALC_TRUE ) {
|
||||||
m_alcEventControlSOFT = (ALCboolean(*)(ALCsizei, ALCenum const*, ALCboolean))alcGetProcAddress( m_device, "alcEventControlSOFT" );
|
m_alcEventControlSOFT = (LPALCEVENTCONTROLSOFT)alcGetProcAddress( m_device, "alcEventControlSOFT" );
|
||||||
m_alcEventCallbackSOFT = (void(*)(alc_event_proc, void*))alcGetProcAddress( m_device, "alcEventCallbackSOFT" );
|
m_alcEventCallbackSOFT = (LPALCEVENTCALLBACKSOFT)alcGetProcAddress( m_device, "alcEventCallbackSOFT" );
|
||||||
if( m_alcEventControlSOFT != nullptr && m_alcEventCallbackSOFT != nullptr ) {
|
if( m_alcEventControlSOFT != nullptr && m_alcEventCallbackSOFT != nullptr ) {
|
||||||
m_alcEventCallbackSOFT( &openal_renderer::device_event_callback, this );
|
m_alcEventCallbackSOFT( &openal_renderer::device_event_callback, this );
|
||||||
ALCenum const events[]{ ALC_EVENT_TYPE_DEFAULT_DEVICE_CHANGED_SOFT, ALC_EVENT_TYPE_DEVICE_REMOVED_SOFT };
|
ALCenum const events[]{ ALC_EVENT_TYPE_DEFAULT_DEVICE_CHANGED_SOFT, ALC_EVENT_TYPE_DEVICE_REMOVED_SOFT };
|
||||||
|
|||||||
@@ -141,12 +141,12 @@ private:
|
|||||||
source_list m_sources;
|
source_list m_sources;
|
||||||
source_sequence m_sourcespares;
|
source_sequence m_sourcespares;
|
||||||
|
|
||||||
// Poprawione deklaracje dla OpenAL 1.25
|
// OpenAL Soft extension entry points, resolved at runtime via al(c)GetProcAddress
|
||||||
void (*m_alDeferUpdatesSOFT)(void) { nullptr };
|
LPALDEFERUPDATESSOFT m_alDeferUpdatesSOFT { nullptr };
|
||||||
void (*m_alProcessUpdatesSOFT)(void) { nullptr };
|
LPALPROCESSUPDATESSOFT m_alProcessUpdatesSOFT { nullptr };
|
||||||
void (*m_alcDevicePauseSOFT)(ALCdevice*) { nullptr };
|
LPALCDEVICEPAUSESOFT m_alcDevicePauseSOFT { nullptr };
|
||||||
void (*m_alcDeviceResumeSOFT)(ALCdevice*) { nullptr };
|
LPALCDEVICERESUMESOFT m_alcDeviceResumeSOFT { nullptr };
|
||||||
ALCboolean (*m_alcReopenDeviceSOFT)(ALCdevice*, ALCchar const*, ALCint const*) { nullptr };
|
LPALCREOPENDEVICESOFT m_alcReopenDeviceSOFT { nullptr };
|
||||||
|
|
||||||
bool m_candetectdisconnect { false };
|
bool m_candetectdisconnect { false };
|
||||||
ALCint m_contextattributes[3] { 0, 0, 0 };
|
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.
|
// 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
|
// 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.
|
// (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* );
|
LPALCEVENTCONTROLSOFT m_alcEventControlSOFT { nullptr };
|
||||||
ALCboolean (*m_alcEventControlSOFT)( ALCsizei, ALCenum const*, ALCboolean ) { nullptr };
|
LPALCEVENTCALLBACKSOFT m_alcEventCallbackSOFT { nullptr };
|
||||||
void (*m_alcEventCallbackSOFT)( alc_event_proc, void* ) { nullptr };
|
|
||||||
bool m_usedeviceevents { false };
|
bool m_usedeviceevents { false };
|
||||||
std::atomic<bool> m_outputchanged { false }; // set from the (possibly off-thread) event callback
|
std::atomic<bool> 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;
|
extern openal_renderer renderer;
|
||||||
|
|||||||
Reference in New Issue
Block a user