Avoid unnecessary loops for setting up effect slot b-format buffer mixing

This commit is contained in:
Chris Robinson 2016-04-14 21:50:36 -07:00
parent 21921cdaff
commit fb97822d8c
5 changed files with 47 additions and 25 deletions

View File

@ -537,7 +537,7 @@ ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const A
for(c = 0;c < num_channels;c++)
{
const ALeffectslot *Slot = SendSlots[i];
ComputeFirstOrderGains(Slot->AmbiCoeffs, Slot->NumChannels, matrix.m[c],
ComputeFirstOrderGainsBF(Slot->ChanMap, Slot->NumChannels, matrix.m[c],
WetGain[i], voice->Send[i].Gains[c].Target);
}
}
@ -579,7 +579,7 @@ ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const A
else
{
const ALeffectslot *Slot = SendSlots[i];
ComputePanningGains(Slot->AmbiCoeffs, Slot->NumChannels, coeffs,
ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, coeffs,
WetGain[i], voice->Send[i].Gains[c].Target);
}
}
@ -636,7 +636,7 @@ ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const A
else
{
const ALeffectslot *Slot = SendSlots[i];
ComputePanningGains(Slot->AmbiCoeffs, Slot->NumChannels, coeffs,
ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, coeffs,
WetGain[i], voice->Send[i].Gains[c].Target);
}
}
@ -697,7 +697,7 @@ ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const A
else
{
const ALeffectslot *Slot = SendSlots[i];
ComputePanningGains(Slot->AmbiCoeffs, Slot->NumChannels, coeffs,
ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, coeffs,
WetGain[i], voice->Send[i].Gains[c].Target);
}
}
@ -1136,7 +1136,7 @@ ALvoid CalcSourceParams(ALvoice *voice, const ALsource *ALSource, const ALCconte
else
{
const ALeffectslot *Slot = SendSlots[i];
ComputePanningGains(Slot->AmbiCoeffs, Slot->NumChannels, coeffs,
ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, coeffs,
WetGain[i], voice->Send[i].Gains[0].Target);
}
}
@ -1198,7 +1198,7 @@ ALvoid CalcSourceParams(ALvoice *voice, const ALsource *ALSource, const ALCconte
else
{
const ALeffectslot *Slot = SendSlots[i];
ComputePanningGains(Slot->AmbiCoeffs, Slot->NumChannels, coeffs,
ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, coeffs,
WetGain[i], voice->Send[i].Gains[0].Target);
}
}

View File

@ -179,6 +179,16 @@ void ComputePanningGains(const ChannelConfig *chancoeffs, ALuint numchans, const
gains[i] = 0.0f;
}
void ComputePanningGainsBF(const BFChannelConfig *chanmap, ALuint numchans, const ALfloat coeffs[MAX_AMBI_COEFFS], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
{
ALuint i;
for(i = 0;i < numchans;i++)
gains[i] = chanmap[i].Scale * coeffs[chanmap[i].Index] * ingain;
for(;i < MAX_OUTPUT_CHANNELS;i++)
gains[i] = 0.0f;
}
void ComputeFirstOrderGains(const ChannelConfig *chancoeffs, ALuint numchans, const ALfloat mtx[4], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
{
ALuint i, j;
@ -194,6 +204,16 @@ void ComputeFirstOrderGains(const ChannelConfig *chancoeffs, ALuint numchans, co
gains[i] = 0.0f;
}
void ComputeFirstOrderGainsBF(const BFChannelConfig *chanmap, ALuint numchans, const ALfloat mtx[4], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
{
ALuint i;
for(i = 0;i < numchans;i++)
gains[i] = chanmap[i].Scale * mtx[chanmap[i].Index] * ingain;
for(;i < MAX_OUTPUT_CHANNELS;i++)
gains[i] = 0.0f;
}
DECL_CONST static inline const char *GetLabelFromChannel(enum Channel channel)
{
@ -936,19 +956,15 @@ no_hrtf:
void aluInitEffectPanning(ALeffectslot *slot)
{
static const ChannelMap FirstOrderN3D[4] = {
{ Aux0, { 1.0f, 0.0f, 0.0f, 0.0f } },
{ Aux1, { 0.0f, 1.0f, 0.0f, 0.0f } },
{ Aux2, { 0.0f, 0.0f, 1.0f, 0.0f } },
{ Aux3, { 0.0f, 0.0f, 0.0f, 1.0f } },
};
static const enum Channel AmbiChannels[MAX_OUTPUT_CHANNELS] = {
Aux0, Aux1, Aux2, Aux3, InvalidChannel
};
ALuint i;
memset(slot->AmbiCoeffs, 0, sizeof(slot->AmbiCoeffs));
memset(slot->ChanMap, 0, sizeof(slot->ChanMap));
slot->NumChannels = 0;
SetChannelMap(AmbiChannels, slot->AmbiCoeffs, FirstOrderN3D, COUNTOF(FirstOrderN3D),
&slot->NumChannels, AL_FALSE);
for(i = 0;i < MAX_EFFECT_CHANNELS;i++)
{
slot->ChanMap[i].Scale = 1.0f;
slot->ChanMap[i].Index = i;
}
slot->NumChannels = i;
}

View File

@ -86,7 +86,7 @@ typedef struct ALeffectslot {
ALuint id;
ALuint NumChannels;
ChannelConfig AmbiCoeffs[MAX_EFFECT_CHANNELS];
BFChannelConfig ChanMap[MAX_EFFECT_CHANNELS];
/* Wet buffer configuration is ACN channel order with N3D scaling:
* * Channel 0 is the unattenuated mono signal.
* * Channel 1 is OpenAL -X

View File

@ -407,6 +407,10 @@ enum RenderMode {
#define MAX_AMBI_COEFFS ((MAX_AMBI_ORDER+1) * (MAX_AMBI_ORDER+1))
typedef ALfloat ChannelConfig[MAX_AMBI_COEFFS];
typedef struct BFChannelConfig {
ALfloat Scale;
ALuint Index;
} BFChannelConfig;
#define HRTF_HISTORY_BITS (6)

View File

@ -338,6 +338,7 @@ void ComputeAmbientGains(const ChannelConfig *chancoeffs, ALuint numchans, ALflo
* pre-calculated direction or angle coefficients.
*/
void ComputePanningGains(const ChannelConfig *chancoeffs, ALuint numchans, const ALfloat coeffs[MAX_AMBI_COEFFS], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]);
void ComputePanningGainsBF(const BFChannelConfig *chanmap, ALuint numchans, const ALfloat coeffs[MAX_AMBI_COEFFS], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]);
/**
* ComputeFirstOrderGains
@ -347,6 +348,7 @@ void ComputePanningGains(const ChannelConfig *chancoeffs, ALuint numchans, const
* orient the sound samples.
*/
void ComputeFirstOrderGains(const ChannelConfig *chancoeffs, ALuint numchans, const ALfloat mtx[4], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]);
void ComputeFirstOrderGainsBF(const BFChannelConfig *chanmap, ALuint numchans, const ALfloat mtx[4], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]);
ALvoid UpdateContextSources(ALCcontext *context);