Merge pull request #713 from jpcima/linear-smoother-fix

Linear smoother fix
This commit is contained in:
JP Cimalando 2021-03-18 14:02:45 +01:00 committed by GitHub
commit 44e48f7003
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,7 +9,10 @@
#include "MathHelpers.h"
#include "SfzHelpers.h"
#include "SIMDHelpers.h"
#include <simde/simde-features.h>
#if SIMDE_NATURAL_VECTOR_SIZE_GE(128)
#include <simde/x86/sse.h>
#endif
namespace sfz {
@ -96,13 +99,14 @@ void LinearSmoother::process(absl::Span<const float> input, absl::Span<float> ou
// int32_t framesToTarget = framesToTarget_;
const int32_t smoothFrames = smoothFrames_;
#if SIMDE_NATURAL_VECTOR_SIZE_GE(128)
for (; i + 15 < count; i += 16) {
const float nextTarget = input[i + 15];
if (target != nextTarget) {
target = nextTarget;
//framesToTarget = (framesToTarget > 0) ? framesToTarget : smoothFrames;
//step = (target - current) / max(1, framesToTarget);
step = (target - current) / max(1, smoothFrames);
//step = (target - current) / (16 * max(1, framesToTarget));
step = (target - current) / (16 * max(1, smoothFrames));
}
const simde__m128 targetX4 = simde_mm_set1_ps(target);
if (target > current) {
@ -143,14 +147,40 @@ void LinearSmoother::process(absl::Span<const float> input, absl::Span<float> ou
}
//framesToTarget -= 16;
}
#else
for (; i + 15 < count; i += 16) {
const float nextTarget = input[i + 15];
if (target != nextTarget) {
target = nextTarget;
//framesToTarget = (framesToTarget > 0) ? framesToTarget : smoothFrames;
//step = (target - current) / (16 * max(1, framesToTarget));
step = (target - current) / (16 * max(1, smoothFrames));
}
if (target > current) {
for (size_t j = 0; j < 16; ++j)
output[i + j] = current = min(target, current + step);
}
else if (target < current) {
for (size_t j = 0; j < 16; ++j)
output[i + j] = current = max(target, current + step);
}
else {
for (size_t j = 0; j < 16; ++j)
output[i + j] = target;
}
//framesToTarget -= 16;
}
#endif
if (i < count) {
const float nextTarget = input[count - 1];
if (target != nextTarget) {
target = nextTarget;
// framesToTarget = (framesToTarget > 0) ? framesToTarget : smoothFrames;
// step = (target - current) / max(1, framesToTarget);
step = (target - current) / max(1, smoothFrames);
// step = (target - current) / ((count - i) * max(1, framesToTarget));
step = (target - current) / ((count - i) * max(1, smoothFrames));
}
if (target > current) {
for (; i < count; ++i)