PV_Freeze modulate phase

Hey, i would like to modulate the phases of the spectra after and only when it has been frozen for some movement.
Right now its modulating not depending on the freeze state. What should i do? thanks.

(
SynthDef(\freeze_spectra, {
	arg out=0, pan=0, amp=0.5, buf=0;
    var sig, in, chain, winsize=1024;

    in = PlayBuf.ar(1, buf, BufRateScale.kr(buf), loop: 1);
    chain = FFT(LocalBuf(winsize), in);
	chain = PV_Freeze(chain, MouseY.kr > 0.5);

	chain = chain.pvcollect(winsize, {
		arg mag, phase, index;
		var pmod;
		pmod = LFNoise1.kr(rrand(0.5,1.1));
		[mag, pmod.range(-pi,pi)]
	},
	frombin:0, tobin:250, zeroothers:1);

	sig = IFFT(chain).dup;

	//sig = TPV.ar(chain, winsize, winsize/2, 50, 20, 1, 4, 0.1);

	sig = Pan2.ar(sig, pan, amp);
    Out.ar(out, sig);
}).add;
)

If you want pvcollect to follow the freeze condition, then that will have to be worked into the loop body. Because it’s in a SynthDef, you can’t do if(MouseY.kr > 0.5) { pmod.range(-pi, pi) } { phase } – for language-side functions, it has to choose one or the other branch at SynthDef compilation time.

So you need a UGen expression that will pass the original phase through if the condition is false, and modulate the phase if it’s true.

This seems to do it. For testing, I put in a second condition (to be sure there’s a difference between normal PV_Freeze and the pvcollect). You can remove that.

(
SynthDef(\freeze_spectra, {
	arg out=0, pan=0, amp=0.5, buf=0;
	var sig, in, chain, winsize=1024;

	// the condition will be used in hundreds of places now
	// so be sure to calculate it only once!
	var freeze = MouseY.kr > 0.5;
	// used this for testing
	var modOn = MouseY.kr > 0.75;
	
	in = PlayBuf.ar(1, buf, BufRateScale.kr(buf), loop: 1);
	chain = FFT(LocalBuf(winsize), in);
	chain = PV_Freeze(chain, freeze);
	
	chain = chain.pvcollect(winsize, {
		arg mag, phase, index;
		var pmod;
		pmod = LFNoise1.kr(rrand(0.5, 1.1)).range(-pi, pi);
		// freeze instead of modOn here, for the final version I guess
		[mag, (pmod - phase) * /*freeze*/ modOn + phase]
	},
	frombin: 0, tobin: 250, zeroothers: 1);

	// you will Pan2 in a moment so no need to dup here
	sig = IFFT(chain) /*.dup*/;

	//sig = TPV.ar(chain, winsize, winsize/2, 50, 20, 1, 4, 0.1);

	sig = Pan2.ar(sig, pan, amp);
	Out.ar(out, sig);
}).add;
)

hjh

thanks @jamshark70 its working fine