One thing is, asInteger
should not be needed for Boolean expressions on UGens. If it is needed, it’s a sign that something is wrong. In your earlier example, you might have needed asInteger
to handle the true
or false
value being returned from ==
. But true
and false
are meaningless in the server – the server really does not know what to do with these. So if you are getting these in context of a SynthDef, this is a hint that ==
is the wrong operator.
If a
or b
is a UGen, then a (some boolean) b
should be a BinaryOpUGen, and the server-side result of this will be either 0.0 or 1.0. Applying asInteger
to either of these values is a no op = unneeded.
Also, I’m puzzled by sig
. LFDNoise3.kr(...).range(1, 10)
must be positive, but then you apply unipolar
to avoid negative values, on a signal that cannot possibly be negative. Latch.kr(sig, 1)
– is it really supposed to hold one value for the entire duration?
Oh, and if you do val / next power of two, then the values would be between 0.5 and 1.0, not 1.0 and 2.0. So let’s do floor
instead.
TBH I think you might be overcomplicating it.
var sig = LFDNoise3.ar(1).range(1, 10);
var lower2Pow = 2 ** floor(log2(sig));
Poll.ar(5, [sig, sig / lower2Pow]);
This will, AFAIK, guarantee values 1.0 <= x < 2.0. E.g., a couple of results from my test run:
UGen(MulAdd): 3.91262
UGen(BinaryOpUGen): 1.95631
UGen(MulAdd): 4.02559
UGen(BinaryOpUGen): 1.0064 <<-- oh! crossed an octave, ratio dropped
The |==| 0
logic is unnecessary because, e.g., log2(2.0) == 1.0 and floor(1.0) == 1.0, so there is no need to force it by Select at all. Unnecessary components = more chances for confusion and bugs.
hjh