Avoid an unnecessary out parameter
This commit is contained in:
parent
a97e6e6a12
commit
2deb5e47d1
67
alc/alu.cpp
67
alc/alu.cpp
@ -834,11 +834,11 @@ void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, con
|
||||
voice->mFlags |= VOICE_HAS_NFC;
|
||||
}
|
||||
|
||||
float coeffs[MAX_AMBI_CHANNELS];
|
||||
if(Device->mRenderMode != StereoPair)
|
||||
CalcDirectionCoeffs({xpos, ypos, zpos}, Spread, coeffs);
|
||||
else
|
||||
auto calc_coeffs = [xpos,ypos,zpos,Spread](RenderMode mode)
|
||||
{
|
||||
if(mode != StereoPair)
|
||||
return CalcDirectionCoeffs({xpos, ypos, zpos}, Spread);
|
||||
|
||||
/* Clamp Y, in case rounding errors caused it to end up outside
|
||||
* of -1...+1.
|
||||
*/
|
||||
@ -850,17 +850,18 @@ void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, con
|
||||
* being moved to +/-90 degrees for direct right and left
|
||||
* speaker responses.
|
||||
*/
|
||||
CalcAngleCoeffs(ScaleAzimuthFront(az, 1.5f), ev, Spread, coeffs);
|
||||
}
|
||||
return CalcAngleCoeffs(ScaleAzimuthFront(az, 1.5f), ev, Spread);
|
||||
};
|
||||
const auto coeffs = calc_coeffs(Device->mRenderMode);
|
||||
|
||||
/* NOTE: W needs to be scaled according to channel scaling. */
|
||||
const float scale0{GetAmbiScales(voice->mAmbiScaling)[0]};
|
||||
ComputePanGains(&Device->Dry, coeffs, DryGain.Base*scale0,
|
||||
ComputePanGains(&Device->Dry, coeffs.data(), DryGain.Base*scale0,
|
||||
voice->mChans[0].mDryParams.Gains.Target);
|
||||
for(ALuint i{0};i < NumSends;i++)
|
||||
{
|
||||
if(const ALeffectslot *Slot{SendSlots[i]})
|
||||
ComputePanGains(&Slot->Wet, coeffs, WetGain[i].Base*scale0,
|
||||
ComputePanGains(&Slot->Wet, coeffs.data(), WetGain[i].Base*scale0,
|
||||
voice->mChans[0].mWetParams[i].Gains.Target);
|
||||
}
|
||||
}
|
||||
@ -924,17 +925,17 @@ void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, con
|
||||
const float scale{scales[acn]};
|
||||
auto in = shrot.cbegin() + offset;
|
||||
|
||||
float coeffs[MAX_AMBI_CHANNELS]{};
|
||||
std::array<float,MAX_AMBI_CHANNELS> coeffs{};
|
||||
for(size_t x{0};x < tocopy;++x)
|
||||
coeffs[offset+x] = in[x][acn] * scale;
|
||||
|
||||
ComputePanGains(&Device->Dry, coeffs, DryGain.Base,
|
||||
ComputePanGains(&Device->Dry, coeffs.data(), DryGain.Base,
|
||||
voice->mChans[c].mDryParams.Gains.Target);
|
||||
|
||||
for(ALuint i{0};i < NumSends;i++)
|
||||
{
|
||||
if(const ALeffectslot *Slot{SendSlots[i]})
|
||||
ComputePanGains(&Slot->Wet, coeffs, WetGain[i].Base,
|
||||
ComputePanGains(&Slot->Wet, coeffs.data(), WetGain[i].Base,
|
||||
voice->mChans[c].mWetParams[i].Gains.Target);
|
||||
}
|
||||
}
|
||||
@ -974,13 +975,12 @@ void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, con
|
||||
*/
|
||||
for(size_t c{0};c < num_channels;c++)
|
||||
{
|
||||
float coeffs[MAX_AMBI_CHANNELS];
|
||||
CalcAngleCoeffs(chans[c].angle, chans[c].elevation, 0.0f, coeffs);
|
||||
const auto coeffs = CalcAngleCoeffs(chans[c].angle, chans[c].elevation, 0.0f);
|
||||
|
||||
for(ALuint i{0};i < NumSends;i++)
|
||||
{
|
||||
if(const ALeffectslot *Slot{SendSlots[i]})
|
||||
ComputePanGains(&Slot->Wet, coeffs, WetGain[i].Base,
|
||||
ComputePanGains(&Slot->Wet, coeffs.data(), WetGain[i].Base,
|
||||
voice->mChans[c].mWetParams[i].Gains.Target);
|
||||
}
|
||||
}
|
||||
@ -1016,8 +1016,7 @@ void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, con
|
||||
/* Calculate the directional coefficients once, which apply to all
|
||||
* input channels of the source sends.
|
||||
*/
|
||||
float coeffs[MAX_AMBI_CHANNELS];
|
||||
CalcDirectionCoeffs({xpos, ypos, zpos}, Spread, coeffs);
|
||||
const auto coeffs = CalcDirectionCoeffs({xpos, ypos, zpos}, Spread);
|
||||
|
||||
for(size_t c{0};c < num_channels;c++)
|
||||
{
|
||||
@ -1027,7 +1026,7 @@ void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, con
|
||||
for(ALuint i{0};i < NumSends;i++)
|
||||
{
|
||||
if(const ALeffectslot *Slot{SendSlots[i]})
|
||||
ComputePanGains(&Slot->Wet, coeffs, WetGain[i].Base * downmix_gain,
|
||||
ComputePanGains(&Slot->Wet, coeffs.data(), WetGain[i].Base * downmix_gain,
|
||||
voice->mChans[c].mWetParams[i].Gains.Target);
|
||||
}
|
||||
}
|
||||
@ -1054,13 +1053,12 @@ void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, con
|
||||
voice->mChans[c].mDryParams.Hrtf.Target.Gain = DryGain.Base;
|
||||
|
||||
/* Normal panning for auxiliary sends. */
|
||||
float coeffs[MAX_AMBI_CHANNELS];
|
||||
CalcAngleCoeffs(chans[c].angle, chans[c].elevation, Spread, coeffs);
|
||||
const auto coeffs = CalcAngleCoeffs(chans[c].angle, chans[c].elevation, Spread);
|
||||
|
||||
for(ALuint i{0};i < NumSends;i++)
|
||||
{
|
||||
if(const ALeffectslot *Slot{SendSlots[i]})
|
||||
ComputePanGains(&Slot->Wet, coeffs, WetGain[i].Base,
|
||||
ComputePanGains(&Slot->Wet, coeffs.data(), WetGain[i].Base,
|
||||
voice->mChans[c].mWetParams[i].Gains.Target);
|
||||
}
|
||||
}
|
||||
@ -1093,15 +1091,15 @@ void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, con
|
||||
/* Calculate the directional coefficients once, which apply to all
|
||||
* input channels.
|
||||
*/
|
||||
float coeffs[MAX_AMBI_CHANNELS];
|
||||
if(Device->mRenderMode != StereoPair)
|
||||
CalcDirectionCoeffs({xpos, ypos, zpos}, Spread, coeffs);
|
||||
else
|
||||
auto calc_coeffs = [xpos,ypos,zpos,Spread](RenderMode mode)
|
||||
{
|
||||
if(mode != StereoPair)
|
||||
return CalcDirectionCoeffs({xpos, ypos, zpos}, Spread);
|
||||
const float ev{std::asin(clampf(ypos, -1.0f, 1.0f))};
|
||||
const float az{std::atan2(xpos, -zpos)};
|
||||
CalcAngleCoeffs(ScaleAzimuthFront(az, 1.5f), ev, Spread, coeffs);
|
||||
}
|
||||
return CalcAngleCoeffs(ScaleAzimuthFront(az, 1.5f), ev, Spread);
|
||||
};
|
||||
const auto coeffs = calc_coeffs(Device->mRenderMode);
|
||||
|
||||
for(size_t c{0};c < num_channels;c++)
|
||||
{
|
||||
@ -1117,12 +1115,12 @@ void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, con
|
||||
continue;
|
||||
}
|
||||
|
||||
ComputePanGains(&Device->Dry, coeffs, DryGain.Base * downmix_gain,
|
||||
ComputePanGains(&Device->Dry, coeffs.data(), DryGain.Base * downmix_gain,
|
||||
voice->mChans[c].mDryParams.Gains.Target);
|
||||
for(ALuint i{0};i < NumSends;i++)
|
||||
{
|
||||
if(const ALeffectslot *Slot{SendSlots[i]})
|
||||
ComputePanGains(&Slot->Wet, coeffs, WetGain[i].Base * downmix_gain,
|
||||
ComputePanGains(&Slot->Wet, coeffs.data(), WetGain[i].Base * downmix_gain,
|
||||
voice->mChans[c].mWetParams[i].Gains.Target);
|
||||
}
|
||||
}
|
||||
@ -1155,19 +1153,16 @@ void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, con
|
||||
continue;
|
||||
}
|
||||
|
||||
float coeffs[MAX_AMBI_CHANNELS];
|
||||
CalcAngleCoeffs(
|
||||
(Device->mRenderMode==StereoPair) ? ScaleAzimuthFront(chans[c].angle, 3.0f)
|
||||
: chans[c].angle,
|
||||
chans[c].elevation, Spread, coeffs
|
||||
);
|
||||
const auto coeffs = CalcAngleCoeffs((Device->mRenderMode == StereoPair)
|
||||
? ScaleAzimuthFront(chans[c].angle, 3.0f) : chans[c].angle,
|
||||
chans[c].elevation, Spread);
|
||||
|
||||
ComputePanGains(&Device->Dry, coeffs, DryGain.Base,
|
||||
ComputePanGains(&Device->Dry, coeffs.data(), DryGain.Base,
|
||||
voice->mChans[c].mDryParams.Gains.Target);
|
||||
for(ALuint i{0};i < NumSends;i++)
|
||||
{
|
||||
if(const ALeffectslot *Slot{SendSlots[i]})
|
||||
ComputePanGains(&Slot->Wet, coeffs, WetGain[i].Base,
|
||||
ComputePanGains(&Slot->Wet, coeffs.data(), WetGain[i].Base,
|
||||
voice->mChans[c].mWetParams[i].Gains.Target);
|
||||
}
|
||||
}
|
||||
|
16
alc/alu.h
16
alc/alu.h
@ -87,8 +87,8 @@ void aluInitEffectPanning(ALeffectslot *slot, ALCdevice *device);
|
||||
* The components are ordered such that OpenAL's X, Y, and Z are the first,
|
||||
* second, and third parameters respectively -- simply negate X and Z.
|
||||
*/
|
||||
void CalcAmbiCoeffs(const float y, const float z, const float x, const float spread,
|
||||
const al::span<float,MAX_AMBI_CHANNELS> coeffs);
|
||||
std::array<float,MAX_AMBI_CHANNELS> CalcAmbiCoeffs(const float y, const float z, const float x,
|
||||
const float spread);
|
||||
|
||||
/**
|
||||
* CalcDirectionCoeffs
|
||||
@ -97,11 +97,11 @@ void CalcAmbiCoeffs(const float y, const float z, const float x, const float spr
|
||||
* vector must be normalized (unit length), and the spread is the angular width
|
||||
* of the sound (0...tau).
|
||||
*/
|
||||
inline void CalcDirectionCoeffs(const float (&dir)[3], const float spread,
|
||||
const al::span<float,MAX_AMBI_CHANNELS> coeffs)
|
||||
inline std::array<float,MAX_AMBI_CHANNELS> CalcDirectionCoeffs(const float (&dir)[3],
|
||||
const float spread)
|
||||
{
|
||||
/* Convert from OpenAL coords to Ambisonics. */
|
||||
CalcAmbiCoeffs(-dir[0], dir[1], -dir[2], spread, coeffs);
|
||||
return CalcAmbiCoeffs(-dir[0], dir[1], -dir[2], spread);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,14 +111,14 @@ inline void CalcDirectionCoeffs(const float (&dir)[3], const float spread,
|
||||
* azimuth and elevation parameters are in radians, going right and up
|
||||
* respectively.
|
||||
*/
|
||||
inline void CalcAngleCoeffs(const float azimuth, const float elevation, const float spread,
|
||||
const al::span<float,MAX_AMBI_CHANNELS> coeffs)
|
||||
inline std::array<float,MAX_AMBI_CHANNELS> CalcAngleCoeffs(const float azimuth,
|
||||
const float elevation, const float spread)
|
||||
{
|
||||
const float x{-std::sin(azimuth) * std::cos(elevation)};
|
||||
const float y{ std::sin(elevation)};
|
||||
const float z{ std::cos(azimuth) * std::cos(elevation)};
|
||||
|
||||
CalcAmbiCoeffs(x, y, z, spread, coeffs);
|
||||
return CalcAmbiCoeffs(x, y, z, spread);
|
||||
}
|
||||
|
||||
|
||||
|
@ -110,12 +110,12 @@ void ChorusState::update(const ALCcontext *Context, const ALeffectslot *Slot, co
|
||||
|
||||
switch(props->Chorus.Waveform)
|
||||
{
|
||||
case AL_CHORUS_WAVEFORM_TRIANGLE:
|
||||
mWaveform = WaveForm::Triangle;
|
||||
break;
|
||||
case AL_CHORUS_WAVEFORM_SINUSOID:
|
||||
mWaveform = WaveForm::Sinusoid;
|
||||
break;
|
||||
case AL_CHORUS_WAVEFORM_TRIANGLE:
|
||||
mWaveform = WaveForm::Triangle;
|
||||
break;
|
||||
case AL_CHORUS_WAVEFORM_SINUSOID:
|
||||
mWaveform = WaveForm::Sinusoid;
|
||||
break;
|
||||
}
|
||||
|
||||
/* The LFO depth is scaled to be relative to the sample delay. Clamp the
|
||||
@ -131,13 +131,12 @@ void ChorusState::update(const ALCcontext *Context, const ALeffectslot *Slot, co
|
||||
mFeedback = props->Chorus.Feedback;
|
||||
|
||||
/* Gains for left and right sides */
|
||||
float coeffs[2][MAX_AMBI_CHANNELS];
|
||||
CalcDirectionCoeffs({-1.0f, 0.0f, 0.0f}, 0.0f, coeffs[0]);
|
||||
CalcDirectionCoeffs({ 1.0f, 0.0f, 0.0f}, 0.0f, coeffs[1]);
|
||||
const auto lcoeffs = CalcDirectionCoeffs({-1.0f, 0.0f, 0.0f}, 0.0f);
|
||||
const auto rcoeffs = CalcDirectionCoeffs({ 1.0f, 0.0f, 0.0f}, 0.0f);
|
||||
|
||||
mOutTarget = target.Main->Buffer;
|
||||
ComputePanGains(target.Main, coeffs[0], Slot->Params.Gain, mGains[0].Target);
|
||||
ComputePanGains(target.Main, coeffs[1], Slot->Params.Gain, mGains[1].Target);
|
||||
ComputePanGains(target.Main, lcoeffs.data(), Slot->Params.Gain, mGains[0].Target);
|
||||
ComputePanGains(target.Main, rcoeffs.data(), Slot->Params.Gain, mGains[1].Target);
|
||||
|
||||
float rate{props->Chorus.Rate};
|
||||
if(!(rate > 0.0f))
|
||||
|
@ -78,11 +78,10 @@ void DedicatedState::update(const ALCcontext*, const ALeffectslot *slot, const E
|
||||
}
|
||||
else
|
||||
{
|
||||
float coeffs[MAX_AMBI_CHANNELS];
|
||||
CalcDirectionCoeffs({0.0f, 0.0f, -1.0f}, 0.0f, coeffs);
|
||||
const auto coeffs = CalcDirectionCoeffs({0.0f, 0.0f, -1.0f}, 0.0f);
|
||||
|
||||
mOutTarget = target.Main->Buffer;
|
||||
ComputePanGains(target.Main, coeffs, Gain, mTargetGains);
|
||||
ComputePanGains(target.Main, coeffs.data(), Gain, mTargetGains);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,11 +82,10 @@ void DistortionState::update(const ALCcontext *context, const ALeffectslot *slot
|
||||
bandwidth = props->Distortion.EQBandwidth / (cutoff * 0.67f);
|
||||
mBandpass.setParamsFromBandwidth(BiquadType::BandPass, cutoff/frequency/4.0f, 1.0f, bandwidth);
|
||||
|
||||
float coeffs[MAX_AMBI_CHANNELS];
|
||||
CalcDirectionCoeffs({0.0f, 0.0f, -1.0f}, 0.0f, coeffs);
|
||||
const auto coeffs = CalcDirectionCoeffs({0.0f, 0.0f, -1.0f}, 0.0f);
|
||||
|
||||
mOutTarget = target.Main->Buffer;
|
||||
ComputePanGains(target.Main, coeffs, slot->Params.Gain*props->Distortion.Gain, mGain);
|
||||
ComputePanGains(target.Main, coeffs.data(), slot->Params.Gain*props->Distortion.Gain, mGain);
|
||||
}
|
||||
|
||||
void DistortionState::process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut)
|
||||
|
@ -99,13 +99,12 @@ void EchoState::update(const ALCcontext *context, const ALeffectslot *slot, cons
|
||||
/* Convert echo spread (where 0 = center, +/-1 = sides) to angle. */
|
||||
const float angle{std::asin(props->Echo.Spread)};
|
||||
|
||||
float coeffs[2][MAX_AMBI_CHANNELS];
|
||||
CalcAngleCoeffs(-angle, 0.0f, 0.0f, coeffs[0]);
|
||||
CalcAngleCoeffs( angle, 0.0f, 0.0f, coeffs[1]);
|
||||
const auto coeffs0 = CalcAngleCoeffs(-angle, 0.0f, 0.0f);
|
||||
const auto coeffs1 = CalcAngleCoeffs( angle, 0.0f, 0.0f);
|
||||
|
||||
mOutTarget = target.Main->Buffer;
|
||||
ComputePanGains(target.Main, coeffs[0], slot->Params.Gain, mGains[0].Target);
|
||||
ComputePanGains(target.Main, coeffs[1], slot->Params.Gain, mGains[1].Target);
|
||||
ComputePanGains(target.Main, coeffs0.data(), slot->Params.Gain, mGains[0].Target);
|
||||
ComputePanGains(target.Main, coeffs1.data(), slot->Params.Gain, mGains[1].Target);
|
||||
}
|
||||
|
||||
void EchoState::process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut)
|
||||
|
@ -148,13 +148,12 @@ void FshifterState::update(const ALCcontext *context, const ALeffectslot *slot,
|
||||
break;
|
||||
}
|
||||
|
||||
float coeffs[2][MAX_AMBI_CHANNELS];
|
||||
CalcDirectionCoeffs({-1.0f, 0.0f, 0.0f}, 0.0f, coeffs[0]);
|
||||
CalcDirectionCoeffs({ 1.0f, 0.0f, 0.0f}, 0.0f, coeffs[1]);
|
||||
const auto lcoeffs = CalcDirectionCoeffs({-1.0f, 0.0f, 0.0f}, 0.0f);
|
||||
const auto rcoeffs = CalcDirectionCoeffs({ 1.0f, 0.0f, 0.0f}, 0.0f);
|
||||
|
||||
mOutTarget = target.Main->Buffer;
|
||||
ComputePanGains(target.Main, coeffs[0], slot->Params.Gain, mGains[0].Target);
|
||||
ComputePanGains(target.Main, coeffs[1], slot->Params.Gain, mGains[1].Target);
|
||||
ComputePanGains(target.Main, lcoeffs.data(), slot->Params.Gain, mGains[0].Target);
|
||||
ComputePanGains(target.Main, rcoeffs.data(), slot->Params.Gain, mGains[1].Target);
|
||||
}
|
||||
|
||||
void FshifterState::process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut)
|
||||
|
@ -130,11 +130,10 @@ void PshifterState::update(const ALCcontext*, const ALeffectslot *slot, const Ef
|
||||
mPitchShiftI = fastf2u(pitch*FRACTIONONE);
|
||||
mPitchShift = mPitchShiftI * double{1.0/FRACTIONONE};
|
||||
|
||||
float coeffs[MAX_AMBI_CHANNELS];
|
||||
CalcDirectionCoeffs({0.0f, 0.0f, -1.0f}, 0.0f, coeffs);
|
||||
const auto coeffs = CalcDirectionCoeffs({0.0f, 0.0f, -1.0f}, 0.0f);
|
||||
|
||||
mOutTarget = target.Main->Buffer;
|
||||
ComputePanGains(target.Main, coeffs, slot->Params.Gain, mTargetGains);
|
||||
ComputePanGains(target.Main, coeffs.data(), slot->Params.Gain, mTargetGains);
|
||||
}
|
||||
|
||||
void PshifterState::process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut)
|
||||
|
@ -882,9 +882,11 @@ void aluInitEffectPanning(ALeffectslot *slot, ALCdevice *device)
|
||||
}
|
||||
|
||||
|
||||
void CalcAmbiCoeffs(const float y, const float z, const float x, const float spread,
|
||||
const al::span<float,MAX_AMBI_CHANNELS> coeffs)
|
||||
std::array<float,MAX_AMBI_CHANNELS> CalcAmbiCoeffs(const float y, const float z, const float x,
|
||||
const float spread)
|
||||
{
|
||||
std::array<float,MAX_AMBI_CHANNELS> coeffs;
|
||||
|
||||
/* Zeroth-order */
|
||||
coeffs[0] = 1.0f; /* ACN 0 = 1 */
|
||||
/* First-order */
|
||||
@ -973,6 +975,8 @@ void CalcAmbiCoeffs(const float y, const float z, const float x, const float spr
|
||||
coeffs[14] *= ZH3_norm;
|
||||
coeffs[15] *= ZH3_norm;
|
||||
}
|
||||
|
||||
return coeffs;
|
||||
}
|
||||
|
||||
void ComputePanGains(const MixParams *mix, const float*RESTRICT coeffs, const float ingain,
|
||||
|
Loading…
x
Reference in New Issue
Block a user