summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2020-02-01 15:58:34 +0100
committerRobin Gareus <robin@gareus.org>2020-02-06 17:30:22 +0100
commit016970df25ef27f9d638bb3cd70204da0ff144de (patch)
tree615ddfecde03d59c0f5a40007cf2d67e33c5a0f7 /scripts
parent00fcf6719c348c84da0e9b4d8a689c485234dde0 (diff)
Readable and AudioROM Lua script examples
Diffstat (limited to 'scripts')
-rw-r--r--scripts/__convolv.lua2
-rw-r--r--scripts/__readable.lua47
-rw-r--r--scripts/_fir.lua36
3 files changed, 84 insertions, 1 deletions
diff --git a/scripts/__convolv.lua b/scripts/__convolv.lua
index b8d82627fb..23ad9034ed 100644
--- a/scripts/__convolv.lua
+++ b/scripts/__convolv.lua
@@ -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
diff --git a/scripts/__readable.lua b/scripts/__readable.lua
new file mode 100644
index 0000000000..b9a991a782
--- /dev/null
+++ b/scripts/__readable.lua
@@ -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
diff --git a/scripts/_fir.lua b/scripts/_fir.lua
new file mode 100644
index 0000000000..64448ef8f6
--- /dev/null
+++ b/scripts/_fir.lua
@@ -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