Common: Replace amuse::clamp with std::clamp

We can use the standardized facility for this now with C++17
This commit is contained in:
Lioncash
2019-08-26 05:02:26 -04:00
parent 88c017926b
commit eaf62288a2
20 changed files with 106 additions and 110 deletions

View File

@@ -114,7 +114,7 @@ void Voice::_doKeyOff() {
void Voice::_setTotalPitch(int32_t cents, bool slew) {
// fprintf(stderr, "PITCH %d %d \n", cents, slew);
int32_t interval = clamp(0, cents, 12700) - m_curSample->getPitch() * 100;
int32_t interval = std::clamp(0, cents, 12700) - m_curSample->getPitch() * 100;
double ratio = std::exp2(interval / 1200.0) * m_dopplerRatio;
m_sampleRate = m_curSample->m_sampleRate * ratio;
m_backendVoice->setPitchRatio(ratio, slew);
@@ -201,7 +201,7 @@ void Voice::_procSamplePre(int16_t& samp) {
if (rem != 0) {
/* Lerp within 160-sample block */
float t = rem / 160.f;
float l = clamp(0.f, m_lastLevel * (1.f - t) + m_nextLevel * t, 1.f);
float l = std::clamp(0.f, m_lastLevel * (1.f - t) + m_nextLevel * t, 1.f);
/* Apply total volume to sample using decibel scale */
samp = ApplyVolume(m_lerpedCache.getVolume(l * m_engine.m_masterVolume, m_dlsVol), samp);
@@ -220,10 +220,10 @@ void Voice::_procSamplePre(int16_t& samp) {
m_envelopeTime += dt;
float start = m_envelopeStart;
float end = m_envelopeEnd;
float t = clamp(0.f, float(m_envelopeTime / m_envelopeDur), 1.f);
float t = std::clamp(0.f, float(m_envelopeTime / m_envelopeDur), 1.f);
if (m_envelopeCurve && m_envelopeCurve->data.size() >= 128)
t = m_envelopeCurve->data[t * 127.f] / 127.f;
m_envelopeVol = clamp(0.f, (start * (1.0f - t)) + (end * t), 1.f);
m_envelopeVol = std::clamp(0.f, (start * (1.0f - t)) + (end * t), 1.f);
// printf("%d %f\n", m_vid, m_envelopeVol);
@@ -280,7 +280,7 @@ void Voice::_procSamplePre(int16_t& samp) {
}
}
m_nextLevel = clamp(0.f, m_nextLevel, 1.f);
m_nextLevel = std::clamp(0.f, m_nextLevel, 1.f);
/* Apply total volume to sample using decibel scale */
samp = ApplyVolume(m_nextLevelCache.getVolume(m_nextLevel * m_engine.m_masterVolume, m_dlsVol), samp);
@@ -289,7 +289,7 @@ void Voice::_procSamplePre(int16_t& samp) {
template <typename T>
T Voice::_procSampleMaster(double time, T samp) {
float evalVol = m_state.m_volumeSel ? (m_state.m_volumeSel.evaluate(time, *this, m_state) / 127.f) : 1.f;
return ApplyVolume(m_masterCache.getVolume(clamp(0.f, evalVol, 1.f), m_dlsVol), samp);
return ApplyVolume(m_masterCache.getVolume(std::clamp(0.f, evalVol, 1.f), m_dlsVol), samp);
}
template <typename T>
@@ -297,7 +297,7 @@ T Voice::_procSampleAuxA(double time, T samp) {
float evalVol = m_state.m_volumeSel ? (m_state.m_volumeSel.evaluate(time, *this, m_state) / 127.f) : 1.f;
evalVol *= m_state.m_reverbSel ? (m_state.m_reverbSel.evaluate(time, *this, m_state) / 127.f) : m_curReverbVol;
evalVol += m_state.m_preAuxASel ? (m_state.m_preAuxASel.evaluate(time, *this, m_state) / 127.f) : 0.f;
return ApplyVolume(m_auxACache.getVolume(clamp(0.f, evalVol, 1.f), m_dlsVol), samp);
return ApplyVolume(m_auxACache.getVolume(std::clamp(0.f, evalVol, 1.f), m_dlsVol), samp);
}
template <typename T>
@@ -305,7 +305,7 @@ T Voice::_procSampleAuxB(double time, T samp) {
float evalVol = m_state.m_volumeSel ? (m_state.m_volumeSel.evaluate(time, *this, m_state) / 127.f) : 1.f;
evalVol *= m_state.m_postAuxB ? (m_state.m_postAuxB.evaluate(time, *this, m_state) / 127.f) : m_curAuxBVol;
evalVol += m_state.m_preAuxBSel ? (m_state.m_preAuxBSel.evaluate(time, *this, m_state) / 127.f) : 0.f;
return ApplyVolume(m_auxBCache.getVolume(clamp(0.f, evalVol, 1.f), m_dlsVol), samp);
return ApplyVolume(m_auxBCache.getVolume(std::clamp(0.f, evalVol, 1.f), m_dlsVol), samp);
}
uint32_t Voice::_GetBlockSampleCount(SampleFormat fmt) {
@@ -343,7 +343,7 @@ void Voice::preSupplyAudio(double dt) {
bool panDirty = false;
if (m_state.m_panSel) {
float evalPan = (m_state.m_panSel.evaluate(m_voiceTime, *this, m_state) - 64.f) / 63.f;
evalPan = clamp(-1.f, evalPan, 1.f);
evalPan = std::clamp(-1.f, evalPan, 1.f);
if (evalPan != m_curPan) {
m_curPan = evalPan;
panDirty = true;
@@ -351,7 +351,7 @@ void Voice::preSupplyAudio(double dt) {
}
if (m_state.m_spanSel) {
float evalSpan = (m_state.m_spanSel.evaluate(m_voiceTime, *this, m_state) - 64.f) / 63.f;
evalSpan = clamp(-1.f, evalSpan, 1.f);
evalSpan = std::clamp(-1.f, evalSpan, 1.f);
if (evalSpan != m_curSpan) {
m_curSpan = evalSpan;
panDirty = true;
@@ -362,7 +362,7 @@ void Voice::preSupplyAudio(double dt) {
if (m_state.m_pitchWheelSel) {
float evalPWheel = (m_state.m_pitchWheelSel.evaluate(m_voiceTime, *this, m_state) - 64.f) / 63.f;
_setPitchWheel(clamp(-1.f, evalPWheel, 1.f));
_setPitchWheel(std::clamp(-1.f, evalPWheel, 1.f));
}
/* Process active pan-sweep */
@@ -372,7 +372,7 @@ void Voice::preSupplyAudio(double dt) {
p.m_time += dt;
double start = (p.m_pos - 64) / 64.0;
double end = (p.m_pos + p.m_width - 64) / 64.0;
double t = clamp(0.0, p.m_time / p.m_dur, 1.0);
double t = std::clamp(0.0, p.m_time / p.m_dur, 1.0);
_setPan(float((start * (1.0 - t)) + (end * t)));
refresh = true;
@@ -387,7 +387,7 @@ void Voice::preSupplyAudio(double dt) {
s.m_time += dt;
double start = (s.m_pos - 64) / 64.0;
double end = (s.m_pos + s.m_width - 64) / 64.0;
double t = clamp(0.0, s.m_time / s.m_dur, 1.0);
double t = std::clamp(0.0, s.m_time / s.m_dur, 1.0);
_setSurroundPan(float((start * (1.0 - t)) + (end * t)));
refresh = true;
@@ -402,7 +402,7 @@ void Voice::preSupplyAudio(double dt) {
m_pitchDirty = false;
if (m_portamentoTime >= 0.f) {
m_portamentoTime += dt;
float t = clamp(0.f, m_portamentoTime / m_state.m_portamentoTime, 1.f);
float t = std::clamp(0.f, m_portamentoTime / m_state.m_portamentoTime, 1.f);
newPitch = (m_curPitch * (1.0f - t)) + (m_portamentoTarget * t);
refresh = true;
@@ -856,7 +856,7 @@ void Voice::startSample(SampleId sampId, int32_t offset) {
offset = ((offset - m_curSample->m_loopStartSample) % m_curSample->m_loopLengthSamples) +
m_curSample->m_loopStartSample;
} else
offset = clamp(0, offset, numSamples);
offset = std::clamp(0, offset, numSamples);
}
m_curSamplePos = offset;
m_prev1 = 0;
@@ -895,7 +895,7 @@ void Voice::setVolume(float vol) {
if (m_destroyed)
return;
m_targetUserVol = clamp(0.f, vol, 1.f);
m_targetUserVol = std::clamp(0.f, vol, 1.f);
for (ObjToken<Voice>& vox : m_childVoices)
vox->setVolume(vol);
}
@@ -1014,9 +1014,9 @@ void Voice::_setPan(float pan) {
if (m_destroyed || m_emitter)
return;
m_curPan = clamp(-1.f, pan, 1.f);
float totalPan = clamp(-1.f, m_curPan, 1.f);
float totalSpan = clamp(-1.f, m_curSpan, 1.f);
m_curPan = std::clamp(-1.f, pan, 1.f);
float totalPan = std::clamp(-1.f, m_curPan, 1.f);
float totalSpan = std::clamp(-1.f, m_curSpan, 1.f);
float coefs[8] = {};
_panLaw(coefs, totalPan, totalPan, totalSpan);
_setChannelCoefs(coefs);
@@ -1032,7 +1032,7 @@ void Voice::setPan(float pan) {
}
void Voice::_setSurroundPan(float span) {
m_curSpan = clamp(-1.f, span, 1.f);
m_curSpan = std::clamp(-1.f, span, 1.f);
_setPan(m_curPan);
}
@@ -1063,8 +1063,8 @@ void Voice::setChannelCoefs(const float coefs[8]) {
void Voice::startEnvelope(double dur, float vol, const Curve* envCurve) {
m_envelopeTime = 0.f;
m_envelopeDur = dur;
m_envelopeStart = clamp(0.f, m_envelopeVol, 1.f);
m_envelopeEnd = clamp(0.f, vol, 1.f);
m_envelopeStart = std::clamp(0.f, m_envelopeVol, 1.f);
m_envelopeEnd = std::clamp(0.f, vol, 1.f);
m_envelopeCurve = envCurve;
}
@@ -1072,7 +1072,7 @@ void Voice::startFadeIn(double dur, float vol, const Curve* envCurve) {
m_envelopeTime = 0.f;
m_envelopeDur = dur;
m_envelopeStart = 0.f;
m_envelopeEnd = clamp(0.f, vol, 1.f);
m_envelopeEnd = std::clamp(0.f, vol, 1.f);
m_envelopeCurve = envCurve;
}
@@ -1137,7 +1137,7 @@ void Voice::setReverbVol(float rvol) {
if (m_destroyed)
return;
m_curReverbVol = clamp(0.f, rvol, 1.f);
m_curReverbVol = std::clamp(0.f, rvol, 1.f);
for (ObjToken<Voice>& vox : m_childVoices)
vox->setReverbVol(rvol);
}
@@ -1146,7 +1146,7 @@ void Voice::setAuxBVol(float bvol) {
if (m_destroyed)
return;
m_curAuxBVol = clamp(0.f, bvol, 1.f);
m_curAuxBVol = std::clamp(0.f, bvol, 1.f);
for (ObjToken<Voice>& vox : m_childVoices)
vox->setAuxBVol(bvol);
}
@@ -1210,7 +1210,7 @@ void Voice::setPitchWheel(float pitchWheel) {
if (m_destroyed)
return;
m_curPitchWheel = amuse::clamp(-1.f, pitchWheel, 1.f);
m_curPitchWheel = std::clamp(-1.f, pitchWheel, 1.f);
_setPitchWheel(m_curPitchWheel);
for (ObjToken<Voice>& vox : m_childVoices)