Move the crossfade curve config to the config

This commit is contained in:
Paul Ferrand 2020-10-06 09:21:49 +02:00 committed by Jean Pierre Cimalando
parent cab43b6641
commit 24624abef1
2 changed files with 11 additions and 13 deletions

View file

@ -126,6 +126,10 @@ namespace config {
@brief Ratio to target under which smoothing is considered as completed @brief Ratio to target under which smoothing is considered as completed
*/ */
static constexpr float smoothingShortcutThreshold = 5e-3; static constexpr float smoothingShortcutThreshold = 5e-3;
// loop crossfade settings
static constexpr int loopXfadeCurve = 2; // 0: linear
// 1: use curves 5 & 6
// 2: use S-shaped curve
} // namespace config } // namespace config
} // namespace sfz } // namespace sfz

View file

@ -588,8 +588,7 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
partitionStarts = absl::MakeSpan(const_cast<int*>(starts), 1); partitionStarts = absl::MakeSpan(const_cast<int*>(starts), 1);
partitionTypes = absl::MakeSpan(const_cast<int*>(types), 1); partitionTypes = absl::MakeSpan(const_cast<int*>(types), 1);
numPartitions = 1; numPartitions = 1;
} } else {
else {
for (auto& buf : partitionBuffers) { for (auto& buf : partitionBuffers) {
buf = resources.bufferPool.getIndexBuffer(numSamples); buf = resources.bufferPool.getIndexBuffer(numSamples);
if (!buf) if (!buf)
@ -601,11 +600,6 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
// computed along with index processing below // computed along with index processing below
} }
// loop crossfade settings
constexpr int loopXfadeUseCurves = 2; // 0: linear
// 1: use curves 5 & 6
// 2: use S-shaped curve
// index preprocessing for loops // index preprocessing for loops
if (isLooping) { if (isLooping) {
int oldIndex {}; int oldIndex {};
@ -699,17 +693,17 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
{ {
// compute out curve // compute out curve
absl::Span<float> xfCurve = xfTemp2->first(ptSize); absl::Span<float> xfCurve = xfTemp2->first(ptSize);
IF_CONSTEXPR (loopXfadeUseCurves == 2) { IF_CONSTEXPR (config::loopXfadeCurve == 2) {
const Curve& xfIn = getSCurve(); const Curve& xfIn = getSCurve();
for (unsigned i = 0; i < ptSize; ++i) for (unsigned i = 0; i < ptSize; ++i)
xfCurve[i] = xfIn.evalNormalized(1.0f - xfCurvePos[i]); xfCurve[i] = xfIn.evalNormalized(1.0f - xfCurvePos[i]);
} }
else IF_CONSTEXPR (loopXfadeUseCurves == 1) { else IF_CONSTEXPR (config::loopXfadeCurve == 1) {
const Curve& xfOut = resources.curves.getCurve(6); const Curve& xfOut = resources.curves.getCurve(6);
for (unsigned i = 0; i < ptSize; ++i) for (unsigned i = 0; i < ptSize; ++i)
xfCurve[i] = xfOut.evalNormalized(xfCurvePos[i]); xfCurve[i] = xfOut.evalNormalized(xfCurvePos[i]);
} }
else IF_CONSTEXPR (loopXfadeUseCurves == 0) { else IF_CONSTEXPR (config::loopXfadeCurve == 0) {
// TODO(jpc) vectorize this // TODO(jpc) vectorize this
for (unsigned i = 0; i < ptSize; ++i) for (unsigned i = 0; i < ptSize; ++i)
xfCurve[i] = clamp(1.0f - xfCurvePos[i], 0.0f, 1.0f); xfCurve[i] = clamp(1.0f - xfCurvePos[i], 0.0f, 1.0f);
@ -749,17 +743,17 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
// compute in curve // compute in curve
absl::Span<float> xfCurve = xfTemp2->first(applySize); absl::Span<float> xfCurve = xfTemp2->first(applySize);
IF_CONSTEXPR (loopXfadeUseCurves == 2) { IF_CONSTEXPR (config::loopXfadeCurve == 2) {
const Curve& xfIn = getSCurve(); const Curve& xfIn = getSCurve();
for (unsigned i = 0; i < applySize; ++i) for (unsigned i = 0; i < applySize; ++i)
xfCurve[i] = xfIn.evalNormalized(xfInCurvePos[i]); xfCurve[i] = xfIn.evalNormalized(xfInCurvePos[i]);
} }
else IF_CONSTEXPR (loopXfadeUseCurves == 1) { else IF_CONSTEXPR (config::loopXfadeCurve == 1) {
const Curve& xfIn = resources.curves.getCurve(5); const Curve& xfIn = resources.curves.getCurve(5);
for (unsigned i = 0; i < applySize; ++i) for (unsigned i = 0; i < applySize; ++i)
xfCurve[i] = xfIn.evalNormalized(xfInCurvePos[i]); xfCurve[i] = xfIn.evalNormalized(xfInCurvePos[i]);
} }
else IF_CONSTEXPR (loopXfadeUseCurves == 0) { else IF_CONSTEXPR (config::loopXfadeCurve == 0) {
// TODO(jpc) vectorize this // TODO(jpc) vectorize this
for (unsigned i = 0; i < applySize; ++i) for (unsigned i = 0; i < applySize; ++i)
xfCurve[i] = clamp(xfInCurvePos[i], 0.0f, 1.0f); xfCurve[i] = clamp(xfInCurvePos[i], 0.0f, 1.0f);