audio: SDL_OpenAudioDeviceStream() now allows a NULL spec.

This commit is contained in:
Ryan C. Gordon 2024-05-25 23:33:39 -04:00
parent 6a40a8eb12
commit 033793faed
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
2 changed files with 14 additions and 2 deletions

View File

@ -1324,7 +1324,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyAudioStream(SDL_AudioStream *stream)
* *
* The `spec` parameter represents the app's side of the audio stream. That * The `spec` parameter represents the app's side of the audio stream. That
* is, for recording audio, this will be the output format, and for playing * is, for recording audio, this will be the output format, and for playing
* audio, this will be the input format. * audio, this will be the input format. If spec is NULL, the system will
* choose the format, and the app can use SDL_GetAudioStreamFormat() to
* obtain this information later.
* *
* If you don't care about opening a specific audio device, you can (and * If you don't care about opening a specific audio device, you can (and
* probably _should_), use SDL_AUDIO_DEVICE_DEFAULT_OUTPUT for playback and * probably _should_), use SDL_AUDIO_DEVICE_DEFAULT_OUTPUT for playback and
@ -1335,9 +1337,12 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyAudioStream(SDL_AudioStream *stream)
* capturing). Otherwise, the callback will begin to fire once the device is * capturing). Otherwise, the callback will begin to fire once the device is
* unpaused. * unpaused.
* *
* Destroying the returned stream with SDL_DestroyAudioStream will also close
* the audio device associated with this stream.
*
* \param devid an audio device to open, or SDL_AUDIO_DEVICE_DEFAULT_OUTPUT or * \param devid an audio device to open, or SDL_AUDIO_DEVICE_DEFAULT_OUTPUT or
* SDL_AUDIO_DEVICE_DEFAULT_CAPTURE. * SDL_AUDIO_DEVICE_DEFAULT_CAPTURE.
* \param spec the audio stream's data format. Required. * \param spec the audio stream's data format. Can be NULL.
* \param callback A callback where the app will provide new data for * \param callback A callback where the app will provide new data for
* playback, or receive new data for capture. Can be NULL, in * playback, or receive new data for capture. Can be NULL, in
* which case the app will need to call SDL_PutAudioStreamData * which case the app will need to call SDL_PutAudioStreamData

View File

@ -1976,6 +1976,13 @@ SDL_AudioStream *SDL_OpenAudioDeviceStream(SDL_AudioDeviceID devid, const SDL_Au
SDL_assert(device != NULL); SDL_assert(device != NULL);
const SDL_bool iscapture = device->iscapture; const SDL_bool iscapture = device->iscapture;
// if the app didn't request a format _at all_, just make a stream that does no conversion; they can query for it later.
SDL_AudioSpec tmpspec;
if (!spec) {
SDL_copyp(&tmpspec, &device->spec);
spec = &tmpspec;
}
if (iscapture) { if (iscapture) {
stream = SDL_CreateAudioStream(&device->spec, spec); stream = SDL_CreateAudioStream(&device->spec, spec);
} else { } else {