aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2023-09-15 20:36:27 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2023-09-15 21:17:08 +0300
commitf9e0e3dea3068453efc0d9559d1b98d22cd5a7cb (patch)
tree33397ea9cca5e97546a3182e1a27bd986ae488c2
parent0b47e7cf9bb7b77fa28a02aea1964540b81a7c84 (diff)
downloadapplause2-f9e0e3dea3068453efc0d9559d1b98d22cd5a7cb.tar.gz
fixed SubStream of cached streams
* in particular: SndfileStream(...):sub(...) for multi-channel audio files. * The fix is more of a workaround just like the initial skipping of samples by sub() is a workaround. I couldn't yet think of a way how to seek in streams elegantly.
-rw-r--r--TODO3
-rw-r--r--applause.lua15
2 files changed, 11 insertions, 7 deletions
diff --git a/TODO b/TODO
index c157b61..d49a831 100644
--- a/TODO
+++ b/TODO
@@ -3,9 +3,6 @@
* Stream:foreach() cannot be interrupted
Perhaps C core should export an interrupted variable that we can check from Lua.
For Stream:play() this is solved differently.
-* SndfileStream(...):sub(...) does not work for multi-channel audio files.
- The reason is that SubStream ticks in gtick() to seek in the source stream
- which cannot work in cached streams (SndfileStream:ctor() caches for multi-channel streams).
# Features
diff --git a/applause.lua b/applause.lua
index 2d86aa6..cac9704 100644
--- a/applause.lua
+++ b/applause.lua
@@ -1707,12 +1707,19 @@ function SubStream:gtick()
-- Perhaps ask stream to skip the first self.i-1 samples
-- Either gtick() could take an argument or introduce an
-- overwritable gtick_seek(). Problem as always is that
- -- this would have to chain to substreams.
+ -- this would have to chain to substreams and its now always
+ -- obvious how to pass it on (e.g. to MapStream...).
-- Perhaps, it would be wiser to let this be handled by
-- an optimizer stage that resolves Stream:sub()-calls.
- -- @fixme Actually, this is plain wrong and does not work
- -- if self.stream is cached.
- for _ = 1, self.i-1 do tick() end
+ for _ = 1, self.i-1 do
+ tick()
+ -- self.stream might be cached (somewhere down the line).
+ -- Therefore it is essential to clear the cache in order to progress
+ -- the stream.
+ -- This however might clear more than necessary,
+ -- resulting in superfluous recalculations.
+ table.clear(sampleCache)
+ end
local i = self.i