cAudio  2.3.0
3d Audio Engine
cOpenALUtil.h
1 
2 #ifndef CAUDIO_COPENALUTIL_H
3 #define CAUDIO_COPENALUTIL_H
4 
5 #include "cAudio.h"
6 
7 #if !defined(CAUDIO_PLATFORM_LINUX)
8 #include <OpenAL/al.h>
9 #include <OpenAL/alc.h>
10 #else
11 #include <AL/al.h>
12 #include <AL/alc.h>
13 #endif
14 
15 #if DEBUG
16 #ifndef __func__
17 #define __func__ __FUNCTION__
18 #endif
19 #define checkALError() checkALErrorInternal(__FILE__, __func__, __LINE__)
20 #else
21 #define checkALError() (false)
22 #endif
23 
24 namespace cAudio {
25 
27  inline bool checkALErrorInternal(const char* file, const char *func, int line)
28  {
29  ALenum error = AL_NO_ERROR;
30  bool anyError = false;
31  while ((error = alGetError()) != AL_NO_ERROR)
32  {
33  const char* errorString = alGetString(error);
34  if(error == AL_OUT_OF_MEMORY) {
35  getLogger()->logCritical("Audio Source", "OpenAL Error: %s:%d:%s, %s.", file, line, func, errorString);
36  } else if (error == -1) {
37  // this occurs randomly and relatively freqently with Apple's OpenAL and does not seem to cause serious problems.
38  getLogger()->logWarning("Audio Source", "OpenAL Warning %s:%d:%s, %s.", file, line, func, errorString);
39  } else {
40  getLogger()->logError("Audio Source", "OpenAL Error: %s:%d:%s, %s.", file, line, func, errorString);
41  }
42  anyError = true;
43  }
44  return anyError;
45  }
46 
48  inline ALenum convertAudioFormatEnum(AudioFormats format)
49  {
50  switch(format)
51  {
52  case EAF_8BIT_MONO:
53  return AL_FORMAT_MONO8;
54  case EAF_16BIT_MONO:
55  return AL_FORMAT_MONO16;
56  case EAF_8BIT_STEREO:
57  return AL_FORMAT_STEREO8;
58  case EAF_16BIT_STEREO:
59  return AL_FORMAT_STEREO16;
60  default:
61  return AL_FORMAT_MONO8;
62  };
63  }
64 
65 }
66 
67 #endif
68 
69 
virtual void logError(const char *sender, const char *msg,...)=0
Used to log an error message to the logging system.
ALenum convertAudioFormatEnum(AudioFormats format)
Converts our audio format enum to OpenAL&#39;s.
Definition: cOpenALUtil.h:48
virtual void logCritical(const char *sender, const char *msg,...)=0
Used to log a critical error message to the logging system.
bool checkALErrorInternal(const char *file, const char *func, int line)
Checks for OpenAL errors and reports them.
Definition: cOpenALUtil.h:27
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.
Definition: cAudio.cpp:45
AudioFormats
Enumeration of audio formats supported by the engine.
Definition: EAudioFormats.h:10
Main namespace for the entire cAudio library.
Definition: cAudioCapture.h:15