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.
7 #include "SoundImpl.hpp"
8 #include "SoundSysImpl.hpp"
10 #include "BufferManager.hpp"
12 #include "../SoundShader.hpp"
14 #include "fmod.h" // FMOD
16 #include "fmod_errors.h" // FMOD Error Messages
20 SoundImplT::SoundImplT(SoundSysImplT
* SoundSys
, bool Is3D_
, const SoundShaderT
* Shader_
, BufferT
* Buffer_
)
28 MaxDistance(1000000000.0f
),
34 // Initialize sound object properties with shader values.
39 SoundImplT::~SoundImplT()
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
);
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;
79 bool SoundImplT::IsPlaying() const
81 if (FSOUND_IsPlaying(ChannelHandle
)) return true;
87 bool SoundImplT::Is3D() const
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_
)
111 void SoundImplT::SetVelocity(const Vector3dT
& Velocity_
)
117 void SoundImplT::SetDirection(const Vector3dT
& Direction_
)
119 Direction
=Direction_
;
123 void SoundImplT::SetPriority(unsigned int Priority_
)
129 void SoundImplT::SetInnerVolume(float 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
171 float SoundImplT::GetInnerVolume() const
177 float SoundImplT::GetMinDistance() const
183 float SoundImplT::GetMaxDistance() const
189 float SoundImplT::GetInnerConeAngle() const
191 // Not supported with FMOD3.
196 float SoundImplT::GetOuterConeAngle() const
198 // Not supported with FMOD3.
203 float SoundImplT::GetOuterVolume() const
205 // Not supported with FMOD3.