Fix amp_veltrack
This commit is contained in:
parent
ebe5339ca3
commit
f5d61fe183
3 changed files with 9 additions and 16 deletions
|
|
@ -432,7 +432,8 @@ bool sfz::Region::parseOpcode(const Opcode& rawOpcode)
|
||||||
setValueFromOpcode(opcode, ampKeytrack, Default::ampKeytrackRange);
|
setValueFromOpcode(opcode, ampKeytrack, Default::ampKeytrackRange);
|
||||||
break;
|
break;
|
||||||
case hash("amp_veltrack"):
|
case hash("amp_veltrack"):
|
||||||
setValueFromOpcode(opcode, ampVeltrack, Default::ampVeltrackRange);
|
if (auto value = readOpcode(opcode.value, Default::ampVeltrackRange))
|
||||||
|
ampVeltrack = normalizePercents(*value);
|
||||||
break;
|
break;
|
||||||
case hash("amp_random"):
|
case hash("amp_random"):
|
||||||
setValueFromOpcode(opcode, ampRandom, Default::ampRandomRange);
|
setValueFromOpcode(opcode, ampRandom, Default::ampRandomRange);
|
||||||
|
|
@ -1517,19 +1518,8 @@ float sfz::Region::velocityCurve(float velocity) const noexcept
|
||||||
{
|
{
|
||||||
ASSERT(velocity >= 0.0f && velocity <= 1.0f);
|
ASSERT(velocity >= 0.0f && velocity <= 1.0f);
|
||||||
|
|
||||||
float gain { 1.0f };
|
float gain = std::fabs(ampVeltrack) * (1.0f - velCurve->evalNormalized(velocity));
|
||||||
if (velCurve) { // Custom velocity curve
|
gain = (ampVeltrack < 0) ? gain : (1.0f - gain);
|
||||||
return velCurve->evalNormalized(velocity);
|
|
||||||
} else { // Standard velocity curve
|
|
||||||
// FIXME: Maybe there's a prettier way to check the boundaries?
|
|
||||||
const float gaindB = [&]() {
|
|
||||||
if (ampVeltrack >= 0)
|
|
||||||
return velocity == 0.0f ? -90.0f : 40 * std::log(velocity) / std::log(10.0f);
|
|
||||||
else
|
|
||||||
return velocity == 1.0f ? -90.0f : 40 * std::log(1 - velocity) / std::log(10.0f);
|
|
||||||
}();
|
|
||||||
gain *= db2mag( gaindB * std::abs(ampVeltrack) / sfz::Default::ampVeltrackRange.getEnd());
|
|
||||||
}
|
|
||||||
|
|
||||||
return gain;
|
return gain;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -331,7 +331,7 @@ struct Region {
|
||||||
float position { normalizePercents(Default::position) }; // position
|
float position { normalizePercents(Default::position) }; // position
|
||||||
uint8_t ampKeycenter { Default::ampKeycenter }; // amp_keycenter
|
uint8_t ampKeycenter { Default::ampKeycenter }; // amp_keycenter
|
||||||
float ampKeytrack { Default::ampKeytrack }; // amp_keytrack
|
float ampKeytrack { Default::ampKeytrack }; // amp_keytrack
|
||||||
float ampVeltrack { Default::ampVeltrack }; // amp_keytrack
|
float ampVeltrack { normalizePercents(Default::ampVeltrack) }; // amp_keytrack
|
||||||
std::vector<std::pair<uint8_t, float>> velocityPoints; // amp_velcurve_N
|
std::vector<std::pair<uint8_t, float>> velocityPoints; // amp_velcurve_N
|
||||||
absl::optional<Curve> velCurve {};
|
absl::optional<Curve> velCurve {};
|
||||||
float ampRandom { Default::ampRandom }; // amp_random
|
float ampRandom { Default::ampRandom }; // amp_random
|
||||||
|
|
|
||||||
|
|
@ -568,7 +568,10 @@ void sfz::Synth::finalizeSfzLoad()
|
||||||
|
|
||||||
if (!region->velocityPoints.empty())
|
if (!region->velocityPoints.empty())
|
||||||
region->velCurve = Curve::buildFromVelcurvePoints(
|
region->velCurve = Curve::buildFromVelcurvePoints(
|
||||||
region->velocityPoints, Curve::Interpolator::Linear, region->ampVeltrack < 0.0f);
|
region->velocityPoints, Curve::Interpolator::Linear);
|
||||||
|
else
|
||||||
|
region->velCurve = resources.curves.getCurve(4);
|
||||||
|
|
||||||
region->registerPitchWheel(0);
|
region->registerPitchWheel(0);
|
||||||
region->registerAftertouch(0);
|
region->registerAftertouch(0);
|
||||||
region->registerTempo(2.0f);
|
region->registerTempo(2.0f);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue