00001 00002 // 00003 // SFML - Simple and Fast Multimedia Library 00004 // Copyright (C) 2007-2009 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 00026 // Headers 00028 #include <SFML/Audio/AudioDevice.hpp> 00029 #include <SFML/Audio/ALCheck.hpp> 00030 #include <SFML/Audio/Listener.hpp> 00031 #include <SFML/System/Err.hpp> 00032 00033 00035 // Private data 00037 namespace 00038 { 00039 ALCdevice* audioDevice = NULL; 00040 ALCcontext* audioContext = NULL; 00041 } 00042 00043 namespace sf 00044 { 00045 namespace priv 00046 { 00048 AudioDevice::AudioDevice() 00049 { 00050 // Create the device 00051 audioDevice = alcOpenDevice(NULL); 00052 00053 if (audioDevice) 00054 { 00055 // Create the context 00056 audioContext = alcCreateContext(audioDevice, NULL); 00057 00058 if (audioContext) 00059 { 00060 // Set the context as the current one (we'll only need one) 00061 alcMakeContextCurrent(audioContext); 00062 } 00063 else 00064 { 00065 Err() << "Failed to create the audio context" << std::endl; 00066 } 00067 } 00068 else 00069 { 00070 Err() << "Failed to open the audio device" << std::endl; 00071 } 00072 } 00073 00074 00076 AudioDevice::~AudioDevice() 00077 { 00078 // Destroy the context 00079 alcMakeContextCurrent(NULL); 00080 if (audioContext) 00081 alcDestroyContext(audioContext); 00082 00083 // Destroy the device 00084 if (audioDevice) 00085 alcCloseDevice(audioDevice); 00086 } 00087 00088 00090 bool AudioDevice::IsExtensionSupported(const std::string& extension) 00091 { 00092 EnsureALInit(); 00093 00094 if ((extension.length() > 2) && (extension.substr(0, 3) == "ALC")) 00095 return alcIsExtensionPresent(audioDevice, extension.c_str()) != AL_FALSE; 00096 else 00097 return alIsExtensionPresent(extension.c_str()) != AL_FALSE; 00098 } 00099 00100 00102 int AudioDevice::GetFormatFromChannelsCount(unsigned int channelsCount) 00103 { 00104 EnsureALInit(); 00105 00106 // Find the good format according to the number of channels 00107 switch (channelsCount) 00108 { 00109 case 1 : return AL_FORMAT_MONO16; 00110 case 2 : return AL_FORMAT_STEREO16; 00111 case 4 : return alGetEnumValue("AL_FORMAT_QUAD16"); 00112 case 6 : return alGetEnumValue("AL_FORMAT_51CHN16"); 00113 case 7 : return alGetEnumValue("AL_FORMAT_61CHN16"); 00114 case 8 : return alGetEnumValue("AL_FORMAT_71CHN16"); 00115 default : return 0; 00116 } 00117 } 00118 00119 } // namespace priv 00120 00121 } // namespace sf
:: Copyright © 2007-2008 Laurent Gomila, all rights reserved :: Documentation generated by doxygen 1.5.2 ::