HISE Logo Forum
    • Categories
    • Register
    • Login

    For You: Hard Saturation in ScriptNode

    Scheduled Pinned Locked Moved Presets / Scripts / Ideas
    1 Posts 1 Posters 439 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.
    • CasmatC
      Casmat
      last edited by Casmat

      Hey!

      To express my gratitude, I'm making this post along with another soft saturation post to share my saturation! All the original dsp was based off of:

      https://www.hackaudio.com/digital-signal-processing/distortion-effects/hard-clipping/
      (Site seems to be ridden with popups and ads now so I'll put the main dsp below)

      out = thresh, when in > thresh

      out = -thresh, when in < -thresh

      out = in, otherwise

      To create the saturation, add the snex_shaper node in scriptnode to your project, press the three dots -> Create new file. Name it and then add a parameter the same way and name it something like thresh. Then open the code editor from the snex node

      Here's the fun stuff:

      template <int NumVoices> struct snex_hardsat
      {
      	SNEX_NODE(snex_hardsat);
      	
      	// Implement the Waveshaper here...
      	float thresh = 0.0f;
      	float out = 0.0f;
      	
      	float getSample(float input)
      	{
      		if(input > thresh)
      		{
      			out = thresh;
      		}
      		else if(input < thresh*-1.0f)
      		{
      			out = thresh * -1.0f;
      		}
      		else
      		{
      			out = input;
      		}
      		return out;
      	}
      	// 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)
      		{
      			thresh = (float)v;
      		}
      	}
      };
      

      What I recommend is just downloading snex_hardsat.zip and then in your project folder -> DspNetworks -> CodeLibrary -> snex_shaper (create one if not there) and place the .h and .xml files in there.. they should show up in the dropdown in the snex shaper all ready to go.

      There you go! Feel free to use it however you want and enjoy!

      Note: this isn't going to give you the full saturation, just the waveshaping (hard part). You still would need to wrap the shaper node in an oversampling node as well as having filters, gain staging, xfaders, etc to make a release ready saturation, shouldn't be too hard to do however since they're all nodes in scriptnode

      Thanks!

      i make music

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

      45

      Online

      1.7k

      Users

      11.7k

      Topics

      101.8k

      Posts