aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2016-01-25 06:11:51 -0800
committerChris Robinson <[email protected]>2016-01-25 06:11:51 -0800
commitf547ef6d391be5e0cd3e0477c3f8de859a47df69 (patch)
treed135e13f3a204af7eaac97a71744e308da661fe2 /Alc
parent79e0f3e747880a3e7d8342a8602b796b84c0f322 (diff)
Separate calculating ambisonic coefficients from the panning gains
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALu.c16
-rw-r--r--Alc/effects/autowah.c4
-rw-r--r--Alc/effects/chorus.c11
-rw-r--r--Alc/effects/compressor.c4
-rw-r--r--Alc/effects/dedicated.c7
-rw-r--r--Alc/effects/distortion.c4
-rw-r--r--Alc/effects/echo.c12
-rw-r--r--Alc/effects/equalizer.c4
-rw-r--r--Alc/effects/flanger.c11
-rw-r--r--Alc/effects/modulator.c4
-rw-r--r--Alc/effects/null.c2
-rw-r--r--Alc/effects/reverb.c19
-rw-r--r--Alc/panning.c73
13 files changed, 98 insertions, 73 deletions
diff --git a/Alc/ALu.c b/Alc/ALu.c
index 91c2aa7f..6a500833 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -471,7 +471,7 @@ ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const A
{ SideRight, DEG2RAD( 90.0f), DEG2RAD(0.0f) }
};
- ALCdevice *Device = ALContext->Device;
+ const ALCdevice *Device = ALContext->Device;
ALfloat SourceVolume,ListenerGain,MinVolume,MaxVolume;
ALbufferlistitem *BufferListItem;
enum FmtChannels Channels;
@@ -646,7 +646,7 @@ ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const A
MixGains *gains = voice->Direct.Gains[c];
ALfloat Target[MAX_OUTPUT_CHANNELS];
- ComputeBFormatGains(Device, matrix.m[c], DryGain, Target);
+ ComputeBFormatGains(Device->AmbiCoeffs, Device->NumChannels, matrix.m[c], DryGain, Target);
for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
gains[i].Target = Target[i];
}
@@ -751,6 +751,7 @@ ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const A
{
MixGains *gains = voice->Direct.Gains[c];
ALfloat Target[MAX_OUTPUT_CHANNELS];
+ ALfloat coeffs[MAX_AMBI_COEFFS];
/* Special-case LFE */
if(chans[c].channel == LFE)
@@ -763,7 +764,9 @@ ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const A
continue;
}
- ComputeAngleGains(Device, chans[c].angle, chans[c].elevation, DryGain, Target);
+ CalcAngleCoeffs(chans[c].angle, chans[c].elevation, coeffs);
+
+ ComputePanningGains(Device->AmbiCoeffs, Device->NumChannels, coeffs, DryGain, Target);
for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
gains[i].Target = Target[i];
}
@@ -826,7 +829,7 @@ ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const A
ALvoid CalcSourceParams(ALvoice *voice, const ALsource *ALSource, const ALCcontext *ALContext)
{
- ALCdevice *Device = ALContext->Device;
+ const ALCdevice *Device = ALContext->Device;
aluVector Position, Velocity, Direction, SourceToListener;
ALfloat InnerAngle,OuterAngle,Angle,Distance,ClampedDist;
ALfloat MinVolume,MaxVolume,MinDist,MaxDist,Rolloff;
@@ -1223,6 +1226,7 @@ ALvoid CalcSourceParams(ALvoice *voice, const ALsource *ALSource, const ALCconte
ALfloat dir[3] = { 0.0f, 0.0f, -1.0f };
ALfloat radius = ALSource->Radius;
ALfloat Target[MAX_OUTPUT_CHANNELS];
+ ALfloat coeffs[MAX_AMBI_COEFFS];
/* Get the localized direction, and compute panned gains. */
if(Distance > FLT_EPSILON)
@@ -1242,10 +1246,12 @@ ALvoid CalcSourceParams(ALvoice *voice, const ALsource *ALSource, const ALCconte
dir[1] *= dirfact;
dir[2] *= dirfact;
}
- ComputeDirectionalGains(Device, dir, DryGain, Target);
+ CalcDirectionCoeffs(dir, coeffs);
+ ComputePanningGains(Device->AmbiCoeffs, Device->NumChannels, coeffs, DryGain, Target);
for(j = 0;j < MAX_OUTPUT_CHANNELS;j++)
gains[j].Target = Target[j];
+
UpdateDryStepping(&voice->Direct, 1, (voice->Direct.Moving ? 64 : 0));
voice->Direct.Moving = AL_TRUE;
diff --git a/Alc/effects/autowah.c b/Alc/effects/autowah.c
index e97083e0..2da75c56 100644
--- a/Alc/effects/autowah.c
+++ b/Alc/effects/autowah.c
@@ -63,7 +63,7 @@ static ALboolean ALautowahState_deviceUpdate(ALautowahState *state, ALCdevice *d
return AL_TRUE;
}
-static ALvoid ALautowahState_update(ALautowahState *state, ALCdevice *device, const ALeffectslot *slot)
+static ALvoid ALautowahState_update(ALautowahState *state, const ALCdevice *device, const ALeffectslot *slot)
{
ALfloat attackTime, releaseTime;
@@ -75,7 +75,7 @@ static ALvoid ALautowahState_update(ALautowahState *state, ALCdevice *device, co
state->PeakGain = slot->EffectProps.Autowah.PeakGain;
state->Resonance = slot->EffectProps.Autowah.Resonance;
- ComputeAmbientGains(device, slot->Gain, state->Gain);
+ ComputeAmbientGains(device->AmbiCoeffs, device->NumChannels, slot->Gain, state->Gain);
}
static ALvoid ALautowahState_process(ALautowahState *state, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[BUFFERSIZE], ALuint NumChannels)
diff --git a/Alc/effects/chorus.c b/Alc/effects/chorus.c
index 7aa5898b..1477d58b 100644
--- a/Alc/effects/chorus.c
+++ b/Alc/effects/chorus.c
@@ -91,11 +91,10 @@ static ALboolean ALchorusState_deviceUpdate(ALchorusState *state, ALCdevice *Dev
return AL_TRUE;
}
-static ALvoid ALchorusState_update(ALchorusState *state, ALCdevice *Device, const ALeffectslot *Slot)
+static ALvoid ALchorusState_update(ALchorusState *state, const ALCdevice *Device, const ALeffectslot *Slot)
{
- static const ALfloat left_dir[3] = { -1.0f, 0.0f, 0.0f };
- static const ALfloat right_dir[3] = { 1.0f, 0.0f, 0.0f };
ALfloat frequency = (ALfloat)Device->Frequency;
+ ALfloat coeffs[MAX_AMBI_COEFFS];
ALfloat rate;
ALint phase;
@@ -113,8 +112,10 @@ static ALvoid ALchorusState_update(ALchorusState *state, ALCdevice *Device, cons
state->delay = fastf2i(Slot->EffectProps.Chorus.Delay * frequency);
/* Gains for left and right sides */
- ComputeDirectionalGains(Device, left_dir, Slot->Gain, state->Gain[0]);
- ComputeDirectionalGains(Device, right_dir, Slot->Gain, state->Gain[1]);
+ CalcXYZCoeffs(-1.0f, 0.0f, 0.0f, coeffs);
+ ComputePanningGains(Device->AmbiCoeffs, Device->NumChannels, coeffs, Slot->Gain, state->Gain[0]);
+ CalcXYZCoeffs( 1.0f, 0.0f, 0.0f, coeffs);
+ ComputePanningGains(Device->AmbiCoeffs, Device->NumChannels, coeffs, Slot->Gain, state->Gain[1]);
phase = Slot->EffectProps.Chorus.Phase;
rate = Slot->EffectProps.Chorus.Rate;
diff --git a/Alc/effects/compressor.c b/Alc/effects/compressor.c
index 9859a085..52a6324d 100644
--- a/Alc/effects/compressor.c
+++ b/Alc/effects/compressor.c
@@ -55,11 +55,11 @@ static ALboolean ALcompressorState_deviceUpdate(ALcompressorState *state, ALCdev
return AL_TRUE;
}
-static ALvoid ALcompressorState_update(ALcompressorState *state, ALCdevice *device, const ALeffectslot *slot)
+static ALvoid ALcompressorState_update(ALcompressorState *state, const ALCdevice *device, const ALeffectslot *slot)
{
state->Enabled = slot->EffectProps.Compressor.OnOff;
- ComputeAmbientGains(device, slot->Gain, state->Gain);
+ ComputeAmbientGains(device->AmbiCoeffs, device->NumChannels, slot->Gain, state->Gain);
}
static ALvoid ALcompressorState_process(ALcompressorState *state, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[BUFFERSIZE], ALuint NumChannels)
diff --git a/Alc/effects/dedicated.c b/Alc/effects/dedicated.c
index dc581ace..fdc20601 100644
--- a/Alc/effects/dedicated.c
+++ b/Alc/effects/dedicated.c
@@ -45,7 +45,7 @@ static ALboolean ALdedicatedState_deviceUpdate(ALdedicatedState *UNUSED(state),
return AL_TRUE;
}
-static ALvoid ALdedicatedState_update(ALdedicatedState *state, ALCdevice *device, const ALeffectslot *Slot)
+static ALvoid ALdedicatedState_update(ALdedicatedState *state, const ALCdevice *device, const ALeffectslot *Slot)
{
ALfloat Gain;
ALuint i;
@@ -69,8 +69,9 @@ static ALvoid ALdedicatedState_update(ALdedicatedState *state, ALCdevice *device
state->gains[idx] = Gain;
else
{
- static const ALfloat front_dir[3] = { 0.0f, 0.0f, -1.0f };
- ComputeDirectionalGains(device, front_dir, Gain, state->gains);
+ ALfloat coeffs[MAX_AMBI_COEFFS];
+ CalcXYZCoeffs(0.0f, 0.0f, -1.0f, coeffs);
+ ComputePanningGains(device->AmbiCoeffs, device->NumChannels, coeffs, Gain, state->gains);
}
}
}
diff --git a/Alc/effects/distortion.c b/Alc/effects/distortion.c
index 221cec39..dc2e280a 100644
--- a/Alc/effects/distortion.c
+++ b/Alc/effects/distortion.c
@@ -52,7 +52,7 @@ static ALboolean ALdistortionState_deviceUpdate(ALdistortionState *UNUSED(state)
return AL_TRUE;
}
-static ALvoid ALdistortionState_update(ALdistortionState *state, ALCdevice *Device, const ALeffectslot *Slot)
+static ALvoid ALdistortionState_update(ALdistortionState *state, const ALCdevice *Device, const ALeffectslot *Slot)
{
ALfloat frequency = (ALfloat)Device->Frequency;
ALfloat bandwidth;
@@ -83,7 +83,7 @@ static ALvoid ALdistortionState_update(ALdistortionState *state, ALCdevice *Devi
cutoff / (frequency*4.0f), calc_rcpQ_from_bandwidth(cutoff / (frequency*4.0f), bandwidth)
);
- ComputeAmbientGains(Device, Slot->Gain, state->Gain);
+ ComputeAmbientGains(Device->AmbiCoeffs, Device->NumChannels, Slot->Gain, state->Gain);
}
static ALvoid ALdistortionState_process(ALdistortionState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALuint NumChannels)
diff --git a/Alc/effects/echo.c b/Alc/effects/echo.c
index f5a53c36..e2bb6407 100644
--- a/Alc/effects/echo.c
+++ b/Alc/effects/echo.c
@@ -81,10 +81,10 @@ static ALboolean ALechoState_deviceUpdate(ALechoState *state, ALCdevice *Device)
return AL_TRUE;
}
-static ALvoid ALechoState_update(ALechoState *state, ALCdevice *Device, const ALeffectslot *Slot)
+static ALvoid ALechoState_update(ALechoState *state, const ALCdevice *Device, const ALeffectslot *Slot)
{
- ALfloat pandir[3] = { 0.0f, 0.0f, 0.0f };
ALuint frequency = Device->Frequency;
+ ALfloat coeffs[MAX_AMBI_COEFFS];
ALfloat gain, lrpan;
state->Tap[0].delay = fastf2u(Slot->EffectProps.Echo.Delay * frequency) + 1;
@@ -103,12 +103,12 @@ static ALvoid ALechoState_update(ALechoState *state, ALCdevice *Device, const AL
gain = Slot->Gain;
/* First tap panning */
- pandir[0] = -lrpan;
- ComputeDirectionalGains(Device, pandir, gain, state->Gain[0]);
+ CalcXYZCoeffs(-lrpan, 0.0f, 0.0f, coeffs);
+ ComputePanningGains(Device->AmbiCoeffs, Device->NumChannels, coeffs, gain, state->Gain[0]);
/* Second tap panning */
- pandir[0] = +lrpan;
- ComputeDirectionalGains(Device, pandir, gain, state->Gain[1]);
+ CalcXYZCoeffs( lrpan, 0.0f, 0.0f, coeffs);
+ ComputePanningGains(Device->AmbiCoeffs, Device->NumChannels, coeffs, gain, state->Gain[1]);
}
static ALvoid ALechoState_process(ALechoState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALuint NumChannels)
diff --git a/Alc/effects/equalizer.c b/Alc/effects/equalizer.c
index 244667ab..4f7846fd 100644
--- a/Alc/effects/equalizer.c
+++ b/Alc/effects/equalizer.c
@@ -90,12 +90,12 @@ static ALboolean ALequalizerState_deviceUpdate(ALequalizerState *UNUSED(state),
return AL_TRUE;
}
-static ALvoid ALequalizerState_update(ALequalizerState *state, ALCdevice *device, const ALeffectslot *slot)
+static ALvoid ALequalizerState_update(ALequalizerState *state, const ALCdevice *device, const ALeffectslot *slot)
{
ALfloat frequency = (ALfloat)device->Frequency;
ALfloat gain, freq_mult;
- ComputeAmbientGains(device, slot->Gain, state->Gain);
+ ComputeAmbientGains(device->AmbiCoeffs, device->NumChannels, slot->Gain, state->Gain);
/* Calculate coefficients for the each type of filter. Note that the shelf
* filters' gain is for the reference frequency, which is the centerpoint
diff --git a/Alc/effects/flanger.c b/Alc/effects/flanger.c
index f6191abd..5fcc8be8 100644
--- a/Alc/effects/flanger.c
+++ b/Alc/effects/flanger.c
@@ -91,11 +91,10 @@ static ALboolean ALflangerState_deviceUpdate(ALflangerState *state, ALCdevice *D
return AL_TRUE;
}
-static ALvoid ALflangerState_update(ALflangerState *state, ALCdevice *Device, const ALeffectslot *Slot)
+static ALvoid ALflangerState_update(ALflangerState *state, const ALCdevice *Device, const ALeffectslot *Slot)
{
- static const ALfloat left_dir[3] = { -1.0f, 0.0f, 0.0f };
- static const ALfloat right_dir[3] = { 1.0f, 0.0f, 0.0f };
ALfloat frequency = (ALfloat)Device->Frequency;
+ ALfloat coeffs[MAX_AMBI_COEFFS];
ALfloat rate;
ALint phase;
@@ -113,8 +112,10 @@ static ALvoid ALflangerState_update(ALflangerState *state, ALCdevice *Device, co
state->delay = fastf2i(Slot->EffectProps.Flanger.Delay * frequency);
/* Gains for left and right sides */
- ComputeDirectionalGains(Device, left_dir, Slot->Gain, state->Gain[0]);
- ComputeDirectionalGains(Device, right_dir, Slot->Gain, state->Gain[1]);
+ CalcXYZCoeffs(-1.0f, 0.0f, 0.0f, coeffs);
+ ComputePanningGains(Device->AmbiCoeffs, Device->NumChannels, coeffs, Slot->Gain, state->Gain[0]);
+ CalcXYZCoeffs( 1.0f, 0.0f, 0.0f, coeffs);
+ ComputePanningGains(Device->AmbiCoeffs, Device->NumChannels, coeffs, Slot->Gain, state->Gain[1]);
phase = Slot->EffectProps.Flanger.Phase;
rate = Slot->EffectProps.Flanger.Rate;
diff --git a/Alc/effects/modulator.c b/Alc/effects/modulator.c
index 32d25c76..9ef5d0dc 100644
--- a/Alc/effects/modulator.c
+++ b/Alc/effects/modulator.c
@@ -123,7 +123,7 @@ static ALboolean ALmodulatorState_deviceUpdate(ALmodulatorState *UNUSED(state),
return AL_TRUE;
}
-static ALvoid ALmodulatorState_update(ALmodulatorState *state, ALCdevice *Device, const ALeffectslot *Slot)
+static ALvoid ALmodulatorState_update(ALmodulatorState *state, const ALCdevice *Device, const ALeffectslot *Slot)
{
ALfloat cw, a;
@@ -148,7 +148,7 @@ static ALvoid ALmodulatorState_update(ALmodulatorState *state, ALCdevice *Device
state->Filter.b2 = 0.0f;
state->Filter.input_gain = a;
- ComputeAmbientGains(Device, Slot->Gain, state->Gain);
+ ComputeAmbientGains(Device->AmbiCoeffs, Device->NumChannels, Slot->Gain, state->Gain);
}
static ALvoid ALmodulatorState_process(ALmodulatorState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALuint NumChannels)
diff --git a/Alc/effects/null.c b/Alc/effects/null.c
index adc4ca81..d5f5bf11 100644
--- a/Alc/effects/null.c
+++ b/Alc/effects/null.c
@@ -33,7 +33,7 @@ static ALboolean ALnullState_deviceUpdate(ALnullState* UNUSED(state), ALCdevice*
/* This updates the effect state. This is called any time the effect is
* (re)loaded into a slot.
*/
-static ALvoid ALnullState_update(ALnullState* UNUSED(state), ALCdevice* UNUSED(device), const ALeffectslot* UNUSED(slot))
+static ALvoid ALnullState_update(ALnullState* UNUSED(state), const ALCdevice* UNUSED(device), const ALeffectslot* UNUSED(slot))
{
}
diff --git a/Alc/effects/reverb.c b/Alc/effects/reverb.c
index e1013309..f3de2116 100644
--- a/Alc/effects/reverb.c
+++ b/Alc/effects/reverb.c
@@ -1065,6 +1065,7 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection
}, LatePanAngles[4] = {
DEG2RAD(45.0f), DEG2RAD(-45.0f), DEG2RAD(135.0f), DEG2RAD(-135.0f)
};
+ ALfloat coeffs[MAX_AMBI_COEFFS];
ALfloat length, ev, az;
ALuint i;
@@ -1072,7 +1073,10 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection
if(!(length > FLT_EPSILON))
{
for(i = 0;i < 4;i++)
- ComputeAngleGains(Device, EarlyPanAngles[i], 0.0f, Gain, State->Early.PanGain[i]);
+ {
+ CalcAngleCoeffs(EarlyPanAngles[i], 0.0f, coeffs);
+ ComputePanningGains(Device->AmbiCoeffs, Device->NumChannels, coeffs, Gain, State->Early.PanGain[i]);
+ }
}
else
{
@@ -1090,7 +1094,8 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection
float offset, naz, nev;
naz = EarlyPanAngles[i] + (modff((az-EarlyPanAngles[i])*length/F_TAU + 1.5f, &offset)-0.5f)*F_TAU;
nev = (modff((ev )*length/F_TAU + 1.5f, &offset)-0.5f)*F_TAU;
- ComputeAngleGains(Device, naz, nev, Gain, State->Early.PanGain[i]);
+ CalcAngleCoeffs(naz, nev, coeffs);
+ ComputePanningGains(Device->AmbiCoeffs, Device->NumChannels, coeffs, Gain, State->Early.PanGain[i]);
}
}
@@ -1098,7 +1103,10 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection
if(!(length > FLT_EPSILON))
{
for(i = 0;i < 4;i++)
- ComputeAngleGains(Device, LatePanAngles[i], 0.0f, Gain, State->Late.PanGain[i]);
+ {
+ CalcAngleCoeffs(LatePanAngles[i], 0.0f, coeffs);
+ ComputePanningGains(Device->AmbiCoeffs, Device->NumChannels, coeffs, Gain, State->Late.PanGain[i]);
+ }
}
else
{
@@ -1111,12 +1119,13 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection
float offset, naz, nev;
naz = LatePanAngles[i] + (modff((az-LatePanAngles[i])*length/F_TAU + 1.5f, &offset)-0.5f)*F_TAU;
nev = (modff((ev )*length/F_TAU + 1.5f, &offset)-0.5f)*F_TAU;
- ComputeAngleGains(Device, naz, nev, Gain, State->Late.PanGain[i]);
+ CalcAngleCoeffs(naz, nev, coeffs);
+ ComputePanningGains(Device->AmbiCoeffs, Device->NumChannels, coeffs, Gain, State->Late.PanGain[i]);
}
}
}
-static ALvoid ALreverbState_update(ALreverbState *State, ALCdevice *Device, const ALeffectslot *Slot)
+static ALvoid ALreverbState_update(ALreverbState *State, const ALCdevice *Device, const ALeffectslot *Slot)
{
const ALeffectProps *props = &Slot->EffectProps;
ALuint frequency = Device->Frequency;
diff --git a/Alc/panning.c b/Alc/panning.c
index 6305bff7..e71a49f6 100644
--- a/Alc/panning.c
+++ b/Alc/panning.c
@@ -33,6 +33,9 @@
#include "bool.h"
+extern inline void CalcXYZCoeffs(ALfloat x, ALfloat y, ALfloat z, ALfloat coeffs[MAX_AMBI_COEFFS]);
+
+
#define ZERO_ORDER_SCALE 0.0f
#define FIRST_ORDER_SCALE 1.0f
#define SECOND_ORDER_SCALE (1.0f / 1.22474f)
@@ -82,35 +85,8 @@ static const ALfloat FuMa2N3DScale[MAX_AMBI_COEFFS] = {
};
-void ComputeAmbientGains(const ALCdevice *device, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
-{
- ALuint i;
-
- for(i = 0;i < device->NumChannels;i++)
- {
- // The W coefficients are based on a mathematical average of the
- // output. The square root of the base average provides for a more
- // perceptual average volume, better suited to non-directional gains.
- gains[i] = sqrtf(device->AmbiCoeffs[i][0]) * ingain;
- }
- for(;i < MAX_OUTPUT_CHANNELS;i++)
- gains[i] = 0.0f;
-}
-
-void ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat elevation, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
-{
- ALfloat dir[3] = {
- sinf(angle) * cosf(elevation),
- sinf(elevation),
- -cosf(angle) * cosf(elevation)
- };
- ComputeDirectionalGains(device, dir, ingain, gains);
-}
-
-void ComputeDirectionalGains(const ALCdevice *device, const ALfloat dir[3], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
+void CalcDirectionCoeffs(const ALfloat dir[3], ALfloat coeffs[MAX_AMBI_COEFFS])
{
- ALfloat coeffs[MAX_AMBI_COEFFS];
- ALuint i, j;
/* Convert from OpenAL coords to Ambisonics. */
ALfloat x = -dir[2];
ALfloat y = -dir[0];
@@ -136,27 +112,58 @@ void ComputeDirectionalGains(const ALCdevice *device, const ALfloat dir[3], ALfl
coeffs[13] = 1.620185175f * x * (5.0f*z*z - 1.0f); /* ACN 13 = sqrt(21/8) * X * (5*Z*Z - 1) */
coeffs[14] = 5.123475383f * z * (x*x - y*y); /* ACN 14 = sqrt(105)/2 * Z * (X*X - Y*Y) */
coeffs[15] = 2.091650066f * x * (x*x - 3.0f*y*y); /* ACN 15 = sqrt(35/8) * X * (X*X - 3*Y*Y) */
+}
+
+void CalcAngleCoeffs(ALfloat angle, ALfloat elevation, ALfloat coeffs[MAX_AMBI_COEFFS])
+{
+ ALfloat dir[3] = {
+ sinf(angle) * cosf(elevation),
+ sinf(elevation),
+ -cosf(angle) * cosf(elevation)
+ };
+ CalcDirectionCoeffs(dir, coeffs);
+}
+
+
+void ComputeAmbientGains(const ChannelConfig *chancoeffs, ALuint numchans, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
+{
+ ALuint i;
+
+ for(i = 0;i < numchans;i++)
+ {
+ // The W coefficients are based on a mathematical average of the
+ // output. The square root of the base average provides for a more
+ // perceptual average volume, better suited to non-directional gains.
+ gains[i] = sqrtf(chancoeffs[i][0]) * ingain;
+ }
+ for(;i < MAX_OUTPUT_CHANNELS;i++)
+ gains[i] = 0.0f;
+}
+
+void ComputePanningGains(const ChannelConfig *chancoeffs, ALuint numchans, const ALfloat coeffs[MAX_AMBI_COEFFS], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
+{
+ ALuint i, j;
- for(i = 0;i < device->NumChannels;i++)
+ for(i = 0;i < numchans;i++)
{
float gain = 0.0f;
for(j = 0;j < MAX_AMBI_COEFFS;j++)
- gain += device->AmbiCoeffs[i][j]*coeffs[j];
+ gain += chancoeffs[i][j]*coeffs[j];
gains[i] = gain * ingain;
}
for(;i < MAX_OUTPUT_CHANNELS;i++)
gains[i] = 0.0f;
}
-void ComputeBFormatGains(const ALCdevice *device, const ALfloat mtx[4], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
+void ComputeBFormatGains(const ChannelConfig *chancoeffs, ALuint numchans, const ALfloat mtx[4], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
{
ALuint i, j;
- for(i = 0;i < device->NumChannels;i++)
+ for(i = 0;i < numchans;i++)
{
float gain = 0.0f;
for(j = 0;j < 4;j++)
- gain += device->AmbiCoeffs[i][j] * mtx[j];
+ gain += chancoeffs[i][j] * mtx[j];
gains[i] = gain * ingain;
}
for(;i < MAX_OUTPUT_CHANNELS;i++)