require "include/protoplug"
local release = 10000
local decayRate = 1/release
polyGen.initTracks(8)
function polyGen.VTrack:init()
self.phase = 0
self.releasePos = release
end
function polyGen.VTrack:addProcessBlock(samples, smax)
local amp = 1
for i = 0,smax do
if not self.noteIsOn then
if self.releasePos>=release then break end
amp = 1-self.releasePos*decayRate
self.releasePos = self.releasePos+1
end
self.phase = self.phase + (self.noteFreq*math.pi*2)
local trackSample = math.sin(self.phase)*amp*0.3
samples[0][i] = samples[0][i] + trackSample samples[1][i] = samples[1][i] + trackSample end
end
function polyGen.VTrack:noteOff(note, ev)
self.releasePos = 0
end
function polyGen.VTrack:noteOn(note, vel, ev)
self.phase = 0
end