iām working on a script to bring arc controled LFOs to midi devices. hereās the whole thing on github
two bottlenecks are keeping it from moving past ānovelty funā to āactually funā:
āpreserving phase on speed change. instead of what you would expect to hear when changing lfo speed, it resets the waveform and gargles the ccs. i think because i calculate phase from current time minus start time? but i canāt work out how to fix it. setting speed to only update at 1/0/-1 is too sluggish.
āmore LFO shapes, ideally control over curves of the shapes as well. this is killing me, i have been trying to make a saw wave LFO for three days. the best reference iāve found so far is this book:
i am looking at the chapter on āclassical waveformsā but i am just not comprehending how to translate the math into the code (which probably means i donāt understand the mathā¦)
here is what i think the relevant code is:
function init()
startTime = util.time()
lfo_metro = metro.init()
lfo_metro.time = .01
lfo_metro.count = -100
lfo_metro.event = function()
currentTime = util.time()
for i = 1,4 do
lfo[i].bpm = lfo[i].freq * 60
lfo[i].amp = params:get("lfo_" .. i .. "_amp")
lfo[i].offset= params:get("lfo_" .. i .. "_offset")
--get phase of LFO
if params:get("lfo_" .. i .. "_type") == 1 then --sin
lfo[i].phase = math.sin((currentTime - startTime) * lfo[i].freq * tau)
elseif params:get("lfo_" .. i .. "_type") == 2 then --square
if math.sin((currentTime - startTime) * lfo[i].freq* tau) > 0 then lfo[i].phase = 1
else lfo[i].phase = -1 end
end
-- clamp ccs
if math.ceil(lfo[i].offset + 64 * lfo[i].phase * lfo[i].amp) < 0 then lfo[i].cc = 0
elseif math.ceil(lfo[i].offset + 64 * lfo[i].phase * lfo[i].amp) > 127 then lfo[i].cc = 127
-- set cc
else lfo[i].cc= math.ceil(lfo[i].offset + 64 * lfo[i].phase * lfo[i].amp) end
--for arc redraw
lfo[i].counter = (lfo[i].counter + (1*lfo[i].freq))%100
lfo[i].ar = lfo[i].counter*.64
send_cc(i,lfo[i].cc)
lfo[i].lastphase = lfo[i].phase
end
end
end
if anyone has suggestions on how to implement more waveforms in lua or what to read to comprehend how to implement waveforms in code i would be so grateful! if nothing else i did get a couple of new ideas to try while writing this up.