Replace some more macros with constexpr variables

This commit is contained in:
Chris Robinson
2020-10-21 16:39:21 -07:00
parent b8f5e1f424
commit 3e62600ecc
14 changed files with 39 additions and 39 deletions
+1 -1
View File
@@ -500,7 +500,7 @@ void InitVoice(Voice *voice, ALsource *source, ALbufferlistitem *BufferList, ALC
if(device->AvgSpeakerDist > 0.0f)
{
const float w1{SPEEDOFSOUNDMETRESPERSEC /
const float w1{SpeedOfSoundMetersPerSec /
(device->AvgSpeakerDist * static_cast<float>(device->Frequency))};
for(auto &chandata : voice->mChans)
chandata.mDryParams.NFCtrlFilter.init(w1);
+5 -5
View File
@@ -214,7 +214,7 @@ START_API_FUNC
break;
case AL_GAIN_LIMIT_SOFT:
if(GAIN_MIX_MAX/context->mGainBoost != 0.0f)
if(GainMixMax/context->mGainBoost != 0.0f)
value = AL_TRUE;
break;
@@ -267,7 +267,7 @@ START_API_FUNC
break;
case AL_GAIN_LIMIT_SOFT:
value = ALdouble{GAIN_MIX_MAX}/context->mGainBoost;
value = ALdouble{GainMixMax}/context->mGainBoost;
break;
case AL_NUM_RESAMPLERS_SOFT:
@@ -318,7 +318,7 @@ START_API_FUNC
break;
case AL_GAIN_LIMIT_SOFT:
value = GAIN_MIX_MAX/context->mGainBoost;
value = GainMixMax/context->mGainBoost;
break;
case AL_NUM_RESAMPLERS_SOFT:
@@ -369,7 +369,7 @@ START_API_FUNC
break;
case AL_GAIN_LIMIT_SOFT:
value = static_cast<ALint>(GAIN_MIX_MAX/context->mGainBoost);
value = static_cast<ALint>(GainMixMax/context->mGainBoost);
break;
case AL_NUM_RESAMPLERS_SOFT:
@@ -420,7 +420,7 @@ START_API_FUNC
break;
case AL_GAIN_LIMIT_SOFT:
value = static_cast<ALint64SOFT>(GAIN_MIX_MAX/context->mGainBoost);
value = static_cast<ALint64SOFT>(GainMixMax/context->mGainBoost);
break;
case AL_NUM_RESAMPLERS_SOFT:
+1 -1
View File
@@ -2241,7 +2241,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
if(device->AvgSpeakerDist > 0.0f)
{
/* Reinitialize the NFC filters for new parameters. */
const float w1{SPEEDOFSOUNDMETRESPERSEC /
const float w1{SpeedOfSoundMetersPerSec /
(device->AvgSpeakerDist * static_cast<float>(device->Frequency))};
for(auto &chandata : voice->mChans)
chandata.mDryParams.NFCtrlFilter.init(w1);
+1 -1
View File
@@ -114,7 +114,7 @@ struct ALCcontext : public al::intrusive_ref<ALCcontext> {
float mDopplerFactor{1.0f};
float mDopplerVelocity{1.0f};
float mSpeedOfSound{SPEEDOFSOUNDMETRESPERSEC};
float mSpeedOfSound{SpeedOfSoundMetersPerSec};
std::atomic_flag mPropsClean;
std::atomic<bool> mDeferUpdates{false};
+12 -12
View File
@@ -839,7 +839,7 @@ void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, con
* excessive bass.
*/
const float mdist{maxf(Distance, Device->AvgSpeakerDist/4.0f)};
const float w0{SPEEDOFSOUNDMETRESPERSEC / (mdist * Frequency)};
const float w0{SpeedOfSoundMetersPerSec / (mdist * Frequency)};
/* Only need to adjust the first channel of a B-Format source. */
voice->mChans[0].mDryParams.NFCtrlFilter.adjust(w0);
@@ -1091,7 +1091,7 @@ void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, con
* excessive bass.
*/
const float mdist{maxf(Distance, Device->AvgSpeakerDist/4.0f)};
const float w0{SPEEDOFSOUNDMETRESPERSEC / (mdist * Frequency)};
const float w0{SpeedOfSoundMetersPerSec / (mdist * Frequency)};
/* Adjust NFC filters. */
for(size_t c{0};c < num_channels;c++)
@@ -1253,14 +1253,14 @@ void CalcNonAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcon
const ALlistener &Listener = ALContext->mListener;
GainTriplet DryGain;
DryGain.Base = minf(clampf(props->Gain, props->MinGain, props->MaxGain) * props->Direct.Gain *
Listener.Params.Gain, GAIN_MIX_MAX);
Listener.Params.Gain, GainMixMax);
DryGain.HF = props->Direct.GainHF;
DryGain.LF = props->Direct.GainLF;
GainTriplet WetGain[MAX_SENDS];
for(ALuint i{0};i < Device->NumAuxSends;i++)
{
WetGain[i].Base = minf(clampf(props->Gain, props->MinGain, props->MaxGain) *
props->Send[i].Gain * Listener.Params.Gain, GAIN_MIX_MAX);
props->Send[i].Gain * Listener.Params.Gain, GainMixMax);
WetGain[i].HF = props->Send[i].GainHF;
WetGain[i].LF = props->Send[i].GainLF;
}
@@ -1299,7 +1299,7 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontex
/* Calculate the distances to where this effect's decay reaches
* -60dB.
*/
DecayDistance[i].Base = SendSlots[i]->Params.DecayTime * SPEEDOFSOUNDMETRESPERSEC;
DecayDistance[i].Base = SendSlots[i]->Params.DecayTime * SpeedOfSoundMetersPerSec;
DecayDistance[i].LF = DecayDistance[i].Base * SendSlots[i]->Params.DecayLFRatio;
DecayDistance[i].HF = DecayDistance[i].Base * SendSlots[i]->Params.DecayHFRatio;
if(SendSlots[i]->Params.DecayHFLimit)
@@ -1312,7 +1312,7 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontex
* decay distance (so it doesn't take any longer to decay
* than the air would allow).
*/
constexpr float log10_decaygain{-3.0f/*std::log10(REVERB_DECAY_GAIN)*/};
constexpr float log10_decaygain{-3.0f/*std::log10(ReverbDecayGain)*/};
const float absorb_dist{log10_decaygain / std::log10(airAbsorption)};
DecayDistance[i].HF = minf(absorb_dist, DecayDistance[i].HF);
}
@@ -1465,13 +1465,13 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontex
/* Apply gain and frequency filters */
DryGain.Base = minf(clampf(DryGain.Base, props->MinGain, props->MaxGain) * props->Direct.Gain *
Listener.Params.Gain, GAIN_MIX_MAX);
Listener.Params.Gain, GainMixMax);
DryGain.HF *= props->Direct.GainHF;
DryGain.LF *= props->Direct.GainLF;
for(ALuint i{0};i < NumSends;i++)
{
WetGain[i].Base = minf(clampf(WetGain[i].Base, props->MinGain, props->MaxGain) *
props->Send[i].Gain * Listener.Params.Gain, GAIN_MIX_MAX);
props->Send[i].Gain * Listener.Params.Gain, GainMixMax);
WetGain[i].HF *= props->Send[i].GainHF;
WetGain[i].LF *= props->Send[i].GainLF;
}
@@ -1483,7 +1483,7 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontex
Listener.Params.MetersPerUnit};
if(props->AirAbsorptionFactor > 0.0f)
{
const float hfattn{std::pow(AIRABSORBGAINHF, meters_base*props->AirAbsorptionFactor)};
const float hfattn{std::pow(AirAbsorbGainHF, meters_base*props->AirAbsorptionFactor)};
DryGain.HF *= hfattn;
std::for_each(std::begin(WetGain), std::begin(WetGain)+NumSends,
[hfattn](GainTriplet &gain) noexcept -> void { gain.HF *= hfattn; });
@@ -1500,16 +1500,16 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontex
if(!(DecayDistance[i].Base > 0.0f))
continue;
const float gain{std::pow(REVERB_DECAY_GAIN, meters_base/DecayDistance[i].Base)};
const float gain{std::pow(ReverbDecayGain, meters_base/DecayDistance[i].Base)};
WetGain[i].Base *= gain;
/* Yes, the wet path's air absorption is applied with
* WetGainAuto on, rather than WetGainHFAuto.
*/
if(gain > 0.0f)
{
float gainhf{std::pow(REVERB_DECAY_GAIN, meters_base/DecayDistance[i].HF)};
float gainhf{std::pow(ReverbDecayGain, meters_base/DecayDistance[i].HF)};
WetGain[i].HF *= minf(gainhf / gain, 1.0f);
float gainlf{std::pow(REVERB_DECAY_GAIN, meters_base/DecayDistance[i].LF)};
float gainlf{std::pow(ReverbDecayGain, meters_base/DecayDistance[i].LF)};
WetGain[i].LF *= minf(gainlf / gain, 1.0f);
}
}
+6 -6
View File
@@ -26,15 +26,15 @@ using MixerFunc = void(*)(const al::span<const float> InSamples,
extern MixerFunc MixSamples;
#define GAIN_MIX_MAX 1000.0f /* +60dB */
constexpr float GainMixMax{1000.0f}; /* +60dB */
#define GAIN_SILENCE_THRESHOLD 0.00001f /* -100dB */
constexpr float GainSilenceThreshold{0.00001f}; /* -100dB */
#define SPEEDOFSOUNDMETRESPERSEC 343.3f
#define AIRABSORBGAINHF 0.99426f /* -0.05dB */
constexpr float SpeedOfSoundMetersPerSec{343.3f};
constexpr float AirAbsorbGainHF{0.99426f}; /* -0.05dB */
/* Target gain for the reverb decay feedback reaching the decay time. */
#define REVERB_DECAY_GAIN 0.001f /* -60 dB */
/** Target gain for the reverb decay feedback reaching the decay time. */
constexpr float ReverbDecayGain{0.001f}; /* -60 dB */
#define FRACTIONBITS 12
#define FRACTIONONE (1<<FRACTIONBITS)
+1 -1
View File
@@ -137,7 +137,7 @@ void CompressorState::process(const size_t samplesToDo, const al::span<const Flo
for(FloatBufferLine &output : samplesOut)
{
const float gain{*(outgains++)};
if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD))
if(!(std::fabs(gain) > GainSilenceThreshold))
continue;
for(size_t i{0u};i < td;i++)
+1 -1
View File
@@ -139,7 +139,7 @@ void DistortionState::process(const size_t samplesToDo, const al::span<const Flo
* storing only one sample out of four.
*/
const float gain{*(outgains++)};
if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD))
if(!(std::fabs(gain) > GainSilenceThreshold))
continue;
for(size_t i{0u};i < todo;i++)
+4 -4
View File
@@ -449,7 +449,7 @@ struct ReverbState final : public EffectState {
const float *RESTRICT input{al::assume_aligned<16>(InSamples)};
InSamples += InStride;
if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD))
if(!(std::fabs(gain) > GainSilenceThreshold))
continue;
for(float &sample : OutBuffer)
@@ -684,14 +684,14 @@ void ReverbState::deviceUpdate(const ALCdevice *device)
* until the decay reaches -60 dB.
*/
inline float CalcDecayCoeff(const float length, const float decayTime)
{ return std::pow(REVERB_DECAY_GAIN, length/decayTime); }
{ return std::pow(ReverbDecayGain, length/decayTime); }
/* Calculate a decay length from a coefficient and the time until the decay
* reaches -60 dB.
*/
inline float CalcDecayLength(const float coeff, const float decayTime)
{
constexpr float log10_decaygain{-3.0f/*std::log10(REVERB_DECAY_GAIN)=std::log10(0.001f)*/};
constexpr float log10_decaygain{-3.0f/*std::log10(ReverbDecayGain)*/};
return std::log10(coeff) * decayTime / log10_decaygain;
}
@@ -740,7 +740,7 @@ float CalcLimitedHfRatio(const float hfRatio, const float airAbsorptionGainHF,
* equation, solve for HF ratio. The delay length is cancelled out of
* the equation, so it can be calculated once for all lines.
*/
float limitRatio{1.0f / SPEEDOFSOUNDMETRESPERSEC /
float limitRatio{1.0f / SpeedOfSoundMetersPerSec /
CalcDecayLength(airAbsorptionGainHF, decayTime)};
/* Using the limit calculated above, apply the upper bound to the HF ratio. */
+2 -2
View File
@@ -48,7 +48,7 @@ inline void MixHrtfBlendBase(const float *InSamples, float2 *RESTRICT AccumSampl
const auto &NewCoeffs = *newparams->Coeffs;
const float newGainStep{newparams->GainStep};
if LIKELY(oldparams->Gain > GAIN_SILENCE_THRESHOLD)
if LIKELY(oldparams->Gain > GainSilenceThreshold)
{
size_t ldelay{HRTF_HISTORY_LENGTH - oldparams->Delay[0]};
size_t rdelay{HRTF_HISTORY_LENGTH - oldparams->Delay[1]};
@@ -64,7 +64,7 @@ inline void MixHrtfBlendBase(const float *InSamples, float2 *RESTRICT AccumSampl
}
}
if LIKELY(newGainStep*static_cast<float>(BufferSize) > GAIN_SILENCE_THRESHOLD)
if LIKELY(newGainStep*static_cast<float>(BufferSize) > GainSilenceThreshold)
{
size_t ldelay{HRTF_HISTORY_LENGTH+1 - newparams->Delay[0]};
size_t rdelay{HRTF_HISTORY_LENGTH+1 - newparams->Delay[1]};
+1 -1
View File
@@ -188,7 +188,7 @@ void Mix_<CTag>(const al::span<const float> InSamples, const al::span<FloatBuffe
++CurrentGains;
++TargetGains;
if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD))
if(!(std::fabs(gain) > GainSilenceThreshold))
continue;
for(;pos != InSamples.size();++pos)
dst[pos] += InSamples[pos] * gain;
+1 -1
View File
@@ -274,7 +274,7 @@ void Mix_<NEONTag>(const al::span<const float> InSamples, const al::span<FloatBu
++CurrentGains;
++TargetGains;
if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD))
if(!(std::fabs(gain) > GainSilenceThreshold))
continue;
if(size_t todo{(InSamples.size()-pos) >> 2})
{
+1 -1
View File
@@ -247,7 +247,7 @@ void Mix_<SSETag>(const al::span<const float> InSamples, const al::span<FloatBuf
++CurrentGains;
++TargetGains;
if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD))
if(!(std::fabs(gain) > GainSilenceThreshold))
continue;
if(size_t todo{(InSamples.size()-pos) >> 2})
{
+2 -2
View File
@@ -255,7 +255,7 @@ void InitDistanceComp(ALCdevice *device, const AmbDecConf *conf,
if(!GetConfigValueBool(devname, "decoder", "distance-comp", 1) || !(maxdist > 0.0f))
return;
const auto distSampleScale = static_cast<float>(device->Frequency) / SPEEDOFSOUNDMETRESPERSEC;
const auto distSampleScale = static_cast<float>(device->Frequency) / SpeedOfSoundMetersPerSec;
const auto ChanDelay = device->ChannelDelay.as_span();
size_t total{0u};
for(size_t i{0u};i < conf->Speakers.size();i++)
@@ -508,7 +508,7 @@ void InitPanning(ALCdevice *device, const bool hqdec=false, const bool stablize=
float nfc_delay{ConfigValueFloat(devname, "decoder", "nfc-ref-delay").value_or(0.0f)};
if(nfc_delay > 0.0f)
InitNearFieldCtrl(device, nfc_delay * SPEEDOFSOUNDMETRESPERSEC, device->mAmbiOrder,
InitNearFieldCtrl(device, nfc_delay * SpeedOfSoundMetersPerSec, device->mAmbiOrder,
true);
}
else