qiemem / eurorack

Firmware customization for Mutable Instruments' Eurorack Modules.
93 stars 16 forks source link

Add unipolar mode for rise & fall slew #32

Closed w-winter closed 3 years ago

w-winter commented 3 years ago

Since polarity switching hasn't been doing anything for the rise & fall slew segment type, and since effective envelope following requires full-wave rectification of the signal, this proposes moving the existing behavior of the R&F slew into its bipolar mode and introducing to its unipolar mode output rectification that makes it more optimal for EF applications. This way, you can still negatively track negative input voltages if you switch into the bipolar mode.

I've tried applying the fabsf at value_ = primary.Next() but this causes the segment to freeze its output at a high voltage when fed a bipolar square wave and when fall time is lower than 25% height. (Switching to other segment types resets the output, but when returning to R&F slew, the output remains stuck somewhere near 8V.) Also, if this is where the rectification happens, we still allow negative voltage on the output (depending on your rise & fall times) which is weird for a unipolar mode.

What I've found is that, if your slew limiter can output negative voltages (like this one can), the following patches produce the same behavior (that is optimal for tracking the amplitude of a varying-amplitude bipolar audio-rate signal, without getting ripples in your EF output):

(a) audio signal => full-wave rectifier => slew limiter (b) audio signal => slew limiter => full-wave rectifier

And I've found that when fabsf is applied at the output when in unipolar (as proposed here), I get similar behavior to doing the (a) patch with a full-wave rectifier and a WMD/SSF Mini Slew. I also can't get it to freeze up, nor to output 0V when rise & fall times are equal and a bipolar square wave is fed into Time. (And obviously with this approach you don't get unexpected negative output from a unipolar mode.)

So I'd say the unipolar mode of R&F slew could be sold as an effective envelope follower, while the bipolar could be presented as a polarity-flexible R&F slew.

qiemem commented 3 years ago

Thanks for the PR! This looks like a great addition.

This PR also uncovered a bug which I've just pushed the fix for. The freezing you describe (I assume that's not just it staying high when the square wave is going) and the fact that you were seeing negative voltage out indicated a bug in the current implementation. The segments output should stay strictly within the limits of the input, so applying an abs to the input should make it impossible for the segment to go negative. This wasn't happening because I wasn't inferring the slider value correctly. I've changed it to just use the slider value directly, which is what I should've been doing in the first place. Sorry about that!

Anyway, all that is to say that applying the fabsf to the input should now work as expected, and I confirmed as such. I also do get somewhat better results with it, in that, e.g., bipolar squares don't have any dips (except right around the switch), and striking Rings repeatedly, I could get away with a lower fall time.

w-winter commented 3 years ago

Got it! fabsf works great on the input now.