Strange TWChoose.ar behavior

Hi all, I’m getting some odd behavior with TWChoose. The weights array is [0,1], so I think I should hear only noise. But, I’m hearing occasional fragments of a sine tone. Oddly, if I swap Dust for Impulse, it seems to work as expected. I’m on SC 3.11.0, macOS 10.14.6. Is this a bug, or am I doing something wrong?

Eli

(
{
	TWChoose.ar(
		Dust.ar(20),
		[
			SinOsc.ar(200),
			PinkNoise.ar(1)
		],
		[0,1]
) * 0.1!2;
}.play
)
1 Like

There is a bug in TWIndex (which is used in TWChoose), which I only just noticed: a variable sum should be initialized to 0 once per trigger, but it’s initialized only once per control block. If there happens to be more than one trigger in a control block, the 2nd, 3rd etc triggers will go to index 0.

I think I can put in a fix later today.

The other potential issue is: if the random number generator produces exactly 0, then it would also go to the first index. But that should be exceedingly rare and almost unreproducible.

hjh

BTW this reproduces the bug:

a = {
	var trig = Impulse.ar(ControlRate.ir * 4),
	index = TWindex.ar(trig, [0, 1]);
	Poll.ar(trig * (index <= 0), index, "failed");
	Line.ar(0, 1, ControlDur.ir, doneAction: 2);
	Silent.ar(1)
}.play;

failed: 0
failed: 0
failed: 0

4 triggers should be generated. The second, third and fourth in the kr block calculate incorrectly.

hjh

Unfortunately, build requirements have become more complex lately, so it will take me some time to update my environment. So it’s definitely not going to happen today.

hjh