Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio Playback stops after ~1 second in compatibility mode #2

Closed
jiaaro opened this issue Sep 14, 2020 · 4 comments
Closed

Audio Playback stops after ~1 second in compatibility mode #2

jiaaro opened this issue Sep 14, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@jiaaro
Copy link

jiaaro commented Sep 14, 2020

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

@Davidobot Davidobot added the bug Something isn't working label Sep 17, 2020
@Davidobot
Copy link
Owner

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?

@rameshvarun
Copy link

rameshvarun commented Nov 18, 2021

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()

@Davidobot
Copy link
Owner

Davidobot commented Nov 18, 2021

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.

@Davidobot Davidobot pinned this issue Nov 18, 2021
This was referenced Jun 9, 2022
@Davidobot
Copy link
Owner

Fixed in 8f9a7b8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants