Sustain Pedal for guitar / anything else

Hello everybody.
My interest was to make a sustain pedal for any Input signal. Specifically targeted at a guitar. I’m not quite sure, but I think i remember somewhere something like that was already implemented for Supercollider but i cannot find it. Maybe my memories also deceive me here…
Does anyone have any ideas how one could implement such a thing? Basically a sustain for any In.ar or SoundIn.ar signal. Not sure if it makes sense to create some infinite reverb or record a buffer and hold it.
Maybe someone has an idea or remembers if there was a posting along this line. Thank you very much.

Hello there,
This is not the expected answer, but maybe it will help.

I’m not sure if there’s an official definition of this kind of sustain. I don’t use it myself, because I like the idea of having an analogical sustain with tremolo, but I think the pedal holds the note of the guitar until another note is played, so it’s repeating a certain timbre at a certain frequency until it detects another timbre or another pitch, right ?

Then I’d say that using an AllpassN or a buffer could be the right solution to sample the sound and play it again and again. I think the problem would be how to loop on the right frequency, I don’t know how to implement a frequency detector myself, but I think FFT can achieve this. Another idea I have is to loop on several cycles and apply an envelope slowly fading in and out, so we don’t hear that the freq is not properly synced with the previous loop. But that’s because I’m a bad sound engineer :grinning: .

I guess FFT is the “best” way to achieve a sustain effect. But it’s possible to get a reasonable sustain/freeze sound with granular synthesis - Eli’s tutorial shows this here:

Heyy, thanks for u responsed. Mh this is what I came up with, its a way of sustaining i guess, not a perfect or optimized at all way. kinda trial and error. If you have some ideas how to improve let me know.
I used Grain for this task now, not entirely sure how I could do it with a FFT.
Anyhow, here is the code, you can test it, if you have a device for SoundIn.ar(0). Pay attention I amplified this signal, for my personal specs:

~b_sus = Buffer.alloc(s, s.sampleRate * 0.1,1);
(
{
	var sig, rec, loop, ptr, buf, run;
	//run is for when the pedal is pressed
	//for demonstration purposes you can
	//use your mouse instead
	//mouse in the left half is just your signal
	//mouse on right half is when the sustain pedal is pressed
	//right now, 'pressing' the pedal mutes your original signal
	run = MouseX.kr(1,0).round;
	//heres the buffer
	buf=~b_sus;
	//your sound input, i used a microphone
	//pay attention to feedback, i amplified this signal!!
	rec = (SoundIn.ar(0)*15).tanh;
	//record and re-record/overdub the previous rec channel
	ptr = Phasor.ar(1, BufRateScale.kr(buf), 0, BufFrames.kr(buf));
	loop = BufRd.ar(1,buf,ptr);
	loop = (rec*run)+(loop*(1-run));
	BufWr.ar(loop, buf, ptr);
	//the actual output signal
	sig = 0.25*GrainBuf.ar(
		numChannels:1,
		trigger:Dust.ar(1000),
		dur:0.08,
		sndbuf:buf,
		rate:1,
		pos:LFSaw.ar(0.1).range(0,0.1)
	);
	//maybe add some reverb? dunno
	// sig = FreeVerb.ar(sig);
	//high pass, since some bass resonance might happen
	sig = HPF.ar(sig,80);
	//plays the record input, with run = 0
	//with run = 1 the sustain effect
	sig = (sig*(1-run.lag(0.1))) + (rec*run.lag(0.1));
}.play
)

You can use the classes PV_Freeze and PV_MagFreeze.
See help files for examples:
https://doc.sccode.org/Classes/PV_Freeze.html
https://doc.sccode.org/Classes/PV_MagFreeze.html

Best,
Paul