Use helpers to set channel gain arrays
Also avoid unnecessary clearing.
This commit is contained in:
parent
99fa5911bc
commit
764ea95781
@ -80,16 +80,12 @@ static ALboolean ALautowahState_deviceUpdate(ALautowahState *state, ALCdevice *d
|
||||
|
||||
static ALvoid ALautowahState_update(ALautowahState *state, ALCdevice *Device, const ALeffectslot *Slot)
|
||||
{
|
||||
ALuint i;
|
||||
ALfloat gain = sqrtf(1.0f / Device->NumChan) * Slot->Gain;
|
||||
|
||||
/* computing high-pass cutoff and bandwidth */
|
||||
const ALfloat cutoff = LOWPASSFREQREF / (Device->Frequency * 4.0f);
|
||||
const ALfloat bandwidth = (cutoff / 2.0f) / (cutoff * 0.67f);
|
||||
ALfloat gain;
|
||||
|
||||
/* computing high-pass filter coefficients */
|
||||
ALfilterState_setParams(&state->high_pass,
|
||||
ALfilterType_HighPass, 1.0f,
|
||||
ALfilterState_setParams(&state->high_pass, ALfilterType_HighPass, 1.0f,
|
||||
cutoff, bandwidth);
|
||||
|
||||
state->AttackTime = Slot->EffectProps.Autowah.AttackTime;
|
||||
@ -102,13 +98,8 @@ static ALvoid ALautowahState_update(ALautowahState *state, ALCdevice *Device, co
|
||||
|
||||
ALfilterState_clear(&state->low_pass);
|
||||
|
||||
for(i = 0;i < MaxChannels;i++)
|
||||
state->Gain[i] = 0.0f;
|
||||
for(i = 0;i < Device->NumChan;i++)
|
||||
{
|
||||
enum Channel chan = Device->Speaker2Chan[i];
|
||||
state->Gain[chan] = gain;
|
||||
}
|
||||
gain = sqrtf(1.0f / Device->NumChan) * Slot->Gain;
|
||||
SetGains(Device, gain, state->Gain);
|
||||
}
|
||||
|
||||
static ALvoid ALautowahState_process(ALautowahState *state, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[BUFFERSIZE])
|
||||
|
@ -103,13 +103,6 @@ static ALvoid ALchorusState_update(ALchorusState *state, ALCdevice *Device, cons
|
||||
ALfloat frequency = (ALfloat)Device->Frequency;
|
||||
ALfloat rate;
|
||||
ALint phase;
|
||||
ALuint it;
|
||||
|
||||
for (it = 0; it < MaxChannels; it++)
|
||||
{
|
||||
state->Gain[0][it] = 0.0f;
|
||||
state->Gain[1][it] = 0.0f;
|
||||
}
|
||||
|
||||
state->waveform = Slot->EffectProps.Chorus.Waveform;
|
||||
state->depth = Slot->EffectProps.Chorus.Depth;
|
||||
|
@ -61,13 +61,14 @@ static ALvoid ALdedicatedState_update(ALdedicatedState *state, ALCdevice *device
|
||||
ALsizei s;
|
||||
|
||||
Gain = Slot->Gain * Slot->EffectProps.Dedicated.Gain;
|
||||
for(s = 0;s < MaxChannels;s++)
|
||||
state->gains[s] = 0.0f;
|
||||
|
||||
if(Slot->EffectType == AL_EFFECT_DEDICATED_DIALOGUE)
|
||||
ComputeAngleGains(device, atan2f(0.0f, 1.0f), 0.0f, Gain, state->gains);
|
||||
else if(Slot->EffectType == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT)
|
||||
{
|
||||
for(s = 0;s < MaxChannels;s++)
|
||||
state->gains[s] = 0.0f;
|
||||
state->gains[LFE] = Gain;
|
||||
}
|
||||
}
|
||||
|
||||
static ALvoid ALdedicatedState_process(ALdedicatedState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE])
|
||||
|
@ -64,20 +64,11 @@ static ALboolean ALdistortionState_deviceUpdate(ALdistortionState *state, ALCdev
|
||||
|
||||
static ALvoid ALdistortionState_update(ALdistortionState *state, ALCdevice *Device, const ALeffectslot *Slot)
|
||||
{
|
||||
ALfloat gain = sqrtf(1.0f / Device->NumChan) * Slot->Gain;
|
||||
ALfloat frequency = (ALfloat)Device->Frequency;
|
||||
ALuint it;
|
||||
ALfloat bandwidth;
|
||||
ALfloat cutoff;
|
||||
ALfloat edge;
|
||||
|
||||
for(it = 0;it < MaxChannels;it++)
|
||||
state->Gain[it] = 0.0f;
|
||||
for(it = 0;it < Device->NumChan;it++)
|
||||
{
|
||||
enum Channel chan = Device->Speaker2Chan[it];
|
||||
state->Gain[chan] = gain;
|
||||
}
|
||||
ALfloat gain;
|
||||
|
||||
/* Store distorted signal attenuation settings */
|
||||
state->attenuation = Slot->EffectProps.Distortion.Gain;
|
||||
@ -100,6 +91,9 @@ static ALvoid ALdistortionState_update(ALdistortionState *state, ALCdevice *Devi
|
||||
bandwidth = Slot->EffectProps.Distortion.EQBandwidth / (cutoff * 0.67f);
|
||||
ALfilterState_setParams(&state->bandpass, ALfilterType_BandPass, 1.0f,
|
||||
cutoff / (frequency*4.0f), bandwidth);
|
||||
|
||||
gain = sqrtf(1.0f / Device->NumChan) * Slot->Gain;
|
||||
SetGains(Device, gain, state->Gain);
|
||||
}
|
||||
|
||||
static ALvoid ALdistortionState_process(ALdistortionState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE])
|
||||
|
@ -93,7 +93,6 @@ static ALvoid ALechoState_update(ALechoState *state, ALCdevice *Device, const AL
|
||||
ALuint frequency = Device->Frequency;
|
||||
ALfloat lrpan, gain;
|
||||
ALfloat dirGain;
|
||||
ALuint i;
|
||||
|
||||
state->Tap[0].delay = fastf2u(Slot->EffectProps.Echo.Delay * frequency) + 1;
|
||||
state->Tap[1].delay = fastf2u(Slot->EffectProps.Echo.LRDelay * frequency);
|
||||
@ -108,12 +107,6 @@ static ALvoid ALechoState_update(ALechoState *state, ALCdevice *Device, const AL
|
||||
(ALfloat)LOWPASSFREQREF/frequency, 0.0f);
|
||||
|
||||
gain = Slot->Gain;
|
||||
for(i = 0;i < MaxChannels;i++)
|
||||
{
|
||||
state->Gain[0][i] = 0.0f;
|
||||
state->Gain[1][i] = 0.0f;
|
||||
}
|
||||
|
||||
dirGain = fabsf(lrpan);
|
||||
|
||||
/* First tap panning */
|
||||
|
@ -104,15 +104,8 @@ static ALvoid ALequalizerState_update(ALequalizerState *state, ALCdevice *device
|
||||
{
|
||||
ALfloat frequency = (ALfloat)device->Frequency;
|
||||
ALfloat gain = sqrtf(1.0f / device->NumChan) * slot->Gain;
|
||||
ALuint it;
|
||||
|
||||
for(it = 0;it < MaxChannels;it++)
|
||||
state->Gain[it] = 0.0f;
|
||||
for(it = 0; it < device->NumChan; it++)
|
||||
{
|
||||
enum Channel chan = device->Speaker2Chan[it];
|
||||
state->Gain[chan] = gain;
|
||||
}
|
||||
SetGains(device, gain, state->Gain);
|
||||
|
||||
/* Calculate coefficients for the each type of filter */
|
||||
ALfilterState_setParams(&state->filter[0], ALfilterType_LowShelf,
|
||||
|
@ -103,13 +103,6 @@ static ALvoid ALflangerState_update(ALflangerState *state, ALCdevice *Device, co
|
||||
ALfloat frequency = (ALfloat)Device->Frequency;
|
||||
ALfloat rate;
|
||||
ALint phase;
|
||||
ALuint it;
|
||||
|
||||
for(it = 0;it < MaxChannels;it++)
|
||||
{
|
||||
state->Gain[0][it] = 0.0f;
|
||||
state->Gain[1][it] = 0.0f;
|
||||
}
|
||||
|
||||
state->waveform = Slot->EffectProps.Flanger.Waveform;
|
||||
state->depth = Slot->EffectProps.Flanger.Depth;
|
||||
|
@ -136,7 +136,6 @@ static ALboolean ALmodulatorState_deviceUpdate(ALmodulatorState *state, ALCdevic
|
||||
static ALvoid ALmodulatorState_update(ALmodulatorState *state, ALCdevice *Device, const ALeffectslot *Slot)
|
||||
{
|
||||
ALfloat gain, cw, a;
|
||||
ALuint index;
|
||||
|
||||
if(Slot->EffectProps.Modulator.Waveform == AL_RING_MODULATOR_SINUSOID)
|
||||
state->Waveform = SINUSOID;
|
||||
@ -161,15 +160,8 @@ static ALvoid ALmodulatorState_update(ALmodulatorState *state, ALCdevice *Device
|
||||
state->Filter.a[1] = -a;
|
||||
state->Filter.a[2] = 0.0f;
|
||||
|
||||
gain = sqrtf(1.0f/Device->NumChan);
|
||||
gain *= Slot->Gain;
|
||||
for(index = 0;index < MaxChannels;index++)
|
||||
state->Gain[index] = 0.0f;
|
||||
for(index = 0;index < Device->NumChan;index++)
|
||||
{
|
||||
enum Channel chan = Device->Speaker2Chan[index];
|
||||
state->Gain[chan] = gain;
|
||||
}
|
||||
gain = sqrtf(1.0f/Device->NumChan) * Slot->Gain;
|
||||
SetGains(Device, gain, state->Gain);
|
||||
}
|
||||
|
||||
static ALvoid ALmodulatorState_process(ALmodulatorState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE])
|
||||
|
@ -1044,7 +1044,6 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection
|
||||
ALfloat ambientGain;
|
||||
ALfloat dirGain;
|
||||
ALfloat length;
|
||||
ALuint index;
|
||||
|
||||
Gain *= ReverbBoost;
|
||||
|
||||
@ -1070,14 +1069,10 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection
|
||||
}
|
||||
|
||||
dirGain = sqrtf(earlyPan[0]*earlyPan[0] + earlyPan[2]*earlyPan[2]);
|
||||
for(index = 0;index < MaxChannels;index++)
|
||||
State->Early.PanGain[index] = 0.0f;
|
||||
ComputeAngleGains(Device, atan2f(earlyPan[0], earlyPan[2]), (1.0f-dirGain)*F_PI,
|
||||
lerp(ambientGain, 1.0f, dirGain) * Gain, State->Early.PanGain);
|
||||
|
||||
dirGain = sqrtf(latePan[0]*latePan[0] + latePan[2]*latePan[2]);
|
||||
for(index = 0;index < MaxChannels;index++)
|
||||
State->Late.PanGain[index] = 0.0f;
|
||||
ComputeAngleGains(Device, atan2f(latePan[0], latePan[2]), (1.0f-dirGain)*F_PI,
|
||||
lerp(ambientGain, 1.0f, dirGain) * Gain, State->Late.PanGain);
|
||||
}
|
||||
@ -1168,18 +1163,9 @@ static ALvoid ALreverbState_update(ALreverbState *State, ALCdevice *Device, cons
|
||||
}
|
||||
else
|
||||
{
|
||||
ALfloat gain = Slot->Gain;
|
||||
ALuint index;
|
||||
|
||||
/* Update channel gains */
|
||||
gain *= sqrtf(2.0f/Device->NumChan) * ReverbBoost;
|
||||
for(index = 0;index < MaxChannels;index++)
|
||||
State->Gain[index] = 0.0f;
|
||||
for(index = 0;index < Device->NumChan;index++)
|
||||
{
|
||||
enum Channel chan = Device->Speaker2Chan[index];
|
||||
State->Gain[chan] = gain;
|
||||
}
|
||||
ALfloat gain = sqrtf(2.0f/Device->NumChan) * ReverbBoost * Slot->Gain;
|
||||
SetGains(Device, gain, State->Gain);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,13 +140,7 @@ static void SetSpeakerArrangement(const char *name, ALfloat SpeakerAngle[MaxChan
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ComputeAngleGains
|
||||
*
|
||||
* Sets channel gains based on a given source's angle and its half-width. The
|
||||
* angle and hwidth parameters are in radians.
|
||||
*/
|
||||
ALvoid ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth, ALfloat ingain, ALfloat *gains)
|
||||
void ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth, ALfloat ingain, ALfloat gains[MaxChannels])
|
||||
{
|
||||
ALfloat tmpgains[MaxChannels] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
enum Channel Speaker2Chan[MaxChannels];
|
||||
@ -164,6 +158,8 @@ ALvoid ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth,
|
||||
if(device->NumChan <= 1 || hwidth >= F_PI)
|
||||
{
|
||||
/* Full coverage for all speakers. */
|
||||
for(i = 0;i < MaxChannels;i++)
|
||||
gains[i] = 0.0f;
|
||||
for(i = 0;i < device->NumChan;i++)
|
||||
{
|
||||
enum Channel chan = Speaker2Chan[i];
|
||||
@ -174,6 +170,8 @@ ALvoid ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth,
|
||||
if(hwidth <= 0.0f)
|
||||
{
|
||||
/* Infinitely small sound point. */
|
||||
for(i = 0;i < MaxChannels;i++)
|
||||
gains[i] = 0.0f;
|
||||
for(i = 0;i < device->NumChan-1;i++)
|
||||
{
|
||||
if(angle >= SpeakerAngle[i] && angle < SpeakerAngle[i+1])
|
||||
|
@ -105,7 +105,24 @@ static inline ALfloat cubic(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat va
|
||||
|
||||
ALvoid aluInitPanning(ALCdevice *Device);
|
||||
|
||||
ALvoid ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth, ALfloat ingain, ALfloat *gains);
|
||||
/**
|
||||
* ComputeAngleGains
|
||||
*
|
||||
* Sets channel gains based on a given source's angle and its half-width. The
|
||||
* angle and hwidth parameters are in radians.
|
||||
*/
|
||||
void ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth, ALfloat ingain, ALfloat gains[MaxChannels]);
|
||||
|
||||
/**
|
||||
* SetGains
|
||||
*
|
||||
* Helper to set the appropriate channels to the specified gain.
|
||||
*/
|
||||
static inline void SetGains(const ALCdevice *device, ALfloat ingain, ALfloat gains[MaxChannels])
|
||||
{
|
||||
ComputeAngleGains(device, 0.0f, F_PI, ingain, gains);
|
||||
}
|
||||
|
||||
|
||||
ALvoid CalcSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
|
||||
ALvoid CalcNonAttnSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
|
||||
|
Loading…
Reference in New Issue
Block a user