Cafu Engine
SoundShader.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_SOUND_SHADER_HPP_INCLUDED
8 #define CAFU_SOUNDSYS_SOUND_SHADER_HPP_INCLUDED
9 
10 #include <string>
11 
12 
13 class TextParserT;
14 
15 
16 /// A SoundShader is a description of a sound with various properties.
17 /// These properties can be specified by the user through a sound shader script.
18 /// The sound system uses a sound shader to load soundfiles and play them with sound shader specific properties.
20 {
21  public:
22 
23  /// SoundType is used to change properties of all sounds from a specific type in the game code.
24  /// e.g. Turn volume of player effects down.
26  {
27  SOUND_MUSIC, ///< Background music.
28  SOUND_EFFECT, ///< Effects like gunshots etc.
29  SOUND_PLAYER, ///< Player sounds like footsteps etc.
30  SOUND_AMBIENT ///< Ambient sounds like birds.
31  };
32 
33  /// Determines how a sound file is loaded into memory.
34  enum LoadTypeE
35  {
36  AUTO, ///< The sound system decides how to load the sound file associated with this shader.
37  STATIC, ///< Load whole sound decrompressed into memory (used for small files).
38  STREAM, ///< Stream sound into memory (decrompressed).
39  COMPRESSED ///< Load whole sound compressed into memory (lower memory usage, but higher CPU usage).
40  };
41 
42 
43  /// Default constructor used to create an "empty" sound shader with default parameters.
44  /// This is useful to create a custom sound shader from game code and adjust its parameters manually.
45  /// @param SoundShaderName Name of this soundshader (since shaders of this kind are never registered with the
46  /// global sound shader manager, their names don't need to be unique or set at all).
47  SoundShaderT(const std::string& SoundShaderName="");
48 
49  /// Constructor to create a sound shader from a scriptfile using the passed TextParser.
50  /// This constructor is used by the sound shader manager to load sound shaders from script files.
51  /// Throws TextParserT::ParseError on failure.
52  /// @param SoundShaderName Name of the sound shader as specified in the material script.
53  /// @param TextParser The textparser that is currently parsing a sound shader script (must be at the position of
54  /// this sound shaders definition).
55  /// @param ModDir The directory of the MOD this shader is created in relative to the executables directory.
56  SoundShaderT(const std::string& SoundShaderName, TextParserT& TextParser, const std::string& ModDir);
57 
58 
59  const std::string Name; ///< The name of the sound shader.
60  std::string AudioFile; ///< The sound file this shader is associated with.
61  float InnerVolume; ///< The volume of this sound (inside its sound cone/at minimal distance). 1.0 meaning 100% volume and 0.0 mute sound.
62  float OuterVolume; ///< The sounds volume if listener is outside the sound cone.
63  float InnerConeAngle; ///< The inner angle of the cone in which the sound is emited at normal volume.
64  float OuterConeAngle; ///< The outer angle of the cone outside which the sound is emited at outside volume.
65  float MinDistance; ///< The minimum distance that the sound will cease to continue growing louder at (stays at max. volume).
66  float MaxDistance; ///< The maximum distance that the sound will cease to attenuate.
67  int NrOfLoops; ///< The number of times this sound should be looped. -1 for infinite, 1 for one time sounds.
68  float Pause; ///< Pause in seconds between two loops.
69  float RollOfFactor; ///< The factor at which the sound is attenuated when listener is outside min distance.
70  float Pitch; ///< Pitch muliplier for this sound.
71  unsigned int Priority; ///< Priority for sounds using this shader (higher values mean higher priority).
72  SoundGroupE SoundGroup; ///< Determines the group this sound belongs to.
73  LoadTypeE LoadType; ///< Determines the way this sound shaders file is loaded into memory.
74 };
75 
76 #endif
SoundGroupE
SoundType is used to change properties of all sounds from a specific type in the game code...
Definition: SoundShader.hpp:25
float RollOfFactor
The factor at which the sound is attenuated when listener is outside min distance.
Definition: SoundShader.hpp:69
The sound system decides how to load the sound file associated with this shader.
Definition: SoundShader.hpp:36
float OuterVolume
The sounds volume if listener is outside the sound cone.
Definition: SoundShader.hpp:62
Effects like gunshots etc.
Definition: SoundShader.hpp:28
Ambient sounds like birds.
Definition: SoundShader.hpp:30
SoundGroupE SoundGroup
Determines the group this sound belongs to.
Definition: SoundShader.hpp:72
unsigned int Priority
Priority for sounds using this shader (higher values mean higher priority).
Definition: SoundShader.hpp:71
SoundShaderT(const std::string &SoundShaderName="")
Default constructor used to create an "empty" sound shader with default parameters.
Definition: SoundShader.cpp:12
float InnerConeAngle
The inner angle of the cone in which the sound is emited at normal volume.
Definition: SoundShader.hpp:63
int NrOfLoops
The number of times this sound should be looped. -1 for infinite, 1 for one time sounds.
Definition: SoundShader.hpp:67
float InnerVolume
The volume of this sound (inside its sound cone/at minimal distance). 1.0 meaning 100% volume and 0...
Definition: SoundShader.hpp:61
Player sounds like footsteps etc.
Definition: SoundShader.hpp:29
std::string AudioFile
The sound file this shader is associated with.
Definition: SoundShader.hpp:60
float Pitch
Pitch muliplier for this sound.
Definition: SoundShader.hpp:70
float Pause
Pause in seconds between two loops.
Definition: SoundShader.hpp:68
Load whole sound decrompressed into memory (used for small files).
Definition: SoundShader.hpp:37
LoadTypeE LoadType
Determines the way this sound shaders file is loaded into memory.
Definition: SoundShader.hpp:73
float OuterConeAngle
The outer angle of the cone outside which the sound is emited at outside volume.
Definition: SoundShader.hpp:64
const std::string Name
The name of the sound shader.
Definition: SoundShader.hpp:59
float MaxDistance
The maximum distance that the sound will cease to attenuate.
Definition: SoundShader.hpp:66
float MinDistance
The minimum distance that the sound will cease to continue growing louder at (stays at max...
Definition: SoundShader.hpp:65
Stream sound into memory (decrompressed).
Definition: SoundShader.hpp:38
LoadTypeE
Determines how a sound file is loaded into memory.
Definition: SoundShader.hpp:34
Background music.
Definition: SoundShader.hpp:27
This is a class for parsing text.
Definition: TextParser.hpp:21
Load whole sound compressed into memory (lower memory usage, but higher CPU usage).
Definition: SoundShader.hpp:39
A SoundShader is a description of a sound with various properties.
Definition: SoundShader.hpp:19