HISE Logo Forum
    • Categories
    • Register
    • Login

    Create Simple Saturation Effect

    Scheduled Pinned Locked Moved Solved ScriptNode
    10 Posts 4 Posters 1.2k 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

      Hey!

      I was wondering how you could make a saturation effect in scriptnode, I noticed the that math operators can be used, but how do I use these operators to change the sound?

      Thanks!

      1 Reply Last reply Reply Quote 1
      • S
        Soundavid
        last edited by

        The best way to do it I think is with the SNEX shaper node, there are some articles in the Forum with a few examples.

        CasmatC 1 Reply Last reply Reply Quote 0
        • CasmatC
          Casmat @Soundavid
          last edited by

          @Soundavid I found this:
          https://www.musicdsp.org/en/latest/Effects/42-soft-saturation.html

          x < a:
            f(x) = x
          x > a:
            f(x) = a + (x-a)/(1+((x-a)/(1-a))^2)
          x > 1:
            f(x) = (a+1)/2
          

          There’s some dsp code on that and I was wondering if that could be used for Snex, or if there’s any conversion needed what the final result would look like.. I also noticed that there’s a math.expr node and was wondering if that’d be easier for this task.

          Thanks!

          CasmatC DanHD 2 Replies Last reply Reply Quote 0
          • CasmatC
            Casmat @Casmat
            last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • CasmatC Casmat has marked this topic as solved on
            • DanHD
              DanH @Casmat
              last edited by

              @Casmat Need to get my head around this a bit more! Did you get a good saturation effect in the end?

              DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
              https://dhplugins.com/ | https://dcbreaks.com/
              London, UK

              CasmatC 1 Reply Last reply Reply Quote 0
              • CasmatC
                Casmat @DanH
                last edited by Casmat

                @DanH Yup! It’s still hard for me to understand it completely but I can piece together the dsp better now after trying to convert existing waveshaping models out there:

                For my hard saturation I used the basic algo in this site:
                https://www.hackaudio.com/digital-signal-processing/distortion-effects/hard-clipping/

                It’s not the most detailed but it’ll get the job done.

                On the other hand my soft sat I just used musicdsp code which in my usecase sounded better than some other algorithms i found on the internet. I just ported that over to snex in the shaper node and it sounds amazing!

                Check the forum for a new post in 15-20 minutes, I'll post some goodies! 😊

                Edit: Just posted!
                https://forum.hise.audio/topic/8958/for-you-hard-saturation-in-scriptnode/1
                https://forum.hise.audio/topic/8959/for-you-soft-saturation-in-scriptnode/1

                LindonL DanHD 2 Replies Last reply Reply Quote 1
                • LindonL
                  Lindon @Casmat
                  last edited by

                  @Casmat the alternative is to use a Faust node... lots of saturation, distortion and clipping options there...:

                  Link Preview Image
                  misceffects - Faust Libraries

                  favicon

                  (faustlibraries.grame.fr)

                  HISE Development for hire.
                  www.channelrobot.com

                  DanHD 1 Reply Last reply Reply Quote 0
                  • DanHD
                    DanH @Lindon
                    last edited by

                    @Lindon Indeed, nice to be a bit more malleable though!

                    DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                    https://dhplugins.com/ | https://dcbreaks.com/
                    London, UK

                    1 Reply Last reply Reply Quote 0
                    • DanHD
                      DanH @Casmat
                      last edited by

                      @Casmat Very kind, thank you! How do you figure out how to convert the equations into snex code?

                      DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                      https://dhplugins.com/ | https://dcbreaks.com/
                      London, UK

                      CasmatC 1 Reply Last reply Reply Quote 0
                      • CasmatC
                        Casmat @DanH
                        last edited by

                        @DanH Lets take a look at soft sat for example, the musicdsp dsp was this:

                        x < a:
                          f(x) = x
                        x > a:
                          f(x) = a + (x-a)/(1+((x-a)/(1-a))^2)
                        x > 1:
                          f(x) = (a+1)/2
                        

                        There is also a note that is important to consider that is also posted by the author of the dsp above:

                        This only works for positive values of x. a should be in the range 0..1

                        We'll use that later

                        Now after creating a snexshaper file and creating the amount parameter (with range 0-1 as said in note) and in the snex code editor of the shaper, you'll see that there's already a base template that is provided. This template basically takes care of most of the stuff you'd need.

                        In the dsp, there's three values x, a, and f(x). Now a is commonly used as a variable for gain, and x is input while f(x) or y is the output. Next I initialized two variables gain for a and out for f(x). We don't need an input variable since there's a input parameter in the template that we can use. I created a separate method saturate(input) to separate things out to fix the problem mentioned in the dsp note. From there, you can see the code in the saturate method is exactly the same as the dsp but the dsp variables swapped out plus the return statement at the end.

                        Next in the getSample(input) method that was provided in the template, I made an if statement to solve the problem in the dsp note where only a positive value worked for the input, which wouldn't result in complete waveshaping. If the input was greater than 0, then saturate using the input, otherwise make the input negative and run it through the saturate function and then reverse the output to affect negative values as well.

                        Everything is set except the parameter linking. To link the parameter, I looked up on the forum for some snex shaper problems and someone had a video and I used the code they used. I don't know why it's not included in template but its the same for everything, create an if statement and if P (parameter?) is equal to 0 (index position of parameter), then link it!

                        That's pretty much it, the hard sat is the same but without the needing to make sure negative values of input are factored in

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

                        15

                        Online

                        1.7k

                        Users

                        11.8k

                        Topics

                        103.0k

                        Posts