Created
June 10, 2019 07:06
-
-
Save FrankBuss/ff204c7d0ec70fb037c003fa98709fa0 to your computer and use it in GitHub Desktop.
testing a slowdown Lua script for VCV Rack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- max buffer length in seconds | |
length = 10 | |
addLabel(50, 125, "Input", 20) | |
addLabel(50, 165, "Trigger", 20) | |
addLabel(50, 205, "Delay", 20) | |
addLabel(190, 125, "Output", 20) | |
input = addInput(20, 120) | |
trigger = addInput(20, 160) | |
delay = addInput(20, 200) | |
output = addOutput(160, 120) | |
lastSampleRate = 0 | |
lastTriggered = 0 | |
triggered = 0 | |
function initBuffer() | |
buffer = {} | |
samples = length * sampleRate | |
for i=0,samples-1 do buffer[i] = 0 end | |
lastSampleRate = sampleRate | |
inIndex = 0 | |
outIndex = 0 | |
print("buffer initializd, size: " .. samples .. " samples") | |
end | |
function process() | |
-- init buffer on sample rate changes and on start | |
if lastSampleRate ~= sampleRate then | |
initBuffer() | |
end | |
-- check trigger (schmitt-trigger implementation with 1 V hysteresis) | |
v = getVoltage(trigger) | |
v2 = 0 | |
if triggered == 1 then | |
if v < 2 then | |
triggered = 0 | |
end | |
else | |
if v > 3 then | |
triggered = 1 | |
end | |
end | |
if lastTriggered == 0 and triggered == 1 then | |
inIndex = 0 | |
outIndex = 0 | |
end | |
lastTriggered = triggered | |
-- store input voltage | |
buffer[inIndex] = getVoltage(input) | |
-- delayed output | |
setVoltage(output, buffer[math.floor(outIndex)]) | |
-- increment index | |
inIndex = inIndex + 1 | |
if inIndex >= samples then | |
inIndex = 0 | |
end | |
outIndex = outIndex + 1 / math.abs(getVoltage(delay)) | |
if outIndex >= samples then | |
outIndex = 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment