Stop BufWr to freeze signal


I would like to freeze an input signal that I record with BufWr. I am not capable of stop recording the BufWr function. I guess since the phase is moving continously? How would I stop recording so the buffer doesnt get rewritten every two seconds? Thank you :slight_smile:

Ndef(\x, { * 0.1 });
Ndef(\x, { * 1 });

~buf = Buffer.alloc(s, 2 * s.sampleRate);

Ndef(\phase, {,, 0, });

//Record into buffer
Ndef(\record, {
	var phase =\phase);
	var in =\x);, ~buf, phase)

Ndef(\Grain, {|rate = 1|
	var trate, dur, sig1, sig2;
	var phase =\phase);
	var buflength =;
	phase = phase - 2000 % buflength;
	sig1 =,, ~buf, rate, phase, 0.3, 0, 0.3, 4);

I think you might want to set Phasor’s rate to 0. That would stop your phase from changing, and make BufRd stuck writing and re-writing the same sample.

Ndef(\phase, {|play=1|,*play, 0, 

Ndef(\phase).set(\play,0) // stop
Ndef(\phase).set(\play,1) // go

If you don’t want to overwrite even that single sample (which I wouldn’t), you could just stop Ndef(\record).
Or you could introduce a parameter to write on the buffer the same content it already has:

Ndef(\record, {|overwrite=1|
	var phase =\phase);
	var in =\x);
	var old_in  =,~buf,phase);
        var writing =,in,overwrite);, ~buf, phase)
// overwrite=1  : write new content (normal)
// overwrite=-1 : re-write old content (no change)
// -1 < overwrite  < 1 : mix old and new content (overdub)

FWIW this is exactly the solution I’m using in some of my code: instead of thinking that the only possible solution is to “stop writing,” another solution is to switch the input between new or old data. (Many programming problems are solved by shifting perspective, rather than looking for another feature.)