How to set doneAction of PlayBuf having a DelayN?

First I had a doneAction in PlayBuf, which didn’t work with the DelayN of 1 sec on a very short sample. Supposedly the disposal happens before I can hear the sound. DelayN has no doneAction, as I understand the documentation. So I tried DetectSilence with several Done values, but now disposal doesn’t happen at all. Any suggestion, how to fix that? Thanks for your help.

(My intention here is bring in some temporal randomness.)

(
SynthDef.new(\bufplay, {
	arg buf=0, rate=1, amp=1, pan=0, delay=1;
	var sig;
	sig = PlayBuf.ar(1, buf, BufRateScale.kr(buf) * rate); // , doneAction: 2);
	sig = DelayN.ar(sig, delay, delay);
	sig = sig * amp;
	sig = Pan2.ar(sig, pan);
	DetectSilence.ar(sig, doneAction: Done.freeSelfAndDeepFreeNext);
	Out.ar(0, sig);
}).add;
)

x = Synth.new(\bufplay, b['mid'][0])

I think like this:

b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");

(
SynthDef.new(\bufplay, {
	arg buf = 0, rate = 1, amp = 1, pan = 0, delay = 1;
	var sig;
	var doneTrig;
	sig = PlayBuf.ar(1, buf, BufRateScale.kr(buf) * rate); // , doneAction: 2);
	
	// note: grab this before other processing
	doneTrig = Done.kr(sig);
	
	sig = DelayN.ar(sig, delay, delay);
	sig = sig * amp;
	sig = Pan2.ar(sig, pan);
	
	doneTrig = TDelay.kr(doneTrig, delay);
	FreeSelf.kr(doneTrig);
	
	Out.ar(0, sig);
}).add;
)

Synth(\bufplay, [buf: b, amp: 0.1]);

hjh

1 Like

wouldn’t figure out this solution. works for me, thanks a lot.