OpenAL.hpp

00001 
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024 
00025 #ifndef SFML_OPENAL_HPP
00026 #define SFML_OPENAL_HPP
00027 
00029 // Headers
00031 #include <SFML/Config.hpp>
00032 #include <AL/al.h>
00033 #include <AL/alc.h>
00034 #include <iostream>
00035 #include <string>
00036 
00037 
00038 namespace sf
00039 {
00040 namespace priv
00041 {
00047 #ifdef SFML_DEBUG
00048 
00049     // If in debug mode, perform a test on every call
00050     #define ALCheck(Func) ((Func), priv::ALCheckError(__FILE__, __LINE__))
00051 
00052 #else
00053 
00054     // Else, we don't add any overhead
00055     #define ALCheck(Func) (Func)
00056 
00057 #endif
00058 
00059 
00064 inline void ALCheckError(const std::string File, unsigned int Line)
00065 {
00066     // Get the last error
00067     ALenum ErrorCode = alGetError();
00068 
00069     if (ErrorCode != AL_NO_ERROR)
00070     {
00071         std::string Error, Desc;
00072 
00073         // Decode the error code
00074         switch (ErrorCode)
00075         {
00076             case AL_INVALID_NAME :
00077             {
00078                 Error = "AL_INVALID_NAME";
00079                 Desc  = "an unacceptable name has been specified";
00080                 break;
00081             }
00082 
00083             case AL_INVALID_ENUM :
00084             {
00085                 Error = "AL_INVALID_ENUM";
00086                 Desc  = "an unacceptable value has been specified for an enumerated argument";
00087                 break;
00088             }
00089 
00090             case AL_INVALID_VALUE :
00091             {
00092                 Error = "AL_INVALID_VALUE";
00093                 Desc  = "a numeric argument is out of range";
00094                 break;
00095             }
00096 
00097             case AL_INVALID_OPERATION :
00098             {
00099                 Error = "AL_INVALID_OPERATION";
00100                 Desc  = "the specified operation is not allowed in the current state";
00101                 break;
00102             }
00103 
00104             case AL_OUT_OF_MEMORY :
00105             {
00106                 Error = "AL_OUT_OF_MEMORY";
00107                 Desc  = "there is not enough memory left to execute the command";
00108                 break;
00109             }
00110         }
00111 
00112         // Log the error
00113         std::cerr << "An internal OpenAL call failed in "
00114                   << File.substr(File.find_last_of("\\/") + 1) << " (" << Line << ") : "
00115                   << Error << ", " << Desc
00116                   << std::endl;
00117     }
00118 }
00119 
00120 } // namespace priv
00121 
00122 } // namespace sf
00123 
00124 
00125 #endif // SFML_OPENAL_HPP