b = Buffer.read(s, "/home/lcoogan/snd/samples/scarlett/textural_nightmare.wav");

c = Buffer.read(s, "/home/lcoogan/snd/live/2025-04-26.Basic_City_Brewery/granular/Cantorial/Cantor_Samuel_Malavsky_Zechor.wav");
b.free;

(
SynthDef(\pvVocalPlay, {
    arg bufnum, fftSize = 1024, amp = 1;
    var in, chain, out;
	var shiftLFO;

    // LFOs
    var brickLFO = SinOsc.kr(0.1).range(0.02, 0.2);      // slowly shift the BrickWall limit
    var smearLFO = LFNoise1.kr(0.3).range(5, 20);        // jittery smear amount
    var randRate = LFNoise1.kr(0.2).range(2, 12);        // random impulse rate

    in = PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum), loop: 0, doneAction: 2);
    chain = FFT(LocalBuf(fftSize), in);

    // Modulated PV processing
	// chain = PV_BrickWall(chain, 0.05);
	chain = PV_MagFreeze(chain);
	chain = PV_RandComb(chain, 0.1, Impulse.kr(randRate));
	chain = PV_MagSmear(chain, smearLFO);
	chain = PV_SpectralEnhance(chain, 1, 1, 0.1);
	chain = PV_BinScramble(chain, 0.5 0.8, 0);
    // Uncomment to experiment
/*	shiftLFO = SinOsc.kr(0.0005).range(0.5, 2.0);
	chain = PV_BinShift(chain, shiftLFO, 1);*/

    out = IFFT(chain);
    Out.ar(0, out ! 2 * amp);
}).add;
)

x = Synth(\pvVocalPlay, [\bufnum, c]);


(
Pbind(
    \instrument, \pvVocalPlay,
    \bufnum, c,  // assuming you've preloaded your buffer
    \dur, 5,     // repeat every 5 seconds
    \fftSize, Pseq([1024, 2048, 512], inf),  // modulate fftSize across events
	// \amp, 4;
	).play;
)


(
// Create a multidimensional modulation map
~modMap = Array.fill([4, 4], { |i, j|
    Pulse.kr(1 * (i + 1) * (j + 1)).range(0.01, 0.9)
});
)
