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

@ -138,7 +138,7 @@ void CurveView::mouseMoveEvent(QMouseEvent* ev) {
if (idx < 0 || idx > 127) {
return;
}
const int val = 127 - amuse::clamp(0, int(std::round(ev->localPos().y() / (height() - 16.0) * 127.0)), 127);
const int val = 127 - std::clamp(0, int(std::round(ev->localPos().y() / (height() - 16.0) * 127.0)), 127);
CurveEditUndoCommand::RedoData newData;
auto& curve = static_cast<amuse::Curve&>(table);
@ -196,7 +196,7 @@ void CurveControls::exprCommit() {
m_errLabel->setText(val.toString());
return;
} else if (val.isNumber()) {
newData[i] = uint8_t(amuse::clamp(0, int(std::round(val.toNumber() * 127.0)), 127));
newData[i] = uint8_t(std::clamp(0, int(std::round(val.toNumber() * 127.0)), 127));
} else {
notANumber = true;
newData[i] = 0;

View File

@ -324,27 +324,27 @@ struct AppCallback : boo::IApplicationCallback {
if (m_seq && m_chanId != -1) {
switch (charCode) {
case 'z':
m_octave = amuse::clamp(-1, m_octave - 1, 8);
m_octave = std::clamp(-1, m_octave - 1, 8);
m_updateDisp = true;
break;
case 'x':
m_octave = amuse::clamp(-1, m_octave + 1, 8);
m_octave = std::clamp(-1, m_octave + 1, 8);
m_updateDisp = true;
break;
case 'c':
m_velocity = amuse::clamp(0, m_velocity - 1, 127);
m_velocity = std::clamp(0, m_velocity - 1, 127);
m_updateDisp = true;
break;
case 'v':
m_velocity = amuse::clamp(0, m_velocity + 1, 127);
m_velocity = std::clamp(0, m_velocity + 1, 127);
m_updateDisp = true;
break;
case 'b':
m_chanId = amuse::clamp(0, m_chanId - 1, 15);
m_chanId = std::clamp(0, m_chanId - 1, 15);
m_updateDisp = true;
break;
case 'n':
m_chanId = amuse::clamp(0, m_chanId + 1, 15);
m_chanId = std::clamp(0, m_chanId + 1, 15);
m_updateDisp = true;
break;
case ',':
@ -397,27 +397,27 @@ struct AppCallback : boo::IApplicationCallback {
setPanic = true;
break;
case 'z':
m_octave = amuse::clamp(-1, m_octave - 1, 8);
m_octave = std::clamp(-1, m_octave - 1, 8);
m_updateDisp = true;
break;
case 'x':
m_octave = amuse::clamp(-1, m_octave + 1, 8);
m_octave = std::clamp(-1, m_octave + 1, 8);
m_updateDisp = true;
break;
case 'c':
m_velocity = amuse::clamp(0, m_velocity - 1, 127);
m_velocity = std::clamp(0, m_velocity - 1, 127);
m_updateDisp = true;
break;
case 'v':
m_velocity = amuse::clamp(0, m_velocity + 1, 127);
m_velocity = std::clamp(0, m_velocity + 1, 127);
m_updateDisp = true;
break;
case 'b':
m_chanId = amuse::clamp(0, m_chanId - 1, 15);
m_chanId = std::clamp(0, m_chanId - 1, 15);
m_updateDisp = true;
break;
case 'n':
m_chanId = amuse::clamp(0, m_chanId + 1, 15);
m_chanId = std::clamp(0, m_chanId + 1, 15);
m_updateDisp = true;
break;
case ',':
@ -844,13 +844,13 @@ void EventCallback::specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods,
break;
case boo::ESpecialKey::Up:
if (m_app.m_volume < 1.f)
m_app.m_volume = amuse::clamp(0.f, m_app.m_volume + 0.05f, 1.f);
m_app.m_volume = std::clamp(0.f, m_app.m_volume + 0.05f, 1.f);
m_app.m_engine->setVolume(m_app.m_volume);
m_app.m_updateDisp = true;
break;
case boo::ESpecialKey::Down:
if (m_app.m_volume > 0.f)
m_app.m_volume = amuse::clamp(0.f, m_app.m_volume - 0.05f, 1.f);
m_app.m_volume = std::clamp(0.f, m_app.m_volume - 0.05f, 1.f);
m_app.m_engine->setVolume(m_app.m_volume);
m_app.m_updateDisp = true;
break;
@ -866,7 +866,7 @@ void EventCallback::specialKeyUp(boo::ESpecialKey key, boo::EModifierKey mods) {
void EventCallback::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton, boo::EModifierKey) {
m_tracking = true;
m_app.m_pitchBend = amuse::clamp(-1.f, coord.norm[1] * 2.f - 1.f, 1.f);
m_app.m_pitchBend = std::clamp(-1.f, coord.norm[1] * 2.f - 1.f, 1.f);
if (m_app.m_vox)
m_app.m_vox->setPitchWheel(m_app.m_pitchBend);
if (m_app.m_seq && m_app.m_chanId != -1)
@ -884,13 +884,13 @@ void EventCallback::mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EM
void EventCallback::mouseMove(const boo::SWindowCoord& coord) {
if (m_tracking) {
m_app.m_modulation = amuse::clamp(0.f, coord.norm[0], 1.f);
m_app.m_modulation = std::clamp(0.f, coord.norm[0], 1.f);
if (m_app.m_vox)
m_app.m_vox->setCtrlValue(1, m_app.m_modulation * 127.f);
if (m_app.m_seq && m_app.m_chanId != -1)
m_app.m_seq->setCtrlValue(m_app.m_chanId, 1, m_app.m_modulation * 127.f);
m_app.m_pitchBend = amuse::clamp(-1.f, coord.norm[1] * 2.f - 1.f, 1.f);
m_app.m_pitchBend = std::clamp(-1.f, coord.norm[1] * 2.f - 1.f, 1.f);
if (m_app.m_vox)
m_app.m_vox->setPitchWheel(m_app.m_pitchBend);
if (m_app.m_seq && m_app.m_chanId != -1)

View File

@ -399,7 +399,7 @@ int main(int argc, const boo::SystemChar** argv)
std::unique_ptr<boo::IAudioVoiceEngine> voxEngine = boo::NewWAVAudioVoiceEngine(pathOut.c_str(), rate, chCount);
amuse::BooBackendVoiceAllocator booBackend(*voxEngine);
amuse::Engine engine(booBackend, amuse::AmplitudeMode::PerSample);
engine.setVolume(float(amuse::clamp(0.0, volume, 1.0)));
engine.setVolume(float(std::clamp(0.0, volume, 1.0)));
/* Load group into engine */
const amuse::AudioGroup* group = engine.addAudioGroup(*selData);

View File

@ -368,11 +368,6 @@ inline int CompareCaseInsensitive(const SystemChar* a, const SystemChar* b) {
#endif
}
template <typename T>
constexpr T clamp(T a, T val, T b) {
return std::max<T>(a, std::min<T>(b, val));
}
template <typename T>
constexpr T ClampFull(float in) noexcept {
if (std::is_floating_point<T>()) {

View File

@ -38,21 +38,21 @@ public:
using ImpType = EffectChorusImp<T>;
void setBaseDelay(uint32_t baseDelay) {
baseDelay = clamp(5u, baseDelay, 15u);
baseDelay = std::clamp(5u, baseDelay, 15u);
x90_baseDelay = baseDelay;
m_dirty = true;
}
uint32_t getBaseDelay() const { return x90_baseDelay; }
void setVariation(uint32_t variation) {
variation = clamp(0u, variation, 5u);
variation = std::clamp(0u, variation, 5u);
x94_variation = variation;
m_dirty = true;
}
uint32_t getVariation() const { return x94_variation; }
void setPeriod(uint32_t period) {
period = clamp(500u, period, 10000u);
period = std::clamp(500u, period, 10000u);
x98_period = period;
m_dirty = true;
}

View File

@ -51,41 +51,41 @@ public:
using ImpType = EffectDelayImp<T>;
void setDelay(uint32_t delay) {
delay = clamp(10u, delay, 5000u);
delay = std::clamp(10u, delay, 5000u);
for (int i = 0; i < 8; ++i)
x3c_delay[i] = delay;
m_dirty = true;
}
void setChanDelay(int chanIdx, uint32_t delay) {
delay = clamp(10u, delay, 5000u);
delay = std::clamp(10u, delay, 5000u);
x3c_delay[chanIdx] = delay;
m_dirty = true;
}
uint32_t getChanDelay(int chanIdx) const { return x3c_delay[chanIdx]; }
void setFeedback(uint32_t feedback) {
feedback = clamp(0u, feedback, 100u);
feedback = std::clamp(0u, feedback, 100u);
for (int i = 0; i < 8; ++i)
x48_feedback[i] = feedback;
m_dirty = true;
}
void setChanFeedback(int chanIdx, uint32_t feedback) {
feedback = clamp(0u, feedback, 100u);
feedback = std::clamp(0u, feedback, 100u);
x48_feedback[chanIdx] = feedback;
m_dirty = true;
}
uint32_t getChanFeedback(int chanIdx) const { return x48_feedback[chanIdx]; }
void setOutput(uint32_t output) {
output = clamp(0u, output, 100u);
output = std::clamp(0u, output, 100u);
for (int i = 0; i < 8; ++i)
x54_output[i] = output;
m_dirty = true;
}
void setChanOutput(int chanIdx, uint32_t output) {
output = clamp(0u, output, 100u);
output = std::clamp(0u, output, 100u);
x54_output[chanIdx] = output;
m_dirty = true;
}
@ -93,9 +93,9 @@ public:
void setParams(const EffectDelayInfo& info) {
for (int i = 0; i < 8; ++i) {
x3c_delay[i] = clamp(10u, info.delay[i], 5000u);
x48_feedback[i] = clamp(0u, info.feedback[i], 100u);
x54_output[i] = clamp(0u, info.output[i], 100u);
x3c_delay[i] = std::clamp(10u, info.delay[i], 5000u);
x48_feedback[i] = std::clamp(0u, info.feedback[i], 100u);
x54_output[i] = std::clamp(0u, info.output[i], 100u);
}
m_dirty = true;
}

View File

@ -75,31 +75,31 @@ public:
using ImpType = EffectReverbStdImp<T>;
void setColoration(float coloration) {
x140_x1c8_coloration = clamp(0.f, coloration, 1.f);
x140_x1c8_coloration = std::clamp(0.f, coloration, 1.f);
m_dirty = true;
}
float getColoration() const { return x140_x1c8_coloration; }
void setMix(float mix) {
x144_x1cc_mix = clamp(0.f, mix, 1.f);
x144_x1cc_mix = std::clamp(0.f, mix, 1.f);
m_dirty = true;
}
float getMix() const { return x144_x1cc_mix; }
void setTime(float time) {
x148_x1d0_time = clamp(0.01f, time, 10.f);
x148_x1d0_time = std::clamp(0.01f, time, 10.f);
m_dirty = true;
}
float getTime() const { return x148_x1d0_time; }
void setDamping(float damping) {
x14c_x1d4_damping = clamp(0.f, damping, 1.f);
x14c_x1d4_damping = std::clamp(0.f, damping, 1.f);
m_dirty = true;
}
float getDamping() const { return x14c_x1d4_damping; }
void setPreDelay(float preDelay) {
x150_x1d8_preDelay = clamp(0.f, preDelay, 0.1f);
x150_x1d8_preDelay = std::clamp(0.f, preDelay, 0.1f);
m_dirty = true;
}
float getPreDelay() const { return x150_x1d8_preDelay; }
@ -126,7 +126,7 @@ public:
using ImpType = EffectReverbHiImp<T>;
void setCrosstalk(float crosstalk) {
x1dc_crosstalk = clamp(0.f, crosstalk, 1.f);
x1dc_crosstalk = std::clamp(0.f, crosstalk, 1.f);
m_dirty = true;
}
float getCrosstalk() const { return x1dc_crosstalk; }

View File

@ -56,7 +56,7 @@ public:
void setVectors(const float* pos, const float* dir);
void setMaxVol(float maxVol) {
m_maxVol = clamp(0.f, maxVol, 1.f);
m_maxVol = std::clamp(0.f, maxVol, 1.f);
m_dirty = true;
}

View File

@ -19,10 +19,10 @@ class Listener {
public:
Listener(float volume, float frontDiff, float backDiff, float soundSpeed)
: m_volume(clamp(0.f, volume, 1.f)), m_frontDiff(frontDiff), m_backDiff(backDiff), m_soundSpeed(soundSpeed) {}
: m_volume(std::clamp(0.f, volume, 1.f)), m_frontDiff(frontDiff), m_backDiff(backDiff), m_soundSpeed(soundSpeed) {}
void setVectors(const float* pos, const float* dir, const float* heading, const float* up);
void setVolume(float vol) {
m_volume = clamp(0.f, vol, 1.f);
m_volume = std::clamp(0.f, vol, 1.f);
m_dirty = true;
}
};

View File

@ -143,9 +143,9 @@ static const float rsmpTab12khz[] =
/* clang-format on */
EffectChorus::EffectChorus(uint32_t baseDelay, uint32_t variation, uint32_t period)
: x90_baseDelay(clamp(5u, baseDelay, 15u))
, x94_variation(clamp(0u, variation, 5u))
, x98_period(clamp(500u, period, 10000u)) {}
: x90_baseDelay(std::clamp(5u, baseDelay, 15u))
, x94_variation(std::clamp(0u, variation, 5u))
, x98_period(std::clamp(500u, period, 10000u)) {}
template <typename T>
EffectChorusImp<T>::EffectChorusImp(uint32_t baseDelay, uint32_t variation, uint32_t period, double sampleRate)

View File

@ -10,9 +10,9 @@ namespace amuse {
template <typename T>
EffectDelayImp<T>::EffectDelayImp(uint32_t initDelay, uint32_t initFeedback, uint32_t initOutput, double sampleRate) {
initDelay = clamp(10u, initDelay, 5000u);
initFeedback = clamp(0u, initFeedback, 100u);
initOutput = clamp(0u, initOutput, 100u);
initDelay = std::clamp(10u, initDelay, 5000u);
initFeedback = std::clamp(0u, initFeedback, 100u);
initOutput = std::clamp(0u, initOutput, 100u);
for (int i = 0; i < 8; ++i) {
x3c_delay[i] = initDelay;
@ -26,9 +26,9 @@ EffectDelayImp<T>::EffectDelayImp(uint32_t initDelay, uint32_t initFeedback, uin
template <typename T>
EffectDelayImp<T>::EffectDelayImp(const EffectDelayInfo& info, double sampleRate) {
for (int i = 0; i < 8; ++i) {
x3c_delay[i] = clamp(10u, info.delay[i], 5000u);
x48_feedback[i] = clamp(0u, info.feedback[i], 100u);
x54_output[i] = clamp(0u, info.output[i], 100u);
x3c_delay[i] = std::clamp(10u, info.delay[i], 5000u);
x48_feedback[i] = std::clamp(0u, info.feedback[i], 100u);
x54_output[i] = std::clamp(0u, info.output[i], 100u);
}
_setup(sampleRate);

View File

@ -57,14 +57,14 @@ void ReverbDelayLine::setdelay(int32_t delay) {
}
EffectReverbStd::EffectReverbStd(float coloration, float mix, float time, float damping, float preDelay)
: x140_x1c8_coloration(clamp(0.f, coloration, 1.f))
, x144_x1cc_mix(clamp(0.f, mix, 1.f))
, x148_x1d0_time(clamp(0.01f, time, 10.f))
, x14c_x1d4_damping(clamp(0.f, damping, 1.f))
, x150_x1d8_preDelay(clamp(0.f, preDelay, 0.1f)) {}
: x140_x1c8_coloration(std::clamp(0.f, coloration, 1.f))
, x144_x1cc_mix(std::clamp(0.f, mix, 1.f))
, x148_x1d0_time(std::clamp(0.01f, time, 10.f))
, x14c_x1d4_damping(std::clamp(0.f, damping, 1.f))
, x150_x1d8_preDelay(std::clamp(0.f, preDelay, 0.1f)) {}
EffectReverbHi::EffectReverbHi(float coloration, float mix, float time, float damping, float preDelay, float crosstalk)
: EffectReverbStd(coloration, mix, time, damping, preDelay), x1dc_crosstalk(clamp(0.f, crosstalk, 1.0f)) {}
: EffectReverbStd(coloration, mix, time, damping, preDelay), x1dc_crosstalk(std::clamp(0.f, crosstalk, 1.0f)) {}
template <typename T>
EffectReverbStdImp<T>::EffectReverbStdImp(float coloration, float mix, float time, float damping, float preDelay,

View File

@ -19,8 +19,8 @@ Emitter::Emitter(Engine& engine, const AudioGroup& group, ObjToken<Voice> vox, f
: Entity(engine, group, vox->getGroupId(), vox->getObjectId())
, m_vox(vox)
, m_maxDist(maxDist)
, m_minVol(clamp(0.f, minVol, 1.f))
, m_falloff(clamp(-1.f, falloff, 1.f))
, m_minVol(std::clamp(0.f, minVol, 1.f))
, m_falloff(std::clamp(-1.f, falloff, 1.f))
, m_doppler(doppler) {}
void Emitter::_destroy() {
@ -62,10 +62,11 @@ void Emitter::_update() {
Delta(listenerToEmitter, m_pos, listener->m_pos);
float dist = Length(listenerToEmitter);
float panDist = Dot(listenerToEmitter, listener->m_right);
float frontPan = clamp(-1.f, panDist / listener->m_frontDiff, 1.f);
float backPan = clamp(-1.f, panDist / listener->m_backDiff, 1.f);
float frontPan = std::clamp(-1.f, panDist / listener->m_frontDiff, 1.f);
float backPan = std::clamp(-1.f, panDist / listener->m_backDiff, 1.f);
float spanDist = -Dot(listenerToEmitter, listener->m_heading);
float span = clamp(-1.f, spanDist > 0.f ? spanDist / listener->m_backDiff : spanDist / listener->m_frontDiff, 1.f);
float span =
std::clamp(-1.f, spanDist > 0.f ? spanDist / listener->m_backDiff : spanDist / listener->m_frontDiff, 1.f);
/* Calculate attenuation */
float att = _attenuationCurve(dist);

View File

@ -251,7 +251,7 @@ ObjToken<Voice> Engine::fxStart(SFXId sfxId, float vol, float pan, ObjToken<Stud
(*ret)->setVolume(vol);
float evalPan = pan != 0.f ? pan : ((entry->panning - 64.f) / 63.f);
evalPan = clamp(-1.f, evalPan, 1.f);
evalPan = std::clamp(-1.f, evalPan, 1.f);
(*ret)->setPan(evalPan);
return *ret;
}
@ -273,7 +273,7 @@ ObjToken<Voice> Engine::fxStart(const AudioGroup* group, GroupId groupId, SFXId
(*ret)->setVolume(vol);
float evalPan = pan != 0.f ? pan : ((entry.panning - 64.f) / 63.f);
evalPan = clamp(-1.f, evalPan, 1.f);
evalPan = std::clamp(-1.f, evalPan, 1.f);
(*ret)->setPan(evalPan);
return *ret;
}

View File

@ -41,7 +41,7 @@ void Envelope::reset(const ADSRDLS* adsr, int8_t note, int8_t vel) {
void Envelope::keyOff(const Voice& vox) {
double releaseTime = m_releaseTime;
if (vox.m_state.m_useAdsrControllers)
releaseTime = MIDItoTIME[clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiRelease)), 103)] / 1000.0;
releaseTime = MIDItoTIME[std::clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiRelease)), 103)] / 1000.0;
m_phase = (releaseTime != 0.0) ? State::Release : State::Complete;
m_curTime = 0.0;
@ -63,7 +63,7 @@ float Envelope::advance(double dt, const Voice& vox) {
case State::Attack: {
double attackTime = m_attackTime;
if (vox.m_state.m_useAdsrControllers)
attackTime = MIDItoTIME[clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiAttack)), 103)] / 1000.0;
attackTime = MIDItoTIME[std::clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiAttack)), 103)] / 1000.0;
if (attackTime == 0.0) {
m_phase = State::Decay;
@ -84,11 +84,11 @@ float Envelope::advance(double dt, const Voice& vox) {
case State::Decay: {
double decayTime = m_decayTime;
if (vox.m_state.m_useAdsrControllers)
decayTime = MIDItoTIME[clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiDecay)), 103)] / 1000.0;
decayTime = MIDItoTIME[std::clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiDecay)), 103)] / 1000.0;
double sustainFactor = m_sustainFactor;
if (vox.m_state.m_useAdsrControllers)
sustainFactor = clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiSustain)), 127) / 127.0;
sustainFactor = std::clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiSustain)), 127) / 127.0;
if (decayTime == 0.0) {
m_phase = State::Sustain;
@ -109,14 +109,14 @@ float Envelope::advance(double dt, const Voice& vox) {
case State::Sustain: {
double sustainFactor = m_sustainFactor;
if (vox.m_state.m_useAdsrControllers)
sustainFactor = clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiSustain)), 127) / 127.0;
sustainFactor = std::clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiSustain)), 127) / 127.0;
return sustainFactor;
}
case State::Release: {
double releaseTime = m_releaseTime;
if (vox.m_state.m_useAdsrControllers)
releaseTime = MIDItoTIME[clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiRelease)), 103)] / 1000.0;
releaseTime = MIDItoTIME[std::clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiRelease)), 103)] / 1000.0;
if (releaseTime == 0.0) {
m_phase = State::Complete;

View File

@ -683,7 +683,7 @@ std::vector<uint8_t> SongConverter::SongToMIDI(const unsigned char* data, int& v
/* Update pitch */
trk.m_pitchVal += trk.m_nextPitchDelta;
events.emplace(regStart + trk.m_nextPitchTick,
Event{PitchEvent{}, trk.m_midiChan, clamp(0, trk.m_pitchVal + 0x2000, 0x4000)});
Event{PitchEvent{}, trk.m_midiChan, std::clamp(0, trk.m_pitchVal + 0x2000, 0x4000)});
if (trk.m_pitchWheelData[0] != 0x80 || trk.m_pitchWheelData[1] != 0x00) {
auto delta = DecodeDelta(trk.m_pitchWheelData);
trk.m_nextPitchTick += delta.first;
@ -700,7 +700,7 @@ std::vector<uint8_t> SongConverter::SongToMIDI(const unsigned char* data, int& v
/* Update modulation */
trk.m_modVal += trk.m_nextModDelta;
events.emplace(regStart + trk.m_nextModTick,
Event{CtrlEvent{}, trk.m_midiChan, 1, uint8_t(clamp(0, trk.m_modVal / 128, 127)), 0});
Event{CtrlEvent{}, trk.m_midiChan, 1, uint8_t(std::clamp(0, trk.m_modVal / 128, 127)), 0});
if (trk.m_modWheelData[0] != 0x80 || trk.m_modWheelData[1] != 0x00) {
auto delta = DecodeDelta(trk.m_modWheelData);
trk.m_nextModTick += delta.first;

View File

@ -443,7 +443,7 @@ bool SongState::Track::advance(Sequencer& seq, double dt) {
if (pitchTick + remPitchTicks > nextTick) {
/* Update pitch */
m_pitchVal += m_nextPitchDelta;
seq.setPitchWheel(m_midiChan, clamp(-1.f, m_pitchVal / 8191.f, 1.f));
seq.setPitchWheel(m_midiChan, std::clamp(-1.f, m_pitchVal / 8191.f, 1.f));
if (m_pitchWheelData[0] != 0x80 || m_pitchWheelData[1] != 0x00) {
auto delta = DecodeDelta(m_pitchWheelData);
m_nextPitchTick += delta.first;
@ -467,7 +467,7 @@ bool SongState::Track::advance(Sequencer& seq, double dt) {
if (modTick + remModTicks > nextTick) {
/* Update modulation */
m_modVal += m_nextModDelta;
seq.setCtrlValue(m_midiChan, 1, int8_t(clamp(0, m_modVal / 127, 127)));
seq.setCtrlValue(m_midiChan, 1, int8_t(std::clamp(0, m_modVal / 127, 127)));
if (m_modWheelData[0] != 0x80 || m_modWheelData[1] != 0x00) {
auto delta = DecodeDelta(m_modWheelData);
m_nextModTick += delta.first;

View File

@ -67,7 +67,7 @@ float SoundMacroState::Evaluator::evaluate(double time, const Voice& vox, const
break;
case 135:
/* Time since macro-start (ms) */
thisValue = clamp(0.f, float(st.m_execTime * 1000.f), 16383.f);
thisValue = std::clamp(0.f, float(st.m_execTime * 1000.f), 16383.f);
break;
default:
thisValue = vox.getCtrlValue(comp.m_midiCtrl);
@ -462,7 +462,7 @@ const SoundMacro::CmdIntrospection SoundMacro::CmdScaleVolume::Introspective = {
{FIELD_HEAD(SoundMacro::CmdScaleVolume, originalVol), "Original Vol"sv, 0, 1, 1}}};
bool SoundMacro::CmdScaleVolume::Do(SoundMacroState& st, Voice& vox) const {
int32_t eval = int32_t(originalVol ? st.m_initVel : st.m_curVel) * scale / 127 + add;
eval = clamp(0, eval, 127);
eval = std::clamp(0, eval, 127);
if (table.id != 0) {
const Curve* curveData = vox.getAudioGroup().getPool().tableAsCurves(table.id);
@ -504,7 +504,7 @@ bool SoundMacro::CmdEnvelope::Do(SoundMacroState& st, Voice& vox) const {
double secTime = ticksOrMs / q;
int32_t eval = int32_t(st.m_curVel) * scale / 127 + add;
eval = clamp(0, eval, 127);
eval = std::clamp(0, eval, 127);
const Curve* curveData;
if (table.id != 0)
@ -601,7 +601,7 @@ bool SoundMacro::CmdFadeIn::Do(SoundMacroState& st, Voice& vox) const {
float secTime = ticksOrMs / q;
int32_t eval = int32_t(st.m_curVel) * scale / 127 + add;
eval = clamp(0, eval, 127);
eval = std::clamp(0, eval, 127);
const Curve* curveData;
if (table.id != 0)

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)

View File

@ -37,7 +37,7 @@ static const float DLSVolumeTable[] = {
0.892802f, 0.907744f, 0.922810f, 0.938000f, 0.953314f, 0.968752f, 0.984314f, 1.000000f, 1.000000f};
float LookupVolume(float vol) {
vol = amuse::clamp(0.f, vol * 127.f, 127.f);
vol = std::clamp(0.f, vol * 127.f, 127.f);
float f = std::floor(vol);
float c = std::ceil(vol);
if (f == c)
@ -47,7 +47,7 @@ float LookupVolume(float vol) {
}
float LookupDLSVolume(float vol) {
vol = amuse::clamp(0.f, vol * 127.f, 127.f);
vol = std::clamp(0.f, vol * 127.f, 127.f);
float f = std::floor(vol);
float c = std::ceil(vol);
if (f == c)