Sound.cpp

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 
00026 // Headers
00028 #include <SFML/Audio/Sound.h>
00029 #include <SFML/Audio/Sound.hpp>
00030 #include <SFML/Audio/SoundBuffer.hpp>
00031 #include <SFML/Internal.h>
00032 
00033 
00034 // WARNING : this structure must always be the SAME as in Audio/SoundBuffer.h
00035 struct sfSoundBuffer
00036 {
00037     sf::SoundBuffer This;
00038 };
00039 struct sfSound
00040 {
00041     sf::Sound      This;
00042     sfSoundBuffer* Buffer;
00043 };
00044 
00045 
00049 sfSound* sfSound_Create()
00050 {
00051     return new sfSound;
00052 }
00053 
00054 
00058 void sfSound_Destroy(sfSound* Sound)
00059 {
00060     delete Sound;
00061 }
00062 
00063 
00067 void sfSound_Play(sfSound* Sound)
00068 {
00069     CSFML_CALL(Sound, Play())
00070 }
00071 
00072 
00076 void sfSound_Pause(sfSound* Sound)
00077 {
00078     CSFML_CALL(Sound, Pause())
00079 }
00080 
00081 
00085 void sfSound_Stop(sfSound* Sound)
00086 {
00087     CSFML_CALL(Sound, Stop())
00088 }
00089 
00090 
00094 void sfSound_SetBuffer(sfSound* Sound, sfSoundBuffer* Buffer)
00095 {
00096     if (Buffer)
00097     {
00098         CSFML_CALL(Sound, SetBuffer(Buffer->This))
00099         Sound->Buffer = Buffer;
00100     }
00101 }
00102 
00103 
00107 sfSoundBuffer* sfSound_GetBuffer(sfSound* Sound)
00108 {
00109     CSFML_CHECK_RETURN(Sound, NULL)
00110 
00111     return Sound->Buffer;
00112 }
00113 
00114 
00118 void sfSound_SetLoop(sfSound* Sound, sfBool Loop)
00119 {
00120     CSFML_CALL(Sound, SetLoop(Loop == sfTrue))
00121 }
00122 
00123 
00127 sfBool sfSound_GetLoop(sfSound* Sound)
00128 {
00129     CSFML_CALL_RETURN(Sound, GetLoop(), sfFalse)
00130 }
00131 
00132 
00136 sfSoundStatus sfSound_GetStatus(sfSound* Sound)
00137 {
00138     CSFML_CHECK_RETURN(Sound, sfStopped);
00139 
00140     return static_cast<sfSoundStatus>(Sound->This.GetStatus());
00141 }
00142 
00143 
00147 void sfSound_SetPitch(sfSound* Sound, float Pitch)
00148 {
00149     CSFML_CALL(Sound, SetPitch(Pitch))
00150 }
00151 
00152 
00156 void sfSound_SetVolume(sfSound* Sound, float Volume)
00157 {
00158     CSFML_CALL(Sound, SetVolume(Volume))
00159 }
00160 
00161 
00165 void sfSound_SetPosition(sfSound* Sound, float X, float Y, float Z)
00166 {
00167     CSFML_CALL(Sound, SetPosition(X, Y, Z))
00168 }
00169 
00170 
00174 float sfSound_GetPitch(sfSound* Sound)
00175 {
00176     CSFML_CALL_RETURN(Sound, GetPitch(), 0.f)
00177 }
00178 
00179 
00183 float sfSound_GetVolume(sfSound* Sound)
00184 {
00185     CSFML_CALL_RETURN(Sound, GetVolume(), 0.f)
00186 }
00187 
00188 
00192 void sfSound_GetPosition(sfSound* Sound, float* X, float* Y, float* Z)
00193 {
00194     if (X && Y && Z)
00195         CSFML_CALL(Sound, GetPosition(*X, *Y, *Z));
00196 }
00197 
00198 
00202 float sfSound_GetPlayingOffset(sfSound* Sound)
00203 {
00204     CSFML_CALL_RETURN(Sound, GetPlayingOffset(), 0.f)
00205 }