Cafu Engine
SoundSys.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_SOUNDSYS_SOUNDSYS_INTERFACE_HPP_INCLUDED
8 #define CAFU_SOUNDSYS_SOUNDSYS_INTERFACE_HPP_INCLUDED
9 
10 #include "Math3D/Vector3.hpp"
11 
12 
13 class SoundI;
14 class SoundShaderT;
15 
16 
17 /// This is an interface to the sound system.
18 /// The interface is specified as ABC in order to be able to share the sound system across exe/dll boundaries.
19 class SoundSysI
20 {
21  public:
22 
23  /// Initializes the sound system.
24  virtual bool Initialize()=0;
25 
26  /// Releases the sound system and removes all sound data from memory.
27  virtual void Release()=0;
28 
29  /// Determine if the sound system is supported on this platform.
30  /// @return Whether or not the sound system is supported.
31  virtual bool IsSupported()=0;
32 
33  /// Returns the preference number for this sound system, so calling code can decide which sound system to use.
34  /// @return Preference number.
35  virtual int GetPreferenceNr()=0;
36 
37  /// Creates a 2 dimensional sound object using the properties of the passed sound shader.
38  /// @param SoundShader Sound shader to use with this sound object.
39  virtual SoundI* CreateSound2D(const SoundShaderT* SoundShader)=0;
40 
41  /// Creates a 3 dimensional sound object using the properties of the passed sound shader.
42  /// @param SoundShader Sound shader to use with this sound object.
43  virtual SoundI* CreateSound3D(const SoundShaderT* SoundShader)=0;
44 
45  /// Deletes a previously created sound object.
46  /// @param Sound The sound object to delete.
47  virtual void DeleteSound(SoundI* Sound)=0;
48 
49  /// Plays a sound on a channel.
50  /// @param Sound The sound object that should be played.
51  /// @return true if sound is played on a channel, false if no channel was free (and playing sound have all greater priority
52  /// than this sound).
53  virtual bool PlaySound(const SoundI* Sound)=0;
54 
55  /// Sets the master volume for this sound system.
56  /// @param Volume The new master volume. Value has to be [0, 1] (higher/lower values are clamped).
57  virtual void SetMasterVolume(float Volume)=0;
58 
59  /// Gets the master volume currently set for this sound system.
60  /// @return The current master volume [0, 1].
61  virtual float GetMasterVolume()=0;
62 
63  /// Updates the position, velocity and orientation of the listener.
64  /// @param Position Position of the listener in the 3D Space.
65  /// @param Velocity Velocity of the listener.
66  /// @param OrientationForward Forward orientation of the listener (unit length vector).
67  /// @param OrientationUp Upwards orientation of the listener (unit length vector).
68  virtual void UpdateListener(const Vector3dT& Position, const Vector3dT& Velocity, const Vector3fT& OrientationForward, const Vector3fT& OrientationUp)=0;
69 
70  /// Upates all channels that are currently being played according to the properties of their sound object.
71  virtual void Update()=0;
72 
73  /// The virtual destructor makes sure that deleting derived classes via a SoundSysI pointer works properly.
74  virtual ~SoundSysI() { }
75 };
76 
77 /// A global pointer to the current soundsystem, for common access by all modules that use it.
78 /// Just set this after you loaded the desired sound DLL to the pointer returned by the DLLs GetSoundSys() function.
79 /// (And NULL it on unloading the DLL.)
80 extern SoundSysI* SoundSystem;
81 
82 
83 #endif
virtual ~SoundSysI()
The virtual destructor makes sure that deleting derived classes via a SoundSysI pointer works properl...
Definition: SoundSys.hpp:74
virtual void Update()=0
Upates all channels that are currently being played according to the properties of their sound object...
virtual float GetMasterVolume()=0
Gets the master volume currently set for this sound system.
virtual bool IsSupported()=0
Determine if the sound system is supported on this platform.
This is an interface to the sound system.
Definition: SoundSys.hpp:19
virtual void SetMasterVolume(float Volume)=0
Sets the master volume for this sound system.
virtual void DeleteSound(SoundI *Sound)=0
Deletes a previously created sound object.
This class represents a sound.
Definition: Sound.hpp:15
virtual bool PlaySound(const SoundI *Sound)=0
Plays a sound on a channel.
virtual void Release()=0
Releases the sound system and removes all sound data from memory.
virtual void UpdateListener(const Vector3dT &Position, const Vector3dT &Velocity, const Vector3fT &OrientationForward, const Vector3fT &OrientationUp)=0
Updates the position, velocity and orientation of the listener.
virtual bool Initialize()=0
Initializes the sound system.
virtual int GetPreferenceNr()=0
Returns the preference number for this sound system, so calling code can decide which sound system to...
virtual SoundI * CreateSound2D(const SoundShaderT *SoundShader)=0
Creates a 2 dimensional sound object using the properties of the passed sound shader.
virtual SoundI * CreateSound3D(const SoundShaderT *SoundShader)=0
Creates a 3 dimensional sound object using the properties of the passed sound shader.
A SoundShader is a description of a sound with various properties.
Definition: SoundShader.hpp:19