When calculating a sample block at audio rate, interesting/chaotic things may happen for input parameters that may have both audio and control rate.
So for example in a delay I am making, I get a pointer to the sample block like so
const float *delayTime = in(1);
This is the delaytime parameter of my plugin.
If I then just access it in my for loop like so:
for (int i = 0; i < nSamples; ++i) {
const float time = delayTime[i];
}
Things work as expected if i then plug an audio rate signal into this parameter in SuperCollider, but undefined behaviour occurs when using control rate input or just a literal like 0.5
. This is of course because the input buffer I have above for the input at index 1 is a full block, but when getting control rate input it only has a value in the first index (control rate = one value per block).
The question then is - how do you handle this in a nice way?
You could use the calc_FullRate enum for comparison to check the input parameter’s rate and then accordingly switch between processing a block of samples or the first sample in the block.
for (int i = 0; i < nSamples; ++i) {
const float time =
(inRate(1) == calc_FullRate) ? delayTime[i] : delayTime[0];
}
What is your preferred way of doing this?