Skip to content

Instantly share code, notes, and snippets.

@interstar
Last active August 16, 2023 02:30
Show Gist options
  • Save interstar/7cc4b8cb99dcd2bccffca21a4d2459ef to your computer and use it in GitHub Desktop.
Save interstar/7cc4b8cb99dcd2bccffca21a4d2459ef to your computer and use it in GitHub Desktop.
Long Delay for Lua Protoplug
--[[
name: Delay Line
description: Simple delay line effect with DC removal
author: osar.fr (adapted by Phil Jones )
See : https://www.youtube.com/watch?v=PEUZZCpzkWo
--]]
require "include/protoplug"
local length, feedback
stereoFx.init()
DELAY_BUFFER_SIZE = 1400000
-- everything is per stereo channel
function stereoFx.Channel:init()
self.delay_buffer = ffi.new("double[1400000]")
self.current_time_idx = 0 -- iterator
self.dc1, self.dc2 = 0,0
end
function stereoFx.Channel:goBack()
local past_idx = self.current_time_idx-length
if past_idx<0 then past_idx = past_idx+DELAY_BUFFER_SIZE end
local v = self.delay_buffer[past_idx]
past_idx = past_idx-1
if past_idx<0 then past_idx = past_idx+DELAY_BUFFER_SIZE end
v = v+self.delay_buffer[past_idx]
v = v*0.4992*feedback
return v
end
function stereoFx.Channel:dcRemove(s) -- don't worry about this
self.dc1 = self.dc1 + (s - self.dc2) * 0.000002
self.dc2 = self.dc2 + self.dc1
self.dc1 = self.dc1 * 0.96
return s-self.dc2
end
function stereoFx.Channel:processBlock(audio_buffer, smax)
for i = 0,smax do
audio_buffer[i] = audio_buffer[i]+self:dcRemove(audio_buffer[i]+self:goBack())
self.delay_buffer[self.current_time_idx] = audio_buffer[i]
self.current_time_idx = self.current_time_idx+1
if self.current_time_idx>=DELAY_BUFFER_SIZE then self.current_time_idx=0 end
end
end
params = plugin.manageParams {
{
name = "Length";
type = "int";
max = DELAY_BUFFER_SIZE;
changed = function(val) length = val end;
};
{
name = "Feedback";
max = 1;
changed = function(val) feedback = val end;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment