Skip to content

Commit

Permalink
refactor: make Autopan RampedSample constexpr, fix cmath abs
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiftb0y committed Sep 23, 2024
1 parent b49184d commit 40c2240
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/effects/backends/builtin/autopaneffect.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <QMap>
#include <cmath>

#include "effects/backends/effectprocessor.h"
#include "engine/filters/enginefilterpansingle.h"
Expand All @@ -13,27 +14,25 @@
// somewhere else (I hear clicks when I change the period of flanger for example).
class RampedSample {
public:
inline RampedSample()
constexpr RampedSample()
: ramped(false),
maxDifference(1.0f),
currentValue(0),
initialized(false) {
}

virtual ~RampedSample(){};

inline void setRampingThreshold(const float newMaxDifference) {
constexpr void setRampingThreshold(float newMaxDifference) {
maxDifference = newMaxDifference;
}

inline void setWithRampingApplied(const float newValue) {
constexpr void setWithRampingApplied(float newValue) {
if (!initialized) {
currentValue = newValue;
initialized = true;
} else {
float difference = newValue - currentValue;
if (fabs(difference) > maxDifference) {
currentValue += difference / fabs(difference) * maxDifference;
if (abs(difference) > maxDifference) {
currentValue += difference / abs(difference) * maxDifference;
ramped = true;
} else {
currentValue = newValue;
Expand All @@ -42,7 +41,7 @@ class RampedSample {
}
}

inline operator float() {
constexpr operator float() {
return currentValue;
}

Expand Down

0 comments on commit 40c2240

Please sign in to comment.