aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-11-05 02:54:11 -0800
committerChris Robinson <[email protected]>2014-11-05 02:54:11 -0800
commitc834c3fae59327a69914b22e8b7b357282963d3e (patch)
tree95587e365aef205eb70aedaddcdca765b9287910
parente5016f814a265ed592a88acea95cf912c4bfdf12 (diff)
Set gains using the device channel index
-rw-r--r--Alc/ALu.c26
-rw-r--r--Alc/effects/dedicated.c10
-rw-r--r--Alc/panning.c49
3 files changed, 45 insertions, 40 deletions
diff --git a/Alc/ALu.c b/Alc/ALu.c
index 6d95a99c..8c491cd0 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -481,11 +481,12 @@ ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const A
for(c = 0;c < num_channels;c++)
{
MixGains *gains = voice->Direct.Mix.Gains[c];
+ int idx;
for(j = 0;j < MaxChannels;j++)
gains[j].Target = 0.0f;
- if(GetChannelIdxByName(Device, chans[c].channel) != -1)
- gains[chans[c].channel].Target = DryGain;
+ if((idx=GetChannelIdxByName(Device, chans[c].channel)) != -1)
+ gains[idx].Target = DryGain;
}
UpdateDryStepping(&voice->Direct, num_channels);
@@ -532,10 +533,11 @@ ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const A
/* Special-case LFE */
if(chans[c].channel == LFE)
{
+ int idx;
for(i = 0;i < MaxChannels;i++)
gains[i].Target = 0.0f;
- if(GetChannelIdxByName(Device, chans[c].channel) != -1)
- gains[chans[c].channel].Target = DryGain;
+ if((idx=GetChannelIdxByName(Device, chans[c].channel)) != -1)
+ gains[idx].Target = DryGain;
continue;
}
@@ -1089,21 +1091,13 @@ static inline ALubyte aluF2UB(ALfloat val)
static void Write_##T(ALCdevice *device, ALvoid **buffer, ALuint SamplesToDo) \
{ \
ALfloat (*restrict DryBuffer)[BUFFERSIZE] = device->DryBuffer; \
- const ALuint numchans = ChannelsFromDevFmt(device->FmtChans); \
- const enum Channel *chans = device->ChannelName; \
+ const ALuint numchans = device->NumSpeakers; \
ALuint i, j; \
\
- for(j = 0;j < MaxChannels;j++) \
+ for(j = 0;j < numchans;j++) \
{ \
- const enum Channel c = chans[j]; \
- const ALfloat *in; \
- T *restrict out; \
- \
- if(c == InvalidChannel) \
- continue; \
- \
- in = DryBuffer[c]; \
- out = (T*)(*buffer) + j; \
+ const ALfloat *in = DryBuffer[j]; \
+ T *restrict out = (T*)(*buffer) + j; \
for(i = 0;i < SamplesToDo;i++) \
out[i*numchans] = func(in[i]); \
} \
diff --git a/Alc/effects/dedicated.c b/Alc/effects/dedicated.c
index e3014967..755ed611 100644
--- a/Alc/effects/dedicated.c
+++ b/Alc/effects/dedicated.c
@@ -56,15 +56,17 @@ static ALvoid ALdedicatedState_update(ALdedicatedState *state, ALCdevice *device
Gain = Slot->Gain * Slot->EffectProps.Dedicated.Gain;
if(Slot->EffectType == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT)
{
- if(GetChannelIdxByName(device, LFE) != -1)
- state->gains[LFE] = Gain;
+ int idx;
+ if((idx=GetChannelIdxByName(device, LFE)) != -1)
+ state->gains[idx] = Gain;
}
else if(Slot->EffectType == AL_EFFECT_DEDICATED_DIALOGUE)
{
+ int idx;
/* Dialog goes to the front-center speaker if it exists, otherwise it
* plays from the front-center location. */
- if(GetChannelIdxByName(device, FrontCenter) != -1)
- state->gains[FrontCenter] = Gain;
+ if((idx=GetChannelIdxByName(device, FrontCenter)) != -1)
+ state->gains[idx] = Gain;
else
{
static const ALfloat front_dir[3] = { 0.0f, 0.0f, -1.0f };
diff --git a/Alc/panning.c b/Alc/panning.c
index dd3b419c..caaefd50 100644
--- a/Alc/panning.c
+++ b/Alc/panning.c
@@ -72,10 +72,9 @@ void ComputeDirectionalGains(const ALCdevice *device, const ALfloat dir[3], ALfl
gains[i] = 0.0f;
for(i = 0;i < device->NumSpeakers;i++)
{
- enum Channel chan = device->Speaker[i].ChanName;
for(j = 0;j < MAX_AMBI_COEFFS;j++)
- gains[chan] += device->Speaker[i].HOACoeff[j]*coeffs[j];
- gains[chan] = maxf(gains[chan], 0.0f) * ingain;
+ gains[i] += device->Speaker[i].HOACoeff[j]*coeffs[j];
+ gains[i] = maxf(gains[i], 0.0f) * ingain;
}
}
@@ -86,10 +85,7 @@ void ComputeAmbientGains(const ALCdevice *device, ALfloat ingain, ALfloat gains[
for(i = 0;i < MaxChannels;i++)
gains[i] = 0.0f;
for(i = 0;i < device->NumSpeakers;i++)
- {
- enum Channel chan = device->Speaker[i].ChanName;
- gains[chan] = device->Speaker[i].HOACoeff[0] * ingain;
- }
+ gains[i] = device->Speaker[i].HOACoeff[0] * ingain;
}
void ComputeBFormatGains(const ALCdevice *device, const ALfloat mtx[4], ALfloat ingain, ALfloat gains[MaxChannels])
@@ -100,10 +96,9 @@ void ComputeBFormatGains(const ALCdevice *device, const ALfloat mtx[4], ALfloat
gains[i] = 0.0f;
for(i = 0;i < device->NumSpeakers;i++)
{
- enum Channel chan = device->Speaker[i].ChanName;
for(j = 0;j < 4;j++)
- gains[chan] += device->Speaker[i].FOACoeff[j] * mtx[j];
- gains[chan] *= ingain;
+ gains[i] += device->Speaker[i].FOACoeff[j] * mtx[j];
+ gains[i] *= ingain;
}
}
@@ -153,7 +148,8 @@ ALvoid aluInitPanning(ALCdevice *device)
{ 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 } }
};
const ChannelConfig *config;
- ALuint i;
+ size_t count;
+ ALuint i, j;
memset(device->Speaker, 0, sizeof(device->Speaker));
device->NumSpeakers = 0;
@@ -161,40 +157,53 @@ ALvoid aluInitPanning(ALCdevice *device)
switch(device->FmtChans)
{
case DevFmtMono:
- device->NumSpeakers = COUNTOF(MonoCfg);
+ count = COUNTOF(MonoCfg);
config = MonoCfg;
break;
case DevFmtStereo:
- device->NumSpeakers = COUNTOF(StereoCfg);
+ count = COUNTOF(StereoCfg);
config = StereoCfg;
break;
case DevFmtQuad:
- device->NumSpeakers = COUNTOF(QuadCfg);
+ count = COUNTOF(QuadCfg);
config = QuadCfg;
break;
case DevFmtX51:
- device->NumSpeakers = COUNTOF(X51Cfg);
+ count = COUNTOF(X51Cfg);
config = X51Cfg;
break;
case DevFmtX51Side:
- device->NumSpeakers = COUNTOF(X51SideCfg);
+ count = COUNTOF(X51SideCfg);
config = X51SideCfg;
break;
case DevFmtX61:
- device->NumSpeakers = COUNTOF(X61Cfg);
+ count = COUNTOF(X61Cfg);
config = X61Cfg;
break;
case DevFmtX71:
- device->NumSpeakers = COUNTOF(X71Cfg);
+ count = COUNTOF(X71Cfg);
config = X71Cfg;
break;
}
- for(i = 0;i < device->NumSpeakers;i++)
- device->Speaker[i] = config[i];
+ for(i = 0;i < MaxChannels && device->ChannelName[i] != InvalidChannel;i++)
+ {
+ device->Speaker[i].ChanName = InvalidChannel;
+ for(j = 0;j < count;j++)
+ {
+ if(device->ChannelName[i] == config[j].ChanName)
+ {
+ device->Speaker[i] = config[j];
+ break;
+ }
+ }
+ if(j == count)
+ ERR("Failed to match channel %u (label %d) in config\n", i, device->ChannelName[i]);
+ }
+ device->NumSpeakers = i;
}