summaryrefslogtreecommitdiffstats
path: root/OpenAL32/Include
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-09-30 07:33:13 -0700
committerChris Robinson <[email protected]>2014-09-30 07:33:13 -0700
commit4d36ef65b2ec1cd3122bf9ee615df452f003d014 (patch)
treeffd165b5c9f2e263521feaac0b580707e1b40275 /OpenAL32/Include
parent4955824c2df321755bfc1b1d8142a969ffc61b08 (diff)
Use an ambisonics-based panning method
For mono sources, third-order ambisonics is utilized to generate panning gains. The general idea is that a panned mono sound can be encoded into b-format ambisonics as: w[i] = sample[i] * 0.7071; x[i] = sample[i] * dir[0]; y[i] = sample[i] * dir[1]; ... and subsequently rendered using: output[chan][i] = w[i] * w_coeffs[chan] + x[i] * x_coeffs[chan] + y[i] * y_coeffs[chan] + ...; By reordering the math, channel gains can be generated by doing: gain[chan] = 0.7071 * w_coeffs[chan] + dir[0] * x_coeffs[chan] + dir[1] * y_coeffs[chan] + ...; which then get applied as normal: output[chan][i] = sample[i] * gain[chan]; One of the reasons to use ambisonics for panning is that it provides arguably better reproduction for sounds emanating from between two speakers. As well, this makes it easier to pan in all 3 dimensions, with for instance a "3D7.1" or 8-channel cube speaker configuration by simply providing the necessary coefficients (this will need some work since some methods still use angle-based panpot, particularly multi-channel sources). Unfortunately, the math to reliably generate the coefficients for a given speaker configuration is too costly to do at run-time. They have to be pre- generated based on a pre-specified speaker arangement, which means the config options for tweaking speaker angles are no longer supportable. Eventually I hope to provide config options for custom coefficients, which can either be generated and written in manually, or via alsoft-config from user-specified speaker positions. The current default set of coefficients were generated using the MATLAB scripts (compatible with GNU Octave) from the excellent Ambisonic Decoder Toolbox, at https://bitbucket.org/ambidecodertoolbox/adt/
Diffstat (limited to 'OpenAL32/Include')
-rw-r--r--OpenAL32/Include/alMain.h5
-rw-r--r--OpenAL32/Include/alu.h8
2 files changed, 13 insertions, 0 deletions
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 805a6f42..a658227b 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -585,6 +585,10 @@ enum DeviceType {
*/
#define BUFFERSIZE (2048u)
+/* The maximum number of Ambisonics coefficients. For a given order (o), the
+ * size needed will be (o+1)**2, thus zero-order has 1, first-order has 4,
+ * second-order has 9, and third-order has 16. */
+#define MAX_AMBI_COEFFS 16
struct ALCdevice_struct
{
@@ -652,6 +656,7 @@ struct ALCdevice_struct
struct {
enum Channel ChanName;
ALfloat Angle;
+ ALfloat Coeff[MAX_AMBI_COEFFS];
} Speaker[MaxChannels];
ALuint NumSpeakers;
diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h
index 55d33988..136025d1 100644
--- a/OpenAL32/Include/alu.h
+++ b/OpenAL32/Include/alu.h
@@ -202,6 +202,14 @@ inline ALfloat cubic(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat val3, ALf
ALvoid aluInitPanning(ALCdevice *Device);
/**
+ * ComputeDirectionalGains
+ *
+ * Sets channel gains based on the given source's direction. The direction must
+ * be a 3-component vector no longer than 1 unit.
+ */
+void ComputeDirectionalGains(const ALCdevice *device, const ALfloat dir[3], ALfloat ingain, ALfloat gains[MaxChannels]);
+
+/**
* ComputeAngleGains
*
* Sets channel gains based on a given source's angle and its half-width. The