Readable and AudioROM Lua script examples

This commit is contained in:
Robin Gareus 2020-02-01 15:58:34 +01:00
parent 00fcf6719c
commit 016970df25
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
3 changed files with 84 additions and 1 deletions

View File

@ -52,7 +52,7 @@ function dsp_run (ins, outs, n_samples)
end
if #outs == 1 then
conv:run (outs[1], n_samples)
conv:run_mono (outs[1], n_samples)
else
conv:run_stereo (outs[1], outs[2], n_samples)
end

47
scripts/__readable.lua Normal file
View File

@ -0,0 +1,47 @@
ardour { ["type"] = "Snippet", name = "Readable Test" }
function factory () return function ()
local file = "/tmp/reverbs/Large Wide Echo Hall.wav"
local rl = ARDOUR.Readable.load (Session, file)
local cmem = ARDOUR.DSP.DspShm (8192)
local d = cmem:to_float (0):array()
for i = 1, 8192 do d[i] = 0 end
d[1] = .5
local ar = ARDOUR.AudioRom.new_rom (cmem:to_float (0), 8192)
rl:push_back (ar)
local c = 1
for rd in rl:iter () do
local n_samples = rd:readable_length ()
assert (rd:n_channels () == 1)
local peak = 0
local pos = 0
repeat
-- read at most 8K samples starting at 'pos'
local s = rd:read (cmem:to_float (0), pos, 8192, 0)
pos = pos + s
-- access the raw audio data
-- 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
if math.abs (d[i]) > peak then
peak = math.abs (d[i])
end
end
until s < 8192
assert (pos == n_samples)
if (peak > 0) then
print ("File:", file, "channel", c, "peak:", 20 * math.log (peak) / math.log(10), "dBFS")
else
print ("File:", file, "channel", c, " is silent")
end
c = c + 1;
end
end end

36
scripts/_fir.lua Normal file
View File

@ -0,0 +1,36 @@
ardour { ["type"] = "dsp", name = "Lua FIR Convolver", license = "MIT", author = "Ardour Lua Task Force", description = [[Another simple DSP example]] }
function dsp_ioconfig () return
{
{ audio_in = 1, audio_out = 1},
}
end
local conv
function dsp_configure (ins, outs)
conv = ARDOUR.DSP.Convolution (Session, ins:n_audio (), outs:n_audio ())
local cmem = ARDOUR.DSP.DspShm (4)
cmem:clear ()
local d = cmem:to_float (0):array()
d[1] = .5
d[2] = .5
local ar = ARDOUR.AudioRom.new_rom (cmem:to_float (0), 4)
conv:add_impdata (0, 0, ar, 1.0, 0, 0, 0, 0)
cmem:to_float (0):set_table({1, -1, 0, 0}, 4)
ar = ARDOUR.AudioRom.new_rom (cmem:to_float (0), 3)
conv:add_impdata (0, 0, ar, 1.0, 0, 0, 0, 0)
conv:restart ()
collectgarbage ()
end
function dsp_latency ()
return conv:latency()
end
function dsp_runmap (bufs, in_map, out_map, n_samples, offset)
conv:run (bufs, in_map, out_map, n_samples, offset)
end