Use a method to set omni-directional channel gains
This commit is contained in:
parent
d8cfdb3f34
commit
6083a684d1
@ -997,7 +997,10 @@ ALvoid CalcSourceParams(ALvoice *voice, const ALsource *ALSource, const ALCconte
|
||||
|
||||
/* Normalize the length, and compute panned gains. */
|
||||
if(!(Distance > FLT_EPSILON))
|
||||
{
|
||||
Position[0] = Position[1] = Position[2] = 0.0f;
|
||||
ComputeAmbientGains(Device, DryGain, Target);
|
||||
}
|
||||
else
|
||||
{
|
||||
ALfloat radius = ALSource->Radius;
|
||||
@ -1005,8 +1008,8 @@ ALvoid CalcSourceParams(ALvoice *voice, const ALsource *ALSource, const ALCconte
|
||||
Position[0] *= invlen;
|
||||
Position[1] *= invlen;
|
||||
Position[2] *= invlen;
|
||||
ComputeDirectionalGains(Device, Position, DryGain, Target);
|
||||
}
|
||||
ComputeDirectionalGains(Device, Position, DryGain, Target);
|
||||
|
||||
for(j = 0;j < MaxChannels;j++)
|
||||
gains[j].Target = Target[j];
|
||||
|
@ -66,7 +66,6 @@ static ALboolean ALautowahState_deviceUpdate(ALautowahState *state, ALCdevice *d
|
||||
static ALvoid ALautowahState_update(ALautowahState *state, ALCdevice *device, const ALeffectslot *slot)
|
||||
{
|
||||
ALfloat attackTime, releaseTime;
|
||||
ALfloat gain;
|
||||
|
||||
attackTime = slot->EffectProps.Autowah.AttackTime * state->Frequency;
|
||||
releaseTime = slot->EffectProps.Autowah.ReleaseTime * state->Frequency;
|
||||
@ -76,8 +75,7 @@ static ALvoid ALautowahState_update(ALautowahState *state, ALCdevice *device, co
|
||||
state->PeakGain = slot->EffectProps.Autowah.PeakGain;
|
||||
state->Resonance = slot->EffectProps.Autowah.Resonance;
|
||||
|
||||
gain = 1.0f/device->NumSpeakers * slot->Gain;
|
||||
SetGains(device, gain, state->Gain);
|
||||
ComputeAmbientGains(device, slot->Gain, state->Gain);
|
||||
}
|
||||
|
||||
static ALvoid ALautowahState_process(ALautowahState *state, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[BUFFERSIZE])
|
||||
|
@ -55,14 +55,11 @@ static ALboolean ALcompressorState_deviceUpdate(ALcompressorState *state, ALCdev
|
||||
return AL_TRUE;
|
||||
}
|
||||
|
||||
static ALvoid ALcompressorState_update(ALcompressorState *state, ALCdevice *Device, const ALeffectslot *Slot)
|
||||
static ALvoid ALcompressorState_update(ALcompressorState *state, ALCdevice *device, const ALeffectslot *slot)
|
||||
{
|
||||
ALfloat gain;
|
||||
state->Enabled = slot->EffectProps.Compressor.OnOff;
|
||||
|
||||
state->Enabled = Slot->EffectProps.Compressor.OnOff;
|
||||
|
||||
gain = 1.0f/Device->NumSpeakers * Slot->Gain;
|
||||
SetGains(Device, gain, state->Gain);
|
||||
ComputeAmbientGains(device, slot->Gain, state->Gain);
|
||||
}
|
||||
|
||||
static ALvoid ALcompressorState_process(ALcompressorState *state, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[BUFFERSIZE])
|
||||
|
@ -58,7 +58,6 @@ static ALvoid ALdistortionState_update(ALdistortionState *state, ALCdevice *Devi
|
||||
ALfloat bandwidth;
|
||||
ALfloat cutoff;
|
||||
ALfloat edge;
|
||||
ALfloat gain;
|
||||
|
||||
/* Store distorted signal attenuation settings */
|
||||
state->attenuation = Slot->EffectProps.Distortion.Gain;
|
||||
@ -82,8 +81,7 @@ static ALvoid ALdistortionState_update(ALdistortionState *state, ALCdevice *Devi
|
||||
ALfilterState_setParams(&state->bandpass, ALfilterType_BandPass, 1.0f,
|
||||
cutoff / (frequency*4.0f), bandwidth);
|
||||
|
||||
gain = 1.0f/Device->NumSpeakers * Slot->Gain;
|
||||
SetGains(Device, gain, state->Gain);
|
||||
ComputeAmbientGains(Device, Slot->Gain, state->Gain);
|
||||
}
|
||||
|
||||
static ALvoid ALdistortionState_process(ALdistortionState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE])
|
||||
|
@ -93,9 +93,8 @@ static ALboolean ALequalizerState_deviceUpdate(ALequalizerState *UNUSED(state),
|
||||
static ALvoid ALequalizerState_update(ALequalizerState *state, ALCdevice *device, const ALeffectslot *slot)
|
||||
{
|
||||
ALfloat frequency = (ALfloat)device->Frequency;
|
||||
ALfloat gain = 1.0f/device->NumSpeakers * slot->Gain;
|
||||
|
||||
SetGains(device, gain, state->Gain);
|
||||
ComputeAmbientGains(device, slot->Gain, state->Gain);
|
||||
|
||||
/* Calculate coefficients for the each type of filter */
|
||||
ALfilterState_setParams(&state->filter[0], ALfilterType_LowShelf,
|
||||
|
@ -125,7 +125,7 @@ static ALboolean ALmodulatorState_deviceUpdate(ALmodulatorState *UNUSED(state),
|
||||
|
||||
static ALvoid ALmodulatorState_update(ALmodulatorState *state, ALCdevice *Device, const ALeffectslot *Slot)
|
||||
{
|
||||
ALfloat gain, cw, a;
|
||||
ALfloat cw, a;
|
||||
|
||||
if(Slot->EffectProps.Modulator.Waveform == AL_RING_MODULATOR_SINUSOID)
|
||||
state->Waveform = SINUSOID;
|
||||
@ -149,8 +149,7 @@ static ALvoid ALmodulatorState_update(ALmodulatorState *state, ALCdevice *Device
|
||||
state->Filter.a[1] = -a;
|
||||
state->Filter.a[2] = 0.0f;
|
||||
|
||||
gain = 1.0f/Device->NumSpeakers * Slot->Gain;
|
||||
SetGains(Device, gain, state->Gain);
|
||||
ComputeAmbientGains(Device, Slot->Gain, state->Gain);
|
||||
}
|
||||
|
||||
static ALvoid ALmodulatorState_process(ALmodulatorState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE])
|
||||
|
@ -1148,8 +1148,7 @@ static ALvoid ALreverbState_update(ALreverbState *State, ALCdevice *Device, cons
|
||||
else
|
||||
{
|
||||
/* Update channel gains */
|
||||
ALfloat gain = 2.0f/Device->NumSpeakers * Slot->Gain * ReverbBoost;
|
||||
SetGains(Device, gain, State->Gain);
|
||||
ComputeAmbientGains(Device, Slot->Gain*2.0f, State->Gain);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,8 +31,6 @@
|
||||
#include "AL/alc.h"
|
||||
#include "alu.h"
|
||||
|
||||
extern inline void SetGains(const ALCdevice *device, ALfloat ingain, ALfloat gains[MaxChannels]);
|
||||
|
||||
|
||||
void ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat elevation, ALfloat ingain, ALfloat gains[MaxChannels])
|
||||
{
|
||||
@ -81,6 +79,19 @@ void ComputeDirectionalGains(const ALCdevice *device, const ALfloat dir[3], ALfl
|
||||
}
|
||||
}
|
||||
|
||||
void ComputeAmbientGains(const ALCdevice *device, ALfloat ingain, ALfloat gains[MaxChannels])
|
||||
{
|
||||
ALuint i;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void ComputeBFormatGains(const ALCdevice *device, const ALfloat mtx[4], ALfloat ingain, ALfloat gains[MaxChannels])
|
||||
{
|
||||
ALuint i, j;
|
||||
|
@ -217,6 +217,13 @@ void ComputeDirectionalGains(const ALCdevice *device, const ALfloat dir[3], ALfl
|
||||
*/
|
||||
void ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat elevation, ALfloat ingain, ALfloat gains[MaxChannels]);
|
||||
|
||||
/**
|
||||
* ComputeAmbientGains
|
||||
*
|
||||
* Sets channel gains for ambient, omni-directional sounds.
|
||||
*/
|
||||
void ComputeAmbientGains(const ALCdevice *device, ALfloat ingain, ALfloat gains[MaxChannels]);
|
||||
|
||||
/**
|
||||
* ComputeBFormatGains
|
||||
*
|
||||
@ -226,20 +233,6 @@ void ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat elevation
|
||||
*/
|
||||
void ComputeBFormatGains(const ALCdevice *device, const ALfloat mtx[4], ALfloat ingain, ALfloat gains[MaxChannels]);
|
||||
|
||||
/**
|
||||
* SetGains
|
||||
*
|
||||
* Helper to set the appropriate channels to the specified gain.
|
||||
*/
|
||||
inline void SetGains(const ALCdevice *device, ALfloat ingain, ALfloat gains[MaxChannels])
|
||||
{
|
||||
ALuint i;
|
||||
for(i = 0;i < MaxChannels;i++)
|
||||
gains[i] = 0.0f;
|
||||
for(i = 0;i < device->NumSpeakers;i++)
|
||||
gains[device->Speaker[i].ChanName] = ingain;
|
||||
}
|
||||
|
||||
|
||||
ALvoid CalcSourceParams(struct ALvoice *voice, const struct ALsource *source, const ALCcontext *ALContext);
|
||||
ALvoid CalcNonAttnSourceParams(struct ALvoice *voice, const struct ALsource *source, const ALCcontext *ALContext);
|
||||
|
Loading…
x
Reference in New Issue
Block a user