HISE Logo Forum
    • Categories
    • Register
    • Login

    template or tutorial for custom c++ scriptnode?

    Scheduled Pinned Locked Moved ScriptNode
    38 Posts 8 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.
    • MorphoiceM
      Morphoice @HISEnberg
      last edited by

      @HISEnberg not fast enough. 90% is trial and error and me not understanding a thing I do lol

      https://instagram.com/morphoice - 80s inspired Synthwave Music, Arcade & Gameboy homebrew!

      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @Morphoice
        last edited by

        @Morphoice said in template or tutorial for custom c++ scriptnode?:

        not fast enough

        You're plenty fast!

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        MorphoiceM 1 Reply Last reply Reply Quote 1
        • MorphoiceM
          Morphoice @d.healey
          last edited by Morphoice

          @HISEnberg @d-healey actually tried implementing the μ-law compression thing from what I could learn around the web, but it's failing to compile and I cant get a debug version setup on mac as @griffinboy's tutorial only covers PC so far ;) So now I'm stuck lol. But yeah, the problem should be minor and some day I'll find out ;)

                              float val = samples[i];
                                
                              // mu-law compress signal
                              float max = 255;
                              float valmu  = sgn(val) * log(1+max*abs(val)) / log(1+max);
                              
                              // Quantize to 8 bits
                              float valmu8 = valmu - fmodf(valmu,1/max);
                              
                              // mu-law expand signal
                              float valex = sgn(valmu8) * (1/max) * (pow(max+1,abs(valmu8))-1);
                              
                              // Apply Demo Gain
                              samples[i] = valex * smoothGain.advance();
          

          I basically know too litte about c++ to know if the syntax in these formulas is even valid but I tried ;)

          https://instagram.com/morphoice - 80s inspired Synthwave Music, Arcade & Gameboy homebrew!

          d.healeyD 1 Reply Last reply Reply Quote 0
          • d.healeyD
            d.healey @Morphoice
            last edited by

            @Morphoice said in template or tutorial for custom c++ scriptnode?:

            but I tried

            Some of us try for years, don't give up after 2 hours :)

            Libre Wave - Freedom respecting instruments and effects
            My Patreon - HISE tutorials
            YouTube Channel - Public HISE tutorials

            MorphoiceM 1 Reply Last reply Reply Quote 0
            • MorphoiceM
              Morphoice @d.healey
              last edited by

              @d-healey thanks to your encouraging words it just came to me that actually I just needed to implement the sgn (sign) function as C++ doesn't seem to have one by default

                  template <typename T> int sgn(T val) {
                      return (T(0) < val) - (val < T(0));
                  }
              

              (yeah that one I copied off the internet lol)

              and then it suddenly worked. I can't believe it! I have just made a μ-law bitcrusher without even so much as knowing what I do lol. God this thing sounds fly. Massively less artifacts on quieter sounds and sizzle on loud ones!

              https://instagram.com/morphoice - 80s inspired Synthwave Music, Arcade & Gameboy homebrew!

              Christoph HartC 1 Reply Last reply Reply Quote 0
              • Christoph HartC
                Christoph Hart @Morphoice
                last edited by

                @Morphoice use hmath::sign() :)

                MorphoiceM 1 Reply Last reply Reply Quote 1
                • MorphoiceM
                  Morphoice @Christoph Hart
                  last edited by Morphoice

                  @Christoph-Hart that would have been to easy ;))
                  In all honesty, I seriously need to learn C++, the things one can do...

                  https://instagram.com/morphoice - 80s inspired Synthwave Music, Arcade & Gameboy homebrew!

                  ustkU 1 Reply Last reply Reply Quote 0
                  • ustkU
                    ustk @Morphoice
                    last edited by ustk

                    @Morphoice everything should work in your code once you:

                    • use the real math functions as Chris suggested
                    • respect the variable types. SNEX is very picky about this which is a good thing, but the errors messages are sometimes not helpful (you get the cast issue at the right line for expressions, but not in variable definitions). In your case, when a var type is float, EVERYTHING needs to be float in the expression. (1.0f)

                    Another suggestion in SNEX, is that you should try to compile for each single line you add to your code, this is especially true at beginning. Because debugging multiple lines you added will be a nightmare as the console writes everything on the same line (remember the Hise Hang ☺)
                    This reminds me to have a look at least to fix this issue...
                    So write a new line -> compile, and if it fails you know where you are 😉

                    Can't help pressing F5 in the forum...

                    MorphoiceM 1 Reply Last reply Reply Quote 0
                    • MorphoiceM
                      Morphoice @ustk
                      last edited by

                      @ustk aye! I did this in C++ not SNEX though. But I agree it looks more correct this way, although it didn't throw a tantrum without. C++ seems to be a bit forgiving there, which is not at all what I heard about it lol

                      float val = samples[i];
                      int max = 255;
                      float valmu  = sgn(val) * log( 1.0f + max * abs(val) ) / log( 1.0f + max);
                      float valmu8 = valmu - fmodf(valmu, 1.0f / max);
                      float valex = sgn(valmu8) * (1.0f / max) * ( pow(max + 1.0f, abs(valmu8)) - 1.0f );                   
                      

                      https://instagram.com/morphoice - 80s inspired Synthwave Music, Arcade & Gameboy homebrew!

                      MorphoiceM 1 Reply Last reply Reply Quote 1
                      • MorphoiceM
                        Morphoice @Morphoice
                        last edited by

                        @Christoph-Hart is there a way to get the custom c++ scriptnode to only process data if there is any sound? as this is intended for one-shots but constantly does the encoding/decoding and a couple of those nodes produce quite a fair amount of cpu

                        https://instagram.com/morphoice - 80s inspired Synthwave Music, Arcade & Gameboy homebrew!

                        ustkU griffinboyG 2 Replies Last reply Reply Quote 0
                        • ustkU
                          ustk @Morphoice
                          last edited by ustk

                          @Morphoice I can think of two ways:

                          • either build a detector that is waiting for a certain value to pass a threshold, then if it does, do your stuff
                          • tell the node a signal is coming with a modulated parameter, which will move the detection part to the graph

                          Can't help pressing F5 in the forum...

                          MorphoiceM 1 Reply Last reply Reply Quote 1
                          • MorphoiceM
                            Morphoice @ustk
                            last edited by

                            @ustk are all nodes generally on? I've read about a hasTail parameter that stops processing when the note is done etc. probably in my case it needs to work only a few ms after a note was fired

                            https://instagram.com/morphoice - 80s inspired Synthwave Music, Arcade & Gameboy homebrew!

                            ustkU 1 Reply Last reply Reply Quote 0
                            • ustkU
                              ustk @Morphoice
                              last edited by

                              @Morphoice I reckon hasTail is for the case where DAWs cut the plugin processing between the clips to save CPU on big projects. hastTail allows your plugin to still read the buffers until a minimum threshold has been reached before effectively cutting the sound (i.e. for reverbs, etc...)

                              If your node is optimised, you shouldn't need to bypass it. If the heavy processing is done then you can just do nothing in the process callback to save CPU using just one branching (if statement)

                              I don't know how your system is built, but if your sound is triggered with MIDI you can use midi events in C++ node with handleHiseEvent, but if it's just reacting to audio then...

                              Can't help pressing F5 in the forum...

                              MorphoiceM 1 Reply Last reply Reply Quote 1
                              • MorphoiceM
                                Morphoice @ustk
                                last edited by

                                @ustk don't VST3 plugins in general only waste cpu when they detect the presence of an audio signal?

                                https://instagram.com/morphoice - 80s inspired Synthwave Music, Arcade & Gameboy homebrew!

                                Christoph HartC 1 Reply Last reply Reply Quote 0
                                • Christoph HartC
                                  Christoph Hart @Morphoice
                                  last edited by

                                  @Morphoice might be true but you can‘t rely on every host to implement this, also there are other plugin formats which you need to factor in.

                                  S 1 Reply Last reply Reply Quote 1
                                  • S
                                    sletz @Christoph Hart
                                    last edited by sletz

                                    In the meantime, written in Faust: https://faustlibraries.grame.fr/libs/basics/#bamulaw_bitcrusher
                                    and the code here https://github.com/grame-cncm/faustlibraries/blob/a222717339e5f528787080e5e5438ffef8da22a9/basics.lib#L2429 and https://github.com/grame-cncm/faustlibraries/blob/a222717339e5f528787080e5e5438ffef8da22a9/basics.lib#L2371

                                    1 Reply Last reply Reply Quote 1
                                    • griffinboyG
                                      griffinboy @Morphoice
                                      last edited by griffinboy

                                      @Morphoice

                                      Yes there are a few ways. The best is probably to use the built in flags at the top of the c++ node. But you can do custom detection too, which I sometimes use if I need specific behaviour.

                                      You'll probably want to optimise the nodes in the first place, I see you've got all the random example scripts (smooth gain ect) that aren't super necessary for your use case. I can give you a more simple template if you want one.

                                      I intend to go back and cover this c++ node stuff better and in more detail but I'm short on time currently. I will be releasing a proper template in the future, with a lightweight library to go along with it, containing efficient approximations of math functions (rather useful for your bitcrusher script), automatic lookuptable creation, and hopefully some tools for SIMD.

                                      And yes - you are progressing really quickly! I get the feeling that you are going to do really well. I don't think I'll have a plugin released until at least two years time 🤦 Too much perfectionism

                                      MorphoiceM 1 Reply Last reply Reply Quote 1
                                      • MorphoiceM
                                        Morphoice @griffinboy
                                        last edited by

                                        @griffinboy thanks man! a simpler template would be awesome, I also figured It would make sense to do the calculations only if samples[i] isnt zero, that should take most of the load in my case.

                                        https://instagram.com/morphoice - 80s inspired Synthwave Music, Arcade & Gameboy homebrew!

                                        griffinboyG 2 Replies Last reply Reply Quote 0
                                        • griffinboyG
                                          griffinboy @Morphoice
                                          last edited by

                                          @Morphoice

                                          Yep that makes sense, since you don't need to process the zero crossings for your effect.

                                          Link Preview Image
                                          C++ Node Templates – Google Drive

                                          favicon

                                          Google Drive (drive.google.com)

                                          Here's a more up to date version of the template. You'll have to wait until I've got time, for me to release the official version of this, which will have many more improvements

                                          1 Reply Last reply Reply Quote 0
                                          • griffinboyG
                                            griffinboy @Morphoice
                                            last edited by

                                            @Morphoice Did a small fix there was an error in the template

                                            Link Preview Image
                                            C++ Node Templates – Google Drive

                                            favicon

                                            Google Drive (drive.google.com)

                                            MorphoiceM LindonL 3 Replies Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            12

                                            Online

                                            1.7k

                                            Users

                                            11.9k

                                            Topics

                                            103.3k

                                            Posts