MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / playSample

Method playSample

framework/sound.cpp:19–49  ·  view source on GitHub ↗

Position is assumed to be in 'map' units, gainMultiplier within 0 and 1

Source from the content-addressed store, hash-verified

17
18// Position is assumed to be in 'map' units, gainMultiplier within 0 and 1
19void SoundBackend::playSample(sp<Sample> sample, Vec3<float> position, float gainMultiplier)
20{
21
22 float distance = glm::length(position - this->listenerPosition);
23
24 /*FIXME: Quick hack at trying to get scaling based on the 3d location of the sample being
25 * played*/
26 float gain = 1.0f;
27
28 for (auto &lutEntry : positionalAudioLUT)
29 {
30 float lutDistance = lutEntry.first;
31 float lutGain = lutEntry.second;
32 if (distance <= lutDistance)
33 {
34 float factor = distance / lutDistance;
35 float newGain = mix(gain, lutGain, factor);
36 gain = newGain;
37 break;
38 }
39 else
40 {
41 gain = lutGain;
42 distance -= lutDistance;
43 }
44 }
45 LogInfo("Playing sample at {%f,%f,%f} - distance to camera %f, gain %f", position.x, position.y,
46 position.z, distance, gain);
47 // Anything within CLOSE_RANGE is at full volume
48 this->playSample(sample, gain * gainMultiplier);
49}
50void SoundBackend::setListenerPosition(Vec3<float> position) { this->listenerPosition = position; }
51}; // namespace OpenApoc

Callers 15

dieMethod · 0.45
startMethod · 0.45
startMethod · 0.45
updateFallingMethod · 0.45
updateSlidingMethod · 0.45
leaveDimensionGateMethod · 0.45
enterDimensionGateMethod · 0.45
dieMethod · 0.45
applyDamageMethod · 0.45
handleProjectileHitMethod · 0.45
fireMethod · 0.45
fireMethod · 0.45

Calls 1

mixFunction · 0.85

Tested by

no test coverage detected