Cafu Engine
SoundImpl.hpp
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 */
6 
7 #ifndef CAFU_SOUND_IMPL_HPP_INCLUDED
8 #define CAFU_SOUND_IMPL_HPP_INCLUDED
9 
10 #include "../Sound.hpp"
11 
12 
13 class SoundShaderT;
14 class BufferT;
15 class MixerTrackT;
16 class SoundSysImplT;
17 
18 
19 /// OpenAL implementation of the SoundI interface.
20 /// @todo Implement copy construtor that takes shader and buffer (+increases references) but sets mixertrack always to NULL.
21 class SoundImplT : public SoundI
22 {
23  public:
24 
25  /// The constructor. Creates a new sound using a specified sound shader and buffer.
26  /// If either sound shader or buffer are NULL the sound is invalid, and playing invalid
27  /// sound files will fail.
28  /// @param SoundSys The sound system this sound is created in.
29  /// @param Is3D_ Whether this sound is created as an 3 dimensional sound or not.
30  /// @param Shader_ The sound shader used by this sound.
31  /// @param Buffer_ The buffer that contains the audio data played by this sound.
32  SoundImplT(SoundSysImplT* SoundSys, bool Is3D_, const SoundShaderT* Shader_=NULL, BufferT* Buffer_=NULL);
33 
34  /// The destructor. Deletes the sound by removing it from its current mixer track (if any) and buffer.
35  ~SoundImplT();
36 
37  // Implement the SoundI interface.
38  bool Play();
39  void Stop();
40  void Pause();
41  bool Resume();
42  bool IsPlaying() const;
43  bool Is3D() const;
44  void ResetProperties();
45  void SetPosition(const Vector3dT& Position_);
46  void SetVelocity(const Vector3dT& Velocity_);
47  void SetDirection(const Vector3dT& Direction_);
48  void SetPriority(unsigned int Priority_);
49  void SetInnerVolume(float InnerVolume_);
50  void SetMinDistance(float MinDist_);
51  void SetMaxDistance(float MaxDist_);
52  void SetInnerConeAngle(float InnerConeAngle_);
53  void SetOuterConeAngle(float OuterConeAngle_);
54  void SetOuterVolume(float OuterVolume_);
55  unsigned int GetPriority() const;
56  float GetInnerVolume() const;
57  float GetMinDistance() const;
58  float GetMaxDistance() const;
59  float GetInnerConeAngle() const;
60  float GetOuterConeAngle() const;
61  float GetOuterVolume() const;
62 
63 
64  BufferT* Buffer; ///< The buffer played by this sound.
65  MixerTrackT* MixerTrack; ///< The mixertrack on which this sound is played.
66  Vector3dT Position; ///< Position of this sound in the world (only relevant if sound is 3D).
67  Vector3dT Velocity; ///< Velocity of the the object that emits this sound (only relevant if sound is 3D).
68  Vector3dT Direction; ///< Direction of the sound (only relevant if ConeAngle (defined in shader) is smaller than 360 degree and sound is 3D).
69  float InnerVolume; ///< The volume of this sound (inside its sound cone/at minimal distance). 1.0 meaning 100% volume and 0.0 mute sound.
70  float OuterVolume; ///< The sounds volume if listener is outside the sound cone.
71  float InnerConeAngle; ///< The inner angle of the cone in which the sound is emited at normal volume.
72  float OuterConeAngle; ///< The outer angle of the cone outside which the sound is emited at outside volume.
73  float MinDistance; ///< The minimum distance that the sound will cease to continue growing louder at (stays at max. volume).
74  float MaxDistance; ///< The maximum distance that the sound will cease to attenuate.
75  const bool Is3DSound; ///< Whether the sound is 2D or 3D.
76  unsigned int Priority; ///< Priority of the sound. Values <0 mean that the priority is not set and therefore obtained from the sound shader.
77 
78 
79  private:
80 
81  const SoundShaderT* m_Shader; ///< The sound shader used by this sound object.
82  SoundSysImplT* m_SoundSys; ///< Pointer to the sound system that created this sound. Needed to control playback trough the sound instead of the soundsystem.
83 };
84 
85 #endif
float OuterVolume
The sounds volume if listener is outside the sound cone.
Definition: SoundImpl.hpp:70
A mixer track represents/encapsulates/abstracs an OpenAL sound source.
Definition: MixerTrack.hpp:22
OpenAL implementation of the sound system.
Definition: SoundSysImpl.hpp:22
~SoundImplT()
The destructor. Deletes the sound by removing it from its current mixer track (if any) and buffer...
Definition: SoundImpl.cpp:40
void Pause()
Pauses the sound.
Definition: SoundImpl.cpp:67
bool Is3D() const
Checks if the sound is for 3D playback.
Definition: SoundImpl.cpp:94
void SetPriority(unsigned int Priority_)
Sets the priority of this sound.
Definition: SoundImpl.cpp:133
unsigned int Priority
Priority of the sound. Values <0 mean that the priority is not set and therefore obtained from the so...
Definition: SoundImpl.hpp:76
float GetOuterVolume() const
Gets the volume inside the outer sound cone.
Definition: SoundImpl.cpp:211
bool Play()
Plays the sound using the current sound system.
Definition: SoundImpl.cpp:50
void SetDirection(const Vector3dT &Direction_)
Sets the direction into which the sound source is moving.
Definition: SoundImpl.cpp:127
OpenAL implementation of the SoundI interface.
Definition: SoundImpl.hpp:21
bool IsPlaying() const
Checks if the sound is currently playing.
Definition: SoundImpl.cpp:85
void SetMinDistance(float MinDist_)
Sets the minimal distance.
Definition: SoundImpl.cpp:145
float GetOuterConeAngle() const
Sets the angle of the outer sound cone.
Definition: SoundImpl.cpp:205
Vector3dT Velocity
Velocity of the the object that emits this sound (only relevant if sound is 3D).
Definition: SoundImpl.hpp:67
float GetInnerConeAngle() const
Gets the angle of the inner sound cone.
Definition: SoundImpl.cpp:199
Vector3dT Direction
Direction of the sound (only relevant if ConeAngle (defined in shader) is smaller than 360 degree and...
Definition: SoundImpl.hpp:68
float OuterConeAngle
The outer angle of the cone outside which the sound is emited at outside volume.
Definition: SoundImpl.hpp:72
This class represents a sound.
Definition: Sound.hpp:15
const bool Is3DSound
Whether the sound is 2D or 3D.
Definition: SoundImpl.hpp:75
bool Resume()
Resumes a previously paused sound.
Definition: SoundImpl.cpp:73
unsigned int GetPriority() const
Gets the priority of this sound.
Definition: SoundImpl.cpp:175
A BufferT encapsulates an audio resource such as a file or a capture device.
Definition: Buffer.hpp:22
BufferT * Buffer
The buffer played by this sound.
Definition: SoundImpl.hpp:64
void ResetProperties()
Resets the sound properties to those of the shader it was created from.
Definition: SoundImpl.cpp:100
void SetInnerConeAngle(float InnerConeAngle_)
Sets the angle of the inner sound cone.
Definition: SoundImpl.cpp:157
void SetInnerVolume(float InnerVolume_)
Sets the volume.
Definition: SoundImpl.cpp:139
MixerTrackT * MixerTrack
The mixertrack on which this sound is played.
Definition: SoundImpl.hpp:65
SoundImplT(SoundSysImplT *SoundSys, bool Is3D_, const SoundShaderT *Shader_=NULL, BufferT *Buffer_=NULL)
The constructor.
Definition: SoundImpl.cpp:18
void SetOuterVolume(float OuterVolume_)
Sets the volume inside the outer sound cone.
Definition: SoundImpl.cpp:169
float InnerConeAngle
The inner angle of the cone in which the sound is emited at normal volume.
Definition: SoundImpl.hpp:71
void Stop()
Stops the sound.
Definition: SoundImpl.cpp:61
float MinDistance
The minimum distance that the sound will cease to continue growing louder at (stays at max...
Definition: SoundImpl.hpp:73
float MaxDistance
The maximum distance that the sound will cease to attenuate.
Definition: SoundImpl.hpp:74
void SetMaxDistance(float MaxDist_)
Sets the maximal distance.
Definition: SoundImpl.cpp:151
float InnerVolume
The volume of this sound (inside its sound cone/at minimal distance). 1.0 meaning 100% volume and 0...
Definition: SoundImpl.hpp:69
float GetMaxDistance() const
Gets the maximal distance.
Definition: SoundImpl.cpp:193
float GetMinDistance() const
Gets the minimal distance.
Definition: SoundImpl.cpp:187
void SetOuterConeAngle(float OuterConeAngle_)
Sets the angle of the outer sound cone.
Definition: SoundImpl.cpp:163
float GetInnerVolume() const
Gets the volume.
Definition: SoundImpl.cpp:181
void SetPosition(const Vector3dT &Position_)
Set the position from which the sound is emanating.
Definition: SoundImpl.cpp:115
Vector3dT Position
Position of this sound in the world (only relevant if sound is 3D).
Definition: SoundImpl.hpp:66
void SetVelocity(const Vector3dT &Velocity_)
Sets the velocity of the source that emits the sound.
Definition: SoundImpl.cpp:121
A SoundShader is a description of a sound with various properties.
Definition: SoundShader.hpp:19