MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / SoundEffect

Function SoundEffect

TombEngine/Sound/sound.cpp:168–337  ·  view source on GitHub ↗

TODO: Use std::optional for pose argument.

Source from the content-addressed store, hash-verified

166
167// TODO: Use std::optional for pose argument.
168bool SoundEffect(int soundID, Pose* pose, SoundEnvironment soundEnv, float pitchMult, float gainMult)
169{
170 if (!g_Configuration.EnableSound)
171 return false;
172
173 if (soundID >= g_Level.SoundMap.size())
174 return false;
175
176 if (BASS_GetDevice() == -1)
177 return false;
178
179 // Test if sound effect environment matches camera environment.
180 if (soundEnv != SoundEnvironment::Always)
181 {
182 bool isCameraUnderwater = TestEnvironment(ENV_FLAG_WATER, Camera.pos.RoomNumber);
183 if ((soundEnv == SoundEnvironment::Underwater && !isCameraUnderwater) ||
184 (soundEnv != SoundEnvironment::Underwater && isCameraUnderwater))
185 {
186 return false;
187 }
188 }
189
190 // Get actual sample index from sound map.
191 int sampleIndex = g_Level.SoundMap[soundID];
192
193 // -1 means no such effect exists in level file.Set to -2 afterwards to prevent further debug message firings.
194 if (sampleIndex == -1)
195 {
196 TENLog("Missing sound effect " + std::to_string(soundID), LogLevel::Warning);
197 g_Level.SoundMap[soundID] = -2;
198 return false;
199 }
200 else if (sampleIndex == -2)
201 {
202 return false;
203 }
204
205 const auto& sample = g_Level.SoundDetails[sampleIndex];
206 if (sample.Number < 0)
207 {
208 TENLog("No valid samples count for effect " + std::to_string(sampleIndex), LogLevel::Warning);
209 return false;
210 }
211
212 // Assign common sample flags.
213 DWORD sampleFlags = SOUND_SAMPLE_FLAGS;
214
215 // Test play chance.
216 if (sample.Randomness && ((GetRandomControl() & UCHAR_MAX) > sample.Randomness))
217 return false;
218
219 // Apply 3D attribute only to sound with position property.
220 if (pose != nullptr)
221 sampleFlags |= BASS_SAMPLE_3D;
222
223 // Set and randomize volume (if needed).
224 float gain = ((float)sample.Volume / UCHAR_MAX) * std::clamp(gainMult, SOUND_MIN_PARAM_MULTIPLIER, SOUND_MAX_PARAM_MULTIPLIER);
225 if ((sample.Flags & SOUND_FLAG_RND_GAIN))

Callers 15

SayNoFunction · 0.85
PlaySoundSourcesFunction · 0.85
ControlSpinningBladeFunction · 0.85
DoSpearGuardianAttackFunction · 0.85
SmallSpiderControlFunction · 0.85
MonkControlFunction · 0.85
SkidooManControlFunction · 0.85
ControlBartoliFunction · 0.85
ControlDragonFunction · 0.85
DoSwordGuardianFlyEffectFunction · 0.85
TestSkidooDismountFunction · 0.85
SkidooControlFunction · 0.85

Calls 15

TestEnvironmentFunction · 0.85
TENLogFunction · 0.85
to_stringFunction · 0.85
GetRandomControlFunction · 0.85
GenerateFloatFunction · 0.85
Sound_DistanceToListenerFunction · 0.85
Sound_AttenuateFunction · 0.85
Sound_EffectIsPlayingFunction · 0.85
Sound_FreeSlotFunction · 0.85
Sound_GetFreeSlotFunction · 0.85

Tested by 1

TestSkidooDismountFunction · 0.68