aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/ALu.c38
-rw-r--r--Alc/panning.c16
-rw-r--r--OpenAL32/Include/alu.h10
3 files changed, 32 insertions, 32 deletions
diff --git a/Alc/ALu.c b/Alc/ALu.c
index bc48dd59..5a5e6fdf 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -679,23 +679,12 @@ static void CalcNonAttnSourceParams(ALvoice *voice, const struct ALsourceProps *
}
if(Device->Render_Mode == StereoPair)
- {
- /* Clamp X so it remains within 30 degrees of 0 or 180 degree azimuth. */
- ALfloat x = sinf(chans[c].angle) * cosf(chans[c].elevation);
- coeffs[0] = clampf(-x, -0.5f, 0.5f) + 0.5f;
- voice->Direct.Params[c].Gains.Target[0] = sqrtf(coeffs[0]) * DryGain;
- voice->Direct.Params[c].Gains.Target[1] = sqrtf(1.0f-coeffs[0]) * DryGain;
- for(j = 2;j < MAX_OUTPUT_CHANNELS;j++)
- voice->Direct.Params[c].Gains.Target[j] = 0.0f;
-
- CalcAngleCoeffs(chans[c].angle, chans[c].elevation, 0.0f, coeffs);
- }
+ CalcAnglePairwiseCoeffs(chans[c].angle, chans[c].elevation, 0.0f, coeffs);
else
- {
CalcAngleCoeffs(chans[c].angle, chans[c].elevation, 0.0f, coeffs);
- ComputePanningGains(Device->Dry, coeffs, DryGain,
- voice->Direct.Params[c].Gains.Target);
- }
+ ComputePanningGains(Device->Dry,
+ coeffs, DryGain, voice->Direct.Params[c].Gains.Target
+ );
for(i = 0;i < NumSends;i++)
{
@@ -1173,22 +1162,15 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALsourceProps *pro
if(Device->Render_Mode == StereoPair)
{
- /* Clamp X so it remains within 30 degrees of 0 or 180 degree azimuth. */
- ALfloat x = -dir[0] * (0.5f * (cosf(spread*0.5f) + 1.0f));
- x = clampf(x, -0.5f, 0.5f) + 0.5f;
- voice->Direct.Params[0].Gains.Target[0] = sqrtf(x) * DryGain;
- voice->Direct.Params[0].Gains.Target[1] = sqrtf(1.0f-x) * DryGain;
- for(i = 2;i < MAX_OUTPUT_CHANNELS;i++)
- voice->Direct.Params[0].Gains.Target[i] = 0.0f;
-
- CalcDirectionCoeffs(dir, spread, coeffs);
+ ALfloat ev = asinf(clampf(dir[1], -1.0f, 1.0f));
+ ALfloat az = atan2f(dir[0], -dir[2]);
+ CalcAnglePairwiseCoeffs(az, ev, radius, coeffs);
}
else
- {
CalcDirectionCoeffs(dir, spread, coeffs);
- ComputePanningGains(Device->Dry, coeffs, DryGain,
- voice->Direct.Params[0].Gains.Target);
- }
+ ComputePanningGains(Device->Dry,
+ coeffs, DryGain, voice->Direct.Params[0].Gains.Target
+ );
for(i = 0;i < NumSends;i++)
{
diff --git a/Alc/panning.c b/Alc/panning.c
index 72b55792..7b551100 100644
--- a/Alc/panning.c
+++ b/Alc/panning.c
@@ -202,6 +202,14 @@ void CalcAngleCoeffs(ALfloat azimuth, ALfloat elevation, ALfloat spread, ALfloat
CalcDirectionCoeffs(dir, spread, coeffs);
}
+void CalcAnglePairwiseCoeffs(ALfloat azimuth, ALfloat elevation, ALfloat spread, ALfloat coeffs[MAX_AMBI_COEFFS])
+{
+ ALfloat sign = (azimuth < 0.0f) ? -1.0f : 1.0f;
+ if(!(fabsf(azimuth) > F_PI_2))
+ azimuth = minf(fabsf(azimuth) * F_PI_2 / (F_PI/6.0f), F_PI_2) * sign;
+ CalcAngleCoeffs(azimuth, elevation, spread, coeffs);
+}
+
void ComputeAmbientGainsMC(const ChannelConfig *chancoeffs, ALsizei numchans, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
{
@@ -237,7 +245,7 @@ void ComputePanningGainsMC(const ChannelConfig *chancoeffs, ALsizei numchans, AL
float gain = 0.0f;
for(j = 0;j < numcoeffs;j++)
gain += chancoeffs[i][j]*coeffs[j];
- gains[i] = gain * ingain;
+ gains[i] = clampf(gain, 0.0f, 1.0f) * ingain;
}
for(;i < MAX_OUTPUT_CHANNELS;i++)
gains[i] = 0.0f;
@@ -262,7 +270,7 @@ void ComputeFirstOrderGainsMC(const ChannelConfig *chancoeffs, ALsizei numchans,
float gain = 0.0f;
for(j = 0;j < 4;j++)
gain += chancoeffs[i][j] * mtx[j];
- gains[i] = gain * ingain;
+ gains[i] = clampf(gain, 0.0f, 1.0f) * ingain;
}
for(;i < MAX_OUTPUT_CHANNELS;i++)
gains[i] = 0.0f;
@@ -454,8 +462,8 @@ static bool MakeSpeakerMap(ALCdevice *device, const AmbDecConf *conf, ALsizei sp
static const ChannelMap MonoCfg[1] = {
{ FrontCenter, { 1.0f } },
}, StereoCfg[2] = {
- { FrontLeft, { 5.00000000e-1f, 2.88675135e-1f, 0.0f, 0.00000000e+0f } },
- { FrontRight, { 5.00000000e-1f, -2.88675135e-1f, 0.0f, 0.00000000e+0f } },
+ { FrontLeft, { 5.00000000e-1f, 2.88675135e-1f, 0.0f, 1.19573156e-1f } },
+ { FrontRight, { 5.00000000e-1f, -2.88675135e-1f, 0.0f, 1.19573156e-1f } },
}, QuadCfg[4] = {
{ BackLeft, { 3.53553391e-1f, 2.04124145e-1f, 0.0f, -2.04124145e-1f } },
{ FrontLeft, { 3.53553391e-1f, 2.04124145e-1f, 0.0f, 2.04124145e-1f } },
diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h
index c9f8760e..402c3181 100644
--- a/OpenAL32/Include/alu.h
+++ b/OpenAL32/Include/alu.h
@@ -297,6 +297,16 @@ inline void CalcXYZCoeffs(ALfloat x, ALfloat y, ALfloat z, ALfloat spread, ALflo
void CalcAngleCoeffs(ALfloat azimuth, ALfloat elevation, ALfloat spread, ALfloat coeffs[MAX_AMBI_COEFFS]);
/**
+ * CalcAnglePairwiseCoeffs
+ *
+ * Calculates ambisonic coefficients based on azimuth and elevation. The
+ * azimuth and elevation parameters are in radians, going right and up
+ * respectively. This pairwise variant warps the result such that +30 azimuth
+ * is full right, and -30 azimuth is full left.
+ */
+void CalcAnglePairwiseCoeffs(ALfloat azimuth, ALfloat elevation, ALfloat spread, ALfloat coeffs[MAX_AMBI_COEFFS]);
+
+/**
* ComputeAmbientGains
*
* Computes channel gains for ambient, omni-directional sounds.