Skip to content

Commit 5c44678

Browse files
committed
audio: Opened device spec must be >= simple minimums, not device's defaults.
Fixes #13159. (cherry picked from commit 83cc3bc)
1 parent 0638fd5 commit 5c44678

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
@@ -1747,9 +1747,14 @@ static bool OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec
17471747
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.
17481748
(or some VoIP library that opens for mono output ruining your surround-sound game because it got there first).
17491749
These are just requests! The backend may change any of these values during OpenDevice method! */
1750-
device->spec.format = (SDL_AUDIO_BITSIZE(device->default_spec.format) >= SDL_AUDIO_BITSIZE(spec.format)) ? device->default_spec.format : spec.format;
1751-
device->spec.freq = SDL_max(device->default_spec.freq, spec.freq);
1752-
device->spec.channels = SDL_max(device->default_spec.channels, spec.channels);
1750+
1751+
const SDL_AudioFormat minimum_format = device->recording ? DEFAULT_AUDIO_RECORDING_FORMAT : DEFAULT_AUDIO_PLAYBACK_FORMAT;
1752+
const int minimum_channels = device->recording ? DEFAULT_AUDIO_RECORDING_CHANNELS : DEFAULT_AUDIO_PLAYBACK_CHANNELS;
1753+
const int minimum_freq = device->recording ? DEFAULT_AUDIO_RECORDING_FREQUENCY : DEFAULT_AUDIO_PLAYBACK_FREQUENCY;
1754+
1755+
device->spec.format = (SDL_AUDIO_BITSIZE(minimum_format) >= SDL_AUDIO_BITSIZE(spec.format)) ? minimum_format : spec.format;
1756+
device->spec.channels = SDL_max(minimum_channels, spec.channels);
1757+
device->spec.freq = SDL_max(minimum_freq, spec.freq);
17531758
device->sample_frames = SDL_GetDefaultSampleFramesFromFreq(device->spec.freq);
17541759
SDL_UpdatedAudioDeviceFormat(device); // start this off sane.
17551760

0 commit comments

Comments
 (0)