aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2015-04-11 14:55:33 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2015-04-11 14:59:27 +0200
commit1a86ac921e28ae259d3ec2125812fdf5e3b75f1f (patch)
tree905cc44b766552f36f91bc6e9a9940b43398b1d4
parente9f20b8a1a3e58c8832bf4bc74afb1c7917fd07e (diff)
downloadapplause2-1a86ac921e28ae259d3ec2125812fdf5e3b75f1f.tar.gz
stop garbage collector temporarily during play()
This improves the real-time properties of sample generation since it avoids CPU spkikes. On the other hand, this may not be ideal as playing a long streams could have non-constant space requirements now. A proper solution would probably involve calling the garbage collector incrementally during the play() loop.
-rw-r--r--applause.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/applause.c b/applause.c
index b0a07dc..b57076d 100644
--- a/applause.c
+++ b/applause.c
@@ -169,6 +169,14 @@ l_Stream_play(lua_State *L)
/* the tick generator function should now be on top of the stack */
luaL_checktype(L, -1, LUA_TFUNCTION);
+ /*
+ * Perform garbage collection cycle and turn it off
+ * temporarily. This improves the realtime properties
+ * of the sample generation loop below.
+ */
+ lua_gc(L, LUA_GCCOLLECT, 0);
+ lua_gc(L, LUA_GCSTOP, 0);
+
for (;;) {
jack_default_audio_sample_t sample;
@@ -183,7 +191,12 @@ l_Stream_play(lua_State *L)
break;
/* copy sample into ring buffer */
- sample = (jack_default_audio_sample_t)luaL_checknumber(L, -1);
+ /*
+ * FIXME: What if sample isn't a number. This
+ * should be handled. But don't forget to restart
+ * the garbage collector
+ */
+ sample = (jack_default_audio_sample_t)lua_tonumber(L, -1);
/*
* FIXME: Buffer may be full -- perhaps we should wait on a
* semaphore
@@ -194,6 +207,8 @@ l_Stream_play(lua_State *L)
lua_pop(L, 1);
}
+ lua_gc(L, LUA_GCRESTART, 0);
+
/* any remaining stack elements are automatically popped */
return 0;
}