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:
Robin Gareus 2020-03-03 00:27:25 +01:00
parent 82541b33a4
commit 1a69bc4a96
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
3 changed files with 4 additions and 4 deletions

View File

@ -29,7 +29,7 @@ function factory () return function ()
-- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
local d = cmem:to_float (0):array()
-- iterate over the audio sample data
for i = 0, s do
for i = 1, s do
if math.abs (d[i]) > peak then
peak = math.abs (d[i])
end

View File

@ -42,10 +42,10 @@ function factory () return function ()
-- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
local d = cmem:to_float (0):array()
-- iterate over the audio sample data
for i = 0, s do
for i = 1, s do
if math.abs (d[i]) > 0 then
if (nonzeropos < 0 or pos + i < nonzeropos) then
nonzeropos = pos + i
nonzeropos = pos + i - 1
end
break
end

View File

@ -41,7 +41,7 @@ function factory () return function ()
-- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray
local d = cmem:to_float (0):array()
-- iterate over the audio sample data
for i = 0, s do
for i = 1, s do
if math.abs (d[i]) > peak then
peak = math.abs (d[i])
end