VCVRack / Fundamental

https://vcvrack.com/Fundamental
Other
235 stars 76 forks source link

Optimise VCO by only processing connected waves #123

Closed rleathart closed 3 years ago

rleathart commented 3 years ago

I've changed the VCO modules to only compute wave types that are actually connected.

Currently VoltageControlledOscillator::process() computes the samples for each wave type regardless of what is connected. We can save a non-trivial amount of CPU time by only processing the connected wave types. This is especially relevant for patches that use many oscillators.

I'm just passing a new parameter to VoltageControlledOscillator::process() that enables or disables the processing for wave types based on the WaveIds enum flags. This is set in VCO::process() based on which outputs are connected. I'd have liked to use enum WaveIds for the type of enabledWaves rather than int but C++ seems to make using enums as flags more difficult than C.

I've also changed the VCO and VCO2 process methods to return immediately if there are no outputs connected since I can't see any reason for this to not be the case?

I don't have any rigorous performance numbers but making these changes resulted in a patch of ~35 oscillators that was previously CPU clipping really badly become playable.

AndrewBelt commented 3 years ago

Since Fundamental will be packaged with VCV Rack for DAWs, I cannot accept contributions to this project. See https://github.com/VCVRack/Rack/blob/v1/.github/CONTRIBUTING.md I will make this more clear by adding a link to the README.