Extra "ports" of juce-based plugins using the distrho build system
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1KB

  1. -- delay line 1
  2. -- with dc filter and shitty linear interpolation
  3. -- todo test full float version
  4. -- and possibly pointer arithmetic version
  5. local function blend(a,b,p) return (a*p + b*(1-p)) end
  6. function Line (bufSize)
  7. local buf = ffi.new("double[?]", bufSize)
  8. local pos = 0 -- todo int
  9. local dc1, dc2 = 0, 0
  10. return {
  11. goBack = function (dt)
  12. -- todo assert dt<bufSize
  13. local fpos = pos - dt
  14. local ipos1 = math.floor(fpos)
  15. local ipos2 = ipos1 + 1
  16. local frac = fpos - ipos1
  17. if ipos1 < 0 then ipos1 = ipos1 + bufSize end
  18. if ipos2 < 0 then ipos2 = ipos2 + bufSize end
  19. if (ipos1)>=bufSize or (ipos1)<0 then error("accessed buf "..(ipos1)) end -- DEBUG
  20. if (ipos2)>=bufSize or (ipos2)<0 then error("accessed buf "..(ipos2)) end -- DEBUG
  21. return blend(buf[ipos2], buf[ipos1], frac)
  22. end;
  23. push = function (s)
  24. pos = pos + 1
  25. if pos >= bufSize then pos = 0 end
  26. dc1 = dc1 + (s - dc2) * 0.000002
  27. dc2 = dc2 + dc1
  28. dc1 = dc1 * 0.96
  29. if (pos)>=bufSize or (pos)<0 then error("accessed buf "..(pos)) end -- DEBUG
  30. buf[pos] = s - dc2
  31. end;
  32. }
  33. end
  34. return Line