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

wasm performance compared to bevy_audio #47

Closed
shnewto opened this issue May 14, 2022 · 6 comments
Closed

wasm performance compared to bevy_audio #47

shnewto opened this issue May 14, 2022 · 6 comments

Comments

@shnewto
Copy link

shnewto commented May 14, 2022

Hello! 👋
Thanks for all your work! I really love this crate ❤️ ❤️

I'm creating this issue because I'd like to document some surprising (to me) behavior of bevy_kira_audio / kira in comparison to bevy_audio 😄

Because of some crackling audio in the browser (see #27) I recently ported a project of mine to bevy_audio in a branch to experiment.

After porting I noticed a significant speedup to load times as well as the crackling audio going away.

Anecdotally, when using bevy_kira_audio it takes a couple seconds for my "Play" button to display and then a couple more after clicking "Play" for the scene to render. When I switched to bevy_audio, everything much quicker, i.e. no delay between startup and "Play" button or after clicking "Play".

project code: https://github.com/shnewto/limbo_pass

wasm branches

  • wasm-rodio
  • wasm-kira

Some of this is definitely a candidate for being system specific, I'm on macOS Monterey 12.3.1. I'd be curious to know if this is or isn't the case for someone with a different setup.

@shnewto
Copy link
Author

shnewto commented May 14, 2022

oof, I'm not sure about the behavior I mentioned above anymore. not sure what I bumped (maybe my head 😅) but my wasm-rodio branch seems to be crackling too and has a delay loading the scene 🤔

@NiklasEi
Copy link
Owner

Thank you for looking into this!
Let's see if #48 changes anything here. I've had fewer issues with Bevy 0.7 so far, but will investigate again after updating to latest Kira.

@shnewto
Copy link
Author

shnewto commented May 25, 2022

Closing because I've spent some time digging and am convinced the crunchy/crackling audio isn't a kira or bevy_kira_audio issue. It's still there when I use rodio. I did get the behavior to change when I increased a default raw audio buffer size in cpal so that's probably where I'll keep looking. Thanks for your time ❤️

@shnewto shnewto closed this as completed May 25, 2022
@NiklasEi
Copy link
Owner

NiklasEi commented Jun 4, 2022

Could you tell me more about the changes in cpal that improved the situation? Maybe this is something that could be made configurable through Kira/rodio?

@shnewto
Copy link
Author

shnewto commented Jun 6, 2022

@NiklasEi The changes I was experimenting with in cpal were mostly in the build_output_stream_raw function here https://github.com/RustAudio/cpal/blob/223f28262a80ac0b81688eb58507a4fb243e0694/src/host/webaudio/mod.rs#L185.

The crunchy audio while loading made me suspect some buffer underrun so I toggled the configuration buffer size, here https://github.com/RustAudio/cpal/blob/223f28262a80ac0b81688eb58507a4fb243e0694/src/host/webaudio/mod.rs#L202-L211

It does look like kira is building up a cpal config object https://github.com/tesselode/kira/blob/acb99e9e322da95cd91c4529d9a9f520e824ac56/crates/kira/src/manager/backend/cpal/wasm.rs#L51 so it might be feasible to expose it.

Fwiw though, I'm not sure toggling that buffer size is ultimately the fix for my crunchy audio issue because I had to make the buffer a lot bigger and from the documentation it seemed like the main use case is actually making it smaller 😅 .

@shnewto
Copy link
Author

shnewto commented Jun 6, 2022

if you're curious to see the behavior, it's deployed here https://limbo-pass-shnewto.vercel.app

At the moment, it sits on the title screen for a good few seconds before drawing the scene, I've been experimenting with trying to get things to load before playing the audio but so far haven't resolved the behavior yet

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