Hello, I’m experimenting with plugin development and I want to add two signals (say from two lfos). When I add the first to the second, the overall voltage rises. This is normal, I know, but what is a good strategy to average the two (of three or four) signals? Is is as simple as

` (input_1.getVoltage() + input_2.getVoltage() + ... + input_x.getVoltage() ) / x (the number of mixed signals there are)?`

Or are there more sophisticated strategies? Thank you

2 Likes

For just two signals it could be useful to add a control for a mix parameter, lets call it “t”, and then do

`input_1.getVoltage()*(1-t) + input_2.getVoltage()*t`

Hi @tprotopgr! Welcome to the forum and best wishes on your upcoming development.

Here’s a bit from the VCV Fundamentals Unity module, which has a switchable average mode. It uses the method you’re describing in context, along with a few bells and whistles (like checking how many signals are connected).

Note that it has two buses with six inputs each (hence the constants in the two loops).

``````for (int i = 0; i < 2; i++) {
// Inputs
for (int j = 0; j < 6; j++) {
mix[i] += inputs[IN_INPUTS + 6 * i + j].getVoltage();
if (inputs[IN_INPUTS + 6 * i + j].isConnected())
count[i]++;
}
}

``````

Then, if the Average parameter is turned on for each bus, simply divide the relevant mix by the count:

``````for (int i = 0; i < 2; i++) {
// Params
if (count[i] > 0 && (int) std::round(params[AVG1_PARAM + i].getValue()) == 1)
mix[i] /= count[i];

// ...
}
``````

You may well know this already, but in my own development I’ve found it very helpful that so much of the Rack library is open-source. Seriously–a goofy amount, including some of the very best modules Rack has to offer!

5 Likes