aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2010-12-09 16:37:23 -0800
committerChris Robinson <[email protected]>2010-12-09 16:37:23 -0800
commitc3cd4c80b2a248918da9d049487213c4cc8c128f (patch)
treee27b6f1f5061b1e4065a796378ffe6e794f67d7e /Alc
parentbe3f3c4bf03dd5800e25f0d3144f2e122bac2f94 (diff)
Use a matrix when rendering to the dry buffer
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALu.c106
-rw-r--r--Alc/mixer.c73
2 files changed, 115 insertions, 64 deletions
diff --git a/Alc/ALu.c b/Alc/ALu.c
index e0fd5c9f..d831e9ca 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -150,15 +150,23 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
break;
}
- if(Channels == FmtStereo)
+ for(i = 0;i < MAXCHANNELS;i++)
{
- for(i = 0;i < MAXCHANNELS;i++)
- ALSource->Params.DryGains[i] = 0.0f;
+ ALuint i2;
+ for(i2 = 0;i2 < MAXCHANNELS;i2++)
+ ALSource->Params.DryGains[i][i2] = 0.0f;
+ }
+ switch(Channels)
+ {
+ case FmtMono:
+ ALSource->Params.DryGains[0][FRONT_CENTER] = DryGain * ListenerGain;
+ break;
+ case FmtStereo:
if(DupStereo == AL_FALSE)
{
- ALSource->Params.DryGains[FRONT_LEFT] = DryGain * ListenerGain;
- ALSource->Params.DryGains[FRONT_RIGHT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[0][FRONT_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[1][FRONT_RIGHT] = DryGain * ListenerGain;
}
else
{
@@ -166,43 +174,81 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
{
case DevFmtMono:
case DevFmtStereo:
- ALSource->Params.DryGains[FRONT_LEFT] = DryGain * ListenerGain;
- ALSource->Params.DryGains[FRONT_RIGHT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[0][FRONT_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[1][FRONT_RIGHT] = DryGain * ListenerGain;
break;
case DevFmtQuad:
case DevFmtX51:
DryGain *= aluSqrt(2.0f/4.0f);
- ALSource->Params.DryGains[FRONT_LEFT] = DryGain * ListenerGain;
- ALSource->Params.DryGains[FRONT_RIGHT] = DryGain * ListenerGain;
- ALSource->Params.DryGains[BACK_LEFT] = DryGain * ListenerGain;
- ALSource->Params.DryGains[BACK_RIGHT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[0][FRONT_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[1][FRONT_RIGHT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[0][BACK_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[1][BACK_RIGHT] = DryGain * ListenerGain;
break;
case DevFmtX61:
DryGain *= aluSqrt(2.0f/4.0f);
- ALSource->Params.DryGains[FRONT_LEFT] = DryGain * ListenerGain;
- ALSource->Params.DryGains[FRONT_RIGHT] = DryGain * ListenerGain;
- ALSource->Params.DryGains[SIDE_LEFT] = DryGain * ListenerGain;
- ALSource->Params.DryGains[SIDE_RIGHT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[0][FRONT_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[1][FRONT_RIGHT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[0][SIDE_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[1][SIDE_RIGHT] = DryGain * ListenerGain;
break;
case DevFmtX71:
DryGain *= aluSqrt(2.0f/6.0f);
- ALSource->Params.DryGains[FRONT_LEFT] = DryGain * ListenerGain;
- ALSource->Params.DryGains[FRONT_RIGHT] = DryGain * ListenerGain;
- ALSource->Params.DryGains[BACK_LEFT] = DryGain * ListenerGain;
- ALSource->Params.DryGains[BACK_RIGHT] = DryGain * ListenerGain;
- ALSource->Params.DryGains[SIDE_LEFT] = DryGain * ListenerGain;
- ALSource->Params.DryGains[SIDE_RIGHT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[0][FRONT_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[1][FRONT_RIGHT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[0][BACK_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[1][BACK_RIGHT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[0][SIDE_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[1][SIDE_RIGHT] = DryGain * ListenerGain;
break;
}
}
- }
- else
- {
- for(i = 0;i < MAXCHANNELS;i++)
- ALSource->Params.DryGains[i] = DryGain * ListenerGain;
+ break;
+
+ case FmtRear:
+ ALSource->Params.DryGains[0][BACK_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[1][BACK_RIGHT] = DryGain * ListenerGain;
+ break;
+
+ case FmtQuad:
+ ALSource->Params.DryGains[0][FRONT_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[1][FRONT_RIGHT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[2][BACK_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[3][BACK_RIGHT] = DryGain * ListenerGain;
+ break;
+
+ case FmtX51:
+ ALSource->Params.DryGains[0][FRONT_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[1][FRONT_RIGHT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[2][FRONT_CENTER] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[3][LFE] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[4][BACK_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[5][BACK_RIGHT] = DryGain * ListenerGain;
+ break;
+
+ case FmtX61:
+ ALSource->Params.DryGains[0][FRONT_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[1][FRONT_RIGHT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[2][FRONT_CENTER] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[3][LFE] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[4][BACK_CENTER] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[5][SIDE_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[6][SIDE_RIGHT] = DryGain * ListenerGain;
+ break;
+
+ case FmtX71:
+ ALSource->Params.DryGains[0][FRONT_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[1][FRONT_RIGHT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[2][FRONT_CENTER] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[3][LFE] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[4][BACK_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[5][BACK_RIGHT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[6][SIDE_LEFT] = DryGain * ListenerGain;
+ ALSource->Params.DryGains[7][SIDE_RIGHT] = DryGain * ListenerGain;
+ break;
}
for(i = 0;i < NumSends;i++)
@@ -615,12 +661,16 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
// has low complexity
AmbientGain = aluSqrt(1.0/Device->NumChan);
for(s = 0;s < MAXCHANNELS;s++)
- ALSource->Params.DryGains[s] = 0.0f;
+ {
+ ALuint s2;
+ for(s2 = 0;s2 < MAXCHANNELS;s2++)
+ ALSource->Params.DryGains[s][s2] = 0.0f;
+ }
for(s = 0;s < (ALsizei)Device->NumChan;s++)
{
Channel chan = Device->Speaker2Chan[s];
ALfloat gain = AmbientGain + (SpeakerGain[chan]-AmbientGain)*DirGain;
- ALSource->Params.DryGains[chan] = DryGain * gain;
+ ALSource->Params.DryGains[0][chan] = DryGain * gain;
}
/* Update filter coefficients. */
diff --git a/Alc/mixer.c b/Alc/mixer.c
index 2ebce319..e0696d26 100644
--- a/Alc/mixer.c
+++ b/Alc/mixer.c
@@ -85,7 +85,7 @@ static void Mix_##T##_Mono_##sampler(ALsource *Source, ALCdevice *Device, \
PendingClicks = Device->PendingClicks; \
DryFilter = &Source->Params.iirFilter; \
for(i = 0;i < MAXCHANNELS;i++) \
- DrySend[i] = Source->Params.DryGains[i]; \
+ DrySend[i] = Source->Params.DryGains[0][i]; \
\
pos = 0; \
frac = *DataPosFrac; \
@@ -197,21 +197,16 @@ static void Mix_##T##_Stereo_##sampler(ALsource *Source, ALCdevice *Device, \
const T *data, ALuint *DataPosInt, ALuint *DataPosFrac, \
ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize) \
{ \
- static const ALuint Channels = 2; \
- static const Channel chans[] = { \
- FRONT_LEFT, FRONT_RIGHT, \
- SIDE_LEFT, SIDE_RIGHT, \
- BACK_LEFT, BACK_RIGHT \
- }; \
+ const ALuint Channels = 2; \
const ALfloat scaler = 1.0f/Channels; \
ALfloat (*DryBuffer)[MAXCHANNELS]; \
ALfloat *ClickRemoval, *PendingClicks; \
ALuint pos, frac; \
- ALfloat DrySend[MAXCHANNELS]; \
+ ALfloat DrySend[Channels][MAXCHANNELS]; \
FILTER *DryFilter; \
ALuint BufferIdx; \
ALuint increment; \
- ALuint i, out; \
+ ALuint i, out, c; \
ALfloat value; \
\
increment = Source->Params.Step; \
@@ -220,8 +215,11 @@ static void Mix_##T##_Stereo_##sampler(ALsource *Source, ALCdevice *Device, \
ClickRemoval = Device->ClickRemoval; \
PendingClicks = Device->PendingClicks; \
DryFilter = &Source->Params.iirFilter; \
- for(i = 0;i < MAXCHANNELS;i++) \
- DrySend[i] = Source->Params.DryGains[i]; \
+ for(i = 0;i < Channels;i++) \
+ { \
+ for(c = 0;c < MAXCHANNELS;c++) \
+ DrySend[i][c] = Source->Params.DryGains[i][c]; \
+ } \
\
pos = 0; \
frac = *DataPosFrac; \
@@ -232,10 +230,9 @@ static void Mix_##T##_Stereo_##sampler(ALsource *Source, ALCdevice *Device, \
{ \
value = sampler(data + pos*Channels + i, Channels, frac); \
\
- value = lpFilter2PC(DryFilter, chans[i]*2, value); \
- ClickRemoval[chans[i+0]] -= value*DrySend[chans[i+0]]; \
- ClickRemoval[chans[i+2]] -= value*DrySend[chans[i+2]]; \
- ClickRemoval[chans[i+4]] -= value*DrySend[chans[i+4]]; \
+ value = lpFilter2PC(DryFilter, i*2, value); \
+ for(c = 0;c < MAXCHANNELS;c++) \
+ ClickRemoval[c] -= value*DrySend[i][c]; \
} \
} \
for(BufferIdx = 0;BufferIdx < BufferSize;BufferIdx++) \
@@ -244,10 +241,9 @@ static void Mix_##T##_Stereo_##sampler(ALsource *Source, ALCdevice *Device, \
{ \
value = sampler(data + pos*Channels + i, Channels, frac); \
\
- value = lpFilter2P(DryFilter, chans[i]*2, value); \
- DryBuffer[OutPos][chans[i+0]] += value*DrySend[chans[i+0]]; \
- DryBuffer[OutPos][chans[i+2]] += value*DrySend[chans[i+2]]; \
- DryBuffer[OutPos][chans[i+4]] += value*DrySend[chans[i+4]]; \
+ value = lpFilter2P(DryFilter, i*2, value); \
+ for(c = 0;c < MAXCHANNELS;c++) \
+ DryBuffer[OutPos][c] += value*DrySend[i][c]; \
} \
\
frac += increment; \
@@ -261,10 +257,9 @@ static void Mix_##T##_Stereo_##sampler(ALsource *Source, ALCdevice *Device, \
{ \
value = sampler(data + pos*Channels + i, Channels, frac); \
\
- value = lpFilter2PC(DryFilter, chans[i]*2, value); \
- PendingClicks[chans[i+0]] += value*DrySend[chans[i+0]]; \
- PendingClicks[chans[i+2]] += value*DrySend[chans[i+2]]; \
- PendingClicks[chans[i+4]] += value*DrySend[chans[i+4]]; \
+ value = lpFilter2PC(DryFilter, i*2, value); \
+ for(c = 0;c < MAXCHANNELS;c++) \
+ PendingClicks[c] += value*DrySend[i][c]; \
} \
} \
\
@@ -296,7 +291,7 @@ static void Mix_##T##_Stereo_##sampler(ALsource *Source, ALCdevice *Device, \
{ \
value = sampler(data + pos*Channels + i, Channels, frac); \
\
- value = lpFilter1PC(WetFilter, chans[i], value); \
+ value = lpFilter1PC(WetFilter, i, value); \
WetClickRemoval[0] -= value*WetSend * scaler; \
} \
} \
@@ -306,7 +301,7 @@ static void Mix_##T##_Stereo_##sampler(ALsource *Source, ALCdevice *Device, \
{ \
value = sampler(data + pos*Channels + i, Channels, frac); \
\
- value = lpFilter1P(WetFilter, chans[i], value); \
+ value = lpFilter1P(WetFilter, i, value); \
WetBuffer[OutPos] += value*WetSend * scaler; \
} \
\
@@ -321,7 +316,7 @@ static void Mix_##T##_Stereo_##sampler(ALsource *Source, ALCdevice *Device, \
{ \
value = sampler(data + pos*Channels + i, Channels, frac); \
\
- value = lpFilter1PC(WetFilter, chans[i], value); \
+ value = lpFilter1PC(WetFilter, i, value); \
WetPendingClicks[0] += value*WetSend * scaler; \
} \
} \
@@ -370,11 +365,11 @@ static void Mix_##T##_##count##_##sampler(ALsource *Source, ALCdevice *Device,\
ALfloat (*DryBuffer)[MAXCHANNELS]; \
ALfloat *ClickRemoval, *PendingClicks; \
ALuint pos, frac; \
- ALfloat DrySend[MAXCHANNELS]; \
+ ALfloat DrySend[Channels][MAXCHANNELS]; \
FILTER *DryFilter; \
ALuint BufferIdx; \
ALuint increment; \
- ALuint i, out; \
+ ALuint i, out, c; \
ALfloat value; \
\
increment = Source->Params.Step; \
@@ -383,8 +378,11 @@ static void Mix_##T##_##count##_##sampler(ALsource *Source, ALCdevice *Device,\
ClickRemoval = Device->ClickRemoval; \
PendingClicks = Device->PendingClicks; \
DryFilter = &Source->Params.iirFilter; \
- for(i = 0;i < MAXCHANNELS;i++) \
- DrySend[i] = Source->Params.DryGains[i]; \
+ for(i = 0;i < Channels;i++) \
+ { \
+ for(c = 0;c < MAXCHANNELS;c++) \
+ DrySend[i][c] = Source->Params.DryGains[i][c]; \
+ } \
\
pos = 0; \
frac = *DataPosFrac; \
@@ -395,8 +393,9 @@ static void Mix_##T##_##count##_##sampler(ALsource *Source, ALCdevice *Device,\
{ \
value = sampler(data + pos*Channels + i, Channels, frac); \
\
- value = lpFilter2PC(DryFilter, chans[i]*2, value); \
- ClickRemoval[chans[i]] -= value*DrySend[chans[i]]; \
+ value = lpFilter2PC(DryFilter, i*2, value); \
+ for(c = 0;c < MAXCHANNELS;c++) \
+ ClickRemoval[c] -= value*DrySend[i][c]; \
} \
} \
for(BufferIdx = 0;BufferIdx < BufferSize;BufferIdx++) \
@@ -405,8 +404,9 @@ static void Mix_##T##_##count##_##sampler(ALsource *Source, ALCdevice *Device,\
{ \
value = sampler(data + pos*Channels + i, Channels, frac); \
\
- value = lpFilter2P(DryFilter, chans[i]*2, value); \
- DryBuffer[OutPos][chans[i]] += value*DrySend[chans[i]]; \
+ value = lpFilter2P(DryFilter, i*2, value); \
+ for(c = 0;c < MAXCHANNELS;c++) \
+ DryBuffer[OutPos][c] += value*DrySend[i][c]; \
} \
\
frac += increment; \
@@ -420,8 +420,9 @@ static void Mix_##T##_##count##_##sampler(ALsource *Source, ALCdevice *Device,\
{ \
value = sampler(data + pos*Channels + i, Channels, frac); \
\
- value = lpFilter2PC(DryFilter, chans[i]*2, value); \
- PendingClicks[chans[i]] += value*DrySend[chans[i]]; \
+ value = lpFilter2PC(DryFilter, i*2, value); \
+ for(c = 0;c < MAXCHANNELS;c++) \
+ PendingClicks[c] += value*DrySend[i][c]; \
} \
} \
\