Skip to content

Commit 83cc3bc

Browse files
committed
audio: Opened device spec must be >= simple minimums, not device's defaults.
Fixes #13159.
1 parent 14a4ae5 commit 83cc3bc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/audio/SDL_audio.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,9 +1771,14 @@ static bool OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec
17711771
something low quality, like an old game using S8/8000Hz audio, from ruining a music thing playing at CD quality that tries to open later.
17721772
(or some VoIP library that opens for mono output ruining your surround-sound game because it got there first).
17731773
These are just requests! The backend may change any of these values during OpenDevice method! */
1774-
device->spec.format = (SDL_AUDIO_BITSIZE(device->default_spec.format) >= SDL_AUDIO_BITSIZE(spec.format)) ? device->default_spec.format : spec.format;
1775-
device->spec.freq = SDL_max(device->default_spec.freq, spec.freq);
1776-
device->spec.channels = SDL_max(device->default_spec.channels, spec.channels);
1774+
1775+
const SDL_AudioFormat minimum_format = device->recording ? DEFAULT_AUDIO_RECORDING_FORMAT : DEFAULT_AUDIO_PLAYBACK_FORMAT;
1776+
const int minimum_channels = device->recording ? DEFAULT_AUDIO_RECORDING_CHANNELS : DEFAULT_AUDIO_PLAYBACK_CHANNELS;
1777+
const int minimum_freq = device->recording ? DEFAULT_AUDIO_RECORDING_FREQUENCY : DEFAULT_AUDIO_PLAYBACK_FREQUENCY;
1778+
1779+
device->spec.format = (SDL_AUDIO_BITSIZE(minimum_format) >= SDL_AUDIO_BITSIZE(spec.format)) ? minimum_format : spec.format;
1780+
device->spec.channels = SDL_max(minimum_channels, spec.channels);
1781+
device->spec.freq = SDL_max(minimum_freq, spec.freq);
17771782
device->sample_frames = SDL_GetDefaultSampleFramesFromFreq(device->spec.freq);
17781783
SDL_UpdatedAudioDeviceFormat(device); // start this off sane.
17791784

0 commit comments

Comments
 (0)