5 #include "cOpenALDeviceContext.h"
8 #include "cAudioEffects.h"
10 #if CAUDIO_EFX_ENABLED == 1
11 # ifdef CAUDIO_PLATFORM_WIN
13 # include <efx-creative.h>
15 # elif defined(CAUDIO_PLATFORM_LINUX)
16 # include <AL/alext.h>
22 cOpenALDeviceContext::cOpenALDeviceContext(IAudioManager* audioManager) : AudioManager(audioManager), Context(NULL), Device(NULL), Initialized(false)
27 cOpenALDeviceContext::~cOpenALDeviceContext()
32 bool cOpenALDeviceContext::initialize(
const char* deviceName,
int outputFrequency,
int eaxEffectSlots)
34 cAudioMutexBasicLock lock(Mutex);
40 ALint attribs[6] = { 0 };
42 unsigned int currentAttrib = 0;
43 if(outputFrequency > 0)
45 attribs[currentAttrib++] = ALC_FREQUENCY;
46 attribs[currentAttrib++] = outputFrequency;
48 #if CAUDIO_EFX_ENABLED == 1
49 if(eaxEffectSlots > 0)
51 attribs[currentAttrib++] = ALC_MAX_AUXILIARY_SENDS;
52 attribs[currentAttrib++] = eaxEffectSlots;
57 Device = alcOpenDevice(deviceName);
66 Context = alcCreateContext(Device, attribs);
71 alcCloseDevice(Device);
76 if(!alcMakeContextCurrent(Context))
80 alcDestroyContext(Context);
81 alcCloseDevice(Device);
91 #if CAUDIO_EFX_ENABLED == 1
92 initEffects.getEFXInterface()->Mutex.lock();
93 EFXSupported = initEffects.getEFXInterface()->CheckEFXSupport(Device);
94 initEffects.getEFXInterface()->Mutex.unlock();
95 initEffects.checkEFXSupportDetails();
99 int EFXMajorVersion = 0;
100 int EFXMinorVersion = 0;
101 alcGetIntegerv(Device, ALC_EFX_MAJOR_VERSION, 1, &EFXMajorVersion);
102 alcGetIntegerv(Device, ALC_EFX_MINOR_VERSION, 1, &EFXMinorVersion);
103 getLogger()->
logInfo(
"AudioManager",
"EFX Version: %i.%i", EFXMajorVersion, EFXMinorVersion);
111 getLogger()->
logWarning(
"AudioManager",
"Supported Extensions: %s", alGetString(AL_EXTENSIONS));
117 void cOpenALDeviceContext::shutDown()
121 cAudioMutexBasicLock lock(Mutex);
123 alcMakeContextCurrent(NULL);
125 alcDestroyContext(Context);
128 if (!alcCloseDevice(Device))
136 void cOpenALDeviceContext::update()
141 IAudioManager* cOpenALDeviceContext::getAudioManager()
const
146 IAudioEffects* cOpenALDeviceContext::getEffects()
const
148 #if CAUDIO_EFX_ENABLED == 1
150 return (IAudioEffects*)&initEffects;
156 ALCcontext* cOpenALDeviceContext::getOpenALContext()
const
161 bool cOpenALDeviceContext::checkError()
163 int error = alGetError();
164 const char* errorString;
166 if (error != AL_NO_ERROR)
168 errorString = alGetString(error);
175 error = alcGetError(Device);
176 if (error != AL_NO_ERROR)
178 errorString = alcGetString(Device, error);
virtual void logError(const char *sender, const char *msg,...)=0
Used to log an error message to the logging system.
virtual void logInfo(const char *sender, const char *msg,...)=0
Used to log an informational message to the logging system.
virtual void logWarning(const char *sender, const char *msg,...)=0
Used to log a warning to the logging system.
CAUDIO_API ILogger * getLogger()
Gets the interface to the logger.