Download a .scd file of this example to open in SuperCollider here
Download the latest version of SuperCollider here
Code checked in SuperCollider 3.6.6

/*
SimpleDelay.scd
prm
Mono and Stereo SynthDefs to create delay effects
*/


// boot the server:
s.boot;

// add the SynthDefs by executing within the parentheses:
(
SynthDef(\prm_SimpleDelayMono, {
  |
  inBus = 0, outBus = 0, amp = 1, delayTime = 0.3, maxDelayTime = 5, feedback = 0.2,
  filterType = 0, cutoff = 20000, rq = 1, mix = 0.5, lagTime = 0.1
  |
  var input, lowPass, highPass, bandPass, filter, localIn, delay, sig;
  // external input into the Synth
  input = In.ar(inBus);
  // Local Return of the feedback loop:
  localIn = LocalIn.ar(1);

  // LowPass Filter processes  feedback return
  lowPass = RLPF.ar(localIn, cutoff, rq);
  // HighPass Filter processes feedback return
  highPass = RHPF.ar(localIn, cutoff, rq);
  // BandPass Filter processes feedback return
  bandPass = BPF.ar(localIn, cutoff, rq);
  // Selects which filter is active (by default, none, or just the sound of the unfiltered feedback return)
  filter = Select.ar(filterType, [localIn, lowPass, highPass, bandPass]);

  // delay line and output
  delay = DelayC.ar(input + (filter * feedback), maxDelayTime, delayTime.lag2(lagTime));
  LocalOut.ar(delay);

  sig = (filter * mix) + (input * (1-mix));
  sig = sig * amp;
  Out.ar(outBus, sig);
}).add;

SynthDef(\prm_SimpleDelayStereo, {
  |
  inBus = 0, outBus = 0, amp = 1, delayTime = 0.3, maxDelayTime = 5, feedback = 0.2,
  filterType = 0, cutoff = 20000, rq = 1, mix = 0.5, lagTime = 0.1
  |
  var input, lowPass, highPass, bandPass, filter, localIn, delay, sig;
  input = In.ar(inBus, 2);
  localIn = LocalIn.ar(2);

  lowPass = RLPF.ar(localIn, cutoff, rq);
  highPass = RHPF.ar(localIn, cutoff, rq);
  bandPass = BPF.ar(localIn, cutoff, rq);
  filter = Select.ar(filterType, [localIn, lowPass, highPass, bandPass]);

  delay = DelayC.ar(input + (filter * feedback), maxDelayTime, delayTime.lag2(lagTime));
  LocalOut.ar(delay);

  sig = (filter * mix) + (input * (1-mix));
  sig = sig * amp;
  Out.ar(outBus, sig);
}).add;
);

//////// Examples:

// create and Audio Bus:
a = Bus.audio;
// create an instance of the Synth:
c = Synth(\prm_SimpleDelayMono, [\inBus, a, \outBus, 0], addAction: \addToTail);


// enveloped saw tooth wave
// subtle echo effect
b = { Out.ar(a, EnvGen.ar(Env.perc(0.01, 0.75, 1, -4), 1, doneAction: 2) * Saw.ar(220)) }.play;


// increase the feedback:
c.set(\feedback, 0.7);
// then listen to the enveloped saw again:
// longer echos
b = { Out.ar(a, EnvGen.ar(Env.perc(0.01, 0.75, 1, -4), 1, doneAction: 2) * Saw.ar(220)) }.play;



//////// Filter Section:

// by default, the filter in the feedback loop is not engaged.
// To return to this mode at any time:
c.set(\filterType, 0);

//// Lowpass Filter:
// The delayed sound becomes increasingly filtered by the LowPass Filter as it decays:
c.set(\filterType, 1);
b = { Out.ar(a, EnvGen.ar(Env.perc(0.01, 0.75, 1, -4), 1, doneAction: 2) * Saw.ar(220)) }.play;

//// HighPass Filter:
(
c.set(\filterType, 2);
c.set(\cutoff, 700);
);
// The delayed sound becomes increasingly filtered by the HighPass Filter as it decays:
b = { Out.ar(a, EnvGen.ar(Env.perc(0.01, 0.75, 1, -4), 1, doneAction: 2) * Saw.ar(220)) }.play;

//// BandPass Filter:
(
c.set(\filterType, 3);
c.set(\cutoff, 1000);
);
// The delayed sound becomes increasingly filtered by the HighPass Filter as it decays:
b = { Out.ar(a, EnvGen.ar(Env.perc(0.01, 0.75, 1, -4), 1, doneAction: 2) * Saw.ar(220)) }.play;

///Each of the filters also has a resonance peak, specified by RQ. The closer RQ is to 0, the greater the resonance of the filter.
// Be careful! Each of the filters can easily self-oscillate at low RQ values and high feedback values.
// The LowPass and HighPass filters are significantly more prone to self-oscillation than the bandpass filter.

//// Delay Time can be changed to create different effects:

// Reset the Synth:
(
c.set(\feedback, 0.9);
c.set(\filterType, 0);
c.set(\delayTime, 1);
c.set(\lagTime, 1);
);

// execute this:
b =  { Out.ar(a, EnvGen.ar(Env.perc(0.01, 5, 1, 4), 1, doneAction: 2) * Saw.ar(220)) }.play;

// then this, directly after:
c.set(\delayTime, 0.1);
// then this:
c.set(\delayTime, 2);
// then this:
c.set(\delayTime, 5);
// finally this:
c.set(\delayTime, 0.05);

// play around with different lag time values for different smearing effects