Skip to content

Commit

Permalink
Replace some macros with constexpr variables
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Jan 14, 2024
1 parent 937a887 commit 96e7157
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions alc/effects/compressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ struct ContextBase;

namespace {

#define AMP_ENVELOPE_MIN 0.5f
#define AMP_ENVELOPE_MAX 2.0f
constexpr float AmpEnvelopeMin{0.5f};
constexpr float AmpEnvelopeMax{2.0f};

#define ATTACK_TIME 0.1f /* 100ms to rise from min to max */
#define RELEASE_TIME 0.2f /* 200ms to drop from max to min */
constexpr float AttackTime{0.1f}; /* 100ms to rise from min to max */
constexpr float ReleaseTime{0.2f}; /* 200ms to drop from max to min */


struct CompressorState final : public EffectState {
Expand Down Expand Up @@ -89,14 +89,14 @@ void CompressorState::deviceUpdate(const DeviceBase *device, const BufferStorage
/* Number of samples to do a full attack and release (non-integer sample
* counts are okay).
*/
const float attackCount{static_cast<float>(device->Frequency) * ATTACK_TIME};
const float releaseCount{static_cast<float>(device->Frequency) * RELEASE_TIME};
const float attackCount{static_cast<float>(device->Frequency) * AttackTime};
const float releaseCount{static_cast<float>(device->Frequency) * ReleaseTime};

/* Calculate per-sample multipliers to attack and release at the desired
* rates.
*/
mAttackMult = std::pow(AMP_ENVELOPE_MAX/AMP_ENVELOPE_MIN, 1.0f/attackCount);
mReleaseMult = std::pow(AMP_ENVELOPE_MIN/AMP_ENVELOPE_MAX, 1.0f/releaseCount);
mAttackMult = std::pow(AmpEnvelopeMax/AmpEnvelopeMin, 1.0f/attackCount);
mReleaseMult = std::pow(AmpEnvelopeMin/AmpEnvelopeMax, 1.0f/releaseCount);
}

void CompressorState::update(const ContextBase*, const EffectSlot *slot,
Expand Down Expand Up @@ -130,8 +130,8 @@ void CompressorState::process(const size_t samplesToDo,
/* Clamp the absolute amplitude to the defined envelope limits,
* then attack or release the envelope to reach it.
*/
const float amplitude{clampf(std::fabs(samplesIn[0][base+i]), AMP_ENVELOPE_MIN,
AMP_ENVELOPE_MAX)};
const float amplitude{clampf(std::fabs(samplesIn[0][base+i]), AmpEnvelopeMin,
AmpEnvelopeMax)};
if(amplitude > env)
env = minf(env*mAttackMult, amplitude);
else if(amplitude < env)
Expand Down

0 comments on commit 96e7157

Please sign in to comment.