aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-05-17 03:52:40 -0700
committerChris Robinson <[email protected]>2018-05-17 03:52:40 -0700
commit0cd375f03c2ab9cc9033dd03481badaa26cc390f (patch)
tree2a8e5c7ea883af4a49e1d5f83f1ea526a911ae39
parent588a6bcb4f79e4be1cae651dbbc14356d039c91b (diff)
Add a function to calculate coefficients from X, Y, Z components
-rw-r--r--Alc/panning.c9
-rw-r--r--OpenAL32/Include/alu.h40
2 files changed, 33 insertions, 16 deletions
diff --git a/Alc/panning.c b/Alc/panning.c
index aaf3f2ca..4a7c592b 100644
--- a/Alc/panning.c
+++ b/Alc/panning.c
@@ -38,6 +38,7 @@
#include "bs2b.h"
+extern inline void CalcDirectionCoeffs(const ALfloat dir[3], ALfloat spread, ALfloat coeffs[MAX_AMBI_COEFFS]);
extern inline void CalcAngleCoeffs(ALfloat azimuth, ALfloat elevation, ALfloat spread, ALfloat coeffs[MAX_AMBI_COEFFS]);
extern inline void ComputeDryPanGains(const DryMixParams *dry, const ALfloat coeffs[MAX_AMBI_COEFFS], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]);
extern inline void ComputeFirstOrderGains(const BFMixParams *foa, const ALfloat mtx[4], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]);
@@ -67,13 +68,9 @@ static const ALsizei ACN2ACN[MAX_AMBI_COEFFS] = {
};
-void CalcDirectionCoeffs(const ALfloat dir[3], ALfloat spread, ALfloat coeffs[MAX_AMBI_COEFFS])
+void CalcAmbiCoeffs(const ALfloat y, const ALfloat z, const ALfloat x, const ALfloat spread,
+ ALfloat coeffs[MAX_AMBI_COEFFS])
{
- /* Convert from OpenAL coords to Ambisonics. */
- ALfloat x = -dir[2];
- ALfloat y = -dir[0];
- ALfloat z = dir[1];
-
/* Zeroth-order */
coeffs[0] = 1.0f; /* ACN 0 = 1 */
/* First-order */
diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h
index b977613c..c09caa65 100644
--- a/OpenAL32/Include/alu.h
+++ b/OpenAL32/Include/alu.h
@@ -431,13 +431,34 @@ void aluInitEffectPanning(struct ALeffectslot *slot);
void aluSelectPostProcess(ALCdevice *device);
/**
+ * Calculates ambisonic encoder coefficients using the X, Y, and Z direction
+ * components, which must represent a normalized (unit length) vector, and the
+ * spread is the angular width of the sound (0...tau).
+ *
+ * NOTE: The components use ambisonic coordinates. As a result:
+ *
+ * Ambisonic Y = OpenAL -X
+ * Ambisonic Z = OpenAL Y
+ * Ambisonic X = OpenAL -Z
+ *
+ * The components are ordered such that OpenAL's X, Y, and Z are the first,
+ * second, and third parameters respectively -- simply negate X and Z.
+ */
+void CalcAmbiCoeffs(const ALfloat y, const ALfloat z, const ALfloat x, const ALfloat spread,
+ ALfloat coeffs[MAX_AMBI_COEFFS]);
+
+/**
* CalcDirectionCoeffs
*
- * Calculates ambisonic coefficients based on a direction vector. The vector
- * must be normalized (unit length), and the spread is the angular width of the
- * sound (0...tau).
+ * Calculates ambisonic coefficients based on an OpenAL direction vector. The
+ * vector must be normalized (unit length), and the spread is the angular width
+ * of the sound (0...tau).
*/
-void CalcDirectionCoeffs(const ALfloat dir[3], ALfloat spread, ALfloat coeffs[MAX_AMBI_COEFFS]);
+inline void CalcDirectionCoeffs(const ALfloat dir[3], ALfloat spread, ALfloat coeffs[MAX_AMBI_COEFFS])
+{
+ /* Convert from OpenAL coords to Ambisonics. */
+ CalcAmbiCoeffs(-dir[0], dir[1], -dir[2], spread, coeffs);
+}
/**
* CalcAngleCoeffs
@@ -448,12 +469,11 @@ void CalcDirectionCoeffs(const ALfloat dir[3], ALfloat spread, ALfloat coeffs[MA
*/
inline void CalcAngleCoeffs(ALfloat azimuth, ALfloat elevation, ALfloat spread, ALfloat coeffs[MAX_AMBI_COEFFS])
{
- ALfloat dir[3] = {
- sinf(azimuth) * cosf(elevation),
- sinf(elevation),
- -cosf(azimuth) * cosf(elevation)
- };
- CalcDirectionCoeffs(dir, spread, coeffs);
+ ALfloat x = -sinf(azimuth) * cosf(elevation);
+ ALfloat y = sinf(elevation);
+ ALfloat z = cosf(azimuth) * cosf(elevation);
+
+ CalcAmbiCoeffs(x, y, z, spread, coeffs);
}
/**