Closed jiaaro closed 2 years ago
Issue is more complex than it seems. Quoting slime:
I'm not sure what the love.js code does currently so maybe this is a redundant idea, but would it make sense for love.event.pump to also process audio, when threads aren't available?
I was able to fix this with the following patch. All it does is call the pool->update function in Event:pump(), which then triggers individual sources to decode more samples into their buffer.
This function is normally called in a loop by a thread, so there are probably some inefficiencies introduced by calling it every frame.
diff --git a/src/modules/audio/openal/Audio.h b/src/modules/audio/openal/Audio.h
index c73a0be7..2e63925a 100644
--- a/src/modules/audio/openal/Audio.h
+++ b/src/modules/audio/openal/Audio.h
@@ -130,6 +130,9 @@ class Audio : public love::audio::Audio
bool getEffectID(const char *name, ALuint &id);
+ // The Pool.
+ Pool *pool;
+
private:
void initializeEFX();
// The OpenAL device.
@@ -152,9 +155,6 @@ class Audio : public love::audio::Audio
int MAX_SCENE_EFFECTS = 64;
int MAX_SOURCE_EFFECTS = 64;
- // The Pool.
- Pool *pool;
-
class PoolThread: public thread::Threadable
{
protected:
diff --git a/src/modules/event/sdl/Event.cpp b/src/modules/event/sdl/Event.cpp
index a3f9ae39..af426001 100644
--- a/src/modules/event/sdl/Event.cpp
+++ b/src/modules/event/sdl/Event.cpp
@@ -30,6 +30,7 @@
#include "window/Window.h"
#include "common/Exception.h"
#include "audio/Audio.h"
+#include "audio/openal/Audio.h"
#include "common/config.h"
#include "timer/Timer.h"
@@ -129,6 +130,8 @@ void Event::pump()
msg->release();
}
}
+
+ Module::getInstance<love::audio::openal::Audio>(Module::M_AUDIO)->pool->update();
}
Message *Event::wait()
Oh that's very cool @rameshvarun!!! I'll test on mine and merge soon.
EDIT: I will probably tinker around with this to make this change happen only when the compat mode is being built, to prevent it from adversely affecting the full mode.
Even with "static", audio stops playing after about 1 second. In Safari it only plays the first time :play() is called, in chrome it plays the first ~1 second each time :play() is called