HISE Logo Forum
    • Categories
    • Register
    • Login

    Move scripted algorithm to a third party C++ lib

    Scheduled Pinned Locked Moved C++ Development
    7 Posts 3 Posters 959 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.
    • ustkU
      ustk
      last edited by ustk

      I am currently computing a cross correlation algorithm of 2 buffers using Hise script. This algorithm is very slow by nature, and running it in Hise script is probably killing the overall effectiveness, especially since the computational hunger is exponentially related to the data length to be correlated.

      My idea is to write a simple C++ library of this algorithm to accelerate the computation time, and to which I pass two buffers and get the result back (with a check on the task advancement in between).
      But I have no idea how to integrate it so it can be called from the script.

      So what are the basics of linking a third party library to Hise script?

      I checked the doc but it seems more related to audio modules/DSP, or I just don't have the real basics and need a level up

      Or maybe I should explore the C++ node side, since I could use setExternalData to pass the 2 buffers to correlate, and include my external library to this node (or just write the algorithm in this very node)?

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

      1 Reply Last reply Reply Quote 1
      • Dan KorneffD
        Dan Korneff
        last edited by

        following as I'm looking to convert by existing SNEX nodes

        Dan Korneff - Producer / Mixer / Audio Nerd

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

          following as I'm looking to convert by existing SNEX nodes

          You don't need to convert them - just slap them in the ThirdParty C++ folder, any SNEX code is valid C++ code.

          Now the other question is a bit more complicated: I would suggest to use a ScriptFX and bypass it (so that it won't process the actual audio signal, then create a DSP network that holds your custom node and call its process method manually for offline processing:

          // Remember when we had to call this everytime, lol, but now we actually need a script reference to the network...
          const var dsp = Engine.createDspNetwork("dsp");
          
          // I'm just adding a sine wave oscillator here (you would have to pass in `project.my_compiled_node` instead).
          const var osc = dsp.createAndAdd("core.oscillator", "osc", "dsp");
          
          // now we'll prepare the offline processing
          dsp.prepareToPlay(44100.0, 512);
          
          // create a multichannel buffer with 512 elements. 
          const var b = [Buffer.create(512), Buffer.create(512)];
          
          // fill the buffers with the sine wave (in a real world use case you would have to process the bigger buffer in chunks).
          dsp.processBlock(b);
          
          Dan KorneffD ustkU 2 Replies Last reply Reply Quote 2
          • Dan KorneffD
            Dan Korneff @Christoph Hart
            last edited by

            @Christoph-Hart pimp.gif

            Dan Korneff - Producer / Mixer / Audio Nerd

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

              @Christoph-Hart Although I am trying to make a very basic C++ class, I am facing an Undefined symbol error when I try to include a header file + cpp.
              It's like it doesn't see the function definition but only its declaration in the class.
              It works if I don't use a cpp file and put only the function definition in the header without a function declaration.

              classTest.h

              class BestDspEver
              {
              public:
                      float noChange(float input);
              };
              

              classTest.cpp

              #include "classTest.h"
              
              float BestDspEver::noChange(float input)
              {
                      return input;
              }
              

              C++ node

              #include <JuceHeader.h>
              #include "src/classTest.h"
              
              // Create DSP object
              BestDspEver dspObject;
              
              // Scriptnode Callbacks ------------------------------------------------------------------------
              	
              float applyDsp(float s)
              {
              	return dspObject.noChange(s);
              }
              
              template <typename T> void processFrame(T& data)
              {
              	for(auto& s: data)
              		s = applyDsp(s);
              }
              

              XCode stays silent about providing any solution...
              Screenshot 2023-07-04 at 15.27.35.png

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

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

                @ustk welcome to C++. Your .cpp file is probably not added to the Xcode project as translation unit (which is C++ gibberish for something that will be compiled).

                Why do you need to split it into .cpp and .h? If you want to keep the implementation organised like this, you need to use a header file which includes the two files.

                // Content of class_test_wrapper.h
                #pragma once
                
                #include "class_test.h"
                #include "class_test.cpp"
                
                namespace project
                {
                //...
                }
                
                ustkU 1 Reply Last reply Reply Quote 1
                • ustkU
                  ustk @Christoph Hart
                  last edited by ustk

                  @Christoph-Hart said in Move scripted algorithm to a third party C++ lib:

                  @ustk welcome to C++. Your .cpp file is probably not added to the Xcode project as translation unit (which is C++ gibberish for something that will be compiled).

                  I have seen that xcode might miss the file on StackOverflow but wasn't sure if it was my case and even less the how to :)

                  Why do you need to split it into .cpp and .h? If you want to keep the implementation organised like this, you need to use a header file which includes the two files.

                  For 2 reasons actually, my own experience, and be able to link existing libraries without too much modifications

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

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

                  11

                  Online

                  1.8k

                  Users

                  11.9k

                  Topics

                  103.8k

                  Posts