Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Update ProtoplugFiles
- Loading branch information
Showing
14 changed files
with
256 additions
and
136 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| --[[ | ||
| name: karplus synth | ||
| description: A simple karplus-string VST/AU. | ||
| author: victor bombi | ||
| --]] | ||
|
|
||
| require "include/protoplug" | ||
|
|
||
| local Fdelay = require "include/dsp/fdelay_line" | ||
| local Filter = require "include/dsp/cookbook filters" | ||
| local Env = require "include/dsp/Env" | ||
| local att_secs = 0 | ||
| local rel_secs = 0.3 | ||
| local fc = 6000 | ||
| local maxbuff = 2048 --44100/20 | ||
|
|
||
| polyGen.initTracks(8) | ||
|
|
||
| function polyGen.VTrack:init() | ||
| -- create per-track fields here | ||
| --self.filter = Filter{type = "hs", f = 15000, gain = -3, Q = 0.1} | ||
| self.filter = Filter{type = "lp", f = fc, gain = -3, Q = 0.707} | ||
| self.filter_excit = Filter{type = "hs", f = 6000, gain = -6, Q = 1} | ||
| self.env = Env.EnvLinear:new{} | ||
| self.envT = Env.EnvTri:new{} | ||
| self.delay = Fdelay(maxbuff) | ||
| end | ||
|
|
||
| function polyGen.VTrack:addProcessBlock(samples, smax) | ||
| local envamp = 1 | ||
| local dt = self.notePeriod - self.filter.phaseDelay(self.noteFreq*plugin.getSampleRate()) -1 | ||
| for i = 0,smax do | ||
| if self.env.ended then break end | ||
| envamp = self.env:get_amp() | ||
| local envampT = self.envT:get_amp() | ||
| local loops = self.delay.goBack(dt) | ||
| local trackSample = self.filter_excit.process(2*math.random()-1)*envampT*self.amp + loops | ||
| trackSample = self.delay.dc_remove(trackSample) | ||
| trackSample = self.filter.process(trackSample) | ||
| self.delay.push(trackSample*0.999) | ||
| trackSample = trackSample *envamp*0.1 | ||
| samples[0][i] = samples[0][i] + trackSample -- left | ||
| samples[1][i] = samples[1][i] + trackSample -- right | ||
| end | ||
| end | ||
|
|
||
| function polyGen.VTrack:noteOff(note, ev) | ||
| self.env:release() | ||
| end | ||
| function linearmap(v,s,e,ds,de) | ||
| return ((de-ds)*(v-s)/(e-s)) + ds | ||
| end | ||
| function polyGen.VTrack:noteOn(note, vel, ev) | ||
| self.env:init(att_secs, rel_secs) | ||
| self.envT:init(0, 0.05) | ||
| self.delay.zero() | ||
| local amp = vel/127 | ||
| self.amp = amp * amp | ||
| self.filter.update{f=fc} | ||
| self.filter_excit.update{f=linearmap(self.amp,0,1,100,16000)} | ||
| end | ||
|
|
||
| params = plugin.manageParams { | ||
| { | ||
| name = "Attack"; | ||
| max = 1; | ||
| changed = function(val) att_secs = val end; | ||
| }; | ||
| { | ||
| name = "Release"; | ||
| max = 1; | ||
| changed = function(val) rel_secs = val end; | ||
| }; | ||
| { | ||
| name = "fc"; | ||
| max = 10000; | ||
| changed = function(val) fc = val end; | ||
| }; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| local M = {} | ||
| local EnvLinear = {att=0,rel=0,ended=true} | ||
| function EnvLinear:init(att,rel) | ||
| self.on = true | ||
| self.ended = false | ||
| self.att = att | ||
| self.att_pos = 0 | ||
| self.rel = rel | ||
| self.rel_pos = 0 | ||
| end | ||
| function EnvLinear:release() | ||
| self.on = false | ||
| self.att_pos = 0 | ||
| self.rel_pos = 0 | ||
| end | ||
| function EnvLinear:get_amp() | ||
| local ret | ||
| if self.on then | ||
| ret = math.min(1,self.att_pos/self.att) | ||
| self.att_pos = self.att_pos + self.tick_len | ||
| elseif self.rel_pos > self.rel then | ||
| self.ended = true | ||
| return 0 | ||
| else | ||
| ret = 1 - self.rel_pos/self.rel | ||
| self.rel_pos = self.rel_pos + self.tick_len | ||
| end | ||
| return ret | ||
| end | ||
| function EnvLinear:new (o) | ||
| setmetatable(o, self) | ||
| self.__index = self | ||
| plugin.addHandler("prepareToPlay", function() o.tick_len = 1/plugin.getSampleRate() end) | ||
| return o | ||
| end | ||
|
|
||
| local EnvTri = {att=0,rel=0,ended=true} | ||
| function EnvTri:init(att,rel) | ||
| self.on = true | ||
| self.ended = false | ||
| self.att = att | ||
| self.rel = rel | ||
| self.pos = 0 | ||
| end | ||
| function EnvTri:release() | ||
| self.on = false | ||
| self.pos = 0 | ||
| end | ||
| function EnvTri:get_amp() | ||
| local ret | ||
| if self.pos < self.att then | ||
| ret = self.pos/self.att | ||
| self.pos = self.pos + self.tick_len | ||
| elseif self.pos > self.rel + self.att then | ||
| self.ended = true | ||
| return 0 | ||
| else | ||
| ret = 1 - (self.pos - self.att)/self.rel | ||
| self.pos = self.pos + self.tick_len | ||
| end | ||
| return ret | ||
| end | ||
| function EnvTri:new (o) | ||
| setmetatable(o, self) | ||
| self.__index = self | ||
| plugin.addHandler("prepareToPlay", function() o.tick_len = 1/plugin.getSampleRate() end) | ||
| return o | ||
| end | ||
|
|
||
| M.EnvLinear = EnvLinear | ||
| M.EnvTri = EnvTri | ||
| return M |
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
File renamed without changes.
61 changes: 61 additions & 0 deletions
61
ports/protoplug/ProtoplugFiles/include/dsp/fdelay_line.lua
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| -- fractional delay line 1 | ||
| -- with lagrange interpolation | ||
|
|
||
|
|
||
| local function FLine (bufSize) | ||
| local n,e = math.frexp(bufSize) | ||
| bufSize = 2^e --nextpoweroftwo | ||
| local buf = ffi.new("double[?]", bufSize) | ||
| local mask = bufSize - 1 | ||
| local h = {[0]=0,0,0,0} | ||
| local pos = 0 | ||
| local ptL = 0 | ||
| local dc1, dc2 = 0, 0 | ||
| local lastdt = math.huge | ||
| local function CalcCoeffs(delay) | ||
| local intd =math.floor(delay); | ||
| local Dm1 = delay - intd; | ||
| intd = intd - 1.; | ||
| local D = Dm1 + 1; | ||
| local Dm2 = Dm1 - 1; | ||
| local Dm3 = Dm1 - 2; | ||
| local DxDm1 = D * Dm1; | ||
| --//float Dm1xDm2 = Dm1 * Dm2; | ||
| local Dm2xDm3 = Dm2 *Dm3; | ||
| h[0] = (-1/6.)* Dm1 * Dm2xDm3; | ||
| h[1] = 0.5 * D * Dm2xDm3; | ||
| h[2] = -0.5 * DxDm1 * Dm3; | ||
| h[3] = (1/6.) * DxDm1 * Dm2; | ||
| return intd ; | ||
| end | ||
| return { | ||
| goBack = function (dt) | ||
| if (dt ~= lastdt) then | ||
| ptL = CalcCoeffs(dt); | ||
| lastdt = dt; | ||
| end | ||
| local sum = 0; | ||
| for i=0,3 do | ||
| sum = sum + buf[bit.band((pos + ptL + i), mask)]*h[i]; | ||
| end | ||
| return sum; | ||
| end; | ||
| push = function (s) | ||
| pos = pos - 1 | ||
| if pos < 0 then pos = mask end | ||
| buf[pos] = s | ||
| end; | ||
| zero = function() | ||
| for i=0,bufSize-1 do buf[i] = 0 end | ||
| end; | ||
| dc_remove = function(s) | ||
| dc1 = dc1 + (s - dc2) * 0.000002 | ||
| dc2 = dc2 + dc1 | ||
| dc1 = dc1 * 0.96 | ||
| return s - dc2 | ||
| end | ||
| } | ||
| end | ||
|
|
||
|
|
||
| return FLine |
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
File renamed without changes.
Oops, something went wrong.