View Single Post
Old 01-19-2020, 11:31 PM   #1
SaulT
Human being with feelings
 
Join Date: Oct 2013
Location: Seattle, WA
Posts: 876
Default A Basic Delay Plugin Explained

I got a request from a fellow user about how to make a basic delay plugin. I figured I would make it a public post so it was open for feedback if anyone else wanted to chime in. This first post will have the full source and the second post will break it down by sections and explain what is happening where.

The purpose is a basic short delay that can create echoes through feedback. I'm not going to claim to be the best teacher or explain the best and I can easily talk too much, but hopefully the user who asked will benefit anyways.

++changelog

2020/01/20 ... incorporated Ashcat's moving the feedback into the function itself, added db2ratio()

Also, I should point out that I put the default values to those exact settings because I liked how it sounded on Otaku Gang's "Ten Crack Commandments (Star Wars Remix)" which is the track I tend to test my plugins out on. And now you know.

Code:
desc:simple delay plugin

slider1:350<1,500,1>Delay (ms)
slider2:-15<-90,0,0.1>Wet (dB)
slider3:-45<-90,0,0.1>Feedback (dB)

@init

buf0 = 100000;
buf1 = 200000;

function db2ratio(db) ( 10^(db * 0.05); );

function delay_set(buffer,ms,fbGain)
 instance(buf,size,frac,pos)
(
  buf = buffer;
  size = srate * ms * 0.001;
  frac = size - floor(size);
  size = floor(size);
  feedbackGain = db2ratio(fbGain);
);

function delay(in)
 instance(pos,buf,old,out,size,frac,feedbackGain)
(
  out = buf[pos];
  out = out*(1-frac) + old*frac;
  old = buf[pos];
  buf[pos] = in + (out * feedbackGain);
  pos += 1;
  pos >= size ? pos -= size;
  out;
);

@slider

delay0.delay_set(buf0,slider1,slider3);
delay1.delay_set(buf1,slider1,slider3);

wetGain = db2ratio(slider2);


@sample

spl0 += delay0.delay(spl0) * wetGain;
spl1 += delay1.delay(spl1) * wetGain;

Last edited by SaulT; 01-20-2020 at 09:04 PM.
SaulT is offline   Reply With Quote