OpenAL.hpp
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#ifndef SFML_OPENAL_HPP
26#define SFML_OPENAL_HPP
27
29// Headers
31#include <SFML/Config.hpp>
32
33#if defined(SFML_SYSTEM_MACOS)
34#include <OpenAL/al.h>
35#include <OpenAL/alc.h>
36#else
37#include <AL/al.h>
38#include <AL/alc.h>
39#endif
40
41#include <iostream>
42#include <string>
43
44
45namespace sf
46{
47namespace priv
48{
54#ifdef SFML_DEBUG
55
56 // If in debug mode, perform a test on every call
57 #define ALCheck(Func) ((Func), priv::ALCheckError(__FILE__, __LINE__))
58
59#else
60
61 // Else, we don't add any overhead
62 #define ALCheck(Func) (Func)
63
64#endif
65
66
71inline void ALCheckError(const std::string& File, unsigned int Line)
72{
73 // Get the last error
74 ALenum ErrorCode = alGetError();
75
76 if (ErrorCode != AL_NO_ERROR)
77 {
78 std::string Error, Desc;
79
80 // Decode the error code
81 switch (ErrorCode)
82 {
83 case AL_INVALID_NAME :
84 {
85 Error = "AL_INVALID_NAME";
86 Desc = "an unacceptable name has been specified";
87 break;
88 }
89
90 case AL_INVALID_ENUM :
91 {
92 Error = "AL_INVALID_ENUM";
93 Desc = "an unacceptable value has been specified for an enumerated argument";
94 break;
95 }
96
97 case AL_INVALID_VALUE :
98 {
99 Error = "AL_INVALID_VALUE";
100 Desc = "a numeric argument is out of range";
101 break;
102 }
103
104 case AL_INVALID_OPERATION :
105 {
106 Error = "AL_INVALID_OPERATION";
107 Desc = "the specified operation is not allowed in the current state";
108 break;
109 }
110
111 case AL_OUT_OF_MEMORY :
112 {
113 Error = "AL_OUT_OF_MEMORY";
114 Desc = "there is not enough memory left to execute the command";
115 break;
116 }
117 }
118
119 // Log the error
120 std::cerr << "An internal OpenAL call failed in "
121 << File.substr(File.find_last_of("\\/") + 1) << " (" << Line << ") : "
122 << Error << ", " << Desc
123 << std::endl;
124 }
125}
126
127} // namespace priv
128
129} // namespace sf
130
131
132#endif // SFML_OPENAL_HPP