View Single Post
Old 01-20-2020, 10:14 AM   #5
ashcat_lt
Human being with feelings
 
Join Date: Dec 2012
Posts: 4,679
Default

db2ratio is such a ubiquitous function, and with all your talk about how useful functions are, you left it out. I’m not sure it would make the @slider section a lot tidier, but if we’re illustrating how functions save us from writing redundant code...

But wait! One big thing and then a slightly smaller thing.

1) We don’t want to feed the mix signal back through the delay at the end there. The feedback split should come before the mixer. In fact, it should probably happen in the delay function itself.

Code:
function delay(in)
 instance(pos,buf,old,out,size,frac)
(
  out = buf[pos];
  out = out*(1-frac) + old*frac;
  old = buf[pos];
  buf[pos] = in + (out * feedbackGain);
  pos += 1;
  pos >= size ? pos -= size;
  out;
);
Then in @sample you just send it the input and remove all references to old0 and old1.


The other thing I wanted to mention is more about the fundamental nature of this very simple type of delay. Basically, it’s gonna glitch hard and strange when you adjust the delay time. Consider what happens when we have a long time and then shorten it. We basically leave a bunch of buffer slots full of stuff, it never actually plays out so we kind of jump back to even further back then we already were, and then if we switch back to a longer time we’ll end up hearing stuff that maybe happened quite a while ago. We expect weird things when simple digital delays are modulated, and I understand that this example wasn’t meant to address that, but just pointing it out for those who might have higher expectations.

Last edited by ashcat_lt; 01-20-2020 at 10:42 AM.
ashcat_lt is online now   Reply With Quote