HISE Logo Forum
    • Categories
    • Register
    • Login

    Apply a waveshaper function

    Scheduled Pinned Locked Moved General Questions
    4 Posts 4 Posters 254 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.
    • dannytaurusD
      dannytaurus
      last edited by dannytaurus

      I have a fairly simple waveshaper function, something like this:

      left = in1
      right = in2
      curve = in3 * some formula
      
      out1 = curve * left
      out2 = curve * right
      

      There's a bit more to it than that but not much. It just takes L and R inputs and a control parameter then performs a function on each input and sends them to the outputs.

      What's the easiest way to implement this?

      Meat Beats: https://meatbeats.com
      Klippr Video: https://klippr.video

      A orangeO Christoph HartC 3 Replies Last reply Reply Quote 0
      • A
        aaronventure @dannytaurus
        last edited by

        @dannytaurus Scriptnode

        Do you have 3 input channels? What is in3?

        1 Reply Last reply Reply Quote 0
        • orangeO
          orange @dannytaurus
          last edited by orange

          @dannytaurus If you do not have a very complex algorithm, you do not have to process separately for left and right in SNEX.

          • Insert a snex_shaper node
          • Create a new file and name it "MyNode"
          • Add a parameter - this will be the Drive knob
          • Paste the code below
          template <int NumVoices> struct MyNode
          {
          	SNEX_NODE(MyNode);
          	
          	// Parameters
          	float Drive = 0.0f;
          	
          	float getSample(float input)
          	{	
          	 	input = Math.tanh(10.0f * Drive * input);	
          		return input;		
              }
          	
          	
          	// These functions are the glue code that call the function above
          	template <typename T> void process(T& data)
          	{
          		for(auto ch: data)
          		{
          			for(auto& s: data.toChannelData(ch))
          			{
          				s = getSample(s);
          			}
          		}
          	}
          	template <typename T> void processFrame(T& data)
          	{
          		for(auto& s: data)
          			s = getSample(s);
          	}
          	void reset()
          	{
          		
          	}
          	void prepare(PrepareSpecs ps)
          	{
          		
          	}
          	
          	void setExternalData(const ExternalData& d, int index)
          	{
          	}
          	template <int P> void setParameter(double v)
          	{
          		if (P == 0) Drive = (float)v;
          	}
          };
          
          

          As you can see, the waveshaper function is:

          out = tanh(10 * Drive * in)

          In SNEX, we can write it like this:

          input = Math.tanh(10.0f * Drive * input);	
          return input;
          

          develop Branch / XCode 13.1
          macOS Monterey / M1 Max

          1 Reply Last reply Reply Quote 2
          • Christoph HartC
            Christoph Hart @dannytaurus
            last edited by

            There's a bit more to it than that but not much. It just takes L and R inputs and a control parameter then performs a function on each input and sends them to the outputs.

            If you're using a stateless function with a single parameter, you are exactly within the bounds of the math.expr node which does exactly this (not more and not less).

            Link Preview Image
            HISE | Docs

            favicon

            (docs.hise.dev)

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

            13

            Online

            1.7k

            Users

            11.9k

            Topics

            103.3k

            Posts