Fix off by one in Lua scripts
Lua arrays (tables) start counting at one. Also `for i = a, b do .. end` is inclusive: a <= i <= b
This commit is contained in:
parent
82541b33a4
commit
1a69bc4a96
@ -29,7 +29,7 @@ function factory () return function ()
|
|||||||
-- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
|
-- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
|
||||||
local d = cmem:to_float (0):array()
|
local d = cmem:to_float (0):array()
|
||||||
-- iterate over the audio sample data
|
-- iterate over the audio sample data
|
||||||
for i = 0, s do
|
for i = 1, s do
|
||||||
if math.abs (d[i]) > peak then
|
if math.abs (d[i]) > peak then
|
||||||
peak = math.abs (d[i])
|
peak = math.abs (d[i])
|
||||||
end
|
end
|
||||||
|
@ -42,10 +42,10 @@ function factory () return function ()
|
|||||||
-- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
|
-- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
|
||||||
local d = cmem:to_float (0):array()
|
local d = cmem:to_float (0):array()
|
||||||
-- iterate over the audio sample data
|
-- iterate over the audio sample data
|
||||||
for i = 0, s do
|
for i = 1, s do
|
||||||
if math.abs (d[i]) > 0 then
|
if math.abs (d[i]) > 0 then
|
||||||
if (nonzeropos < 0 or pos + i < nonzeropos) then
|
if (nonzeropos < 0 or pos + i < nonzeropos) then
|
||||||
nonzeropos = pos + i
|
nonzeropos = pos + i - 1
|
||||||
end
|
end
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
@ -41,7 +41,7 @@ function factory () return function ()
|
|||||||
-- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
|
-- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
|
||||||
local d = cmem:to_float (0):array()
|
local d = cmem:to_float (0):array()
|
||||||
-- iterate over the audio sample data
|
-- iterate over the audio sample data
|
||||||
for i = 0, s do
|
for i = 1, s do
|
||||||
if math.abs (d[i]) > peak then
|
if math.abs (d[i]) > peak then
|
||||||
peak = math.abs (d[i])
|
peak = math.abs (d[i])
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user