diff options
-rw-r--r-- | al/state.cpp | 327 |
1 files changed, 118 insertions, 209 deletions
diff --git a/al/state.cpp b/al/state.cpp index 777492ef..7b7377f7 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -248,56 +248,32 @@ END_API_FUNC AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum pname) START_API_FUNC { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return AL_FALSE; - - std::lock_guard<std::mutex> _{context->mPropLock}; - ALboolean value{AL_FALSE}; switch(pname) { case AL_DOPPLER_FACTOR: - if(context->mDopplerFactor != 0.0f) - value = AL_TRUE; - break; - case AL_DOPPLER_VELOCITY: - context->debugMessage(DebugSource::API, DebugType::DeprecatedBehavior, 0, - DebugSeverity::Medium, -1, - "AL_DOPPLER_VELOCITY is deprecated in AL 1.1, use AL_SPEED_OF_SOUND; " - "AL_DOPPLER_VELOCITY -> AL_SPEED_OF_SOUND / 343.3f"); - if(context->mDopplerVelocity != 0.0f) - value = AL_TRUE; - break; + case AL_SPEED_OF_SOUND: + case AL_GAIN_LIMIT_SOFT: + return alGetFloat(pname) != 0.0f; case AL_DISTANCE_MODEL: - if(context->mDistanceModel == DistanceModel::Default) - value = AL_TRUE; - break; + case AL_NUM_RESAMPLERS_SOFT: + case AL_DEFAULT_RESAMPLER_SOFT: + return alGetInteger(pname) != 0; + } - case AL_SPEED_OF_SOUND: - if(context->mSpeedOfSound != 0.0f) - value = AL_TRUE; - break; + ContextRef context{GetContextRef()}; + if(!context) UNLIKELY return AL_FALSE; + std::lock_guard<std::mutex> _{context->mPropLock}; + ALboolean value{AL_FALSE}; + switch(pname) + { case AL_DEFERRED_UPDATES_SOFT: if(context->mDeferUpdates) value = AL_TRUE; break; - case AL_GAIN_LIMIT_SOFT: - if(GainMixMax/context->mGainBoost != 0.0f) - value = AL_TRUE; - break; - - case AL_NUM_RESAMPLERS_SOFT: - /* Always non-0. */ - value = AL_TRUE; - break; - - case AL_DEFAULT_RESAMPLER_SOFT: - value = static_cast<int>(ResamplerDefault) ? AL_TRUE : AL_FALSE; - break; - default: context->setError(AL_INVALID_VALUE, "Invalid boolean property 0x%04x", pname); } @@ -309,50 +285,30 @@ END_API_FUNC AL_API ALdouble AL_APIENTRY alGetDouble(ALenum pname) START_API_FUNC { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return 0.0; - - std::lock_guard<std::mutex> _{context->mPropLock}; - ALdouble value{0.0}; switch(pname) { case AL_DOPPLER_FACTOR: - value = context->mDopplerFactor; - break; - case AL_DOPPLER_VELOCITY: - context->debugMessage(DebugSource::API, DebugType::DeprecatedBehavior, 0, - DebugSeverity::Medium, -1, - "AL_DOPPLER_VELOCITY is deprecated in AL 1.1, use AL_SPEED_OF_SOUND; " - "AL_DOPPLER_VELOCITY -> AL_SPEED_OF_SOUND / 343.3f"); - value = context->mDopplerVelocity; - break; - - case AL_DISTANCE_MODEL: - value = static_cast<ALdouble>(ALenumFromDistanceModel(context->mDistanceModel)); - break; - case AL_SPEED_OF_SOUND: - value = context->mSpeedOfSound; - break; + case AL_GAIN_LIMIT_SOFT: + return alGetFloat(pname); case AL_DEFERRED_UPDATES_SOFT: - if(context->mDeferUpdates) - value = static_cast<ALdouble>(AL_TRUE); - break; - - case AL_GAIN_LIMIT_SOFT: - value = ALdouble{GainMixMax}/context->mGainBoost; - break; + return alGetBoolean(pname) ? 1.0 : 0.0; + case AL_DISTANCE_MODEL: case AL_NUM_RESAMPLERS_SOFT: - value = static_cast<ALdouble>(Resampler::Max) + 1.0; - break; - case AL_DEFAULT_RESAMPLER_SOFT: - value = static_cast<ALdouble>(ResamplerDefault); - break; + return alGetInteger(pname); + } + + ContextRef context{GetContextRef()}; + if(!context) UNLIKELY return 0.0; + std::lock_guard<std::mutex> _{context->mPropLock}; + ALdouble value{0.0}; + switch(pname) + { default: context->setError(AL_INVALID_VALUE, "Invalid double property 0x%04x", pname); } @@ -364,6 +320,18 @@ END_API_FUNC AL_API ALfloat AL_APIENTRY alGetFloat(ALenum pname) START_API_FUNC { + switch(pname) + { + case AL_DISTANCE_MODEL: + case AL_NUM_RESAMPLERS_SOFT: + case AL_DEFAULT_RESAMPLER_SOFT: + return static_cast<ALfloat>(alGetInteger(pname)); + break; + + case AL_DEFERRED_UPDATES_SOFT: + return alGetBoolean(pname) ? 1.0f : 0.0f; + } + ContextRef context{GetContextRef()}; if(!context) UNLIKELY return 0.0f; @@ -383,29 +351,12 @@ START_API_FUNC value = context->mDopplerVelocity; break; - case AL_DISTANCE_MODEL: - value = static_cast<ALfloat>(ALenumFromDistanceModel(context->mDistanceModel)); - break; - case AL_SPEED_OF_SOUND: value = context->mSpeedOfSound; break; - case AL_DEFERRED_UPDATES_SOFT: - if(context->mDeferUpdates) - value = static_cast<ALfloat>(AL_TRUE); - break; - case AL_GAIN_LIMIT_SOFT: - value = GainMixMax/context->mGainBoost; - break; - - case AL_NUM_RESAMPLERS_SOFT: - value = static_cast<ALfloat>(Resampler::Max) + 1.0f; - break; - - case AL_DEFAULT_RESAMPLER_SOFT: - value = static_cast<ALfloat>(ResamplerDefault); + value = GainMixMax / context->mGainBoost; break; default: @@ -419,6 +370,18 @@ END_API_FUNC AL_API ALint AL_APIENTRY alGetInteger(ALenum pname) START_API_FUNC { + switch(pname) + { + case AL_DOPPLER_FACTOR: + case AL_DOPPLER_VELOCITY: + case AL_SPEED_OF_SOUND: + case AL_GAIN_LIMIT_SOFT: + return static_cast<ALint>(alGetFloat(pname)); + + case AL_DEFERRED_UPDATES_SOFT: + return alGetBoolean(pname); + } + ContextRef context{GetContextRef()}; if(!context) UNLIKELY return 0; @@ -426,41 +389,16 @@ START_API_FUNC ALint value{0}; switch(pname) { - case AL_DOPPLER_FACTOR: - value = static_cast<ALint>(context->mDopplerFactor); - break; - - case AL_DOPPLER_VELOCITY: - context->debugMessage(DebugSource::API, DebugType::DeprecatedBehavior, 0, - DebugSeverity::Medium, -1, - "AL_DOPPLER_VELOCITY is deprecated in AL 1.1, use AL_SPEED_OF_SOUND; " - "AL_DOPPLER_VELOCITY -> AL_SPEED_OF_SOUND / 343.3f"); - value = static_cast<ALint>(context->mDopplerVelocity); - break; - case AL_DISTANCE_MODEL: value = ALenumFromDistanceModel(context->mDistanceModel); break; - case AL_SPEED_OF_SOUND: - value = static_cast<ALint>(context->mSpeedOfSound); - break; - - case AL_DEFERRED_UPDATES_SOFT: - if(context->mDeferUpdates) - value = AL_TRUE; - break; - - case AL_GAIN_LIMIT_SOFT: - value = static_cast<ALint>(GainMixMax/context->mGainBoost); - break; - case AL_NUM_RESAMPLERS_SOFT: - value = static_cast<int>(Resampler::Max) + 1; + value = al::to_underlying(Resampler::Max) + 1; break; case AL_DEFAULT_RESAMPLER_SOFT: - value = static_cast<int>(ResamplerDefault); + value = al::to_underlying(ResamplerDefault); break; #ifdef ALSOFT_EAX @@ -468,30 +406,21 @@ START_API_FUNC #define EAX_ERROR "[alGetInteger] EAX not enabled." case AL_EAX_RAM_SIZE: - if (eax_g_is_enabled) - { + if(eax_g_is_enabled) value = eax_x_ram_max_size; - } else - { context->setError(AL_INVALID_VALUE, EAX_ERROR); - } - break; case AL_EAX_RAM_FREE: - if (eax_g_is_enabled) + if(eax_g_is_enabled) { auto device = context->mALDevice.get(); std::lock_guard<std::mutex> device_lock{device->BufferLock}; - value = static_cast<ALint>(device->eax_x_ram_free_size); } else - { context->setError(AL_INVALID_VALUE, EAX_ERROR); - } - break; #undef EAX_ERROR @@ -509,50 +438,30 @@ END_API_FUNC AL_API ALint64SOFT AL_APIENTRY alGetInteger64SOFT(ALenum pname) START_API_FUNC { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return 0_i64; - - std::lock_guard<std::mutex> _{context->mPropLock}; - ALint64SOFT value{0}; switch(pname) { case AL_DOPPLER_FACTOR: - value = static_cast<ALint64SOFT>(context->mDopplerFactor); - break; - case AL_DOPPLER_VELOCITY: - context->debugMessage(DebugSource::API, DebugType::DeprecatedBehavior, 0, - DebugSeverity::Medium, -1, - "AL_DOPPLER_VELOCITY is deprecated in AL 1.1, use AL_SPEED_OF_SOUND; " - "AL_DOPPLER_VELOCITY -> AL_SPEED_OF_SOUND / 343.3f"); - value = static_cast<ALint64SOFT>(context->mDopplerVelocity); - break; - - case AL_DISTANCE_MODEL: - value = ALenumFromDistanceModel(context->mDistanceModel); - break; - case AL_SPEED_OF_SOUND: - value = static_cast<ALint64SOFT>(context->mSpeedOfSound); - break; + case AL_GAIN_LIMIT_SOFT: + return static_cast<ALint64SOFT>(alGetFloat(pname)); case AL_DEFERRED_UPDATES_SOFT: - if(context->mDeferUpdates) - value = AL_TRUE; - break; - - case AL_GAIN_LIMIT_SOFT: - value = static_cast<ALint64SOFT>(GainMixMax/context->mGainBoost); - break; + return alGetBoolean(pname); + case AL_DISTANCE_MODEL: case AL_NUM_RESAMPLERS_SOFT: - value = static_cast<ALint64SOFT>(Resampler::Max) + 1; - break; - case AL_DEFAULT_RESAMPLER_SOFT: - value = static_cast<ALint64SOFT>(ResamplerDefault); - break; + return alGetInteger(pname); + } + + ContextRef context{GetContextRef()}; + if(!context) UNLIKELY return 0_i64; + std::lock_guard<std::mutex> _{context->mPropLock}; + ALint64SOFT value{0}; + switch(pname) + { default: context->setError(AL_INVALID_VALUE, "Invalid integer64 property 0x%04x", pname); } @@ -602,16 +511,16 @@ START_API_FUNC { switch(pname) { - case AL_DOPPLER_FACTOR: - case AL_DOPPLER_VELOCITY: - case AL_DISTANCE_MODEL: - case AL_SPEED_OF_SOUND: - case AL_DEFERRED_UPDATES_SOFT: - case AL_GAIN_LIMIT_SOFT: - case AL_NUM_RESAMPLERS_SOFT: - case AL_DEFAULT_RESAMPLER_SOFT: - values[0] = alGetBoolean(pname); - return; + case AL_DOPPLER_FACTOR: + case AL_DOPPLER_VELOCITY: + case AL_DISTANCE_MODEL: + case AL_SPEED_OF_SOUND: + case AL_DEFERRED_UPDATES_SOFT: + case AL_GAIN_LIMIT_SOFT: + case AL_NUM_RESAMPLERS_SOFT: + case AL_DEFAULT_RESAMPLER_SOFT: + values[0] = alGetBoolean(pname); + return; } } @@ -635,16 +544,16 @@ START_API_FUNC { switch(pname) { - case AL_DOPPLER_FACTOR: - case AL_DOPPLER_VELOCITY: - case AL_DISTANCE_MODEL: - case AL_SPEED_OF_SOUND: - case AL_DEFERRED_UPDATES_SOFT: - case AL_GAIN_LIMIT_SOFT: - case AL_NUM_RESAMPLERS_SOFT: - case AL_DEFAULT_RESAMPLER_SOFT: - values[0] = alGetDouble(pname); - return; + case AL_DOPPLER_FACTOR: + case AL_DOPPLER_VELOCITY: + case AL_DISTANCE_MODEL: + case AL_SPEED_OF_SOUND: + case AL_DEFERRED_UPDATES_SOFT: + case AL_GAIN_LIMIT_SOFT: + case AL_NUM_RESAMPLERS_SOFT: + case AL_DEFAULT_RESAMPLER_SOFT: + values[0] = alGetDouble(pname); + return; } } @@ -668,16 +577,16 @@ START_API_FUNC { switch(pname) { - case AL_DOPPLER_FACTOR: - case AL_DOPPLER_VELOCITY: - case AL_DISTANCE_MODEL: - case AL_SPEED_OF_SOUND: - case AL_DEFERRED_UPDATES_SOFT: - case AL_GAIN_LIMIT_SOFT: - case AL_NUM_RESAMPLERS_SOFT: - case AL_DEFAULT_RESAMPLER_SOFT: - values[0] = alGetFloat(pname); - return; + case AL_DOPPLER_FACTOR: + case AL_DOPPLER_VELOCITY: + case AL_DISTANCE_MODEL: + case AL_SPEED_OF_SOUND: + case AL_DEFERRED_UPDATES_SOFT: + case AL_GAIN_LIMIT_SOFT: + case AL_NUM_RESAMPLERS_SOFT: + case AL_DEFAULT_RESAMPLER_SOFT: + values[0] = alGetFloat(pname); + return; } } @@ -701,16 +610,16 @@ START_API_FUNC { switch(pname) { - case AL_DOPPLER_FACTOR: - case AL_DOPPLER_VELOCITY: - case AL_DISTANCE_MODEL: - case AL_SPEED_OF_SOUND: - case AL_DEFERRED_UPDATES_SOFT: - case AL_GAIN_LIMIT_SOFT: - case AL_NUM_RESAMPLERS_SOFT: - case AL_DEFAULT_RESAMPLER_SOFT: - values[0] = alGetInteger(pname); - return; + case AL_DOPPLER_FACTOR: + case AL_DOPPLER_VELOCITY: + case AL_DISTANCE_MODEL: + case AL_SPEED_OF_SOUND: + case AL_DEFERRED_UPDATES_SOFT: + case AL_GAIN_LIMIT_SOFT: + case AL_NUM_RESAMPLERS_SOFT: + case AL_DEFAULT_RESAMPLER_SOFT: + values[0] = alGetInteger(pname); + return; } } @@ -734,16 +643,16 @@ START_API_FUNC { switch(pname) { - case AL_DOPPLER_FACTOR: - case AL_DOPPLER_VELOCITY: - case AL_DISTANCE_MODEL: - case AL_SPEED_OF_SOUND: - case AL_DEFERRED_UPDATES_SOFT: - case AL_GAIN_LIMIT_SOFT: - case AL_NUM_RESAMPLERS_SOFT: - case AL_DEFAULT_RESAMPLER_SOFT: - values[0] = alGetInteger64SOFT(pname); - return; + case AL_DOPPLER_FACTOR: + case AL_DOPPLER_VELOCITY: + case AL_DISTANCE_MODEL: + case AL_SPEED_OF_SOUND: + case AL_DEFERRED_UPDATES_SOFT: + case AL_GAIN_LIMIT_SOFT: + case AL_NUM_RESAMPLERS_SOFT: + case AL_DEFAULT_RESAMPLER_SOFT: + values[0] = alGetInteger64SOFT(pname); + return; } } |