Skip to content

Commit

Permalink
Negative feedback does the squaring thing (#70)
Browse files Browse the repository at this point in the history
just like surge

Closes #68
  • Loading branch information
baconpaul authored Jan 3, 2025
1 parent 0973135 commit 3d687d7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/dsp/op_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define BACONPAUL_SIX_SINES_DSP_OP_SOURCE_H

#include <cstdint>
#include <cmath>

#include "configuration.h"

Expand Down Expand Up @@ -178,6 +179,13 @@ struct alignas(16) OpSource : public EnvelopeSupport<Patch::SourceNode>,

phase += dPhase;
auto fb = 0.5 * (fbVal[0] + fbVal[1]);
auto sb = std::signbit(feedbackLevel[i]);
// fb = sb ? fb * fb : fb. Ugh a branch. but bool = 0/1, so
// (1-sb) * fb + sb * fb * fb - 3 mul, 2 add
// fb - sb * fb + sb * fb * fb - 3 nul 2 add
// fb * ( 1 - sb * ( 1 - fb)) - 2 mul 2 add
fb = fb * (1 - sb * (1 - fb));

auto ph = phase + phaseInput[i] + (int32_t)(feedbackLevel[i] * fb);
auto out = st.at(ph);

Expand Down
2 changes: 1 addition & 1 deletion src/synth/patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ struct Patch
static constexpr uint32_t idBase{10000}, idStride{100};
SelfNode(size_t idx)
: fbLevel(floatMd()
.asPercent()
.asPercentBipolar()
.withName(name(idx) + " Level")
.withGroupName(name(idx))
.withDefault(0.0)
Expand Down

0 comments on commit 3d687d7

Please sign in to comment.