Faust - if/else condition multiplies the input by 6
-
Here is a basic Faust question guys.
When I add ba.if, the input goes to 6 inputs, I can't understand why. What do I need to do to have stereo in - stereo out? I would be glad if you can help me.
The purpose here is to add separate filters and waveshapers to the positive and negative parts of the sound.
import("stdfaust.lib"); drive = vslider("Drive [style:knob]", 0.5, 0.01, 1, 0.01); cutoff_pos = hslider("Cutoff Frequency (Positive) [Hz]", 1000, 20, 20000, 1); gain_pos = hslider("Gain (Positive) [dB]", 0, -24, 24, 0.1); q_pos = hslider("Q (Positive)", 0.7, 0.1, 10.0, 0.01); cutoff_neg = hslider("Cutoff Frequency (Negative) [Hz]", 500, 20, 20000, 1); gain_neg = hslider("Gain (Negative) [dB]", 0, -24, 24, 0.1); q_neg = hslider("Q (Negative)", 0.7, 0.1, 10.0, 0.01); // Distortion shaper function shaper_pos(drive, x) = ma.tanh(10 * drive * x); shaper_neg(drive, x) = 2.0 * ma.tanh(2.0 * drive * x); // Apply different fi.svf.bell filters based on the sign of the input out(x, cutoff_pos, q_pos, gain_pos, cutoff_neg, q_neg, gain_neg, drive) = ba.if(x >= 0, // If the input x is positive: fi.svf.bell(cutoff_pos, q_pos, gain_pos) : shaper_pos(drive), // Use positive bell filter fi.svf.bell(cutoff_neg, q_neg, gain_neg) : shaper_neg(drive)); // Else, use negative bell filter // Process for stereo output process = out(_, cutoff_pos, q_pos, gain_pos, cutoff_neg, q_neg, gain_neg, drive), out(_, cutoff_pos, q_pos, gain_pos, cutoff_neg, q_neg, gain_neg, drive);
-
You want the same
x
signal to go inside the cond computation (thex >= 0
) and the "then", and "else " branches right ? Then use the split<:
operator like:// Apply different fi.svf.bell filters based on the sign of the input out(x, cutoff_pos, q_pos, gain_pos, cutoff_neg, q_neg, gain_neg, drive) = x <: (ba.if(x >= 0, // If the input x is positive: x : fi.svf.bell(cutoff_pos, q_pos, gain_pos) : shaper_pos(drive), // Use positive bell filter x : fi.svf.bell(cutoff_neg, q_neg, gain_neg) : shaper_neg(drive))); // Else, use negative bell filter
-
@sletz Interesting! Thank you.