-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEffect.cpp
More file actions
155 lines (116 loc) · 3.09 KB
/
Effect.cpp
File metadata and controls
155 lines (116 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "Common.h"
ALuint Extension::EffectGetFromID(int ID)
{
map<int, ALuint>::iterator FoundEffect = EffectMap.find(ID);
//An effect with the ID was found, return its handle.
if(FoundEffect != EffectMap.end())
return FoundEffect->second;
//Nothing found, return zero.
return 0;
}
ALenum Extension::EffectGetParameterIndex(const char* Name)
{
if(!Effect)
return 0;
const char* EffectName = 0;
//Find the current effect type.
ALint EffectType;
alGetEffecti(Effect, AL_EFFECT_TYPE, &EffectType);
switch(EffectType)
{
case AL_EFFECT_ECHO: EffectName = "ECHO"; break;
case AL_EFFECT_EAXREVERB: EffectName = "EAXREVERB"; break;
case AL_EFFECT_RING_MODULATOR: EffectName = "RING_MODULATOR"; break;
}
if(!EffectName)
return 0;
//Make parameter name CONSTANT_LIKE.
char CapitalizedName[24] = {0};
for(int i = 0; Name[i]; ++i)
CapitalizedName[i] = Name[i] == ' ' ? '_' : toupper(Name[i]);
//Construct OpenAL enum string.
char EnumName[64] = {'A','L','_', 0};
strcat(EnumName, EffectName);
strcat(EnumName,"_");
strcat(EnumName, CapitalizedName);
return alGetEnumValue(EnumName);
}
void Extension::EffectCreate(int Type)
{
//Generate an object.
alGenEffects(1, &Effect);
int ID = ++LastEffectIndex;
//Store the effect in the map and assign the effect type to it.
if(Effect)
{
//Delete the old effect in the map.
//if(EffectMap.find(ID) != EffectMap.end())
// alDeleteEffects(1, &EffectMap[ID]);
EffectMap[ID] = Effect;
alEffecti(Effect, AL_EFFECT_TYPE, Type);
}
//Effect and aux slots are merged for now.
AuxEffectSlotCreate(ID);
AuxEffectSlotLoadEffect(Effect);
}
/* Actions */
void Extension::EffectSelectByID(int ID)
{
Effect = EffectGetFromID(ID);
//Effect and aux slots are merged for now.
AuxEffectSlotSelectByID(ID);
}
void Extension::EffectCreateReverb()
{
EffectCreate(AL_EFFECT_EAXREVERB);
}
void Extension::EffectCreateEcho()
{
EffectCreate(AL_EFFECT_ECHO);
}
void Extension::EffectCreateRingModulator()
{
EffectCreate(AL_EFFECT_RING_MODULATOR);
}
void Extension::EffectSetFloatParameter(const char* Name, float Value)
{
if(!Effect || !*Name || strlen(Name) >= 24)
return;
//Try to find the parameter enum.
ALenum Parameter = EffectGetParameterIndex(Name);
//On success, set the parameter.
if(Parameter)
{
alEffectf(Effect, Parameter, Value);
//Effect and aux slots are merged for now.
AuxEffectSlotLoadEffect(Effect);
}
}
void Extension::EffectSetIntParameter(const char* Name, int Value)
{
if(!Effect || !*Name || strlen(Name) >= 24)
return;
//Try to find the parameter enum.
ALenum Parameter = EffectGetParameterIndex(Name);
//On success, set the parameter.
if(Parameter)
{
alEffecti(Effect, Parameter, Value);
//Effect and aux slots are merged for now.
AuxEffectSlotLoadEffect(Effect);
}
}
void Extension::EffectLoadReverbPreset(const char* Preset)
{
if(!Effect)
return;
//This function is so ugly that it's in Globals.cpp!
LoadReverbPreset(Effect, Preset);
//Effect and aux slots are merged for now.
AuxEffectSlotLoadEffect(Effect);
}
/* Expressions */
int Extension::EffectGetLast()
{
return LastEffectIndex;
}