From 5baec48c28360e186afa41efe56e59517b9ce4c6 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 3 Oct 2024 08:26:11 +0200 Subject: [PATCH] two wavefolding algorithms --- clip/wavefolder.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/clip/wavefolder.h b/clip/wavefolder.h index 40201ea..90b579c 100644 --- a/clip/wavefolder.h +++ b/clip/wavefolder.h @@ -11,7 +11,23 @@ public: } private: + // folds the wave from -1 to 1 float fold(float _sample) + { + while (_sample > 1.0 || _sample < -1.0) { + + if (_sample > 1.0) { + _sample = 2.0 - _sample; + } else if (_sample < -1.0) { + _sample = -2.0 - _sample; + } + } + + return _sample; + } + + // folds the positive part of the wave independently from the negative part. + float fold_bipolar(float _sample) { // fold positive values if (_sample > 1.0) {