Crossfade between Buffers with BufRd Vosc style

The math here is not that complicated – but every time I have to reproduce it, I make every possible mistake, and the next time I have to do it, I make every possible mistake again… anyway this works.

s.boot;

b = Buffer.allocConsecutive(8, s, 2048, 1, { |buf, i|
	buf.sine1Msg((1 .. ((i+1) * 10)).reciprocal, asWavetable: false)
});

(
a = { |freq = 440, firstbuf|
	var mod = SinOsc.kr(0.1).range(0, 7);
	var evenIndex = min(7.999, mod.round(2));
	var oddIndex = mod.trunc(2) + 1;
	var phase = Phasor.ar(0, freq * SampleDur.ir, 0, 1) * BufFrames.ir(firstbuf);
	var sig = BufRd.ar(1, firstbuf + [evenIndex, oddIndex], phase);
	// LinXFade because I made the buffers to be phase correlated
	// if they are not correlated, use XFade2
	sig = LinXFade2.ar(sig[0], sig[1], mod.fold(0, 1) * 2 - 1);
	(sig * 0.1).dup
}.play(args: [freq: 100, firstbuf: b.first]);
)

(fold(0, 1) always confuses me – at first I wrote fold(0, 2), but this has a cycle of 4. fold(0, 1) has the desired cycle of 2.)

hjh

2 Likes