HISE Logo Forum
    • Categories
    • Register
    • Login

    Faust - if/else condition multiplies the input by 6

    Scheduled Pinned Locked Moved General Questions
    3 Posts 2 Posters 194 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JulesVJ
      JulesV
      last edited by

      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);
       
      

      Screen Shot 2024-10-07 at 19.13.14.png

      1 Reply Last reply Reply Quote 0
      • S
        sletz
        last edited by

        You want the same x signal to go inside the cond computation (the x >= 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
        
        JulesVJ 1 Reply Last reply Reply Quote 1
        • JulesVJ
          JulesV @sletz
          last edited by

          @sletz Interesting! Thank you.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          11

          Online

          1.8k

          Users

          11.9k

          Topics

          103.8k

          Posts