OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4SoundModifiers.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2015-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Plays sound effects */
19 
20 #ifndef INC_C4SoundModifiers
21 #define INC_C4SoundModifiers
22 
24 #include "script/C4PropList.h"
25 
27 {
28 public:
29  enum Type
30  {
31  C4SMT_None = 0x0,
32  C4SMT_Reverb = 0x1,
33  C4SMT_Echo = 0x4,
35  C4SMT_Max = 0xc // value of largest type
36  };
37 
38  C4SoundModifier(C4PropList *in_props);
39  virtual ~C4SoundModifier();
40 
41 private:
42  // associated prop list for script interface
43  C4Value props;
44 
45  // number of sound instances currently using the modifier
46  int32_t instance_count;
47 
48  // set to true for sound modifiers released by script but with instance_count>0
49  bool released;
50 
51 #if AUDIO_TK == AUDIO_TK_OPENAL
52 protected:
53  ALuint effect, slot;
54 #endif
55 
56 protected:
57  // get a property from the props proplist and divide by factor for float representation
58  float GetFloatProp(C4PropertyName key, float ratio, float default_value);
59  bool GetBoolProp(C4PropertyName key, bool default_value);
60 
61 public:
62  // update from props and mark as not released
63  virtual void Update();
64 
65  // effect is deleted when marked for release and no instances are running
66  void Release() {
67  if (!instance_count) delete this; else { released = true; props.Set0(); }
68  }
69  void AddRef() { ++instance_count; }
70  void DelRef() { if (!--instance_count && released) delete this; }
71  int32_t GetRefCount() const { return instance_count; }
72 
73  const C4PropList *GetProps() const { return props._getPropList(); }
74 
75 #if AUDIO_TK == AUDIO_TK_OPENAL
76  // apply to AL buffer
77  void ApplyTo(ALuint source);
78 #endif
79 };
80 
81 // Reverb sound modifier: Adds effect of sound reflections in enclosed spaces
83 {
84 public:
86 
87 public:
88  void Update() override;
89 };
90 
91 // Echo: Repeats dampened version of input signal
93 {
94 public:
96 
97 public:
98  void Update() override;
99 };
100 
101 // Equalizer: Allows to specify low- mid- and high-frequency amplification and reduction
103 {
104 public:
106 
107 public:
108  void Update() override;
109 };
110 
111 // member of C4SoundSystem: Handles modifier management and EFX initialization
113 {
114 private:
115  bool is_initialized;
116  bool is_effect_available[C4SoundModifier::C4SMT_Max+1];
117  std::list<C4SoundModifier *> sound_modifiers;
118  std::vector<C4SoundModifier *> global_modifiers; // global modifiers indexed by player number+1. Global modifier for all players in index 0.
119 public:
121  void Init();
122  void Add(C4SoundModifier *new_modifier) { sound_modifiers.push_back(new_modifier); }
123  void Remove(C4SoundModifier *prev_modifier) { sound_modifiers.remove(prev_modifier); }
124  C4SoundModifier *Get(class C4PropList *props, bool create_if_not_found);
125  void Clear();
126  void SetGlobalModifier(C4SoundModifier *new_modifier, int32_t player_index);
127  C4SoundModifier *GetGlobalModifier(int32_t player_index) const;
128 
129 };
130 
131 #endif
C4SoundModifierEqualizer(C4PropList *in_props)
float GetFloatProp(C4PropertyName key, float ratio, float default_value)
void Set0()
Definition: C4Value.h:336
void Update() override
C4SoundModifierReverb(C4PropList *in_props)
C4SoundModifier * Get(class C4PropList *props, bool create_if_not_found)
virtual ~C4SoundModifier()
C4SoundModifier * GetGlobalModifier(int32_t player_index) const
void Remove(C4SoundModifier *prev_modifier)
C4PropertyName
void SetGlobalModifier(C4SoundModifier *new_modifier, int32_t player_index)
const C4PropList * GetProps() const
void ApplyTo(ALuint source)
bool GetBoolProp(C4PropertyName key, bool default_value)
C4SoundModifier(C4PropList *in_props)
C4SoundModifierEcho(C4PropList *in_props)
void Add(C4SoundModifier *new_modifier)
virtual void Update()
C4PropList * _getPropList() const
Definition: C4Value.h:129
int32_t GetRefCount() const