I think the issue is, if the phasor is currently close to the end and you set \end to a lower value, then the phasor must jump backward into the new range. That is, if you start with start = s1 and end = e1, and you switch to a new s2 and e2, you shouldn’t get a click if s2 <= phasor < e2 at that moment. Otherwise, “pop.”
Crossfading within one synth means that you will need two phasors and two BufRds, and use a trigger and envelope to switch between them.
- The trigger detects when the crossfade is needed.
- A ToggleFF could act as a gate for one envelope;
1 - toggleis the gate for the other.
Maybe like this.
s.boot;
b = Buffer.read(s, Platform.resourceDir ++ "/sounds/a11wlk01.wav");
(
Ndef(\rate, 1.0);
// fading start or end values will make the synth logic
// really complicated, I suggest to avoid that
Ndef(\start, 0).fadeTime_(0);
Ndef(\end, b.numFrames-1).fadeTime_(0);
// Le Ndef qui jouera le son
Ndef(\sound, {
var start = Ndef(\start).kr(1),
end = Ndef(\end).kr(1),
// in the synth, '+' is analogous to 'or'
trig = (Changed.kr(start) + Changed.kr(end)) > 0,
gate1 = ToggleFF.kr(trig),
gates = [gate1, 1.0 - gate1],
// phasor ranges should update on trigger but not otherwise
starts = Latch.kr(start, gates),
ends = Latch.kr(end, gates),
phasors = Phasor.ar(
trig: 0,
rate: Ndef(\rate).kr(1),
start: starts,
end: ends
),
bufs = BufRd.ar(1, b, phase: phasors, loop: 1),
egs = EnvGen.kr(Env.asr(0.01, 1, 0.01), gates);
Mix(bufs * egs).dup
});
)
Ndef(\sound).play;
Ndef(\start, (40000)); Ndef(\end, 80000);
Ndef(\start, (10000)); Ndef(\end, 100000);
Ndef(\start, (30000)); Ndef(\end, 160000);
Ndef(\start, (60000)); Ndef(\end, 200000);
Ndef(\start, (20000)); Ndef(\end, 80000);
Ndef(\sound).stop;
hjh