trowaSoft-VCV icon indicating copy to clipboard operation
trowaSoft-VCV copied to clipboard

Easy patch to drastically reduce CPU overhead of trigSeq(64) and and voldSeq

Open Stubs42 opened this issue 3 years ago • 0 comments

Hi,

did a patch in my sandbox to reduce the cpu overhead of your sequencers when running on external clock. This was neccessary for me because I like trigSeq64 very much but with more than 10% CPU usage it rendered no longer usable for my patches. With the performance patch I implemented, trigSeq64 now uses less than 1 % CPU without running in any issue yet.

The code changes are Module_trigSeq.cpp and Module_voltSeq.cpp in their process() method:

. . .
if (!initialized)
        return;

// adapt the lightLambda used to calculate step light fading
// because the process is executed completely only every 32nd time
if (inputs[EXT_CLOCK_INPUT].isConnected())
        lightLambda = 0.05 / IDLESKIP;
else
        lightLambda = 0.05;
 idleCnt = (idleCnt + 1) % IDLESKIP;
 double newExtTrg = inputs[EXT_CLOCK_INPUT].getVoltage();
 // return if not each 32th sample, ext clk is connected and the trigger input did not change
 if (idleCnt != 0 && inputs[EXT_CLOCK_INPUT].isConnected() && newExtTrg == extTrg) {
        return; // return if idle to reduce cpu time
}
// save old ext trigger input state to detect change
extTrg = newExtTrg;

bool gOn = true;
bool pulse = false;
. . .

and in TSSequencerModuleBase.hpp:

. . .
// If this was loaded from a save, what version
int saveVersion = -1;
// removed conts to allow changing depending on ext clk connect state
float lightLambda = 0.05;
// The number of structured random patterns to actually use. 
// Should be <= TROWA_SEQ_NUM_RANDOM_PATTERNS.
int numStructuredRandomPatterns = TROWA_SEQ_BOOLEAN_NUM_RANDOM_PATTERNS;

// defines and global variables used by my hack 
#define IDLESKIP 32
int idleCnt = -1;
double extTrg = 0;

//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
. . .

See also https://community.vcvrack.com/t/trowasoft-trigseq-and-voltseq-performance/13082

Would be great if you would include this patch in your code line or implement a similar patch.

Regards Dieter

Stubs42 avatar Apr 19 '21 16:04 Stubs42