Hi!

I'm currently trying to create a waveshaper using different functions according to its input signal and I'm stuck at what would be the best approach doing so using Faust.

Here is the concept:

If the signal is x=s(t), the waveshaper is F(x) where:
F(x) = log10(x)+1 when x > e/10
F(x) = 10x/(e*log(10)) when x >= e/10 and x >=- e/10
F(x) = -log10(-x)-1 when x < -e/10

Here is a quick and incomplete sketch for further discussions:
import("stdfaust.lib");
UpperSignal = _ : log10 : _+1 : _ ;  // when x  >  e/10
LinearSignal = _ : _*1.59768011306 : _ ; // when x >= e/10 and x >=- e/10
LowerSignal = _ : _*-1 : log10 : _*-1 : _-1 : _ ; //when x  < - e/10
UpperThreshold = 0.27182818284 ; // e/10
LowerThreshold = -0.27182818284 ; // -e/10
process = _ <: UpperSignal,LinearSignal,LowerSignal:>_;

The attached picture is a visual representation where the dashed orange lines are thresholds, red sections of the curve are UpperSignal and LowerSignal and the black section of the curve is LinearSignal.

This is an example of a commonly used method for waveshaping where you use different functions according to the input signal.

Here are two interesting articles using this method with various degrees of complexity: - https://medium.com/@jatinchowdhury18/complex-nonlinearities-episode-1-double-soft-clipper-5ce826fa82d6
- https://www.ampbooks.com/mobile/dsp/preamp/

In a non functional language, I would have used a classic if/then/else but, as specified in the faust manual: "WARNING: since select2 is strict (always evaluating both branches), the resulting if does not have the usual "lazy" semantic of the C if form, and thus cannot be used to protect against forbidden computations like division-by-zero for instance."

Ideally,  only one of the three functions should be computed by correctly routing the input signal (using ! or another mean).

What would be the Faustian way to do so?

Best regards,
Yoann


_______________________________________________
Faudiostream-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/faudiostream-users

Reply via email to