VarLag behaviour 180° out of phase from Lag

Hi,

considering VarLag:

(
{ 
	var pulse = LFPulse.ar(5).range(300,1000); 
	[ 
	pulse,
	Lag.ar(    pulse, lagTime:1/10),
	VarLag.ar( pulse, time:1/10, curvature:-5) 
	] 
}.plot(2)
)

Why is the VarLag plot half a cycle ‘late’? I would be most grateful if someone would explain this?

Also:

(
{ 
	var pulse = LFPulse.ar(1/4).range(300,1000); 
	[ 
	pulse,
	Lag.ar(    pulse, lagTime:1),
	VarLag.ar( pulse, time:1, curvature:-5) 
	] 
}.plot(30)
)

produces a ‘gap’ after 2.5 cycles, but it returns to the signal 180% out of phase from Lag.ar one.

VarLag.ar is not reliable.

VarLag uses EnvGen to produce the (curved) line segments.

EnvGen’s inputs are kr only.

If an audio-rate input is jumping to another level in the middle of a control block, EnvGen will read it late. How that translates to an inverted signal, I don’t have time to analyze right now – but, if you change all the .ar to .kr, then the signals are in phase.

TL;DR - don’t use VarLag.ar.

FWIW: http://doc.sccode.org/Classes/VarLag.html - “WARNING: VarLag.ar currently accepts audio-rate input, but the underlying implementation treats the input as control rate. Effectively, then, the “sampling rate” of VarLag’s input is ControlRate.ir or server.sampleRate / server.options.blockSize, and the maximum safe frequency to feed into VarLag is half of this. VarLag does not currently yield correct results for full-bandwidth audio-rate signals. Use VarLag.ar at your own risk.”

hjh

1 Like

I remember what it is now.

EnvGen’s gate input is audio rate, but the envelope parameters are control rate.

When the VarLag input changes in the middle of a control block, the gate trigger is processed immediately, but using the value from the beginning of the control cycle (the old input). The new input will be available at the start of the next control cycle – but there is no trigger at that time, so the new value won’t be handled until the next trigger – but then, the “new” value has become the old value. So the curve is late.

hjh

1 Like

thank you for the explanation. conceptually/functionally VarLag seems like a great UGen, but it’s too bad that it is not implemented in the way that it would be consistent and reliable.

What do you want to achieve? There is also DemandEnvGen.