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

Stutter on first playback of sound effect #405

Open
bkoropoff opened this issue Jun 13, 2023 · 6 comments
Open

Stutter on first playback of sound effect #405

bkoropoff opened this issue Jun 13, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@bkoropoff
Copy link
Contributor

bkoropoff commented Jun 13, 2023

dsda-doom is prone to stuttering when a lump is first accessed, especially if the wad file is on a spinning HDD. This is likely because it memory maps wad files, so data is read from disk just in time as the program accesses the mapped region. This can cause the main thread to hang while the disk spins up/seeks on first access of a lump. Options:

  • Don't use memory mapping
  • Get the OS to prefetch the entire mapping with posix_madvise(..., POSIX_MADV_WILLNEED) or PrefetchVirtualMemory
  • Strategically prefetch just graphics/sound lumps on wad load or map load
@bkoropoff
Copy link
Contributor Author

OK, there is existing sound precache code. Not sure why I'm getting stutter on first sound access, then.

@kraflab
Copy link
Owner

kraflab commented Jun 13, 2023

When I added that precache it fixed the problem for some people but not for others. No clue what causes it

@fabiangreffrath
Copy link
Collaborator

Well, while indeed the sound lumps are cached, the SFX that they contain are still not in the right samplerate/channels/bits configuration for SDL2_Mixer to feed to your hardware. What you need, though, is to cache the sound lumps converted to your sound hardware spec.

@kraflab
Copy link
Owner

kraflab commented Jul 20, 2024

@fabiangreffrath any idea how to go about doing that? 😸
Does it work already like that in woof?

@fabiangreffrath
Copy link
Collaborator

We had this in Woof before we did the switch from SDL2_Mixer to OpenAL Soft. What you will need to do, in a nut shell, is to load the sound lumps, convert them to your current format/channels/samplerate configuration, store this data in a buffer and feed this into the SDL Mixer.

A complete implementation of this solution can be found in our CacheSound() function at this point of the code history, i.e. right before we switched over to OpenAL Soft. Please note that we use libsndfile to load non-Doom format sound samples, but I think there is already some solution in the PRBoom+ code base to load at least 16-bit WAV samples.

https://github.com/fabiangreffrath/woof/blob/49abe0d28a671ba9c841446ac957dd22efca6635/src/i_sound.c#L209

@fabiangreffrath
Copy link
Collaborator

Second part, call CacheSound() for every sound effect once at engine start:

https://github.com/fabiangreffrath/woof/blob/49abe0d28a671ba9c841446ac957dd22efca6635/src/i_sound.c#L706

@kraflab kraflab added the enhancement New feature or request label Jul 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants