Cabbage Logo
Back to Cabbage Site

Use a-rate value in if-statement condition?

Currently writing a UDO for freezing audio for a set period of time. Figured I could check when the a-rate phasor value reaches 1 to exit an if-statement and avoid rewriting the audio buffer, but it seems like it’s not possible to use a-rate variables in if-statements?

I’m getting this error:

error: boolean expression '>=' with arg types ac not found, line 36

Any suggestions on how I could do this otherwise? I tried a k-rate phasor for the if-statement, but it doesn’t update often enough to hit 1 it seems.

You can access the vector that contains the a- values of a signal (all ksmps values which are calculated during the k-pass) with vaget opcode. Here is the manual page.
With a while ... do block, you can read each one of them and make decisions according to their value.

Thanks for the suggestion. Figured out in my case the easiest solution was to replace phasor with linseg and convert that to k-rate with k(aVar).

A typical solution to this kind of problem is to create a UDO with ksmps set to 1, then your k-rate signals are basically a-rate, and you can do your comparisons, for example…(pseudo code, untested…)

opcode k, k
aInput xin
kInput downsamp aInput
if kInput == 1 then
....