aboutsummaryrefslogtreecommitdiffhomepage
path: root/applause.lua
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2016-09-17 01:43:47 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2024-03-28 05:22:51 +0300
commit8d9361995e7123af8813753b10625dddda6d4fd6 (patch)
tree5495dc83454cbc20721d0d1e8b740e7c9dd0a96a /applause.lua
parent22f88459f2950eb163a8844badd884b3e1d193cd (diff)
downloadapplause2-8d9361995e7123af8813753b10625dddda6d4fd6.tar.gz
InputStream(): work in progressinputstream
* It still results in gaps (???). Under FreeBSD, even the expression `InputStream():play()` produces noise. Apparently, there is some kind of data corruption. * it's probably necessary to increase the input buffer size and tell Jackd about the difference (output - input buffer size) as an additional latency.
Diffstat (limited to 'applause.lua')
-rw-r--r--applause.lua45
1 files changed, 45 insertions, 0 deletions
diff --git a/applause.lua b/applause.lua
index 5d1ba5a..fc5c31b 100644
--- a/applause.lua
+++ b/applause.lua
@@ -1422,6 +1422,51 @@ end
-- If given, this value will be returned by the @{Stream:new} method instead.
-- @see Stream:ctor
+--
+-- A stream for retrieving data from Jack input ports.
+-- This will block until data is available so constructs
+-- like InputStream():save("foo.wav") are possible.
+--
+InputStream = DeriveClass(Stream)
+
+function InputStream:ctor(first_port, len)
+ first_port = first_port or 1
+ len = len or 1
+ assert(len >= 1, "Invalid length specified")
+
+ if len > 1 then
+ -- Since MuxStream is the only allowed multi-channel stream,
+ -- automatically mux for multichannel input streams.
+ local streams = {}
+ for i = 1, len do
+ streams[i] = InputStream:new(first_port+i-1)
+ end
+ return MuxStream:new(unpack(streams))
+ end
+
+ -- Single channel InputStream
+ self.port = first_port
+end
+
+function InputStream:gtick()
+ local port = self.port
+ local sample_buffer = ffi.new("double[1]")
+
+ return function()
+ local state = C.applause_pull_sample(port, sample_buffer)
+
+ -- React to buffer overruns.
+ -- This is done here instead of in the realtime thread
+ -- even though it is already overloaded, so as not to
+ -- affect other applications in the Jack graph.
+ if state == C.APPLAUSE_AUDIO_XRUN then
+ io.stderr:write("WARNING: Buffer overrun detected\n")
+ end
+
+ return tonumber(sample_buffer[0])
+ end
+end
+
--- Class for caching streams.
-- Cached streams are calculated only once per tick.
-- @type CachedStream