Fix issue in Rocket.lua script.
[Cafu-Engine.git] / Libs / SoundSystem / SoundSysFMOD3 / SoundImpl.cpp
blob30967599c005ebdb3f95fc895500512efba57802
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
7 #include "SoundImpl.hpp"
8 #include "SoundSysImpl.hpp"
9 #include "Buffer.hpp"
10 #include "BufferManager.hpp"
12 #include "../SoundShader.hpp"
14 #include "fmod.h" // FMOD
15 #ifdef _WIN32
16 #include "fmod_errors.h" // FMOD Error Messages
17 #endif
20 SoundImplT::SoundImplT(SoundSysImplT* SoundSys, bool Is3D_, const SoundShaderT* Shader_, BufferT* Buffer_)
21 : Buffer(Buffer_),
22 ChannelHandle(-1),
23 Position(),
24 Velocity(),
25 Direction(),
26 Volume(0.5f),
27 MinDistance(0.0f),
28 MaxDistance(1000000000.0f),
29 Is3DSound(Is3D_),
30 Priority(0),
31 m_Shader(Shader_),
32 m_SoundSys(SoundSys)
34 // Initialize sound object properties with shader values.
35 ResetProperties();
39 SoundImplT::~SoundImplT()
41 if (Buffer)
42 BufferManagerT::GetInstance()->ReleaseBuffer(Buffer);
46 bool SoundImplT::Play()
48 return m_SoundSys->PlaySound(this);
52 void SoundImplT::Stop()
54 if (ChannelHandle==-1) return;
56 FSOUND_StopSound(ChannelHandle);
57 Buffer->Rewind();
61 void SoundImplT::Pause()
63 if (ChannelHandle==-1) return;
65 FSOUND_SetPaused(ChannelHandle, true);
69 bool SoundImplT::Resume()
71 if (ChannelHandle==-1) return false;
73 if (!FSOUND_SetPaused(ChannelHandle, false)) return false;
75 return true;
79 bool SoundImplT::IsPlaying() const
81 if (FSOUND_IsPlaying(ChannelHandle)) return true;
83 return false;
87 bool SoundImplT::Is3D() const
89 return Is3DSound;
93 void SoundImplT::ResetProperties()
95 if (!m_Shader) return;
97 // If sound object has a valid shader use it to reset sound object properties.
98 Volume =m_Shader->InnerVolume;
99 MinDistance=m_Shader->MinDistance;
100 MaxDistance=m_Shader->MaxDistance;
101 Priority =m_Shader->Priority;
105 void SoundImplT::SetPosition(const Vector3dT& Position_)
107 Position=Position_;
111 void SoundImplT::SetVelocity(const Vector3dT& Velocity_)
113 Velocity=Velocity_;
117 void SoundImplT::SetDirection(const Vector3dT& Direction_)
119 Direction=Direction_;
123 void SoundImplT::SetPriority(unsigned int Priority_)
125 Priority=Priority_;
129 void SoundImplT::SetInnerVolume(float InnerVolume_)
131 Volume=InnerVolume_;
135 void SoundImplT::SetMinDistance(float MinDist_)
137 MinDistance=MinDist_;
141 void SoundImplT::SetMaxDistance(float MaxDist_)
143 MaxDistance=MaxDist_;
147 void SoundImplT::SetInnerConeAngle(float InnerConeAngle_)
149 // Not supported with FMOD3.
153 void SoundImplT::SetOuterConeAngle(float OuterConeAngle_)
155 // Not supported with FMOD3.
159 void SoundImplT::SetOuterVolume(float OuterVolume_)
161 // Not supported with FMOD3.
165 unsigned int SoundImplT::GetPriority() const
167 return Priority;
171 float SoundImplT::GetInnerVolume() const
173 return Volume;
177 float SoundImplT::GetMinDistance() const
179 return MinDistance;
183 float SoundImplT::GetMaxDistance() const
185 return MaxDistance;
189 float SoundImplT::GetInnerConeAngle() const
191 // Not supported with FMOD3.
192 return 0.0f;
196 float SoundImplT::GetOuterConeAngle() const
198 // Not supported with FMOD3.
199 return 0.0f;
203 float SoundImplT::GetOuterVolume() const
205 // Not supported with FMOD3.
206 return 0.0f;