mirror of https://github.com/AxioDL/amuse.git
General: Amend clamp parameter order
Batch replace on switching to standardized variants assumed common ordering, which evidently wasn't the case
This commit is contained in:
parent
5da58eb1da
commit
50c4b5cdab
|
@ -38,21 +38,21 @@ public:
|
||||||
using ImpType = EffectChorusImp<T>;
|
using ImpType = EffectChorusImp<T>;
|
||||||
|
|
||||||
void setBaseDelay(uint32_t baseDelay) {
|
void setBaseDelay(uint32_t baseDelay) {
|
||||||
baseDelay = std::clamp(5u, baseDelay, 15u);
|
baseDelay = std::clamp(baseDelay, 5u, 15u);
|
||||||
x90_baseDelay = baseDelay;
|
x90_baseDelay = baseDelay;
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
uint32_t getBaseDelay() const { return x90_baseDelay; }
|
uint32_t getBaseDelay() const { return x90_baseDelay; }
|
||||||
|
|
||||||
void setVariation(uint32_t variation) {
|
void setVariation(uint32_t variation) {
|
||||||
variation = std::clamp(0u, variation, 5u);
|
variation = std::clamp(variation, 0u, 5u);
|
||||||
x94_variation = variation;
|
x94_variation = variation;
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
uint32_t getVariation() const { return x94_variation; }
|
uint32_t getVariation() const { return x94_variation; }
|
||||||
|
|
||||||
void setPeriod(uint32_t period) {
|
void setPeriod(uint32_t period) {
|
||||||
period = std::clamp(500u, period, 10000u);
|
period = std::clamp(period, 500u, 10000u);
|
||||||
x98_period = period;
|
x98_period = period;
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,41 +51,41 @@ public:
|
||||||
using ImpType = EffectDelayImp<T>;
|
using ImpType = EffectDelayImp<T>;
|
||||||
|
|
||||||
void setDelay(uint32_t delay) {
|
void setDelay(uint32_t delay) {
|
||||||
delay = std::clamp(10u, delay, 5000u);
|
delay = std::clamp(delay, 10u, 5000u);
|
||||||
for (int i = 0; i < 8; ++i)
|
for (int i = 0; i < 8; ++i)
|
||||||
x3c_delay[i] = delay;
|
x3c_delay[i] = delay;
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
void setChanDelay(int chanIdx, uint32_t delay) {
|
void setChanDelay(int chanIdx, uint32_t delay) {
|
||||||
delay = std::clamp(10u, delay, 5000u);
|
delay = std::clamp(delay, 10u, 5000u);
|
||||||
x3c_delay[chanIdx] = delay;
|
x3c_delay[chanIdx] = delay;
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
uint32_t getChanDelay(int chanIdx) const { return x3c_delay[chanIdx]; }
|
uint32_t getChanDelay(int chanIdx) const { return x3c_delay[chanIdx]; }
|
||||||
|
|
||||||
void setFeedback(uint32_t feedback) {
|
void setFeedback(uint32_t feedback) {
|
||||||
feedback = std::clamp(0u, feedback, 100u);
|
feedback = std::clamp(feedback, 0u, 100u);
|
||||||
for (int i = 0; i < 8; ++i)
|
for (int i = 0; i < 8; ++i)
|
||||||
x48_feedback[i] = feedback;
|
x48_feedback[i] = feedback;
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setChanFeedback(int chanIdx, uint32_t feedback) {
|
void setChanFeedback(int chanIdx, uint32_t feedback) {
|
||||||
feedback = std::clamp(0u, feedback, 100u);
|
feedback = std::clamp(feedback, 0u, 100u);
|
||||||
x48_feedback[chanIdx] = feedback;
|
x48_feedback[chanIdx] = feedback;
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
uint32_t getChanFeedback(int chanIdx) const { return x48_feedback[chanIdx]; }
|
uint32_t getChanFeedback(int chanIdx) const { return x48_feedback[chanIdx]; }
|
||||||
|
|
||||||
void setOutput(uint32_t output) {
|
void setOutput(uint32_t output) {
|
||||||
output = std::clamp(0u, output, 100u);
|
output = std::clamp(output, 0u, 100u);
|
||||||
for (int i = 0; i < 8; ++i)
|
for (int i = 0; i < 8; ++i)
|
||||||
x54_output[i] = output;
|
x54_output[i] = output;
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setChanOutput(int chanIdx, uint32_t output) {
|
void setChanOutput(int chanIdx, uint32_t output) {
|
||||||
output = std::clamp(0u, output, 100u);
|
output = std::clamp(output, 0u, 100u);
|
||||||
x54_output[chanIdx] = output;
|
x54_output[chanIdx] = output;
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
|
@ -93,9 +93,9 @@ public:
|
||||||
|
|
||||||
void setParams(const EffectDelayInfo& info) {
|
void setParams(const EffectDelayInfo& info) {
|
||||||
for (int i = 0; i < 8; ++i) {
|
for (int i = 0; i < 8; ++i) {
|
||||||
x3c_delay[i] = std::clamp(10u, info.delay[i], 5000u);
|
x3c_delay[i] = std::clamp(info.delay[i], 10u, 5000u);
|
||||||
x48_feedback[i] = std::clamp(0u, info.feedback[i], 100u);
|
x48_feedback[i] = std::clamp(info.feedback[i], 0u, 100u);
|
||||||
x54_output[i] = std::clamp(0u, info.output[i], 100u);
|
x54_output[i] = std::clamp(info.output[i], 0u, 100u);
|
||||||
}
|
}
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,31 +75,31 @@ public:
|
||||||
using ImpType = EffectReverbStdImp<T>;
|
using ImpType = EffectReverbStdImp<T>;
|
||||||
|
|
||||||
void setColoration(float coloration) {
|
void setColoration(float coloration) {
|
||||||
x140_x1c8_coloration = std::clamp(0.f, coloration, 1.f);
|
x140_x1c8_coloration = std::clamp(coloration, 0.f, 1.f);
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
float getColoration() const { return x140_x1c8_coloration; }
|
float getColoration() const { return x140_x1c8_coloration; }
|
||||||
|
|
||||||
void setMix(float mix) {
|
void setMix(float mix) {
|
||||||
x144_x1cc_mix = std::clamp(0.f, mix, 1.f);
|
x144_x1cc_mix = std::clamp(mix, 0.f, 1.f);
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
float getMix() const { return x144_x1cc_mix; }
|
float getMix() const { return x144_x1cc_mix; }
|
||||||
|
|
||||||
void setTime(float time) {
|
void setTime(float time) {
|
||||||
x148_x1d0_time = std::clamp(0.01f, time, 10.f);
|
x148_x1d0_time = std::clamp(time, 0.01f, 10.f);
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
float getTime() const { return x148_x1d0_time; }
|
float getTime() const { return x148_x1d0_time; }
|
||||||
|
|
||||||
void setDamping(float damping) {
|
void setDamping(float damping) {
|
||||||
x14c_x1d4_damping = std::clamp(0.f, damping, 1.f);
|
x14c_x1d4_damping = std::clamp(damping, 0.f, 1.f);
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
float getDamping() const { return x14c_x1d4_damping; }
|
float getDamping() const { return x14c_x1d4_damping; }
|
||||||
|
|
||||||
void setPreDelay(float preDelay) {
|
void setPreDelay(float preDelay) {
|
||||||
x150_x1d8_preDelay = std::clamp(0.f, preDelay, 0.1f);
|
x150_x1d8_preDelay = std::clamp(preDelay, 0.f, 0.1f);
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
float getPreDelay() const { return x150_x1d8_preDelay; }
|
float getPreDelay() const { return x150_x1d8_preDelay; }
|
||||||
|
@ -126,7 +126,7 @@ public:
|
||||||
using ImpType = EffectReverbHiImp<T>;
|
using ImpType = EffectReverbHiImp<T>;
|
||||||
|
|
||||||
void setCrosstalk(float crosstalk) {
|
void setCrosstalk(float crosstalk) {
|
||||||
x1dc_crosstalk = std::clamp(0.f, crosstalk, 1.f);
|
x1dc_crosstalk = std::clamp(crosstalk, 0.f, 1.f);
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
float getCrosstalk() const { return x1dc_crosstalk; }
|
float getCrosstalk() const { return x1dc_crosstalk; }
|
||||||
|
|
|
@ -56,7 +56,7 @@ public:
|
||||||
|
|
||||||
void setVectors(const float* pos, const float* dir);
|
void setVectors(const float* pos, const float* dir);
|
||||||
void setMaxVol(float maxVol) {
|
void setMaxVol(float maxVol) {
|
||||||
m_maxVol = std::clamp(0.f, maxVol, 1.f);
|
m_maxVol = std::clamp(maxVol, 0.f, 1.f);
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,10 @@ class Listener {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Listener(float volume, float frontDiff, float backDiff, float soundSpeed)
|
Listener(float volume, float frontDiff, float backDiff, float soundSpeed)
|
||||||
: m_volume(std::clamp(0.f, volume, 1.f)), m_frontDiff(frontDiff), m_backDiff(backDiff), m_soundSpeed(soundSpeed) {}
|
: m_volume(std::clamp(volume, 0.f, 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 setVectors(const float* pos, const float* dir, const float* heading, const float* up);
|
||||||
void setVolume(float vol) {
|
void setVolume(float vol) {
|
||||||
m_volume = std::clamp(0.f, vol, 1.f);
|
m_volume = std::clamp(vol, 0.f, 1.f);
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -143,9 +143,9 @@ static const float rsmpTab12khz[] =
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
|
||||||
EffectChorus::EffectChorus(uint32_t baseDelay, uint32_t variation, uint32_t period)
|
EffectChorus::EffectChorus(uint32_t baseDelay, uint32_t variation, uint32_t period)
|
||||||
: x90_baseDelay(std::clamp(5u, baseDelay, 15u))
|
: x90_baseDelay(std::clamp(baseDelay, 5u, 15u))
|
||||||
, x94_variation(std::clamp(0u, variation, 5u))
|
, x94_variation(std::clamp(variation, 0u, 5u))
|
||||||
, x98_period(std::clamp(500u, period, 10000u)) {}
|
, x98_period(std::clamp(period, 500u, 10000u)) {}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
EffectChorusImp<T>::EffectChorusImp(uint32_t baseDelay, uint32_t variation, uint32_t period, double sampleRate)
|
EffectChorusImp<T>::EffectChorusImp(uint32_t baseDelay, uint32_t variation, uint32_t period, double sampleRate)
|
||||||
|
|
|
@ -10,9 +10,9 @@ namespace amuse {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
EffectDelayImp<T>::EffectDelayImp(uint32_t initDelay, uint32_t initFeedback, uint32_t initOutput, double sampleRate) {
|
EffectDelayImp<T>::EffectDelayImp(uint32_t initDelay, uint32_t initFeedback, uint32_t initOutput, double sampleRate) {
|
||||||
initDelay = std::clamp(10u, initDelay, 5000u);
|
initDelay = std::clamp(initDelay, 10u, 5000u);
|
||||||
initFeedback = std::clamp(0u, initFeedback, 100u);
|
initFeedback = std::clamp(initFeedback, 0u, 100u);
|
||||||
initOutput = std::clamp(0u, initOutput, 100u);
|
initOutput = std::clamp(initOutput, 0u, 100u);
|
||||||
|
|
||||||
for (int i = 0; i < 8; ++i) {
|
for (int i = 0; i < 8; ++i) {
|
||||||
x3c_delay[i] = initDelay;
|
x3c_delay[i] = initDelay;
|
||||||
|
@ -26,9 +26,9 @@ EffectDelayImp<T>::EffectDelayImp(uint32_t initDelay, uint32_t initFeedback, uin
|
||||||
template <typename T>
|
template <typename T>
|
||||||
EffectDelayImp<T>::EffectDelayImp(const EffectDelayInfo& info, double sampleRate) {
|
EffectDelayImp<T>::EffectDelayImp(const EffectDelayInfo& info, double sampleRate) {
|
||||||
for (int i = 0; i < 8; ++i) {
|
for (int i = 0; i < 8; ++i) {
|
||||||
x3c_delay[i] = std::clamp(10u, info.delay[i], 5000u);
|
x3c_delay[i] = std::clamp(info.delay[i], 10u, 5000u);
|
||||||
x48_feedback[i] = std::clamp(0u, info.feedback[i], 100u);
|
x48_feedback[i] = std::clamp(info.feedback[i], 0u, 100u);
|
||||||
x54_output[i] = std::clamp(0u, info.output[i], 100u);
|
x54_output[i] = std::clamp(info.output[i], 0u, 100u);
|
||||||
}
|
}
|
||||||
|
|
||||||
_setup(sampleRate);
|
_setup(sampleRate);
|
||||||
|
|
|
@ -57,14 +57,14 @@ void ReverbDelayLine::setdelay(int32_t delay) {
|
||||||
}
|
}
|
||||||
|
|
||||||
EffectReverbStd::EffectReverbStd(float coloration, float mix, float time, float damping, float preDelay)
|
EffectReverbStd::EffectReverbStd(float coloration, float mix, float time, float damping, float preDelay)
|
||||||
: x140_x1c8_coloration(std::clamp(0.f, coloration, 1.f))
|
: x140_x1c8_coloration(std::clamp(coloration, 0.f, 1.f))
|
||||||
, x144_x1cc_mix(std::clamp(0.f, mix, 1.f))
|
, x144_x1cc_mix(std::clamp(mix, 0.f, 1.f))
|
||||||
, x148_x1d0_time(std::clamp(0.01f, time, 10.f))
|
, x148_x1d0_time(std::clamp(time, 0.01f, 10.f))
|
||||||
, x14c_x1d4_damping(std::clamp(0.f, damping, 1.f))
|
, x14c_x1d4_damping(std::clamp(damping, 0.f, 1.f))
|
||||||
, x150_x1d8_preDelay(std::clamp(0.f, preDelay, 0.1f)) {}
|
, x150_x1d8_preDelay(std::clamp(preDelay, 0.f, 0.1f)) {}
|
||||||
|
|
||||||
EffectReverbHi::EffectReverbHi(float coloration, float mix, float time, float damping, float preDelay, float crosstalk)
|
EffectReverbHi::EffectReverbHi(float coloration, float mix, float time, float damping, float preDelay, float crosstalk)
|
||||||
: EffectReverbStd(coloration, mix, time, damping, preDelay), x1dc_crosstalk(std::clamp(0.f, crosstalk, 1.0f)) {}
|
: EffectReverbStd(coloration, mix, time, damping, preDelay), x1dc_crosstalk(std::clamp(crosstalk, 0.f, 1.0f)) {}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
EffectReverbStdImp<T>::EffectReverbStdImp(float coloration, float mix, float time, float damping, float preDelay,
|
EffectReverbStdImp<T>::EffectReverbStdImp(float coloration, float mix, float time, float damping, float preDelay,
|
||||||
|
|
|
@ -19,8 +19,8 @@ Emitter::Emitter(Engine& engine, const AudioGroup& group, ObjToken<Voice> vox, f
|
||||||
: Entity(engine, group, vox->getGroupId(), vox->getObjectId())
|
: Entity(engine, group, vox->getGroupId(), vox->getObjectId())
|
||||||
, m_vox(vox)
|
, m_vox(vox)
|
||||||
, m_maxDist(maxDist)
|
, m_maxDist(maxDist)
|
||||||
, m_minVol(std::clamp(0.f, minVol, 1.f))
|
, m_minVol(std::clamp(minVol, 0.f, 1.f))
|
||||||
, m_falloff(std::clamp(-1.f, falloff, 1.f))
|
, m_falloff(std::clamp(falloff, -1.f, 1.f))
|
||||||
, m_doppler(doppler) {}
|
, m_doppler(doppler) {}
|
||||||
|
|
||||||
void Emitter::_destroy() {
|
void Emitter::_destroy() {
|
||||||
|
@ -60,13 +60,13 @@ void Emitter::_update() {
|
||||||
for (auto& listener : m_engine.m_activeListeners) {
|
for (auto& listener : m_engine.m_activeListeners) {
|
||||||
Vector3f listenerToEmitter;
|
Vector3f listenerToEmitter;
|
||||||
Delta(listenerToEmitter, m_pos, listener->m_pos);
|
Delta(listenerToEmitter, m_pos, listener->m_pos);
|
||||||
float dist = Length(listenerToEmitter);
|
const float dist = Length(listenerToEmitter);
|
||||||
float panDist = Dot(listenerToEmitter, listener->m_right);
|
const float panDist = Dot(listenerToEmitter, listener->m_right);
|
||||||
float frontPan = std::clamp(-1.f, panDist / listener->m_frontDiff, 1.f);
|
const float frontPan = std::clamp(panDist / listener->m_frontDiff, -1.f, 1.f);
|
||||||
float backPan = std::clamp(-1.f, panDist / listener->m_backDiff, 1.f);
|
const float backPan = std::clamp(panDist / listener->m_backDiff, -1.f, 1.f);
|
||||||
float spanDist = -Dot(listenerToEmitter, listener->m_heading);
|
const float spanDist = -Dot(listenerToEmitter, listener->m_heading);
|
||||||
float span =
|
const float span =
|
||||||
std::clamp(-1.f, spanDist > 0.f ? spanDist / listener->m_backDiff : spanDist / listener->m_frontDiff, 1.f);
|
std::clamp(spanDist > 0.f ? spanDist / listener->m_backDiff : spanDist / listener->m_frontDiff, -1.f, 1.f);
|
||||||
|
|
||||||
/* Calculate attenuation */
|
/* Calculate attenuation */
|
||||||
float att = _attenuationCurve(dist);
|
float att = _attenuationCurve(dist);
|
||||||
|
|
|
@ -251,7 +251,7 @@ ObjToken<Voice> Engine::fxStart(SFXId sfxId, float vol, float pan, ObjToken<Stud
|
||||||
|
|
||||||
(*ret)->setVolume(vol);
|
(*ret)->setVolume(vol);
|
||||||
float evalPan = pan != 0.f ? pan : ((entry->panning - 64.f) / 63.f);
|
float evalPan = pan != 0.f ? pan : ((entry->panning - 64.f) / 63.f);
|
||||||
evalPan = std::clamp(-1.f, evalPan, 1.f);
|
evalPan = std::clamp(evalPan, -1.f, 1.f);
|
||||||
(*ret)->setPan(evalPan);
|
(*ret)->setPan(evalPan);
|
||||||
return *ret;
|
return *ret;
|
||||||
}
|
}
|
||||||
|
@ -273,7 +273,7 @@ ObjToken<Voice> Engine::fxStart(const AudioGroup* group, GroupId groupId, SFXId
|
||||||
|
|
||||||
(*ret)->setVolume(vol);
|
(*ret)->setVolume(vol);
|
||||||
float evalPan = pan != 0.f ? pan : ((entry.panning - 64.f) / 63.f);
|
float evalPan = pan != 0.f ? pan : ((entry.panning - 64.f) / 63.f);
|
||||||
evalPan = std::clamp(-1.f, evalPan, 1.f);
|
evalPan = std::clamp(evalPan, -1.f, 1.f);
|
||||||
(*ret)->setPan(evalPan);
|
(*ret)->setPan(evalPan);
|
||||||
return *ret;
|
return *ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,8 +42,9 @@ void Envelope::reset(const ADSRDLS* adsr, int8_t note, int8_t vel) {
|
||||||
|
|
||||||
void Envelope::keyOff(const Voice& vox) {
|
void Envelope::keyOff(const Voice& vox) {
|
||||||
double releaseTime = m_releaseTime;
|
double releaseTime = m_releaseTime;
|
||||||
if (vox.m_state.m_useAdsrControllers)
|
if (vox.m_state.m_useAdsrControllers) {
|
||||||
releaseTime = MIDItoTIME[std::clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiRelease)), 103)] / 1000.0;
|
releaseTime = MIDItoTIME[std::clamp(int(vox.getCtrlValue(vox.m_state.m_midiRelease)), 0, 103)] / 1000.0;
|
||||||
|
}
|
||||||
|
|
||||||
m_phase = (releaseTime != 0.0) ? State::Release : State::Complete;
|
m_phase = (releaseTime != 0.0) ? State::Release : State::Complete;
|
||||||
m_curTime = 0.0;
|
m_curTime = 0.0;
|
||||||
|
@ -64,8 +65,9 @@ float Envelope::advance(double dt, const Voice& vox) {
|
||||||
switch (m_phase) {
|
switch (m_phase) {
|
||||||
case State::Attack: {
|
case State::Attack: {
|
||||||
double attackTime = m_attackTime;
|
double attackTime = m_attackTime;
|
||||||
if (vox.m_state.m_useAdsrControllers)
|
if (vox.m_state.m_useAdsrControllers) {
|
||||||
attackTime = MIDItoTIME[std::clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiAttack)), 103)] / 1000.0;
|
attackTime = MIDItoTIME[std::clamp(int(vox.getCtrlValue(vox.m_state.m_midiAttack)), 0, 103)] / 1000.0;
|
||||||
|
}
|
||||||
|
|
||||||
if (attackTime == 0.0) {
|
if (attackTime == 0.0) {
|
||||||
m_phase = State::Decay;
|
m_phase = State::Decay;
|
||||||
|
@ -85,12 +87,14 @@ float Envelope::advance(double dt, const Voice& vox) {
|
||||||
}
|
}
|
||||||
case State::Decay: {
|
case State::Decay: {
|
||||||
double decayTime = m_decayTime;
|
double decayTime = m_decayTime;
|
||||||
if (vox.m_state.m_useAdsrControllers)
|
if (vox.m_state.m_useAdsrControllers) {
|
||||||
decayTime = MIDItoTIME[std::clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiDecay)), 103)] / 1000.0;
|
decayTime = MIDItoTIME[std::clamp(int(vox.getCtrlValue(vox.m_state.m_midiDecay)), 0, 103)] / 1000.0;
|
||||||
|
}
|
||||||
|
|
||||||
double sustainFactor = m_sustainFactor;
|
double sustainFactor = m_sustainFactor;
|
||||||
if (vox.m_state.m_useAdsrControllers)
|
if (vox.m_state.m_useAdsrControllers) {
|
||||||
sustainFactor = std::clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiSustain)), 127) / 127.0;
|
sustainFactor = std::clamp(int(vox.getCtrlValue(vox.m_state.m_midiSustain)), 0, 127) / 127.0;
|
||||||
|
}
|
||||||
|
|
||||||
if (decayTime == 0.0) {
|
if (decayTime == 0.0) {
|
||||||
m_phase = State::Sustain;
|
m_phase = State::Sustain;
|
||||||
|
@ -110,15 +114,17 @@ float Envelope::advance(double dt, const Voice& vox) {
|
||||||
}
|
}
|
||||||
case State::Sustain: {
|
case State::Sustain: {
|
||||||
double sustainFactor = m_sustainFactor;
|
double sustainFactor = m_sustainFactor;
|
||||||
if (vox.m_state.m_useAdsrControllers)
|
if (vox.m_state.m_useAdsrControllers) {
|
||||||
sustainFactor = std::clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiSustain)), 127) / 127.0;
|
sustainFactor = std::clamp(int(vox.getCtrlValue(vox.m_state.m_midiSustain)), 0, 127) / 127.0;
|
||||||
|
}
|
||||||
|
|
||||||
return sustainFactor;
|
return sustainFactor;
|
||||||
}
|
}
|
||||||
case State::Release: {
|
case State::Release: {
|
||||||
double releaseTime = m_releaseTime;
|
double releaseTime = m_releaseTime;
|
||||||
if (vox.m_state.m_useAdsrControllers)
|
if (vox.m_state.m_useAdsrControllers) {
|
||||||
releaseTime = MIDItoTIME[std::clamp(0, int(vox.getCtrlValue(vox.m_state.m_midiRelease)), 103)] / 1000.0;
|
releaseTime = MIDItoTIME[std::clamp(int(vox.getCtrlValue(vox.m_state.m_midiRelease)), 0, 103)] / 1000.0;
|
||||||
|
}
|
||||||
|
|
||||||
if (releaseTime == 0.0) {
|
if (releaseTime == 0.0) {
|
||||||
m_phase = State::Complete;
|
m_phase = State::Complete;
|
||||||
|
|
|
@ -683,7 +683,7 @@ std::vector<uint8_t> SongConverter::SongToMIDI(const unsigned char* data, int& v
|
||||||
/* Update pitch */
|
/* Update pitch */
|
||||||
trk.m_pitchVal += trk.m_nextPitchDelta;
|
trk.m_pitchVal += trk.m_nextPitchDelta;
|
||||||
events.emplace(regStart + trk.m_nextPitchTick,
|
events.emplace(regStart + trk.m_nextPitchTick,
|
||||||
Event{PitchEvent{}, trk.m_midiChan, std::clamp(0, trk.m_pitchVal + 0x2000, 0x4000)});
|
Event{PitchEvent{}, trk.m_midiChan, std::clamp(trk.m_pitchVal + 0x2000, 0, 0x4000)});
|
||||||
if (trk.m_pitchWheelData[0] != 0x80 || trk.m_pitchWheelData[1] != 0x00) {
|
if (trk.m_pitchWheelData[0] != 0x80 || trk.m_pitchWheelData[1] != 0x00) {
|
||||||
auto delta = DecodeDelta(trk.m_pitchWheelData);
|
auto delta = DecodeDelta(trk.m_pitchWheelData);
|
||||||
trk.m_nextPitchTick += delta.first;
|
trk.m_nextPitchTick += delta.first;
|
||||||
|
@ -700,7 +700,7 @@ std::vector<uint8_t> SongConverter::SongToMIDI(const unsigned char* data, int& v
|
||||||
/* Update modulation */
|
/* Update modulation */
|
||||||
trk.m_modVal += trk.m_nextModDelta;
|
trk.m_modVal += trk.m_nextModDelta;
|
||||||
events.emplace(regStart + trk.m_nextModTick,
|
events.emplace(regStart + trk.m_nextModTick,
|
||||||
Event{CtrlEvent{}, trk.m_midiChan, 1, uint8_t(std::clamp(0, trk.m_modVal / 128, 127)), 0});
|
Event{CtrlEvent{}, trk.m_midiChan, 1, uint8_t(std::clamp(trk.m_modVal / 128, 0, 127)), 0});
|
||||||
if (trk.m_modWheelData[0] != 0x80 || trk.m_modWheelData[1] != 0x00) {
|
if (trk.m_modWheelData[0] != 0x80 || trk.m_modWheelData[1] != 0x00) {
|
||||||
auto delta = DecodeDelta(trk.m_modWheelData);
|
auto delta = DecodeDelta(trk.m_modWheelData);
|
||||||
trk.m_nextModTick += delta.first;
|
trk.m_nextModTick += delta.first;
|
||||||
|
|
|
@ -443,7 +443,7 @@ bool SongState::Track::advance(Sequencer& seq, double dt) {
|
||||||
if (pitchTick + remPitchTicks > nextTick) {
|
if (pitchTick + remPitchTicks > nextTick) {
|
||||||
/* Update pitch */
|
/* Update pitch */
|
||||||
m_pitchVal += m_nextPitchDelta;
|
m_pitchVal += m_nextPitchDelta;
|
||||||
seq.setPitchWheel(m_midiChan, std::clamp(-1.f, m_pitchVal / 8191.f, 1.f));
|
seq.setPitchWheel(m_midiChan, std::clamp(m_pitchVal / 8191.f, -1.f, 1.f));
|
||||||
if (m_pitchWheelData[0] != 0x80 || m_pitchWheelData[1] != 0x00) {
|
if (m_pitchWheelData[0] != 0x80 || m_pitchWheelData[1] != 0x00) {
|
||||||
auto delta = DecodeDelta(m_pitchWheelData);
|
auto delta = DecodeDelta(m_pitchWheelData);
|
||||||
m_nextPitchTick += delta.first;
|
m_nextPitchTick += delta.first;
|
||||||
|
@ -467,7 +467,7 @@ bool SongState::Track::advance(Sequencer& seq, double dt) {
|
||||||
if (modTick + remModTicks > nextTick) {
|
if (modTick + remModTicks > nextTick) {
|
||||||
/* Update modulation */
|
/* Update modulation */
|
||||||
m_modVal += m_nextModDelta;
|
m_modVal += m_nextModDelta;
|
||||||
seq.setCtrlValue(m_midiChan, 1, int8_t(std::clamp(0, m_modVal / 127, 127)));
|
seq.setCtrlValue(m_midiChan, 1, int8_t(std::clamp(m_modVal / 127, 0, 127)));
|
||||||
if (m_modWheelData[0] != 0x80 || m_modWheelData[1] != 0x00) {
|
if (m_modWheelData[0] != 0x80 || m_modWheelData[1] != 0x00) {
|
||||||
auto delta = DecodeDelta(m_modWheelData);
|
auto delta = DecodeDelta(m_modWheelData);
|
||||||
m_nextModTick += delta.first;
|
m_nextModTick += delta.first;
|
||||||
|
|
|
@ -67,7 +67,7 @@ float SoundMacroState::Evaluator::evaluate(double time, const Voice& vox, const
|
||||||
break;
|
break;
|
||||||
case 135:
|
case 135:
|
||||||
/* Time since macro-start (ms) */
|
/* Time since macro-start (ms) */
|
||||||
thisValue = std::clamp(0.f, float(st.m_execTime * 1000.f), 16383.f);
|
thisValue = std::clamp(float(st.m_execTime * 1000.f), 0.f, 16383.f);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
thisValue = vox.getCtrlValue(comp.m_midiCtrl);
|
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}}};
|
{FIELD_HEAD(SoundMacro::CmdScaleVolume, originalVol), "Original Vol"sv, 0, 1, 1}}};
|
||||||
bool SoundMacro::CmdScaleVolume::Do(SoundMacroState& st, Voice& vox) const {
|
bool SoundMacro::CmdScaleVolume::Do(SoundMacroState& st, Voice& vox) const {
|
||||||
int32_t eval = int32_t(originalVol ? st.m_initVel : st.m_curVel) * scale / 127 + add;
|
int32_t eval = int32_t(originalVol ? st.m_initVel : st.m_curVel) * scale / 127 + add;
|
||||||
eval = std::clamp(0, eval, 127);
|
eval = std::clamp(eval, 0, 127);
|
||||||
|
|
||||||
if (table.id != 0) {
|
if (table.id != 0) {
|
||||||
const Curve* curveData = vox.getAudioGroup().getPool().tableAsCurves(table.id);
|
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;
|
double secTime = ticksOrMs / q;
|
||||||
|
|
||||||
int32_t eval = int32_t(st.m_curVel) * scale / 127 + add;
|
int32_t eval = int32_t(st.m_curVel) * scale / 127 + add;
|
||||||
eval = std::clamp(0, eval, 127);
|
eval = std::clamp(eval, 0, 127);
|
||||||
|
|
||||||
const Curve* curveData;
|
const Curve* curveData;
|
||||||
if (table.id != 0)
|
if (table.id != 0)
|
||||||
|
@ -601,7 +601,7 @@ bool SoundMacro::CmdFadeIn::Do(SoundMacroState& st, Voice& vox) const {
|
||||||
float secTime = ticksOrMs / q;
|
float secTime = ticksOrMs / q;
|
||||||
|
|
||||||
int32_t eval = int32_t(st.m_curVel) * scale / 127 + add;
|
int32_t eval = int32_t(st.m_curVel) * scale / 127 + add;
|
||||||
eval = std::clamp(0, eval, 127);
|
eval = std::clamp(eval, 0, 127);
|
||||||
|
|
||||||
const Curve* curveData;
|
const Curve* curveData;
|
||||||
if (table.id != 0)
|
if (table.id != 0)
|
||||||
|
|
101
lib/Voice.cpp
101
lib/Voice.cpp
|
@ -114,8 +114,8 @@ void Voice::_doKeyOff() {
|
||||||
|
|
||||||
void Voice::_setTotalPitch(int32_t cents, bool slew) {
|
void Voice::_setTotalPitch(int32_t cents, bool slew) {
|
||||||
// fprintf(stderr, "PITCH %d %d \n", cents, slew);
|
// fprintf(stderr, "PITCH %d %d \n", cents, slew);
|
||||||
int32_t interval = std::clamp(0, cents, 12700) - m_curSample->getPitch() * 100;
|
const int32_t interval = std::clamp(cents, 0, 12700) - m_curSample->getPitch() * 100;
|
||||||
double ratio = std::exp2(interval / 1200.0) * m_dopplerRatio;
|
const double ratio = std::exp2(interval / 1200.0) * m_dopplerRatio;
|
||||||
m_sampleRate = m_curSample->m_sampleRate * ratio;
|
m_sampleRate = m_curSample->m_sampleRate * ratio;
|
||||||
m_backendVoice->setPitchRatio(ratio, slew);
|
m_backendVoice->setPitchRatio(ratio, slew);
|
||||||
}
|
}
|
||||||
|
@ -200,8 +200,8 @@ void Voice::_procSamplePre(int16_t& samp) {
|
||||||
dt = m_sampleRate * 160;
|
dt = m_sampleRate * 160;
|
||||||
if (rem != 0) {
|
if (rem != 0) {
|
||||||
/* Lerp within 160-sample block */
|
/* Lerp within 160-sample block */
|
||||||
float t = rem / 160.f;
|
const float t = rem / 160.f;
|
||||||
float l = std::clamp(0.f, m_lastLevel * (1.f - t) + m_nextLevel * t, 1.f);
|
const float l = std::clamp(m_lastLevel * (1.f - t) + m_nextLevel * t, 0.f, 1.f);
|
||||||
|
|
||||||
/* Apply total volume to sample using decibel scale */
|
/* Apply total volume to sample using decibel scale */
|
||||||
samp = ApplyVolume(m_lerpedCache.getVolume(l * m_engine.m_masterVolume, m_dlsVol), samp);
|
samp = ApplyVolume(m_lerpedCache.getVolume(l * m_engine.m_masterVolume, m_dlsVol), samp);
|
||||||
|
@ -218,12 +218,13 @@ void Voice::_procSamplePre(int16_t& samp) {
|
||||||
/* Process active envelope */
|
/* Process active envelope */
|
||||||
if (m_envelopeTime >= 0.0) {
|
if (m_envelopeTime >= 0.0) {
|
||||||
m_envelopeTime += dt;
|
m_envelopeTime += dt;
|
||||||
float start = m_envelopeStart;
|
const float start = m_envelopeStart;
|
||||||
float end = m_envelopeEnd;
|
const float end = m_envelopeEnd;
|
||||||
float t = std::clamp(0.f, float(m_envelopeTime / m_envelopeDur), 1.f);
|
float t = std::clamp(float(m_envelopeTime / m_envelopeDur), 0.f, 1.f);
|
||||||
if (m_envelopeCurve && m_envelopeCurve->data.size() >= 128)
|
if (m_envelopeCurve && m_envelopeCurve->data.size() >= 128) {
|
||||||
t = m_envelopeCurve->data[t * 127.f] / 127.f;
|
t = m_envelopeCurve->data[t * 127.f] / 127.f;
|
||||||
m_envelopeVol = std::clamp(0.f, (start * (1.0f - t)) + (end * t), 1.f);
|
}
|
||||||
|
m_envelopeVol = std::clamp((start * (1.0f - t)) + (end * t), 0.f, 1.f);
|
||||||
|
|
||||||
// printf("%d %f\n", m_vid, m_envelopeVol);
|
// printf("%d %f\n", m_vid, m_envelopeVol);
|
||||||
|
|
||||||
|
@ -280,7 +281,7 @@ void Voice::_procSamplePre(int16_t& samp) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_nextLevel = std::clamp(0.f, m_nextLevel, 1.f);
|
m_nextLevel = std::clamp(m_nextLevel, 0.f, 1.f);
|
||||||
|
|
||||||
/* Apply total volume to sample using decibel scale */
|
/* Apply total volume to sample using decibel scale */
|
||||||
samp = ApplyVolume(m_nextLevelCache.getVolume(m_nextLevel * m_engine.m_masterVolume, m_dlsVol), samp);
|
samp = ApplyVolume(m_nextLevelCache.getVolume(m_nextLevel * m_engine.m_masterVolume, m_dlsVol), samp);
|
||||||
|
@ -288,8 +289,8 @@ void Voice::_procSamplePre(int16_t& samp) {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T Voice::_procSampleMaster(double time, T samp) {
|
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;
|
const float evalVol = m_state.m_volumeSel ? (m_state.m_volumeSel.evaluate(time, *this, m_state) / 127.f) : 1.f;
|
||||||
return ApplyVolume(m_masterCache.getVolume(std::clamp(0.f, evalVol, 1.f), m_dlsVol), samp);
|
return ApplyVolume(m_masterCache.getVolume(std::clamp(evalVol, 0.f, 1.f), m_dlsVol), samp);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -297,7 +298,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;
|
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_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;
|
evalVol += m_state.m_preAuxASel ? (m_state.m_preAuxASel.evaluate(time, *this, m_state) / 127.f) : 0.f;
|
||||||
return ApplyVolume(m_auxACache.getVolume(std::clamp(0.f, evalVol, 1.f), m_dlsVol), samp);
|
return ApplyVolume(m_auxACache.getVolume(std::clamp(evalVol, 0.f, 1.f), m_dlsVol), samp);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -305,7 +306,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;
|
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_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;
|
evalVol += m_state.m_preAuxBSel ? (m_state.m_preAuxBSel.evaluate(time, *this, m_state) / 127.f) : 0.f;
|
||||||
return ApplyVolume(m_auxBCache.getVolume(std::clamp(0.f, evalVol, 1.f), m_dlsVol), samp);
|
return ApplyVolume(m_auxBCache.getVolume(std::clamp(evalVol, 0.f, 1.f), m_dlsVol), samp);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Voice::_GetBlockSampleCount(SampleFormat fmt) {
|
uint32_t Voice::_GetBlockSampleCount(SampleFormat fmt) {
|
||||||
|
@ -343,7 +344,7 @@ void Voice::preSupplyAudio(double dt) {
|
||||||
bool panDirty = false;
|
bool panDirty = false;
|
||||||
if (m_state.m_panSel) {
|
if (m_state.m_panSel) {
|
||||||
float evalPan = (m_state.m_panSel.evaluate(m_voiceTime, *this, m_state) - 64.f) / 63.f;
|
float evalPan = (m_state.m_panSel.evaluate(m_voiceTime, *this, m_state) - 64.f) / 63.f;
|
||||||
evalPan = std::clamp(-1.f, evalPan, 1.f);
|
evalPan = std::clamp(evalPan, -1.f, 1.f);
|
||||||
if (evalPan != m_curPan) {
|
if (evalPan != m_curPan) {
|
||||||
m_curPan = evalPan;
|
m_curPan = evalPan;
|
||||||
panDirty = true;
|
panDirty = true;
|
||||||
|
@ -351,7 +352,7 @@ void Voice::preSupplyAudio(double dt) {
|
||||||
}
|
}
|
||||||
if (m_state.m_spanSel) {
|
if (m_state.m_spanSel) {
|
||||||
float evalSpan = (m_state.m_spanSel.evaluate(m_voiceTime, *this, m_state) - 64.f) / 63.f;
|
float evalSpan = (m_state.m_spanSel.evaluate(m_voiceTime, *this, m_state) - 64.f) / 63.f;
|
||||||
evalSpan = std::clamp(-1.f, evalSpan, 1.f);
|
evalSpan = std::clamp(evalSpan, -1.f, 1.f);
|
||||||
if (evalSpan != m_curSpan) {
|
if (evalSpan != m_curSpan) {
|
||||||
m_curSpan = evalSpan;
|
m_curSpan = evalSpan;
|
||||||
panDirty = true;
|
panDirty = true;
|
||||||
|
@ -361,8 +362,8 @@ void Voice::preSupplyAudio(double dt) {
|
||||||
_setPan(m_curPan);
|
_setPan(m_curPan);
|
||||||
|
|
||||||
if (m_state.m_pitchWheelSel) {
|
if (m_state.m_pitchWheelSel) {
|
||||||
float evalPWheel = (m_state.m_pitchWheelSel.evaluate(m_voiceTime, *this, m_state) - 64.f) / 63.f;
|
const float evalPWheel = (m_state.m_pitchWheelSel.evaluate(m_voiceTime, *this, m_state) - 64.f) / 63.f;
|
||||||
_setPitchWheel(std::clamp(-1.f, evalPWheel, 1.f));
|
_setPitchWheel(std::clamp(evalPWheel, -1.f, 1.f));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Process active pan-sweep */
|
/* Process active pan-sweep */
|
||||||
|
@ -370,9 +371,9 @@ void Voice::preSupplyAudio(double dt) {
|
||||||
if (!m_panningQueue.empty()) {
|
if (!m_panningQueue.empty()) {
|
||||||
Panning& p = m_panningQueue.front();
|
Panning& p = m_panningQueue.front();
|
||||||
p.m_time += dt;
|
p.m_time += dt;
|
||||||
double start = (p.m_pos - 64) / 64.0;
|
const double start = (p.m_pos - 64) / 64.0;
|
||||||
double end = (p.m_pos + p.m_width - 64) / 64.0;
|
const double end = (p.m_pos + p.m_width - 64) / 64.0;
|
||||||
double t = std::clamp(0.0, p.m_time / p.m_dur, 1.0);
|
const double t = std::clamp(p.m_time / p.m_dur, 0.0, 1.0);
|
||||||
_setPan(float((start * (1.0 - t)) + (end * t)));
|
_setPan(float((start * (1.0 - t)) + (end * t)));
|
||||||
refresh = true;
|
refresh = true;
|
||||||
|
|
||||||
|
@ -385,9 +386,9 @@ void Voice::preSupplyAudio(double dt) {
|
||||||
if (!m_spanningQueue.empty()) {
|
if (!m_spanningQueue.empty()) {
|
||||||
Panning& s = m_spanningQueue.front();
|
Panning& s = m_spanningQueue.front();
|
||||||
s.m_time += dt;
|
s.m_time += dt;
|
||||||
double start = (s.m_pos - 64) / 64.0;
|
const double start = (s.m_pos - 64) / 64.0;
|
||||||
double end = (s.m_pos + s.m_width - 64) / 64.0;
|
const double end = (s.m_pos + s.m_width - 64) / 64.0;
|
||||||
double t = std::clamp(0.0, s.m_time / s.m_dur, 1.0);
|
const double t = std::clamp(s.m_time / s.m_dur, 0.0, 1.0);
|
||||||
_setSurroundPan(float((start * (1.0 - t)) + (end * t)));
|
_setSurroundPan(float((start * (1.0 - t)) + (end * t)));
|
||||||
refresh = true;
|
refresh = true;
|
||||||
|
|
||||||
|
@ -402,7 +403,7 @@ void Voice::preSupplyAudio(double dt) {
|
||||||
m_pitchDirty = false;
|
m_pitchDirty = false;
|
||||||
if (m_portamentoTime >= 0.f) {
|
if (m_portamentoTime >= 0.f) {
|
||||||
m_portamentoTime += dt;
|
m_portamentoTime += dt;
|
||||||
float t = std::clamp(0.f, m_portamentoTime / m_state.m_portamentoTime, 1.f);
|
const float t = std::clamp(m_portamentoTime / m_state.m_portamentoTime, 0.f, 1.f);
|
||||||
|
|
||||||
newPitch = (m_curPitch * (1.0f - t)) + (m_portamentoTarget * t);
|
newPitch = (m_curPitch * (1.0f - t)) + (m_portamentoTarget * t);
|
||||||
refresh = true;
|
refresh = true;
|
||||||
|
@ -849,14 +850,15 @@ void Voice::startSample(SampleId sampId, int32_t offset) {
|
||||||
m_backendVoice->resetSampleRate(m_curSample->m_sampleRate);
|
m_backendVoice->resetSampleRate(m_curSample->m_sampleRate);
|
||||||
m_needsSlew = false;
|
m_needsSlew = false;
|
||||||
|
|
||||||
int32_t numSamples = m_curSample->getNumSamples();
|
const int32_t numSamples = m_curSample->getNumSamples();
|
||||||
if (offset) {
|
if (offset) {
|
||||||
if (m_curSample->isLooped()) {
|
if (m_curSample->isLooped()) {
|
||||||
if (offset > int32_t(m_curSample->m_loopStartSample))
|
if (offset > int32_t(m_curSample->m_loopStartSample))
|
||||||
offset = ((offset - m_curSample->m_loopStartSample) % m_curSample->m_loopLengthSamples) +
|
offset = ((offset - m_curSample->m_loopStartSample) % m_curSample->m_loopLengthSamples) +
|
||||||
m_curSample->m_loopStartSample;
|
m_curSample->m_loopStartSample;
|
||||||
} else
|
} else {
|
||||||
offset = std::clamp(0, offset, numSamples);
|
offset = std::clamp(offset, 0, numSamples);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_curSamplePos = offset;
|
m_curSamplePos = offset;
|
||||||
m_prev1 = 0;
|
m_prev1 = 0;
|
||||||
|
@ -895,7 +897,7 @@ void Voice::setVolume(float vol) {
|
||||||
if (m_destroyed)
|
if (m_destroyed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_targetUserVol = std::clamp(0.f, vol, 1.f);
|
m_targetUserVol = std::clamp(vol, 0.f, 1.f);
|
||||||
for (ObjToken<Voice>& vox : m_childVoices)
|
for (ObjToken<Voice>& vox : m_childVoices)
|
||||||
vox->setVolume(vol);
|
vox->setVolume(vol);
|
||||||
}
|
}
|
||||||
|
@ -1011,12 +1013,13 @@ void Voice::_panLaw(float coefs[8], float frontPan, float backPan, float totalSp
|
||||||
}
|
}
|
||||||
|
|
||||||
void Voice::_setPan(float pan) {
|
void Voice::_setPan(float pan) {
|
||||||
if (m_destroyed || m_emitter)
|
if (m_destroyed || m_emitter) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_curPan = std::clamp(-1.f, pan, 1.f);
|
m_curPan = std::clamp(pan, -1.f, 1.f);
|
||||||
float totalPan = std::clamp(-1.f, m_curPan, 1.f);
|
const float totalPan = std::clamp(m_curPan, -1.f, 1.f);
|
||||||
float totalSpan = std::clamp(-1.f, m_curSpan, 1.f);
|
const float totalSpan = std::clamp(m_curSpan, -1.f, 1.f);
|
||||||
float coefs[8] = {};
|
float coefs[8] = {};
|
||||||
_panLaw(coefs, totalPan, totalPan, totalSpan);
|
_panLaw(coefs, totalPan, totalPan, totalSpan);
|
||||||
_setChannelCoefs(coefs);
|
_setChannelCoefs(coefs);
|
||||||
|
@ -1032,7 +1035,7 @@ void Voice::setPan(float pan) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Voice::_setSurroundPan(float span) {
|
void Voice::_setSurroundPan(float span) {
|
||||||
m_curSpan = std::clamp(-1.f, span, 1.f);
|
m_curSpan = std::clamp(span, -1.f, 1.f);
|
||||||
_setPan(m_curPan);
|
_setPan(m_curPan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1063,8 +1066,8 @@ void Voice::setChannelCoefs(const float coefs[8]) {
|
||||||
void Voice::startEnvelope(double dur, float vol, const Curve* envCurve) {
|
void Voice::startEnvelope(double dur, float vol, const Curve* envCurve) {
|
||||||
m_envelopeTime = 0.f;
|
m_envelopeTime = 0.f;
|
||||||
m_envelopeDur = dur;
|
m_envelopeDur = dur;
|
||||||
m_envelopeStart = std::clamp(0.f, m_envelopeVol, 1.f);
|
m_envelopeStart = std::clamp(m_envelopeVol, 0.f, 1.f);
|
||||||
m_envelopeEnd = std::clamp(0.f, vol, 1.f);
|
m_envelopeEnd = std::clamp(vol, 0.f, 1.f);
|
||||||
m_envelopeCurve = envCurve;
|
m_envelopeCurve = envCurve;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1072,7 +1075,7 @@ void Voice::startFadeIn(double dur, float vol, const Curve* envCurve) {
|
||||||
m_envelopeTime = 0.f;
|
m_envelopeTime = 0.f;
|
||||||
m_envelopeDur = dur;
|
m_envelopeDur = dur;
|
||||||
m_envelopeStart = 0.f;
|
m_envelopeStart = 0.f;
|
||||||
m_envelopeEnd = std::clamp(0.f, vol, 1.f);
|
m_envelopeEnd = std::clamp(vol, 0.f, 1.f);
|
||||||
m_envelopeCurve = envCurve;
|
m_envelopeCurve = envCurve;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1134,22 +1137,26 @@ void Voice::setPitchSweep2(uint8_t times, int16_t add) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Voice::setReverbVol(float rvol) {
|
void Voice::setReverbVol(float rvol) {
|
||||||
if (m_destroyed)
|
if (m_destroyed) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_curReverbVol = std::clamp(0.f, rvol, 1.f);
|
m_curReverbVol = std::clamp(rvol, 0.f, 1.f);
|
||||||
for (ObjToken<Voice>& vox : m_childVoices)
|
for (ObjToken<Voice>& vox : m_childVoices) {
|
||||||
vox->setReverbVol(rvol);
|
vox->setReverbVol(rvol);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Voice::setAuxBVol(float bvol) {
|
void Voice::setAuxBVol(float bvol) {
|
||||||
if (m_destroyed)
|
if (m_destroyed) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_curAuxBVol = std::clamp(0.f, bvol, 1.f);
|
m_curAuxBVol = std::clamp(bvol, 0.f, 1.f);
|
||||||
for (ObjToken<Voice>& vox : m_childVoices)
|
for (ObjToken<Voice>& vox : m_childVoices) {
|
||||||
vox->setAuxBVol(bvol);
|
vox->setAuxBVol(bvol);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Voice::setAdsr(ObjectId adsrId, bool dls) {
|
void Voice::setAdsr(ObjectId adsrId, bool dls) {
|
||||||
if (m_destroyed)
|
if (m_destroyed)
|
||||||
|
@ -1207,15 +1214,17 @@ void Voice::_setPitchWheel(float pitchWheel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Voice::setPitchWheel(float pitchWheel) {
|
void Voice::setPitchWheel(float pitchWheel) {
|
||||||
if (m_destroyed)
|
if (m_destroyed) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_curPitchWheel = std::clamp(-1.f, pitchWheel, 1.f);
|
m_curPitchWheel = std::clamp(pitchWheel, -1.f, 1.f);
|
||||||
_setPitchWheel(m_curPitchWheel);
|
_setPitchWheel(m_curPitchWheel);
|
||||||
|
|
||||||
for (ObjToken<Voice>& vox : m_childVoices)
|
for (ObjToken<Voice>& vox : m_childVoices) {
|
||||||
vox->setPitchWheel(pitchWheel);
|
vox->setPitchWheel(pitchWheel);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Voice::setPitchWheelRange(int8_t up, int8_t down) {
|
void Voice::setPitchWheelRange(int8_t up, int8_t down) {
|
||||||
if (m_destroyed)
|
if (m_destroyed)
|
||||||
|
|
|
@ -37,22 +37,28 @@ static const float DLSVolumeTable[] = {
|
||||||
0.892802f, 0.907744f, 0.922810f, 0.938000f, 0.953314f, 0.968752f, 0.984314f, 1.000000f, 1.000000f};
|
0.892802f, 0.907744f, 0.922810f, 0.938000f, 0.953314f, 0.968752f, 0.984314f, 1.000000f, 1.000000f};
|
||||||
|
|
||||||
float LookupVolume(float vol) {
|
float LookupVolume(float vol) {
|
||||||
vol = std::clamp(0.f, vol * 127.f, 127.f);
|
vol = std::clamp(vol * 127.f, 0.f, 127.f);
|
||||||
float f = std::floor(vol);
|
const float f = std::floor(vol);
|
||||||
float c = std::ceil(vol);
|
const float c = std::ceil(vol);
|
||||||
if (f == c)
|
|
||||||
|
if (f == c) {
|
||||||
return VolumeTable[int(f)];
|
return VolumeTable[int(f)];
|
||||||
float t = vol - f;
|
}
|
||||||
|
|
||||||
|
const float t = vol - f;
|
||||||
return (1.f - t) * VolumeTable[int(f)] + t * VolumeTable[int(c)];
|
return (1.f - t) * VolumeTable[int(f)] + t * VolumeTable[int(c)];
|
||||||
}
|
}
|
||||||
|
|
||||||
float LookupDLSVolume(float vol) {
|
float LookupDLSVolume(float vol) {
|
||||||
vol = std::clamp(0.f, vol * 127.f, 127.f);
|
vol = std::clamp(vol * 127.f, 0.f, 127.f);
|
||||||
float f = std::floor(vol);
|
const float f = std::floor(vol);
|
||||||
float c = std::ceil(vol);
|
const float c = std::ceil(vol);
|
||||||
if (f == c)
|
|
||||||
|
if (f == c) {
|
||||||
return DLSVolumeTable[int(f)];
|
return DLSVolumeTable[int(f)];
|
||||||
float t = vol - f;
|
}
|
||||||
|
|
||||||
|
const float t = vol - f;
|
||||||
return (1.f - t) * DLSVolumeTable[int(f)] + t * DLSVolumeTable[int(c)];
|
return (1.f - t) * DLSVolumeTable[int(f)] + t * DLSVolumeTable[int(c)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue