30 #define OV_EXCLUDE_STATIC_CALLBACKS
32 #undef OV_EXCLUDE_STATIC_CALLBACKS
37 static void * LoadLibrary(
const char *
const &
file) {
38 return dlopen(file, RTLD_LAZY);
41 static int FreeLibrary(
void *
const &
handle) {
42 return dlclose(handle);
45 static void * GetProcAddress(
void *
const &handle,
const char *
const &
name) {
46 return dlsym(handle, name);
50 Sound_Renderer_AL::Sound_Renderer_AL()
58 m_openal32 = LoadLibrary(
"OpenAL32.dll");
60 m_openal32 = LoadLibrary(
"soft_oal.dll");
62 m_openal32 = LoadLibrary(
"libopenal.so");
64 m_openal32 = LoadLibrary(
"libopenal.so.1");
67 std::cerr <<
"Locating OpenAL32.dll/libopenal.so failed." << std::endl;
69 throw Sound_Init_Failure();
72 g_alBufferData = (alBufferData_fcn)GetProcAddress(m_openal32,
"alBufferData");
73 g_alcCloseDevice = (alcCloseDevice_fcn)GetProcAddress(m_openal32,
"alcCloseDevice");
74 g_alcCreateContext = (alcCreateContext_fcn)GetProcAddress(m_openal32,
"alcCreateContext");
75 g_alcDestroyContext = (alcDestroyContext_fcn)GetProcAddress(m_openal32,
"alcDestroyContext");
76 g_alIsExtensionPresent = (alIsExtensionPresent_fcn)GetProcAddress(m_openal32,
"alIsExtensionPresent");
77 g_alcMakeContextCurrent = (alcMakeContextCurrent_fcn)GetProcAddress(m_openal32,
"alcMakeContextCurrent");
78 g_alcOpenDevice = (alcOpenDevice_fcn)GetProcAddress(m_openal32,
"alcOpenDevice");
79 g_alDeleteBuffers = (alDeleteBuffers_fcn)GetProcAddress(m_openal32,
"alDeleteBuffers");
80 g_alDeleteSources = (alDeleteSources_fcn)GetProcAddress(m_openal32,
"alDeleteSources");
81 g_alGenBuffers = (alGenBuffers_fcn)GetProcAddress(m_openal32,
"alGenBuffers");
82 g_alGetError = (alGetError_fcn)GetProcAddress(m_openal32,
"alGetError");
83 g_alGetListenerf = (alGetListenerf_fcn)GetProcAddress(m_openal32,
"alGetListenerf");
84 g_alGetListenerfv = (alGetListenerfv_fcn)GetProcAddress(m_openal32,
"alGetListenerfv");
85 g_alGetSourcef = (alGetSourcef_fcn)GetProcAddress(m_openal32,
"alGetSourcef");
86 g_alGetSourcefv = (alGetSourcefv_fcn)GetProcAddress(m_openal32,
"alGetSourcefv");
87 g_alGetSourcei = (alGetSourcei_fcn)GetProcAddress(m_openal32,
"alGetSourcei");
88 g_alGenSources = (alGenSources_fcn)GetProcAddress(m_openal32,
"alGenSources");
89 g_alListenerf = (alListenerf_fcn)GetProcAddress(m_openal32,
"alListenerf");
90 g_alListenerfv = (alListenerfv_fcn)GetProcAddress(m_openal32,
"alListenerfv");
91 g_alSourcef = (alSourcef_fcn)GetProcAddress(m_openal32,
"alSourcef");
92 g_alSourcefv = (alSourcefv_fcn)GetProcAddress(m_openal32,
"alSourcefv");
93 g_alSourcei = (alSourcei_fcn)GetProcAddress(m_openal32,
"alSourcei");
94 g_alSourcePause = (alSourcePause_fcn)GetProcAddress(m_openal32,
"alSourcePause");
95 g_alSourcePlay = (alSourcePlay_fcn)GetProcAddress(m_openal32,
"alSourcePlay");
96 g_alSourceStop = (alSourceStop_fcn)GetProcAddress(m_openal32,
"alSourceStop");
97 g_alSourceQueueBuffers = (alSourceQueueBuffers_fcn)GetProcAddress(m_openal32,
"alSourceQueueBuffers");
98 g_alSourceUnqueueBuffers = (alSourceUnqueueBuffers_fcn)GetProcAddress(m_openal32,
"alSourceUnqueueBuffers");
99 if(!g_alBufferData || !g_alcCloseDevice || !g_alcCreateContext || !g_alcDestroyContext ||
100 !g_alIsExtensionPresent || !g_alcMakeContextCurrent || !g_alcOpenDevice || !g_alDeleteBuffers ||
101 !g_alDeleteSources || !g_alGenBuffers || !g_alGetError || !g_alGetListenerf ||
102 !g_alGetListenerfv || !g_alGetSourcef || !g_alGetSourcefv || !g_alGetSourcei ||
103 !g_alGenSources || !g_alListenerf || !g_alListenerfv || !g_alSourcef ||
104 !g_alSourcefv || !g_alSourcei || !g_alSourcePause || !g_alSourcePlay ||
105 !g_alSourceStop || !g_alSourceQueueBuffers || !g_alSourceUnqueueBuffers)
107 std::cerr <<
"Loading OpenAL32.dll/libopenal.so failed." << std::endl;
110 FreeLibrary(m_openal32);
112 throw Sound_Init_Failure();
134 g_alSourcef = (alSourcef_fcn)::
alSourcef;
136 g_alSourcei = (alSourcei_fcn)::
alSourcei;
148 FreeLibrary(m_openal32);
151 throw Sound_Init_Failure();
160 FreeLibrary(m_openal32);
163 throw Sound_Init_Failure();
172 FreeLibrary(m_openal32);
175 throw Sound_Init_Failure();
182 ALfloat listener_position[] = {0.0f, 0.0f, 0.0f};
183 ALfloat listener_velocity[] = {0.0f, 0.0f, 0.0f};
184 ALfloat listener_forward_and_up[] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
191 Sound_Renderer_AL::~Sound_Renderer_AL() {
196 FreeLibrary(m_openal32);
210 default:
return "AL_UNKNOWN_ERROR";
break;
218 return "OpenAL not initialized";
222 ALfloat listener_position[3] = {position.
x, position.
y, position.
z};
227 ALfloat listener_velocity[3] = {velocity.
i, velocity.
j, velocity.
k};
232 ALfloat listener_forward_and_up[6] = {forward.
i, forward.
j, forward.
k, up.
i, up.
j, up.
k};
241 ALfloat lfau[6] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
243 return std::make_pair(
Vector3f(lfau[0], lfau[1], lfau[2]),
Vector3f(lfau[3], lfau[4], lfau[5]));
246 void Sound_Renderer_AL::zero_handles() {
248 g_alcCloseDevice = 0;
249 g_alcCreateContext = 0;
250 g_alcDestroyContext = 0;
251 g_alIsExtensionPresent = 0;
252 g_alcMakeContextCurrent = 0;
254 g_alDeleteBuffers = 0;
255 g_alDeleteSources = 0;
258 g_alGetListenerf = 0;
259 g_alGetListenerfv = 0;
272 g_alSourceQueueBuffers = 0;
273 g_alSourceUnqueueBuffers = 0;
309 void * this_pointer_is_silent_sound = (
void *)0xDEADBEEF;
AL_API void AL_APIENTRY alSourcePlay(ALuint source)
void set_listener_position(const Point3f &position)
Set the position of the listener and BGM.
void(AL_APIENTRY * alBufferData_fcn)(ALuint bid, ALenum format, const ALvoid *data, ALsizei size, ALsizei freq)
void(AL_APIENTRY * alSourcePause_fcn)(ALuint sid)
static alListenerf_fcn alListenerf()
void(AL_APIENTRY * alSourceUnqueueBuffers_fcn)(ALuint sid, ALsizei numEntries, ALuint *bids)
AL_API void AL_APIENTRY alBufferData(ALuint buffer, ALenum format, const ALvoid *data, ALsizei size, ALsizei freq)
static alcDestroyContext_fcn alcDestroyContext()
ALboolean(AL_APIENTRY * alIsExtensionPresent_fcn)(const ALchar *extname)
ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *Device)
void(AL_APIENTRY * alListenerfv_fcn)(ALenum param, const ALfloat *values)
AL_API ALenum AL_APIENTRY alGetError(void)
ALCdevice *(ALC_APIENTRY * alcOpenDevice_fcn)(const ALCchar *devicename)
AL_API void AL_APIENTRY alGetSourcei(ALuint source, ALenum param, ALint *value)
ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
ALCboolean(ALC_APIENTRY * alcMakeContextCurrent_fcn)(ALCcontext *context)
EGLImageKHR EGLint * name
static alGetListenerfv_fcn alGetListenerfv()
ALenum(AL_APIENTRY * alGetError_fcn)(void)
void(AL_APIENTRY * alSourcei_fcn)(ALuint sid, ALenum param, ALint value)
AL_API void AL_APIENTRY alGenSources(ALsizei n, ALuint *sources)
std::pair< Vector3f, Vector3f > get_listener_forward_and_up() const
Set the orientation of the listener.
void(AL_APIENTRY * alGetSourcefv_fcn)(ALuint sid, ALenum param, ALfloat *values)
AL_API void AL_APIENTRY alListenerf(ALenum param, ALfloat value)
void(AL_APIENTRY * alGenBuffers_fcn)(ALsizei n, ALuint *buffers)
A 3D Point represented with floats.
ALCboolean(ALC_APIENTRY * alcCloseDevice_fcn)(ALCdevice *device)
void set_listener_velocity(const Vector3f &velocity)
Set the velocity of the listener and BGM for the doppler effect.
AL_API void AL_APIENTRY alSourceStop(ALuint source)
A Featureful 3-Space Vector Class.
void(AL_APIENTRY * alGetSourcei_fcn)(ALuint sid, ALenum param, ALint *value)
void(AL_APIENTRY * alSourcePlay_fcn)(ALuint sid)
AL_API void AL_APIENTRY alGetSourcefv(ALuint source, ALenum param, ALfloat *values)
void(AL_APIENTRY * alSourceStop_fcn)(ALuint sid)
static String errorString()
void(AL_APIENTRY * alListenerf_fcn)(ALenum param, ALfloat value)
AL_API void AL_APIENTRY alGetSourcef(ALuint source, ALenum param, ALfloat *value)
void(AL_APIENTRY * alDeleteBuffers_fcn)(ALsizei n, const ALuint *buffers)
AL_API void AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers)
void(ALC_APIENTRY * alcDestroyContext_fcn)(ALCcontext *context)
ALC_API ALCcontext *ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint *attrList)
ALCcontext *(ALC_APIENTRY * alcCreateContext_fcn)(ALCdevice *device, const ALCint *attrlist)
AL_API void AL_APIENTRY alSourcef(ALuint source, ALenum param, ALfloat value)
void(AL_APIENTRY * alSourceQueueBuffers_fcn)(ALuint sid, ALsizei numEntries, const ALuint *bids)
static alGetError_fcn alGetError()
AL_API ALboolean AL_APIENTRY alIsExtensionPresent(const ALchar *extname)
AL_API void AL_APIENTRY alSourceQueueBuffers(ALuint source, ALsizei nb, const ALuint *buffers)
void set_listener_gain(const float &gain)
Set the listener gain.
AL_API void AL_APIENTRY alGetListenerf(ALenum param, ALfloat *value)
void(AL_APIENTRY * alGenSources_fcn)(ALsizei n, ALuint *sources)
void(AL_APIENTRY * alDeleteSources_fcn)(ALsizei n, const ALuint *sources)
static alListenerfv_fcn alListenerfv()
AL_API void AL_APIENTRY alSourceUnqueueBuffers(ALuint source, ALsizei nb, ALuint *buffers)
static alcCloseDevice_fcn alcCloseDevice()
void(AL_APIENTRY * alGetListenerfv_fcn)(ALenum param, ALfloat *values)
AL_API void AL_APIENTRY alDeleteBuffers(ALsizei n, const ALuint *buffers)
EGLImageKHR EGLint EGLint * handle
void(AL_APIENTRY * alSourcefv_fcn)(ALuint sid, ALenum param, const ALfloat *values)
AL_API void AL_APIENTRY alSourcefv(ALuint source, ALenum param, const ALfloat *values)
ALC_API ALCdevice *ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
AL_API void AL_APIENTRY alSourcei(ALuint source, ALenum param, ALint value)
AL_API void AL_APIENTRY alListenerfv(ALenum param, const ALfloat *values)
void(AL_APIENTRY * alSourcef_fcn)(ALuint sid, ALenum param, ALfloat value)
void(AL_APIENTRY * alGetListenerf_fcn)(ALenum param, ALfloat *value)
AL_API void AL_APIENTRY alSourcePause(ALuint source)
#define AL_INVALID_OPERATION
void(AL_APIENTRY * alGetSourcef_fcn)(ALuint sid, ALenum param, ALfloat *value)
AL_API void AL_APIENTRY alGetListenerfv(ALenum param, ALfloat *values)
AL_API void AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources)
void set_listener_forward_and_up(const Vector3f &forward, const Vector3f &up)
Set the orientation of the listener.