aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2016-04-15 17:31:04 -0700
committerChris Robinson <[email protected]>2016-04-15 17:31:04 -0700
commitbd65f64d0506be6f20d69311c9a6ade3d0a8d01d (patch)
tree7c4fb19c07978556b815dc666f4b90bde4003522 /Alc
parente27fad90dec951f75b40004dcd32470ca404921d (diff)
Avoid mixing all coefficients together when only some are used
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALu.c10
-rw-r--r--Alc/effects/chorus.c8
-rw-r--r--Alc/effects/dedicated.c2
-rw-r--r--Alc/effects/echo.c8
-rw-r--r--Alc/effects/flanger.c10
-rw-r--r--Alc/effects/reverb.c24
-rw-r--r--Alc/panning.c72
7 files changed, 75 insertions, 59 deletions
diff --git a/Alc/ALu.c b/Alc/ALu.c
index 5823bd5f..1703b43b 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -682,8 +682,9 @@ ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const A
else
{
CalcAngleCoeffs(chans[c].angle, chans[c].elevation, coeffs);
- ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels, coeffs,
- DryGain, voice->Direct.Gains[c].Target);
+ ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels,
+ Device->Dry.CoeffCount, coeffs, DryGain, voice->Direct.Gains[c].Target
+ );
}
for(i = 0;i < NumSends;i++)
@@ -1183,8 +1184,9 @@ ALvoid CalcSourceParams(ALvoice *voice, const ALsource *ALSource, const ALCconte
else
{
CalcDirectionCoeffs(dir, coeffs);
- ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels, coeffs,
- DryGain, voice->Direct.Gains[0].Target);
+ ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels,
+ Device->Dry.CoeffCount, coeffs, DryGain, voice->Direct.Gains[0].Target
+ );
}
for(i = 0;i < NumSends;i++)
diff --git a/Alc/effects/chorus.c b/Alc/effects/chorus.c
index e212cd75..a55983ab 100644
--- a/Alc/effects/chorus.c
+++ b/Alc/effects/chorus.c
@@ -113,9 +113,13 @@ static ALvoid ALchorusState_update(ALchorusState *state, const ALCdevice *Device
/* Gains for left and right sides */
CalcXYZCoeffs(-1.0f, 0.0f, 0.0f, coeffs);
- ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels, coeffs, Slot->Gain, state->Gain[0]);
+ ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels,
+ Device->Dry.CoeffCount, coeffs, Slot->Gain, state->Gain[0]
+ );
CalcXYZCoeffs( 1.0f, 0.0f, 0.0f, coeffs);
- ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels, coeffs, Slot->Gain, state->Gain[1]);
+ ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels,
+ Device->Dry.CoeffCount, coeffs, Slot->Gain, state->Gain[1]
+ );
phase = Slot->EffectProps.Chorus.Phase;
rate = Slot->EffectProps.Chorus.Rate;
diff --git a/Alc/effects/dedicated.c b/Alc/effects/dedicated.c
index 893f3abc..9fd10177 100644
--- a/Alc/effects/dedicated.c
+++ b/Alc/effects/dedicated.c
@@ -84,7 +84,7 @@ static ALvoid ALdedicatedState_update(ALdedicatedState *state, const ALCdevice *
ALfloat coeffs[MAX_AMBI_COEFFS];
CalcXYZCoeffs(0.0f, 0.0f, -1.0f, coeffs);
ComputePanningGains(device->Dry.AmbiCoeffs, device->Dry.NumChannels,
- coeffs, Gain, state->gains);
+ device->Dry.CoeffCount, coeffs, Gain, state->gains);
}
STATIC_CAST(ALeffectState,state)->OutBuffer = device->Dry.Buffer;
STATIC_CAST(ALeffectState,state)->OutChannels = device->Dry.NumChannels;
diff --git a/Alc/effects/echo.c b/Alc/effects/echo.c
index 1f5925ef..00bf5d9f 100644
--- a/Alc/effects/echo.c
+++ b/Alc/effects/echo.c
@@ -104,13 +104,13 @@ static ALvoid ALechoState_update(ALechoState *state, const ALCdevice *Device, co
/* First tap panning */
CalcXYZCoeffs(-lrpan, 0.0f, 0.0f, coeffs);
- ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels, coeffs,
- gain, state->Gain[0]);
+ ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels,
+ Device->Dry.CoeffCount, coeffs, gain, state->Gain[0]);
/* Second tap panning */
CalcXYZCoeffs( lrpan, 0.0f, 0.0f, coeffs);
- ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels, coeffs,
- gain, state->Gain[1]);
+ ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels,
+ Device->Dry.CoeffCount, coeffs, gain, state->Gain[1]);
}
static ALvoid ALechoState_process(ALechoState *state, ALuint SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALuint NumChannels)
diff --git a/Alc/effects/flanger.c b/Alc/effects/flanger.c
index d29e0f25..c323c17a 100644
--- a/Alc/effects/flanger.c
+++ b/Alc/effects/flanger.c
@@ -113,11 +113,13 @@ static ALvoid ALflangerState_update(ALflangerState *state, const ALCdevice *Devi
/* Gains for left and right sides */
CalcXYZCoeffs(-1.0f, 0.0f, 0.0f, coeffs);
- ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels, coeffs,
- Slot->Gain, state->Gain[0]);
+ ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels,
+ Device->Dry.CoeffCount, coeffs, Slot->Gain, state->Gain[0]
+ );
CalcXYZCoeffs( 1.0f, 0.0f, 0.0f, coeffs);
- ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels, coeffs,
- Slot->Gain, state->Gain[1]);
+ ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels,
+ Device->Dry.CoeffCount, coeffs, Slot->Gain, state->Gain[1]
+ );
phase = Slot->EffectProps.Flanger.Phase;
rate = Slot->EffectProps.Flanger.Rate;
diff --git a/Alc/effects/reverb.c b/Alc/effects/reverb.c
index 2aea0763..e5c19d82 100644
--- a/Alc/effects/reverb.c
+++ b/Alc/effects/reverb.c
@@ -720,7 +720,8 @@ static ALvoid UpdateMixedPanning(const ALCdevice *Device, const ALfloat *Reflect
length = minf(length, 1.0f);
CalcDirectionCoeffs(pan, coeffs);
- ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels, coeffs, Gain, DirGains);
+ ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels,
+ Device->Dry.CoeffCount, coeffs, Gain, DirGains);
for(i = 0;i < Device->Dry.NumChannels;i++)
State->Early.PanGain[3][i] = DirGains[i] * EarlyGain * length;
for(i = 0;i < Device->RealOut.NumChannels;i++)
@@ -744,7 +745,8 @@ static ALvoid UpdateMixedPanning(const ALCdevice *Device, const ALfloat *Reflect
length = minf(length, 1.0f);
CalcDirectionCoeffs(pan, coeffs);
- ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels, coeffs, Gain, DirGains);
+ ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels,
+ Device->Dry.CoeffCount, coeffs, Gain, DirGains);
for(i = 0;i < Device->Dry.NumChannels;i++)
State->Late.PanGain[3][i] = DirGains[i] * LateGain * length;
for(i = 0;i < Device->RealOut.NumChannels;i++)
@@ -785,8 +787,8 @@ static ALvoid UpdateDirectPanning(const ALCdevice *Device, const ALfloat *Reflec
length = minf(length, 1.0f);
CalcDirectionCoeffs(pan, coeffs);
- ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels, coeffs,
- Gain, DirGains);
+ ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels,
+ Device->Dry.CoeffCount, coeffs, Gain, DirGains);
for(i = 0;i < Device->Dry.NumChannels;i++)
State->Early.PanGain[i&3][i] = lerp(AmbientGains[i], DirGains[i], length) * EarlyGain;
}
@@ -808,8 +810,8 @@ static ALvoid UpdateDirectPanning(const ALCdevice *Device, const ALfloat *Reflec
length = minf(length, 1.0f);
CalcDirectionCoeffs(pan, coeffs);
- ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels, coeffs,
- Gain, DirGains);
+ ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels,
+ Device->Dry.CoeffCount, coeffs, Gain, DirGains);
for(i = 0;i < Device->Dry.NumChannels;i++)
State->Late.PanGain[i&3][i] = lerp(AmbientGains[i], DirGains[i], length) * LateGain;
}
@@ -859,8 +861,9 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection
for(i = 0;i < 4;i++)
{
CalcDirectionCoeffs(PanDirs[i], coeffs);
- ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels, coeffs,
- Gain*EarlyGain*gain[i], State->Early.PanGain[i]);
+ ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels,
+ Device->Dry.CoeffCount, coeffs, Gain*EarlyGain*gain[i],
+ State->Early.PanGain[i]);
}
gain[0] = gain[1] = gain[2] = gain[3] = 0.5f;
@@ -890,8 +893,9 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection
for(i = 0;i < 4;i++)
{
CalcDirectionCoeffs(PanDirs[i], coeffs);
- ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels, coeffs,
- Gain*LateGain*gain[i], State->Late.PanGain[i]);
+ ComputePanningGains(Device->Dry.AmbiCoeffs, Device->Dry.NumChannels,
+ Device->Dry.CoeffCount, coeffs, Gain*LateGain*gain[i],
+ State->Late.PanGain[i]);
}
}
diff --git a/Alc/panning.c b/Alc/panning.c
index a3b9b293..6691373e 100644
--- a/Alc/panning.c
+++ b/Alc/panning.c
@@ -164,14 +164,14 @@ void ComputeAmbientGains(const ChannelConfig *chancoeffs, ALuint numchans, ALflo
gains[i] = 0.0f;
}
-void ComputePanningGains(const ChannelConfig *chancoeffs, ALuint numchans, const ALfloat coeffs[MAX_AMBI_COEFFS], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
+void ComputePanningGains(const ChannelConfig *chancoeffs, ALuint numchans, ALuint numcoeffs, const ALfloat coeffs[MAX_AMBI_COEFFS], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
{
ALuint i, j;
for(i = 0;i < numchans;i++)
{
float gain = 0.0f;
- for(j = 0;j < MAX_AMBI_COEFFS;j++)
+ for(j = 0;j < numcoeffs;j++)
gain += chancoeffs[i][j]*coeffs[j];
gains[i] = gain * ingain;
}
@@ -443,15 +443,6 @@ static const ChannelMap MonoCfg[1] = {
{ BackRight, { 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 } },
{ SideLeft, { 0.224739f, 0.000000f, 0.340644f, 0.0f, 0.0f, 0.0f, 0.0f, -0.210697f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, -0.065795f } },
{ SideRight, { 0.224739f, 0.000000f, -0.340644f, 0.0f, 0.0f, 0.0f, 0.0f, -0.210697f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, 0.065795f } },
-}, Cube8Cfg[8] = {
- { UpperFrontLeft, { 0.176776695f, 0.072168784f, 0.072168784f, 0.072168784f } },
- { UpperFrontRight, { 0.176776695f, 0.072168784f, -0.072168784f, 0.072168784f } },
- { UpperBackLeft, { 0.176776695f, -0.072168784f, 0.072168784f, 0.072168784f } },
- { UpperBackRight, { 0.176776695f, -0.072168784f, -0.072168784f, 0.072168784f } },
- { LowerFrontLeft, { 0.176776695f, 0.072168784f, 0.072168784f, -0.072168784f } },
- { LowerFrontRight, { 0.176776695f, 0.072168784f, -0.072168784f, -0.072168784f } },
- { LowerBackLeft, { 0.176776695f, -0.072168784f, 0.072168784f, -0.072168784f } },
- { LowerBackRight, { 0.176776695f, -0.072168784f, -0.072168784f, -0.072168784f } },
}, BFormat2D[3] = {
{ Aux0, { 1.0f, 0.0f, 0.0f, 0.0f } },
{ Aux1, { 0.0f, 1.0f, 0.0f, 0.0f } },
@@ -466,16 +457,11 @@ static const ChannelMap MonoCfg[1] = {
static void InitPanning(ALCdevice *device)
{
const ChannelMap *chanmap = NULL;
+ ALuint coeffcount = 0;
ALfloat ambiscale;
size_t count = 0;
ALuint i, j;
- memset(device->Dry.AmbiCoeffs, 0, sizeof(device->Dry.AmbiCoeffs));
- device->Dry.NumChannels = 0;
-
- for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
- device->Dry.ChannelName[i] = device->RealOut.ChannelName[i];
-
ambiscale = 1.0f;
switch(device->FmtChans)
{
@@ -483,53 +469,64 @@ static void InitPanning(ALCdevice *device)
count = COUNTOF(MonoCfg);
chanmap = MonoCfg;
ambiscale = ZERO_ORDER_SCALE;
+ coeffcount = 1;
break;
case DevFmtStereo:
count = COUNTOF(StereoCfg);
chanmap = StereoCfg;
ambiscale = FIRST_ORDER_SCALE;
+ coeffcount = 4;
break;
case DevFmtQuad:
count = COUNTOF(QuadCfg);
chanmap = QuadCfg;
ambiscale = SECOND_ORDER_SCALE;
+ coeffcount = 9;
break;
case DevFmtX51:
count = COUNTOF(X51SideCfg);
chanmap = X51SideCfg;
ambiscale = SECOND_ORDER_SCALE;
+ coeffcount = 9;
break;
case DevFmtX51Rear:
count = COUNTOF(X51RearCfg);
chanmap = X51RearCfg;
ambiscale = SECOND_ORDER_SCALE;
+ coeffcount = 9;
break;
case DevFmtX61:
count = COUNTOF(X61Cfg);
chanmap = X61Cfg;
ambiscale = THIRD_ORDER_SCALE;
+ coeffcount = 16;
break;
case DevFmtX71:
count = COUNTOF(X71Cfg);
chanmap = X71Cfg;
ambiscale = THIRD_ORDER_SCALE;
+ coeffcount = 16;
break;
case DevFmtBFormat3D:
count = COUNTOF(BFormat3D);
chanmap = BFormat3D;
ambiscale = FIRST_ORDER_SCALE;
+ coeffcount = 4;
break;
}
+ for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
+ device->Dry.ChannelName[i] = device->RealOut.ChannelName[i];
SetChannelMap(device->Dry.ChannelName, device->Dry.AmbiCoeffs, chanmap, count,
&device->Dry.NumChannels, AL_TRUE);
+ device->Dry.CoeffCount = coeffcount;
memset(device->FOAOut.AmbiCoeffs, 0, sizeof(device->FOAOut.AmbiCoeffs));
for(i = 0;i < device->Dry.NumChannels;i++)
@@ -547,12 +544,6 @@ static void InitCustomPanning(ALCdevice *device, const AmbDecConf *conf, const A
ALfloat ambiscale = 1.0f;
ALuint i, j;
- memset(device->Dry.AmbiCoeffs, 0, sizeof(device->Dry.AmbiCoeffs));
- device->Dry.NumChannels = 0;
-
- for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
- device->Dry.ChannelName[i] = device->RealOut.ChannelName[i];
-
if(conf->FreqBands != 1)
ERR("Basic renderer uses the high-frequency matrix as single-band (xover_freq = %.0fhz)\n",
conf->XOverFreq);
@@ -592,8 +583,12 @@ static void InitCustomPanning(ALCdevice *device, const AmbDecConf *conf, const A
}
}
+ for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
+ device->Dry.ChannelName[i] = device->RealOut.ChannelName[i];
SetChannelMap(device->Dry.ChannelName, device->Dry.AmbiCoeffs, chanmap,
- conf->NumSpeakers, &device->Dry.NumChannels, AL_FALSE);
+ conf->NumSpeakers, &device->Dry.NumChannels, AL_FALSE);
+ device->Dry.CoeffCount = (conf->ChanMask > 0x1ff) ? 16 :
+ (conf->ChanMask > 0xf) ? 9 : 4;
memset(device->FOAOut.AmbiCoeffs, 0, sizeof(device->FOAOut.AmbiCoeffs));
for(i = 0;i < device->Dry.NumChannels;i++)
@@ -639,9 +634,6 @@ static void InitHQPanning(ALCdevice *device, const AmbDecConf *conf, const ALuin
size_t count;
ALuint i;
- memset(device->Dry.AmbiCoeffs, 0, sizeof(device->Dry.AmbiCoeffs));
- device->Dry.NumChannels = 0;
-
if((conf->ChanMask & ~0x831b))
{
count = (conf->ChanMask > 0xf) ? 9 : 4;
@@ -663,6 +655,8 @@ static void InitHQPanning(ALCdevice *device, const AmbDecConf *conf, const ALuin
device->Dry.ChannelName[i] = InvalidChannel;
SetChannelMap(device->Dry.ChannelName, device->Dry.AmbiCoeffs, chanmap, count,
&device->Dry.NumChannels, AL_FALSE);
+ device->Dry.CoeffCount = (conf->ChanMask > 0x1ff) ? 16 :
+ (conf->ChanMask > 0xf) ? 9 : 4;
TRACE("Enabling %s-band %s-order%s ambisonic decoder\n",
(conf->FreqBands == 1) ? "single" : "dual",
@@ -687,6 +681,16 @@ static void InitHQPanning(ALCdevice *device, const AmbDecConf *conf, const ALuin
static void InitHrtfPanning(ALCdevice *device)
{
+ static const ChannelMap Cube8Cfg[8] = {
+ { UpperFrontLeft, { 0.176776695f, 0.072168784f, 0.072168784f, 0.072168784f } },
+ { UpperFrontRight, { 0.176776695f, 0.072168784f, -0.072168784f, 0.072168784f } },
+ { UpperBackLeft, { 0.176776695f, -0.072168784f, 0.072168784f, 0.072168784f } },
+ { UpperBackRight, { 0.176776695f, -0.072168784f, -0.072168784f, 0.072168784f } },
+ { LowerFrontLeft, { 0.176776695f, 0.072168784f, 0.072168784f, -0.072168784f } },
+ { LowerFrontRight, { 0.176776695f, 0.072168784f, -0.072168784f, -0.072168784f } },
+ { LowerBackLeft, { 0.176776695f, -0.072168784f, 0.072168784f, -0.072168784f } },
+ { LowerBackRight, { 0.176776695f, -0.072168784f, -0.072168784f, -0.072168784f } },
+ };
static const struct {
enum Channel Channel;
ALfloat Angle;
@@ -705,18 +709,16 @@ static void InitHrtfPanning(ALCdevice *device)
size_t count = COUNTOF(Cube8Cfg);
ALuint i;
- memset(device->Dry.AmbiCoeffs, 0, sizeof(device->Dry.AmbiCoeffs));
- device->Dry.NumChannels = 0;
-
for(i = 0;i < count;i++)
device->Dry.ChannelName[i] = chanmap[i].ChanName;
for(;i < MAX_OUTPUT_CHANNELS;i++)
device->Dry.ChannelName[i] = InvalidChannel;
SetChannelMap(device->Dry.ChannelName, device->Dry.AmbiCoeffs, chanmap, count,
&device->Dry.NumChannels, AL_TRUE);
+ device->Dry.CoeffCount = 4;
memcpy(device->FOAOut.AmbiCoeffs, device->Dry.AmbiCoeffs,
- sizeof(device->FOAOut.AmbiCoeffs));
+ sizeof(device->FOAOut.AmbiCoeffs));
for(i = 0;i < device->Dry.NumChannels;i++)
{
@@ -732,15 +734,13 @@ static void InitUhjPanning(ALCdevice *device)
size_t count = COUNTOF(BFormat2D);
ALuint i;
- memset(device->Dry.AmbiCoeffs, 0, sizeof(device->Dry.AmbiCoeffs));
- device->Dry.NumChannels = 0;
-
for(i = 0;i < count;i++)
device->Dry.ChannelName[i] = chanmap[i].ChanName;
for(;i < MAX_OUTPUT_CHANNELS;i++)
device->Dry.ChannelName[i] = InvalidChannel;
SetChannelMap(device->Dry.ChannelName, device->Dry.AmbiCoeffs, chanmap, count,
&device->Dry.NumChannels, AL_TRUE);
+ device->Dry.CoeffCount = 4;
memcpy(device->FOAOut.AmbiCoeffs, device->Dry.AmbiCoeffs,
sizeof(device->FOAOut.AmbiCoeffs));
@@ -759,6 +759,10 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf
al_string_clear(&device->Hrtf_Name);
device->Render_Mode = NormalRender;
+ memset(device->Dry.AmbiCoeffs, 0, sizeof(device->Dry.AmbiCoeffs));
+ device->Dry.CoeffCount = 0;
+ device->Dry.NumChannels = 0;
+
if(device->FmtChans != DevFmtStereo)
{
ALuint speakermap[MAX_OUTPUT_CHANNELS];