2010-08-03 07:21:36 +00:00
|
|
|
/**
|
|
|
|
* OpenAL cross platform audio library
|
|
|
|
* Copyright (C) 1999-2010 by authors.
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2014-08-18 12:11:03 +00:00
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2010-08-03 07:21:36 +00:00
|
|
|
* Or go to http://www.gnu.org/copyleft/lgpl.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "alMain.h"
|
|
|
|
#include "AL/al.h"
|
|
|
|
#include "AL/alc.h"
|
|
|
|
#include "alu.h"
|
|
|
|
|
|
|
|
|
2014-10-03 01:05:42 +00:00
|
|
|
void ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat elevation, ALfloat ingain, ALfloat gains[MaxChannels])
|
2012-04-28 14:28:36 +00:00
|
|
|
{
|
2014-10-03 01:05:42 +00:00
|
|
|
ALfloat dir[3] = {
|
2014-11-05 11:06:32 +00:00
|
|
|
sinf(angle) * cosf(elevation),
|
2014-10-03 01:05:42 +00:00
|
|
|
sinf(elevation),
|
|
|
|
-cosf(angle) * cosf(elevation)
|
|
|
|
};
|
|
|
|
ComputeDirectionalGains(device, dir, ingain, gains);
|
2012-04-28 14:28:36 +00:00
|
|
|
}
|
|
|
|
|
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/
2014-09-30 14:33:13 +00:00
|
|
|
void ComputeDirectionalGains(const ALCdevice *device, const ALfloat dir[3], ALfloat ingain, ALfloat gains[MaxChannels])
|
|
|
|
{
|
|
|
|
ALfloat coeffs[MAX_AMBI_COEFFS];
|
|
|
|
ALuint i, j;
|
|
|
|
/* Convert from OpenAL coords to Ambisonics. */
|
2014-10-03 03:25:30 +00:00
|
|
|
ALfloat x = -dir[2];
|
|
|
|
ALfloat y = -dir[0];
|
|
|
|
ALfloat z = dir[1];
|
|
|
|
|
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/
2014-09-30 14:33:13 +00:00
|
|
|
coeffs[0] = 0.7071f; /* sqrt(1.0 / 2.0) */
|
2014-10-03 03:25:30 +00:00
|
|
|
coeffs[1] = x; /* X */
|
|
|
|
coeffs[2] = y; /* Y */
|
|
|
|
coeffs[3] = z; /* Z */
|
|
|
|
coeffs[4] = 0.5f * (3.0f*z*z - 1.0f); /* 0.5 * (3*Z*Z - 1) */
|
|
|
|
coeffs[5] = 2.0f * z * x; /* 2*Z*X */
|
|
|
|
coeffs[6] = 2.0f * y * z; /* 2*Y*Z */
|
|
|
|
coeffs[7] = x*x - y*y; /* X*X - Y*Y */
|
|
|
|
coeffs[8] = 2.0f * x * y; /* 2*X*Y */
|
|
|
|
coeffs[9] = 0.5f * z * (5.0f*z*z - 3.0f); /* 0.5 * Z * (5*Z*Z - 3) */
|
|
|
|
coeffs[10] = 0.7262f * x * (5.0f*z*z - 1.0f); /* sqrt(135.0 / 256.0) * X * (5*Z*Z - 1) */
|
|
|
|
coeffs[11] = 0.7262f * y * (5.0f*z*z - 1.0f); /* sqrt(135.0 / 256.0) * Y * (5*Z*Z - 1) */
|
|
|
|
coeffs[12] = 2.5981f * z * (x*x - y*y); /* sqrt(27.0 / 4.0) * Z * (X*X - Y*Y) */
|
|
|
|
coeffs[13] = 5.1962f * x * y * z; /* sqrt(27) * X * Y * Z */
|
|
|
|
coeffs[14] = x * (x*x - 3.0f*y*y); /* X * (X*X - 3*Y*Y) */
|
|
|
|
coeffs[15] = y * (3.0f*x*x - y*y); /* Y * (3*X*X - Y*Y) */
|
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/
2014-09-30 14:33:13 +00:00
|
|
|
|
|
|
|
for(i = 0;i < MaxChannels;i++)
|
|
|
|
gains[i] = 0.0f;
|
|
|
|
for(i = 0;i < device->NumSpeakers;i++)
|
|
|
|
{
|
|
|
|
for(j = 0;j < MAX_AMBI_COEFFS;j++)
|
2014-11-05 10:54:11 +00:00
|
|
|
gains[i] += device->Speaker[i].HOACoeff[j]*coeffs[j];
|
|
|
|
gains[i] = maxf(gains[i], 0.0f) * ingain;
|
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/
2014-09-30 14:33:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-04 11:33:35 +00:00
|
|
|
void ComputeAmbientGains(const ALCdevice *device, ALfloat ingain, ALfloat gains[MaxChannels])
|
|
|
|
{
|
|
|
|
ALuint i;
|
|
|
|
|
|
|
|
for(i = 0;i < MaxChannels;i++)
|
|
|
|
gains[i] = 0.0f;
|
|
|
|
for(i = 0;i < device->NumSpeakers;i++)
|
2014-11-05 10:54:11 +00:00
|
|
|
gains[i] = device->Speaker[i].HOACoeff[0] * ingain;
|
2014-11-04 11:33:35 +00:00
|
|
|
}
|
|
|
|
|
2014-11-01 05:43:13 +00:00
|
|
|
void ComputeBFormatGains(const ALCdevice *device, const ALfloat mtx[4], ALfloat ingain, ALfloat gains[MaxChannels])
|
2014-11-01 00:18:45 +00:00
|
|
|
{
|
2014-11-01 05:43:13 +00:00
|
|
|
ALuint i, j;
|
2014-11-01 00:18:45 +00:00
|
|
|
|
|
|
|
for(i = 0;i < MaxChannels;i++)
|
|
|
|
gains[i] = 0.0f;
|
|
|
|
for(i = 0;i < device->NumSpeakers;i++)
|
|
|
|
{
|
2014-11-01 05:43:13 +00:00
|
|
|
for(j = 0;j < 4;j++)
|
2014-11-05 10:54:11 +00:00
|
|
|
gains[i] += device->Speaker[i].FOACoeff[j] * mtx[j];
|
|
|
|
gains[i] *= ingain;
|
2014-11-01 00:18:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-29 12:04:46 +00:00
|
|
|
|
2014-11-05 11:46:00 +00:00
|
|
|
typedef struct ChannelMap {
|
|
|
|
enum Channel ChanName;
|
|
|
|
ChannelConfig Config;
|
|
|
|
} ChannelMap;
|
|
|
|
|
2014-09-11 00:53:01 +00:00
|
|
|
ALvoid aluInitPanning(ALCdevice *device)
|
2010-08-03 07:21:36 +00:00
|
|
|
{
|
2014-11-05 11:46:00 +00:00
|
|
|
static const ChannelMap MonoCfg[1] = {
|
|
|
|
{ FrontCenter, { DEG2RAD(0.0f), DEG2RAD(0.0f), { 1.4142f }, { 1.4142f } } },
|
2014-10-03 03:25:30 +00:00
|
|
|
}, StereoCfg[2] = {
|
2014-11-05 11:46:00 +00:00
|
|
|
{ FrontLeft, { DEG2RAD(-90.0f), DEG2RAD(0.0f), { 0.7071f, 0.0f, 0.5f, 0.0f }, { 0.7071f, 0.0f, 0.5f, 0.0f } } },
|
|
|
|
{ FrontRight, { DEG2RAD( 90.0f), DEG2RAD(0.0f), { 0.7071f, 0.0f, -0.5f, 0.0f }, { 0.7071f, 0.0f, -0.5f, 0.0f } } },
|
2014-10-03 03:25:30 +00:00
|
|
|
}, QuadCfg[4] = {
|
2014-11-05 11:46:00 +00:00
|
|
|
{ FrontLeft, { DEG2RAD( -45.0f), DEG2RAD(0.0f), { 0.353558f, 0.306181f, 0.306192f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, 0.117183f }, { 0.353553f, 0.250000f, 0.250000f, 0.0f } } },
|
|
|
|
{ FrontRight, { DEG2RAD( 45.0f), DEG2RAD(0.0f), { 0.353543f, 0.306181f, -0.306192f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, -0.117193f }, { 0.353553f, 0.250000f, -0.250000f, 0.0f } } },
|
|
|
|
{ BackLeft, { DEG2RAD(-135.0f), DEG2RAD(0.0f), { 0.353543f, -0.306192f, 0.306181f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, -0.117193f }, { 0.353553f, -0.250000f, 0.250000f, 0.0f } } },
|
|
|
|
{ BackRight, { DEG2RAD( 135.0f), DEG2RAD(0.0f), { 0.353558f, -0.306192f, -0.306181f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, 0.117183f }, { 0.353553f, -0.250000f, -0.250000f, 0.0f } } },
|
2014-11-07 08:54:16 +00:00
|
|
|
}, X51SideCfg[6] = {
|
|
|
|
{ FrontLeft, { DEG2RAD( -30.0f), DEG2RAD(0.0f), { 0.208954f, 0.212846f, 0.238350f, 0.0f, 0.0f, 0.0f, 0.0f, -0.017738f, 0.204014f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.051023f, 0.047490f }, { 0.208954f, 0.162905f, 0.182425f, 0.0f } } },
|
|
|
|
{ FrontRight, { DEG2RAD( 30.0f), DEG2RAD(0.0f), { 0.208954f, 0.212846f, -0.238350f, 0.0f, 0.0f, 0.0f, 0.0f, -0.017738f, -0.204014f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.051023f, -0.047490f }, { 0.208954f, 0.162905f, -0.182425f, 0.0f } } },
|
|
|
|
{ FrontCenter, { DEG2RAD( 0.0f), DEG2RAD(0.0f), { 0.109403f, 0.179490f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.142031f, -0.000002f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.072024f, -0.000001f }, { 0.109403f, 0.137375f, 0.000000f, 0.0f } } },
|
|
|
|
{ LFE, { 0.0f, 0.0f, { 0.0f }, { 0.0f } } },
|
|
|
|
{ SideLeft, { DEG2RAD(-110.0f), DEG2RAD(0.0f), { 0.470936f, -0.369626f, 0.349386f, 0.0f, 0.0f, 0.0f, 0.0f, -0.031375f, -0.058144f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.007119f, -0.043968f }, { 0.470934f, -0.282903f, 0.267406f, 0.0f } } },
|
|
|
|
{ SideRight, { DEG2RAD( 110.0f), DEG2RAD(0.0f), { 0.470936f, -0.369626f, -0.349386f, 0.0f, 0.0f, 0.0f, 0.0f, -0.031375f, 0.058144f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.007119f, 0.043968f }, { 0.470934f, -0.282903f, -0.267406f, 0.0f } } },
|
|
|
|
}, X51RearCfg[6] = {
|
2014-11-05 11:46:00 +00:00
|
|
|
{ FrontLeft, { DEG2RAD( -30.0f), DEG2RAD(0.0f), { 0.208954f, 0.212846f, 0.238350f, 0.0f, 0.0f, 0.0f, 0.0f, -0.017738f, 0.204014f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.051023f, 0.047490f }, { 0.208954f, 0.162905f, 0.182425f, 0.0f } } },
|
|
|
|
{ FrontRight, { DEG2RAD( 30.0f), DEG2RAD(0.0f), { 0.208954f, 0.212846f, -0.238350f, 0.0f, 0.0f, 0.0f, 0.0f, -0.017738f, -0.204014f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.051023f, -0.047490f }, { 0.208954f, 0.162905f, -0.182425f, 0.0f } } },
|
|
|
|
{ FrontCenter, { DEG2RAD( 0.0f), DEG2RAD(0.0f), { 0.109403f, 0.179490f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.142031f, -0.000002f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.072024f, -0.000001f }, { 0.109403f, 0.137375f, 0.000000f, 0.0f } } },
|
|
|
|
{ LFE, { 0.0f, 0.0f, { 0.0f }, { 0.0f } } },
|
|
|
|
{ BackLeft, { DEG2RAD(-110.0f), DEG2RAD(0.0f), { 0.470936f, -0.369626f, 0.349386f, 0.0f, 0.0f, 0.0f, 0.0f, -0.031375f, -0.058144f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.007119f, -0.043968f }, { 0.470934f, -0.282903f, 0.267406f, 0.0f } } },
|
|
|
|
{ BackRight, { DEG2RAD( 110.0f), DEG2RAD(0.0f), { 0.470936f, -0.369626f, -0.349386f, 0.0f, 0.0f, 0.0f, 0.0f, -0.031375f, 0.058144f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.007119f, 0.043968f }, { 0.470934f, -0.282903f, -0.267406f, 0.0f } } },
|
2014-11-04 12:09:29 +00:00
|
|
|
}, X61Cfg[7] = {
|
2014-11-05 11:46:00 +00:00
|
|
|
{ FrontLeft, { DEG2RAD(-30.0f), DEG2RAD(0.0f), { 0.167065f, 0.200583f, 0.172695f, 0.0f, 0.0f, 0.0f, 0.0f, 0.029855f, 0.186407f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.039241f, 0.068910f }, { 0.167065f, 0.153519f, 0.132175f, 0.0f } } },
|
|
|
|
{ FrontRight, { DEG2RAD( 30.0f), DEG2RAD(0.0f), { 0.167065f, 0.200583f, -0.172695f, 0.0f, 0.0f, 0.0f, 0.0f, 0.029855f, -0.186407f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.039241f, -0.068910f }, { 0.167065f, 0.153519f, -0.132175f, 0.0f } } },
|
|
|
|
{ FrontCenter, { DEG2RAD( 0.0f), DEG2RAD(0.0f), { 0.109403f, 0.179490f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.142031f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.072024f, -0.000001f }, { 0.109403f, 0.137375f, 0.000000f, 0.0f } } },
|
|
|
|
{ LFE, { 0.0f, 0.0f, { 0.0f }, { 0.0f } } },
|
|
|
|
{ BackCenter, { DEG2RAD(180.0f), DEG2RAD(0.0f), { 0.353556f, -0.461940f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.165723f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, 0.000005f }, { 0.353556f, -0.353554f, 0.000000f, 0.0f } } },
|
|
|
|
{ SideLeft, { DEG2RAD(-90.0f), DEG2RAD(0.0f), { 0.289151f, -0.081301f, 0.401292f, 0.0f, 0.0f, 0.0f, 0.0f, -0.188208f, -0.071420f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.010099f, -0.032897f }, { 0.289151f, -0.062225f, 0.307136f, 0.0f } } },
|
|
|
|
{ SideRight, { DEG2RAD( 90.0f), DEG2RAD(0.0f), { 0.289151f, -0.081301f, -0.401292f, 0.0f, 0.0f, 0.0f, 0.0f, -0.188208f, 0.071420f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.010099f, 0.032897f }, { 0.289151f, -0.062225f, -0.307136f, 0.0f } } },
|
2014-11-04 12:09:29 +00:00
|
|
|
}, X71Cfg[8] = {
|
2014-11-05 11:46:00 +00:00
|
|
|
{ FrontLeft, { DEG2RAD( -30.0f), DEG2RAD(0.0f), { 0.167065f, 0.200583f, 0.172695f, 0.0f, 0.0f, 0.0f, 0.0f, 0.029855f, 0.186407f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.039241f, 0.068910f }, { 0.167065f, 0.153519f, 0.132175f, 0.0f } } },
|
|
|
|
{ FrontRight, { DEG2RAD( 30.0f), DEG2RAD(0.0f), { 0.167065f, 0.200583f, -0.172695f, 0.0f, 0.0f, 0.0f, 0.0f, 0.029855f, -0.186407f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.039241f, -0.068910f }, { 0.167065f, 0.153519f, -0.132175f, 0.0f } } },
|
|
|
|
{ FrontCenter, { DEG2RAD( 0.0f), DEG2RAD(0.0f), { 0.109403f, 0.179490f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.142031f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.072024f, 0.000000f }, { 0.109403f, 0.137375f, 0.000000f, 0.0f } } },
|
|
|
|
{ LFE, { 0.0f, 0.0f, { 0.0f }, { 0.0f } } },
|
|
|
|
{ BackLeft, { DEG2RAD(-150.0f), DEG2RAD(0.0f), { 0.224752f, -0.295009f, 0.170325f, 0.0f, 0.0f, 0.0f, 0.0f, 0.105349f, -0.182473f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, 0.065799f }, { 0.224752f, -0.225790f, 0.130361f, 0.0f } } },
|
|
|
|
{ BackRight, { DEG2RAD( 150.0f), DEG2RAD(0.0f), { 0.224752f, -0.295009f, -0.170325f, 0.0f, 0.0f, 0.0f, 0.0f, 0.105349f, 0.182473f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, -0.065799f }, { 0.224752f, -0.225790f, -0.130361f, 0.0f } } },
|
|
|
|
{ SideLeft, { DEG2RAD( -90.0f), DEG2RAD(0.0f), { 0.224739f, 0.000002f, 0.340644f, 0.0f, 0.0f, 0.0f, 0.0f, -0.210697f, 0.000002f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, -0.065795f }, { 0.224739f, 0.000000f, 0.260717f, 0.0f } } },
|
|
|
|
{ SideRight, { DEG2RAD( 90.0f), DEG2RAD(0.0f), { 0.224739f, 0.000002f, -0.340644f, 0.0f, 0.0f, 0.0f, 0.0f, -0.210697f, -0.000002f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, 0.065795f }, { 0.224739f, 0.000000f, -0.260717f, 0.0f } } },
|
2014-10-03 03:25:30 +00:00
|
|
|
};
|
2014-11-07 07:05:21 +00:00
|
|
|
const ChannelMap *chanmap = NULL;
|
|
|
|
size_t count = 0;
|
2014-11-05 10:54:11 +00:00
|
|
|
ALuint i, j;
|
2014-10-03 03:25:30 +00:00
|
|
|
|
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/
2014-09-30 14:33:13 +00:00
|
|
|
memset(device->Speaker, 0, sizeof(device->Speaker));
|
|
|
|
device->NumSpeakers = 0;
|
2010-08-03 07:21:36 +00:00
|
|
|
|
2014-09-11 00:53:01 +00:00
|
|
|
switch(device->FmtChans)
|
2010-08-03 07:21:36 +00:00
|
|
|
{
|
2010-12-05 03:50:00 +00:00
|
|
|
case DevFmtMono:
|
2014-11-05 10:54:11 +00:00
|
|
|
count = COUNTOF(MonoCfg);
|
2014-11-05 11:46:00 +00:00
|
|
|
chanmap = MonoCfg;
|
2010-08-03 07:21:36 +00:00
|
|
|
break;
|
|
|
|
|
2010-12-05 03:50:00 +00:00
|
|
|
case DevFmtStereo:
|
2014-11-05 10:54:11 +00:00
|
|
|
count = COUNTOF(StereoCfg);
|
2014-11-05 11:46:00 +00:00
|
|
|
chanmap = StereoCfg;
|
2010-08-03 07:21:36 +00:00
|
|
|
break;
|
|
|
|
|
2010-12-05 03:50:00 +00:00
|
|
|
case DevFmtQuad:
|
2014-11-05 10:54:11 +00:00
|
|
|
count = COUNTOF(QuadCfg);
|
2014-11-05 11:46:00 +00:00
|
|
|
chanmap = QuadCfg;
|
2010-08-03 07:21:36 +00:00
|
|
|
break;
|
|
|
|
|
2010-12-05 03:50:00 +00:00
|
|
|
case DevFmtX51:
|
2014-11-05 10:54:11 +00:00
|
|
|
count = COUNTOF(X51SideCfg);
|
2014-11-05 11:46:00 +00:00
|
|
|
chanmap = X51SideCfg;
|
2011-05-29 02:35:32 +00:00
|
|
|
break;
|
|
|
|
|
2014-11-07 08:54:16 +00:00
|
|
|
case DevFmtX51Rear:
|
|
|
|
count = COUNTOF(X51RearCfg);
|
|
|
|
chanmap = X51RearCfg;
|
|
|
|
break;
|
|
|
|
|
2010-12-05 03:50:00 +00:00
|
|
|
case DevFmtX61:
|
2014-11-05 10:54:11 +00:00
|
|
|
count = COUNTOF(X61Cfg);
|
2014-11-05 11:46:00 +00:00
|
|
|
chanmap = X61Cfg;
|
2010-08-03 07:21:36 +00:00
|
|
|
break;
|
|
|
|
|
2010-12-05 03:50:00 +00:00
|
|
|
case DevFmtX71:
|
2014-11-05 10:54:11 +00:00
|
|
|
count = COUNTOF(X71Cfg);
|
2014-11-05 11:46:00 +00:00
|
|
|
chanmap = X71Cfg;
|
2010-08-03 07:21:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-11-05 10:54:11 +00:00
|
|
|
for(i = 0;i < MaxChannels && device->ChannelName[i] != InvalidChannel;i++)
|
|
|
|
{
|
|
|
|
for(j = 0;j < count;j++)
|
|
|
|
{
|
2014-11-05 11:46:00 +00:00
|
|
|
if(device->ChannelName[i] == chanmap[j].ChanName)
|
2014-11-05 10:54:11 +00:00
|
|
|
{
|
2014-11-05 11:46:00 +00:00
|
|
|
device->Speaker[i] = chanmap[j].Config;
|
2014-11-05 10:54:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(j == count)
|
|
|
|
ERR("Failed to match channel %u (label %d) in config\n", i, device->ChannelName[i]);
|
|
|
|
}
|
|
|
|
device->NumSpeakers = i;
|
2010-08-03 07:21:36 +00:00
|
|
|
}
|