Position is assumed to be in 'map' units, gainMultiplier within 0 and 1
| 17 | |
| 18 | // Position is assumed to be in 'map' units, gainMultiplier within 0 and 1 |
| 19 | void 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 | } |
| 50 | void SoundBackend::setListenerPosition(Vec3<float> position) { this->listenerPosition = position; } |
| 51 | }; // namespace OpenApoc |
no test coverage detected