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/SoundSource.hpp> 00029 #include <SFML/Audio/ALCheck.hpp> 00030 00031 00032 namespace sf 00033 { 00035 SoundSource::SoundSource() 00036 { 00037 priv::EnsureALInit(); 00038 00039 ALCheck(alGenSources(1, &mySource)); 00040 ALCheck(alSourcei(mySource, AL_BUFFER, 0)); 00041 } 00042 00043 00045 SoundSource::SoundSource(const SoundSource& copy) 00046 { 00047 priv::EnsureALInit(); 00048 00049 ALCheck(alGenSources(1, &mySource)); 00050 ALCheck(alSourcei(mySource, AL_BUFFER, 0)); 00051 00052 SetPitch(copy.GetPitch()); 00053 SetVolume(copy.GetVolume()); 00054 SetPosition(copy.GetPosition()); 00055 SetRelativeToListener(copy.IsRelativeToListener()); 00056 SetMinDistance(copy.GetMinDistance()); 00057 SetAttenuation(copy.GetAttenuation()); 00058 } 00059 00060 00062 SoundSource::~SoundSource() 00063 { 00064 ALCheck(alSourcei(mySource, AL_BUFFER, 0)); 00065 ALCheck(alDeleteSources(1, &mySource)); 00066 } 00067 00068 00070 void SoundSource::SetPitch(float pitch) 00071 { 00072 ALCheck(alSourcef(mySource, AL_PITCH, pitch)); 00073 } 00074 00075 00077 void SoundSource::SetVolume(float volume) 00078 { 00079 ALCheck(alSourcef(mySource, AL_GAIN, volume * 0.01f)); 00080 } 00081 00083 void SoundSource::SetPosition(float x, float y, float z) 00084 { 00085 ALCheck(alSource3f(mySource, AL_POSITION, x, y, z)); 00086 } 00087 00088 00090 void SoundSource::SetPosition(const Vector3f& position) 00091 { 00092 SetPosition(position.x, position.y, position.z); 00093 } 00094 00095 00097 void SoundSource::SetRelativeToListener(bool relative) 00098 { 00099 ALCheck(alSourcei(mySource, AL_SOURCE_RELATIVE, relative)); 00100 } 00101 00102 00104 void SoundSource::SetMinDistance(float distance) 00105 { 00106 ALCheck(alSourcef(mySource, AL_REFERENCE_DISTANCE, distance)); 00107 } 00108 00109 00111 void SoundSource::SetAttenuation(float attenuation) 00112 { 00113 ALCheck(alSourcef(mySource, AL_ROLLOFF_FACTOR, attenuation)); 00114 } 00115 00116 00118 float SoundSource::GetPitch() const 00119 { 00120 ALfloat pitch; 00121 ALCheck(alGetSourcef(mySource, AL_PITCH, &pitch)); 00122 00123 return pitch; 00124 } 00125 00126 00128 float SoundSource::GetVolume() const 00129 { 00130 ALfloat gain; 00131 ALCheck(alGetSourcef(mySource, AL_GAIN, &gain)); 00132 00133 return gain * 100.f; 00134 } 00135 00136 00138 Vector3f SoundSource::GetPosition() const 00139 { 00140 Vector3f position; 00141 ALCheck(alGetSource3f(mySource, AL_POSITION, &position.x, &position.y, &position.z)); 00142 00143 return position; 00144 } 00145 00146 00148 bool SoundSource::IsRelativeToListener() const 00149 { 00150 ALint relative; 00151 ALCheck(alGetSourcei(mySource, AL_SOURCE_RELATIVE, &relative)); 00152 00153 return relative != 0; 00154 } 00155 00156 00158 float SoundSource::GetMinDistance() const 00159 { 00160 ALfloat distance; 00161 ALCheck(alGetSourcef(mySource, AL_REFERENCE_DISTANCE, &distance)); 00162 00163 return distance; 00164 } 00165 00166 00168 float SoundSource::GetAttenuation() const 00169 { 00170 ALfloat attenuation; 00171 ALCheck(alGetSourcef(mySource, AL_ROLLOFF_FACTOR, &attenuation)); 00172 00173 return attenuation; 00174 } 00175 00176 00178 SoundSource::Status SoundSource::GetStatus() const 00179 { 00180 ALint status; 00181 ALCheck(alGetSourcei(mySource, AL_SOURCE_STATE, &status)); 00182 00183 switch (status) 00184 { 00185 case AL_INITIAL : 00186 case AL_STOPPED : return Stopped; 00187 case AL_PAUSED : return Paused; 00188 case AL_PLAYING : return Playing; 00189 } 00190 00191 return Stopped; 00192 } 00193 00194 } // namespace sf
:: Copyright © 2007-2008 Laurent Gomila, all rights reserved :: Documentation generated by doxygen 1.5.2 ::