Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update ProtoplugFiles
  • Loading branch information
falkTX committed Aug 24, 2017
1 parent 7d271ed commit b2d5cd5
Show file tree
Hide file tree
Showing 14 changed files with 256 additions and 136 deletions.
Expand Up @@ -90,7 +90,7 @@ <h2>Classes</h2>
--]]</span>

<span class="global">require</span> <span class="string">"include/protoplug"</span>
<span class="keyword">local</span> cbFilter = <span class="global">require</span> <span class="string">"include/pac/cookbook filters"</span>
<span class="keyword">local</span> cbFilter = <span class="global">require</span> <span class="string">"include/dsp/cookbook filters"</span>
<span class="keyword">local</span> filters = {}

stereoFx.init()
Expand Down
2 changes: 1 addition & 1 deletion ports/protoplug/ProtoplugFiles/effects/classic-filter.lua
Expand Up @@ -7,7 +7,7 @@ author: osar.fr
--]]

require "include/protoplug"
local cbFilter = require "include/pac/cookbook filters"
local cbFilter = require "include/dsp/cookbook filters"
local filters = {}

stereoFx.init()
Expand Down
30 changes: 15 additions & 15 deletions ports/protoplug/ProtoplugFiles/effects/distortion - power.lua
Expand Up @@ -4,34 +4,34 @@ description: The one from the website
author: osar.fr
--]]
require "include/protoplug"
local cbFilter = require "include/pac/cookbook filters"
local cbFilter = require "include/dsp/cookbook filters"

local power

local function dist (x)
if x<0 then return -1*math.pow (-1*x,power) end
return math.pow (x,power)
if x<0 then return -1*math.pow (-1*x,power) end
return math.pow (x,power)
end

stereoFx.init ()
function stereoFx.Channel:init ()
-- create per-channel fields (filters)
self.low = cbFilter {type = "lp"; f = 100; gain = 0; Q = 0.3}
self.high = cbFilter {type = "hp"; f = 50; gain = 0; Q = 0.3}
-- create per-channel fields (filters)
self.low = cbFilter {type = "lp"; f = 100; gain = 0; Q = 0.3}
self.high = cbFilter {type = "hp"; f = 50; gain = 0; Q = 0.3}
end

function stereoFx.Channel:processBlock (samples, smax)
for i = 0, smax do
local s = dist (self.high.process (samples[i]))
samples[i] = s + self.low.process (samples[i])*2
end
for i = 0, smax do
local s = dist (self.high.process (samples[i]))
samples[i] = s + self.low.process (samples[i])*2
end
end

params = plugin.manageParams {
{
{
name = "Power";
min = 1;
max = 0.01;
changed = function (val) power = val end;
};
min = 1;
max = 0.01;
changed = function (val) power = val end;
};
}
2 changes: 1 addition & 1 deletion ports/protoplug/ProtoplugFiles/effects/pitch distort.lua
Expand Up @@ -140,7 +140,7 @@ end


-- Graphics --
local Freqgraph = require "include/pac/freqgraph"
local Freqgraph = require "include/gui-extras/freqgraph"
local J = require "include/protojuce"

local fg = Freqgraph {
Expand Down
2 changes: 1 addition & 1 deletion ports/protoplug/ProtoplugFiles/effects/spectral filter.lua
Expand Up @@ -95,7 +95,7 @@ end


-- Graphics --
local Freqgraph = require "include/pac/freqgraph"
local Freqgraph = require "include/gui-extras/freqgraph"
local J = require "include/protojuce"

local fg = Freqgraph {
Expand Down
6 changes: 3 additions & 3 deletions ports/protoplug/ProtoplugFiles/generators/fft sweeper.lua
Expand Up @@ -10,9 +10,9 @@ fftlib = script.ffiLoad("libfftw3.so.3", "libfftw3-3")

ffi.cdef[[
typedef enum {
FFTW_R2HC=0, FFTW_HC2R=1, FFTW_DHT=2,
FFTW_REDFT00=3, FFTW_REDFT01=4, FFTW_REDFT10=5, FFTW_REDFT11=6,
FFTW_RODFT00=7, FFTW_RODFT01=8, FFTW_RODFT10=9, FFTW_RODFT11=10
FFTW_R2HC=0, FFTW_HC2R=1, FFTW_DHT=2,
FFTW_REDFT00=3, FFTW_REDFT01=4, FFTW_REDFT10=5, FFTW_REDFT11=6,
FFTW_RODFT00=7, FFTW_RODFT01=8, FFTW_RODFT10=9, FFTW_RODFT11=10
} fftw_r2r_kind;
void *fftw_plan_r2r_1d(int n, double *in, double *out, fftw_r2r_kind kind, unsigned int flags);
void fftw_execute(void *plan);
Expand Down
79 changes: 79 additions & 0 deletions ports/protoplug/ProtoplugFiles/generators/karplus.lua
@@ -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;
};
}
72 changes: 72 additions & 0 deletions ports/protoplug/ProtoplugFiles/include/dsp/Env.lua
@@ -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
Expand Up @@ -90,7 +90,26 @@ local function Filter(params)
error("Unsupported filter type " .. params.type)
end
end;

phaseDelay = function(frequency)
local omegaT = 2 * math.pi * frequency / plugin.getSampleRate();
local real, imag = 0.0, 0.0;
for i,b in ipairs{b0,b1,b2} do
real = real + b/a0 * math.cos( (i-1) * omegaT );
imag = imag - b/a0 * math.sin( (i-1) * omegaT );
end

local phase = math.atan2( imag, real );

real = 0.0; imag = 0.0;
for i,a in ipairs{a0,a1,a2} do
real = real + a/a0 * math.cos( (i-1) * omegaT );
imag = imag - a/a0 * math.sin( (i-1) * omegaT );
end

phase = phase - math.atan2( imag, real );
phase = math.fmod( -phase, 2 * math.pi );
return phase / omegaT;
end;
process = function (x0)
y2, y1 = y1, y0
y0 = (b0 / a0) * x0 + (b1 / a0) * x1 + (b2 / a0) * x2 - (a1 / a0) * y1 - (a2 / a0) * y2
Expand Down
61 changes: 61 additions & 0 deletions ports/protoplug/ProtoplugFiles/include/dsp/fdelay_line.lua
@@ -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
Expand Up @@ -3,7 +3,7 @@
an interactive histogram-ish frequency graph
used in "spectral filter" and "pitch distort"
usage :
local Freqgraph = require "include/pac/freqgraph"
local Freqgraph = require "include/gui-extras/freqgraph"
local fg = Freqgraph {
-- required paramters :
-- an array (Lua or C) containing the values to be read and modified by the interactive graph
Expand Down Expand Up @@ -173,7 +173,7 @@ function M:InitBackBuffer()

-- draw the Y axis labels
g:saveState()
g:addTransform(J.AffineTransform(0, -1, self.bounds.w, 1, 0, self.frame.y))
g:addTransform(J.AffineTransform(0, -1, self.bounds.w, 1, 0, self.frame.y))
g:setFont(16)
g:drawText(self.yAxis.name, 0, 0, self.frame.h, 20, J.Justification.centred)
g:restoreState()
Expand Down

0 comments on commit b2d5cd5

Please sign in to comment.