Add options to reverse local X and Y coordinates

To go along with reverse-z on the other axii. This is only for games that have
position/orientation errors causing top-bottom (or left-right) inversion.
master
Chris Robinson 2022-03-10 22:37:02 -08:00
parent a2d34e4c2a
commit e28937d1f6
5 changed files with 36 additions and 11 deletions

View File

@ -1121,14 +1121,20 @@ void alc_initconfig(void)
AllowRTTimeLimit = *limopt;
CompatFlagBitset compatflags{};
if(auto optval = al::getenv("__ALSOFT_REVERSE_Z"))
auto checkflag = [](const char *envname, const char *optname) -> bool
{
if(al::strcasecmp(optval->c_str(), "true") == 0
|| strtol(optval->c_str(), nullptr, 0) == 1)
compatflags.set(CompatFlags::ReverseZ);
}
else if(GetConfigValueBool(nullptr, "game_compat", "reverse-z", false))
compatflags.set(CompatFlags::ReverseZ);
if(auto optval = al::getenv(envname))
{
if(al::strcasecmp(optval->c_str(), "true") == 0
|| strtol(optval->c_str(), nullptr, 0) == 1)
return true;
return false;
}
return GetConfigValueBool(nullptr, "game_compat", optname, false);
};
compatflags.set(CompatFlags::ReverseX, checkflag("__ALSOFT_REVERSE_X", "reverse-x"));
compatflags.set(CompatFlags::ReverseY, checkflag("__ALSOFT_REVERSE_Y", "reverse-y"));
compatflags.set(CompatFlags::ReverseZ, checkflag("__ALSOFT_REVERSE_Z", "reverse-z"));
aluInit(compatflags);
Voice::InitMixer(ConfigValueStr(nullptr, nullptr, "resampler"));

View File

@ -128,9 +128,11 @@ float InitConeScale()
/* Cone scalar */
const float ConeScale{InitConeScale()};
/* Localized Z scalar for mono sources (initialized in aluInit, after
/* Localized scalars for mono sources (initialized in aluInit, after
* configuration is loaded).
*/
float XScale{1.0f};
float YScale{1.0f};
float ZScale{1.0f};
} // namespace
@ -245,6 +247,8 @@ inline ResamplerFunc SelectResampler(Resampler resampler, uint increment)
void aluInit(CompatFlagBitset flags)
{
MixDirectHrtf = SelectHrtfMixer();
XScale = flags.test(CompatFlags::ReverseX) ? -1.0f : 1.0f;
YScale = flags.test(CompatFlags::ReverseY) ? -1.0f : 1.0f;
ZScale = flags.test(CompatFlags::ReverseZ) ? -1.0f : 1.0f;
}
@ -1516,7 +1520,7 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ContextBa
else if(Distance > 0.0f)
spread = std::asin(props->Radius/Distance) * 2.0f;
CalcPanningAndFilters(voice, ToSource[0], ToSource[1], ToSource[2]*ZScale,
CalcPanningAndFilters(voice, ToSource[0]*XScale, ToSource[1]*YScale, ToSource[2]*ZScale,
Distance*context->mParams.MetersPerUnit, spread, DryGain, WetGain, SendSlots, props,
context->mParams, Device);
}

View File

@ -16,6 +16,8 @@ constexpr float GainMixMax{1000.0f}; /* +60dB */
enum CompatFlags : uint8_t {
ReverseX,
ReverseY,
ReverseZ,
Count

View File

@ -598,6 +598,14 @@
##
[game_compat]
## reverse-x: (global)
# Reverses the local X (left-right) position of 3D sound sources.
#reverse-x = false
## reverse-y: (global)
# Reverses the local Y (up-down) position of 3D sound sources.
#reverse-y = false
## reverse-z: (global)
# Reverses the local Z (front-back) position of 3D sound sources.
#reverse-z = false

View File

@ -64,8 +64,13 @@ to it before passing in 3D coordinates. Depending on how exactly this is done,
it can cause correct output for stereo but incorrect Z panning for surround
sound (i.e., sounds that are supposed to be behind you sound like they're in
front, and vice-versa). Setting this to "true" or "1" will negate the localized
Z coordinate to attempt to fix output for apps that have incorrect front/back
panning.
Z coordinate to flip front/back panning for 3D sources.
__ALSOFT_REVERSE_Y
Same as for __ALSOFT_REVERSE_Z, but for Y (up/down) panning.
__ALSOFT_REVERSE_X
Same as for __ALSOFT_REVERSE_Z, but for X (left/right) panning.
__ALSOFT_SUSPEND_CONTEXT
Due to the OpenAL spec not being very clear about them, behavior of the