DXMix Crossfade BufRd

Hey, im using one cycle waveforms from AKWF FREE (waveform samples) : Adventure Kid loaded into Buffers, played back via BufRd and was trying to use FM inspired by Frequency Modulation – Phase Modulation – Delay Modulation (FM / PM / DM).

I want to crossfade/morph between two different waveforms while the pattern is playing and was trying to use DXMix. Its working i guess but i get some artefacts from time to time. Is this the right way to do it, with two BufRd.ar and two Sweep.ar? At first I thought that probably the waveforms are not accurate in terms of zero crossings, so i was testing with two buffers filled with sineFill, and also with LeakDC and equalPower, 0, But the artefacts are still there.

I was also using a single BufRd with \bufindex, Pwhite(11,13,inf), without DXMix which is not exactly the behaviour Im trying to achieve. But i get no artefacts then, so it has something to do with the crossfading.

(
u = Signal.sineFill(512, [1]);
~b1 = Buffer.loadCollection(s, u, 1);
~b2 = Buffer.loadCollection(s, u, 1);
)

(
SynthDef(\test, {
	arg out=0, pan=0, freq=150, sndBuf1=0, sndBuf2=0, amp=0.2;

	var gainEnv = \gainEnv.kr(Env.newClear(8).asArray);

    var sig, pos1, pos2, playbuf;
	var mod = \mod.kr(1.5);
	var index = \index.kr(0.5);
	var dev = mod * index;
	var bufFrames1 = BufFrames.kr(sndBuf1);
	var bufFrames2 = BufFrames.kr(sndBuf2);

	pos1 = Sweep.ar(0, SinOsc.ar(mod, 0, dev, freq) * bufFrames1 * BufRateScale.ir(sndBuf1)).mod(bufFrames1);
	pos2 = Sweep.ar(0, SinOsc.ar(mod, 0, dev, freq) * bufFrames2 * BufRateScale.ir(sndBuf2)).mod(bufFrames2);

	//crossfading between buffers
    playbuf = DXMix.ar(
        Dseq([0, 1], inf),
        `[
            BufRd.ar(1, sndBuf1, pos1, interpolation:4),
            BufRd.ar(1, sndBuf2, pos2, interpolation:4)
        ],
        fadeTime: Dwhite(0.01, 0.20),
        stepTime: 0.15,
        fadeMode: 2,
		equalPower: 0,
    );

	//amp envelope
	gainEnv = EnvGen.kr(gainEnv, doneAction:2);
	sig = playbuf * gainEnv;

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

(
Pdef(\test,
	Pbind(
		\type, \hasEnv,
		\instrument, \test,
		
		\sndBuf1, ~b1,
		\sndBuf2, ~b2,
/*
		\bufIndex1, 9,
		\bufIndex2, 11,

		\sndBuf1, Pfunc{|event|
			~samples[\AKWF_sinharm][event[\bufIndex1]]
		},

		\sndBuf2, Pfunc{|event|
			~samples[\AKWF_sinharm][event[\bufIndex2]]
		},
*/
		//FM Synthese
		\mod, 1.5,
		\index, -0.53,

		\dur, 0.5 * Pseg( Pseq([1, 5],inf), Pseq([4, 1],inf), \linear),

		\degree, Pstutter(1, Pseq([
				Pseq([[0,3,5,7]], 1),
				0 + Prand([[0,1,2]], 1),
				-1 + Prand([[0,1,2]], 1),
				Prand([[-1,0,2]], 1),
				Prand([[0,2,3,6]], 1)
		], inf)),

		\scale, Scale.minor(\just),
		\root, 0,
		\octave, Prand([[3,4,5,6]],inf),

		\legato, 0.8,
		\atk, 0.01,
		\sus, (1 - Pkey(\atk)) * Pexprand(0.35,0.50,inf),

		\gainEnv, Pfunc{|e|
			var rel = (1 - e.atk - e.sus);
			var c1 = exprand(2,6);
			var c2 = exprand(-2,-6);
			Env([0,1,1,0],[e.atk, e.sus, rel],[c1,0,c2])
		},

		\amp, 0.45,
		\finish, ~utils[\hasEnv],
	)
).play(t, quant:1);
)

i dont know exactly why. but its working now :slight_smile: