aboutsummaryrefslogtreecommitdiffhomepage
path: root/sndfile-stream.lua
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2024-03-27 17:56:47 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2024-03-27 18:10:30 +0300
commit22f88459f2950eb163a8844badd884b3e1d193cd (patch)
tree5f6be4d38bcb7993c727a3dd39b3db7cd221e70c /sndfile-stream.lua
parent476261186fb6ca6bccd752546d18b2bd63eb1a64 (diff)
downloadapplause2-22f88459f2950eb163a8844badd884b3e1d193cd.tar.gz
replaced Stream:foreach() with Stream:iter()
* This allows the native syntax `for f in Stream:iter() do ... end` without using lambda functions. Also you can use `break` and `return` statements. * On the other hand we cannot exploit the extended xpcall() semantics and had to introduce another lambda in Stream:play(). * In general the number of function calls per tick stays the same. Stream:gtick() itself could be used as an iterator, but Stream:iter() adds checking for CTRL+C, resetting of the sample cache and binding functions.
Diffstat (limited to 'sndfile-stream.lua')
-rw-r--r--sndfile-stream.lua4
1 files changed, 2 insertions, 2 deletions
diff --git a/sndfile-stream.lua b/sndfile-stream.lua
index 1c394b8..ba5a0f3 100644
--- a/sndfile-stream.lua
+++ b/sndfile-stream.lua
@@ -113,7 +113,7 @@ function Stream:save(filename, format)
local frame_buffer = sndfile.frame_type(channels)
- self:foreach(function(frame)
+ for frame in self:iter() do
-- NOTE: This should be (hopefully) automatically
-- unrolled for single-channel streams
-- Otherwise each loop copies an entire frame.
@@ -129,7 +129,7 @@ function Stream:save(filename, format)
-- (i.e. multichannel streams)
-- FIXME: Check return value
hnd:writef(frame_buffer)
- end)
+ end
hnd:close()
end