Move scripted algorithm to a third party C++ lib
-
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)? -
following as I'm looking to convert by existing SNEX nodes
-
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);
-
-
@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...
-
@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 { //... }
-
@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