Skip to content

Commit

Permalink
Merge pull request #1125 from catfact/fix-filter-smoother
Browse files Browse the repository at this point in the history
small fix to filters.smoother
  • Loading branch information
catfact authored May 29, 2020
2 parents 127cb8b + e949588 commit 75140d9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lua/lib/filters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ end

--- clear a filter's history
function f:clear()
for i=1,self.bufsize do self.buf[i]=0 end
for i=1,self.bufsize do
self.buf[i]=0
end
end

-- debug function to print the buffer
Expand Down Expand Up @@ -159,6 +161,7 @@ function smoother.new(time, sr)
new.bufsize = 1
new:clear()
new.x = 0
new.a = 1
new.sr = sr
new.t = time
new:calc_coeff()
Expand All @@ -168,8 +171,8 @@ end


function smoother:calc_coeff()
self.b = math.exp(-6.9 / (self.t * self.sr))
print(self.b)
self.a = 1 - math.exp(-6.9 / (self.t * self.sr))
print(self.a)
end

-- set convergence time
Expand All @@ -195,12 +198,12 @@ function smoother:next(x)
if x == nil then x = self.x
else self.x = x end

local d = self.buf[1] - x
local d = x - self.buf[1]

if math.abs(d) < smoother.EPSILON then
self.buf[1] = x
else
self.buf[1] = x + (self.b * d)
self.buf[1] = self.buf[1] + (self.a * d)
end
return self.buf[1]
end
Expand All @@ -209,7 +212,6 @@ end
-- @param new value
function smoother:set_value(x)
self.buf[1] = x
self.y = x
end

-- set target without updating
Expand Down

0 comments on commit 75140d9

Please sign in to comment.