Skip to content

fix(audio): fix SDL backend buffer sizing issues causing audio cuts/glitches when CPU is struggling#1107

Open
bassdr wants to merge 1 commit into
Kenix3:mainfrom
bassdr:fix/SDLAudioPlayer-SoundGlitches
Open

fix(audio): fix SDL backend buffer sizing issues causing audio cuts/glitches when CPU is struggling#1107
bassdr wants to merge 1 commit into
Kenix3:mainfrom
bassdr:fix/SDLAudioPlayer-SoundGlitches

Conversation

@bassdr

@bassdr bassdr commented May 19, 2026

Copy link
Copy Markdown
  • Double the hardware buffer size (SampleLength * 2) to reduce backend underruns without affecting emulator buffering logic
  • Remove the hardcoded 6000-frame fill guard in DoPlay(); the guard was an arbitrary threshold that caused audio starvation on slow frames. SDL's internal queue handles backpressure naturally
  • Read actual channel count from SDL's 'have' spec instead of assuming the requested value was honored
  • Minor: NULL → nullptr, coding style cleanup, improved log format

…CPU is struggling

- Use SDL_InitSubSystem(SDL_INIT_AUDIO) instead of SDL_Init() to avoid
  reinitializing unrelated SDL subsystems
- Double the hardware buffer size (SampleLength * 2) to reduce backend
  underruns without affecting emulator buffering logic
- Remove the hardcoded 6000-frame fill guard in DoPlay(); the guard was
  an arbitrary threshold that caused audio starvation on slow frames.
  SDL's internal queue handles backpressure naturally
- Read actual channel count from SDL's 'have' spec instead of assuming
  the requested value was honored
- Minor: NULL → nullptr, coding style cleanup, improved log format
@bassdr bassdr changed the title audio/SDL: fix buffer sizing issues causing audio cuts/glitches when … audio/SDL: fix buffer sizing issues causing audio cuts/glitches when CPU is struggling May 19, 2026
@bassdr bassdr changed the title audio/SDL: fix buffer sizing issues causing audio cuts/glitches when CPU is struggling fix(audio): fix SDL backend buffer sizing issues causing audio cuts/glitches when CPU is struggling May 19, 2026
Comment thread src/ship/audio/SDLAudioPlayer.cpp
Comment thread src/ship/audio/SDLAudioPlayer.cpp
Comment thread src/ship/audio/SDLAudioPlayer.cpp
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

Successfully merging this pull request may close these issues.

2 participants