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

Sound: Play one-off sound, then stop audio thread again? #66

Closed
BafDyce opened this issue Dec 25, 2020 · 7 comments
Closed

Sound: Play one-off sound, then stop audio thread again? #66

BafDyce opened this issue Dec 25, 2020 · 7 comments

Comments

@BafDyce
Copy link

BafDyce commented Dec 25, 2020

I would like to add some sound an application. However, I only need to play a short sound (a few seconds) every few minutes. When using rg3d-sound, the Context spawns a mixer thread in the background which consumes 100% cpu (of one core). Unfortunately, I cannot find a way to stop this thread again (not even if I execute std::mem::drop(context) after playing the sound).

Is there some way to create a Context in such a way that it automatically stops itself again after playing the sound, so that my application doesnt need that high CPU resources all the time?

@mrDIMAS
Copy link
Member

mrDIMAS commented Dec 25, 2020

Hello! It actually sounds like a bug in a backend. Which OS do you use?

I just checked how it works on Windows and single core load was around 2-5%.

@BafDyce
Copy link
Author

BafDyce commented Dec 25, 2020

Hi! Thanks for the quick response, given that its holiday season :)

I'm on Linux, so using the alsa backend.

@mrDIMAS
Copy link
Member

mrDIMAS commented Dec 25, 2020

Should be fixed now. Changes are in 34591e9 . Could you please confirm if CPU usage is ok now?

@mrDIMAS
Copy link
Member

mrDIMAS commented Dec 25, 2020

I checked on virtual machine and it was something around 0.6-1.0%, previously it was ~98%.

@BafDyce
Copy link
Author

BafDyce commented Dec 26, 2020

Edit: Figured my problems out. (Note: When upgrading from 0.18.0, one has to create a SoundEngine and register the context there)

YES, the issue is now fixed! There's no thread consuming 100% CPU anymore. CPU usage is back to very low levels (as expected). Thanks for the quick work!

@BafDyce
Copy link
Author

BafDyce commented Dec 26, 2020

Note: I don't know if its a side effect or if it worked before already but (at least on my system) sounds also play flawlessly now in debug mode.

@mrDIMAS
Copy link
Member

mrDIMAS commented Dec 26, 2020

Cool. Yeah, I changed design a bit to support multiple contexts. I'm closing the issue then, it is good that you spotted this issue, thanks! I'll try to publish 0.19.0 on crates.io as soon as possible.

@mrDIMAS mrDIMAS closed this as completed Dec 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants