Cafu Engine
SoundSysImpl.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_SYS_IMPL_HPP_INCLUDED
8 #define CAFU_SOUND_SYS_IMPL_HPP_INCLUDED
9 
10 #include "OpenALIncl.hpp"
11 #include "MixerTrackMan.hpp"
12 #include "../SoundSys.hpp"
13 #include "Templates/Array.hpp"
14 #include <map>
15 
16 
17 class SoundStreamT;
18 class BufferManagerT;
19 
20 
21 /// OpenAL implementation of the sound system.
22 class SoundSysImplT : public SoundSysI
23 {
24  public:
25 
26  // Implement the SoundSysI interface.
27  bool Initialize();
28  void Release();
29 
30  bool IsSupported();
31  int GetPreferenceNr();
32 
33  SoundI* CreateSound2D(const SoundShaderT* SoundShader);
34  SoundI* CreateSound3D(const SoundShaderT* SoundShader);
35  void DeleteSound(SoundI* Sound);
36 
37  bool PlaySound(const SoundI* Sound);
38 
39  void SetMasterVolume(float Volume);
40  float GetMasterVolume();
41 
42  void Update();
43  void UpdateListener(const Vector3dT& Position, const Vector3dT& Velocity, const Vector3fT& OrientationForward, const Vector3fT& OrientationUp);
44 
45 
46  /// Creates an instance of the OpenAL sound system.
47  static SoundSysImplT& GetInstance();
48 
49 
50  private:
51 
52  // Note that the order in which these two members are destroyed is important: First the mixer track manager needs to be destroyed
53  // because it detaches all buffers from currently connected sources. Then all buffers can be deleted by destroying the buffer manager.
54  BufferManagerT* m_BufferManager; ///< Buffer manager used by this sound system.
55  MixerTrackManT* m_MixerTrackManager; ///< Mixer track manager used by this sound system.
56 
57  ALCdevice* m_Device; ///< The device which OpenAL is using to play sounds.
58  ALCcontext* m_Context; ///< The context in which the sounds are played.
59 
60  bool m_IsInitialized; ///< Whether the sound system has been initialized.
61 
62  SoundSysImplT(); ///< Private constructor for the Singleton pattern.
63  ~SoundSysImplT(); ///< Private destructor.
64 };
65 
66 #endif
void Release()
Releases the sound system and removes all sound data from memory.
Definition: SoundSysImpl.cpp:159
This class efficiently manages audio buffers by employing resource sharing whenever possible...
Definition: BufferManager.hpp:20
void DeleteSound(SoundI *Sound)
Deletes a previously created sound object.
Definition: SoundSysImpl.cpp:241
OpenAL implementation of the sound system.
Definition: SoundSysImpl.hpp:22
This is an interface to the sound system.
Definition: SoundSys.hpp:19
SoundI * CreateSound3D(const SoundShaderT *SoundShader)
Creates a 3 dimensional sound object using the properties of the passed sound shader.
Definition: SoundSysImpl.cpp:220
void SetMasterVolume(float Volume)
Sets the master volume for this sound system.
Definition: SoundSysImpl.cpp:264
static SoundSysImplT & GetInstance()
Creates an instance of the OpenAL sound system.
Definition: SoundSysImpl.cpp:19
This class represents a sound.
Definition: Sound.hpp:15
The mixer track manager manages the limited mixer tracks that are needed to playback a sound object...
Definition: MixerTrackMan.hpp:17
void Update()
Upates all channels that are currently being played according to the properties of their sound object...
Definition: SoundSysImpl.cpp:285
SoundI * CreateSound2D(const SoundShaderT *SoundShader)
Creates a 2 dimensional sound object using the properties of the passed sound shader.
Definition: SoundSysImpl.cpp:199
Represents a 16 Bit encoded mono or stereo raw PCM data stream.
Definition: SoundStream.hpp:14
float GetMasterVolume()
Gets the master volume currently set for this sound system.
Definition: SoundSysImpl.cpp:275
bool PlaySound(const SoundI *Sound)
Plays a sound on a channel.
Definition: SoundSysImpl.cpp:247
void UpdateListener(const Vector3dT &Position, const Vector3dT &Velocity, const Vector3fT &OrientationForward, const Vector3fT &OrientationUp)
Updates the position, velocity and orientation of the listener.
Definition: SoundSysImpl.cpp:292
int GetPreferenceNr()
Returns the preference number for this sound system, so calling code can decide which sound system to...
Definition: SoundSysImpl.cpp:193
bool Initialize()
Initializes the sound system.
Definition: SoundSysImpl.cpp:43
bool IsSupported()
Determine if the sound system is supported on this platform.
Definition: SoundSysImpl.cpp:179
A SoundShader is a description of a sound with various properties.
Definition: SoundShader.hpp:19