Latch.ar with reset

I’m working on a looper UGen which uses Latch.ar to set a loop point:

loopPoint = Latch.ar(recPointer, \startLoop.tr);

But what if I wanted to reset the loopPoint to zero? It would have been nice with a reset input to the latch UGen that resets the output to zero upon receiving a trigger.

You can just overlay a second trigger, which sets the latch input to zero during triggering. Something like

reset = \reset.tr;
loopPoint = Latch.ar(recPointer * (1 - reset), \startLoop.tr | reset);

should work. Or

latchPos = Select.ar(reset, [ recPointer, DC.ar(0) ]);
loopPoint = Latch.ar(latchPos, \startLoop.tr | reset);
1 Like

Thanks a lot! I can get this one to work:

latchPos = Select.ar(reset, [ recPointer, DC.ar(0) ]);
loopPoint = Latch.ar(latchPos, \startLoop.tr | reset);

but this one doesn’t:

reset = \reset.tr;
loopPoint = Latch.ar(recPointer * (1 - reset), \startLoop.tr | reset);

But I made it work by converting reset to audio rate:

reset = \reset.tr;
loopPoint = Latch.ar(recPointer * (1 - T2A.ar(reset)), \startLoop.tr | reset);

This is my test code:

(
Ndef(\looper, {
	var reset, loopPoint, recPointer;
	recPointer = Phasor.ar(end: 44100);
	reset = \reset.tr;
	loopPoint = Latch.ar(recPointer * (1 - T2A.ar(reset)), \startLoop.tr | reset).poll;
});
)

Ndef(\looper).set(\startLoop, 1);
Ndef(\looper).set(\reset, 1);

The reason why this one fails, I think, is because of interpolation in the * operator.

Audio-rate recPointer is multiplied by control-rate 1 - reset. The kr operand needs to be promoted to ar, which I believe is done by making a linear ramp over the duration of the control block. So the first value of 1 - reset, when reset rises to 1, would be 63/64, assuming default settings – certainly not the 0 required to suppress the recPointer.

I’d go one step further: 1 - reset is not exactly a valid way to invert a trigger. It is a valid way to negate the result of a signal comparison operator, because that result is guaranteed to be 0 or 1. But a trigger is not guaranteed to be only exactly 0 or 1, so you can’t apply the same logic to triggers.

I’d write reset <= 0 instead.

But that alone won’t solve the problem because the interpolation is in the subsequent * operator. T2A is valid to deal with that. I had thought there might be some alternative but on second thought, nope, that’s the droid you’re looking for.

hjh

1 Like

Thanks for the explanation. It makes sense to use reset <= 0 instead to support any type of trigger signal.