Cabbage Logo
Back to Cabbage Site

Confused about efficient calculation

I’m trying to understand when I need to worry about efficiency in doing calculations and when it is already handled by Cabbage/Csound.

As an example, I have a slider that is ultimately used to send a k-signal to several instruments. The slider takes values from 0-1. I use cabbageGetValue to read it into csound. I then transform that value and apply a portamento to smooth when the slider moves. Finally, that signal is sent to the Csound bus using chnset. Several instruments then use chnget to learn the value.

Do I need to worry about the unneeded recalculation of the transformation and the smoothing when the slider value doesn’t change? It seems silly to keep recalculating the same number and assessing if it needs to be smoothed. But maybe that’s handled in csound?

Is a bus the right way to handle sending a control signal across instruments? I noticed that RAM use went up when I switched to this approach, which surprised me. If anything, I thought system demands were going to decrease since I shifted from doing the transformation/portamento globally instead of for each instrument instance.

EDIT - I might have misinterpreted the RAM use. After restarting Cabbage things are back to where I expected.

Thank you!

It’s certainly one way to do it. It’s also the approach I would take. I am not sure if it’s more performant than global vars though. I’d say the difference is negligible.

Thanks. It initially seemed slow, but that was my misinterpretation of RAM use.

Any thoughts about my first question? Is it ok to always have that cabbageGetValue/transform/portk step running, even when the cabbage value doesn’t change? I’m not doing any cabbageSet steps, just updating k-rate variables.

I don’t think it makes a difference as there is no memory allocation being done.

1 Like

Great! I was worried I was going to have to go through and optimize in a bunch of places.

I’m trying to eliminate any bottlenecks for processing and memory. And I don’t know enough about how the inner workings work.

1 Like