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

Change: Use same audio buffer size and config parameter for all sound drivers. #12227

Merged
merged 1 commit into from Mar 7, 2024

Conversation

PeterN
Copy link
Member

@PeterN PeterN commented Mar 7, 2024

Motivation / Problem

For Allegro, SDL and SDLv2 sound drivers, the parameter to change audio frame size is samples, however for the two Windows sound drivers (win32 and xaudio2) the parameter is named bufsize.

The default value for all drivers that use samples is 1024, but the default for drivers that use bufsize is 8192.

At 44100 Hz, these sizes provide a latency per buffer (usually there are at least 2 buffers) of 23 ms and 186 ms respectively.

Our audio mixer is limited to only playing 8 sound effects at once, and that limit applies to the whole buffer size. Therefore with a larger buffer size, it is more likely that mixer channels will be used up and new sounds get blocked from playing.

Description

Bring the two Windows driver in line by changing the parameter name to samples for all drivers, and change the default buffer size to 1024.

Limitations

This does not touch the Cocoa driver, with how the macOS API works we don't actually set the buffer size and just use what we're given.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

…nd drivers.

Windows drivers used a default buffer size of 8192 instead of 1024, which results in a considerable 186ms latency.
@PeterN
Copy link
Member Author

PeterN commented Mar 7, 2024

Forgot to mention. Due to how our audio mixer works, all sounds are started at the start of the audio buffer. Therefore, if the game tick (27ms) is shorter than the 'audio tick' (186ms), sounds started on different game ticks will be started at the same time in the audio mixer.

This is mitigated (but not fully resolved) by this change.

@PeterN PeterN merged commit 25aeb1c into OpenTTD:master Mar 7, 2024
19 checks passed
@PeterN PeterN deleted the snd-buffer branch March 7, 2024 23:20
TrueBrain pushed a commit to TrueBrain/OpenTTD that referenced this pull request Mar 16, 2024
…nd drivers. (OpenTTD#12227)

Windows drivers used a default buffer size of 8192 instead of 1024, which results in a considerable 186ms latency.
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.

None yet

2 participants