Here’s a concrete example:
(
SynthDef(\test, { |out = 0, modAmt = 0.1, modRate = 100, bufnum|
var frames = BufFrames.kr(bufnum);
var phase = Phasor.ar(0, 1, 0, frames);
var mod = LFDNoise3.kr(modRate) * 0.5 + 0.5;
var writer = BufWr.ar(WhiteNoise.ar, bufnum, phase);
var reader = BufRd.ar(1, bufnum,
phase - (mod * frames * modAmt),
loop: 1
);
Out.ar(out, reader);
}).dumpUGens;
)
[ 0_Control, control, nil ]
[ 1_BufFrames, control, [ 0_Control[3] ] ]
[ 2_Phasor, audio, [ 0, 1, 0, 1_BufFrames, 0.0 ] ]
[ 3_LFDNoise3, control, [ 0_Control[2] ] ]
[ 4_MulAdd, control, [ 3_LFDNoise3, 0.5, 0.5 ] ]
[ 5_*, control, [ 4_MulAdd, 1_BufFrames ] ]
[ 6_*, control, [ 5_*, 0_Control[1] ] ]
[ 7_-, audio, [ 2_Phasor, 6_* ] ]
[ 8_BufRd, audio, [ 0_Control[3], 7_-, 1, 2 ] ]
[ 9_Out, audio, [ 0_Control[0], 8_BufRd[0] ] ]
// after this point, this is not what we want
[ 10_WhiteNoise, audio, [ ] ]
[ 11_BufWr, audio, [ 0_Control[3], 2_Phasor, 1.0, 10_WhiteNoise ] ]
The UGen sort first follows the mod
chain all the way down to BufRd, then backtracks and fills in BufWr. BufWr was written earlier than BufRd, but processes later.
With the <! tweak:
(
SynthDef(\test, { |out = 0, modAmt = 0.1, modRate = 100, bufnum|
var frames = BufFrames.kr(bufnum);
var phase = Phasor.ar(0, 1, 0, frames);
var mod = LFDNoise3.kr(modRate) * 0.5 + 0.5;
var writer = BufWr.ar(WhiteNoise.ar, bufnum, phase);
var reader = BufRd.ar(1,
bufnum <! writer, // <-- here's the currently available fix
phase - (mod * frames * modAmt),
loop: 1
);
Out.ar(out, reader);
}).dumpUGens;
)
[ 0_Control, control, nil ]
[ 1_BufFrames, control, [ 0_Control[3] ] ]
[ 2_Phasor, audio, [ 0, 1, 0, 1_BufFrames, 0.0 ] ]
[ 3_LFDNoise3, control, [ 0_Control[2] ] ]
[ 4_MulAdd, control, [ 3_LFDNoise3, 0.5, 0.5 ] ]
[ 5_*, control, [ 4_MulAdd, 1_BufFrames ] ]
[ 6_*, control, [ 5_*, 0_Control[1] ] ]
[ 7_-, audio, [ 2_Phasor, 6_* ] ]
[ 8_WhiteNoise, audio, [ ] ] // now we are writing first, then reading
[ 9_BufWr, audio, [ 0_Control[3], 2_Phasor, 1.0, 8_WhiteNoise ] ]
[ 10_firstArg, audio, [ 0_Control[3], 9_BufWr ] ]
[ 11_BufRd, audio, [ 10_firstArg, 7_-, 1, 2 ] ]
[ 12_Out, audio, [ 0_Control[0], 11_BufRd[0] ] ]
hjh