From 813457aa713abb7cf4defdc2c93ed45897cd5e4f Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Mon, 16 Feb 2015 00:10:11 -0400 Subject: [PATCH] Pre-emptive fix for an attenuation distance issue in iOS' OpenAL implementation. --HG-- branch : minor --- src/modules/audio/openal/Source.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/modules/audio/openal/Source.cpp b/src/modules/audio/openal/Source.cpp index 4abad116f..9c852adfe 100644 --- a/src/modules/audio/openal/Source.cpp +++ b/src/modules/audio/openal/Source.cpp @@ -25,6 +25,7 @@ // STD #include #include +#include namespace love { @@ -33,6 +34,13 @@ namespace audio namespace openal { +#ifdef LOVE_IOS +// OpenAL on iOS barfs if the max distance is +inf. +static const float MAX_ATTENUATION_DISTANCE = 1000000.0f; +#else +static const float MAX_ATTENUATION_DISTANCE = FLT_MAX; +#endif + class InvalidFormatException : public love::Exception { public: @@ -81,7 +89,7 @@ Source::Source(Pool *pool, love::sound::SoundData *soundData) , maxVolume(1.0f) , referenceDistance(1.0f) , rolloffFactor(1.0f) - , maxDistance(FLT_MAX) + , maxDistance(MAX_ATTENUATION_DISTANCE) , cone() , offsetSamples(0) , offsetSeconds(0) @@ -120,7 +128,7 @@ Source::Source(Pool *pool, love::sound::Decoder *decoder) , maxVolume(1.0f) , referenceDistance(1.0f) , rolloffFactor(1.0f) - , maxDistance(FLT_MAX) + , maxDistance(MAX_ATTENUATION_DISTANCE) , cone() , offsetSamples(0) , offsetSeconds(0) @@ -872,6 +880,8 @@ void Source::setMaxDistance(float distance) if (channels > 1) throw SpatialSupportException(); + distance = std::min(distance, MAX_ATTENUATION_DISTANCE); + if (valid) { alSourcef(source, AL_MAX_DISTANCE, distance);