Forráskód Böngészése

audio: SDL_OpenAudioDeviceStream() now allows a NULL spec.

Ryan C. Gordon 10 hónapja
szülő
commit
033793faed
2 módosított fájl, 14 hozzáadás és 2 törlés
  1. 7 2
      include/SDL3/SDL_audio.h
  2. 7 0
      src/audio/SDL_audio.c

+ 7 - 2
include/SDL3/SDL_audio.h

@@ -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
  * 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
  * 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
  * 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
  *              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
  *                 playback, or receive new data for capture. Can be NULL, in
  *                 which case the app will need to call SDL_PutAudioStreamData

+ 7 - 0
src/audio/SDL_audio.c

@@ -1976,6 +1976,13 @@ SDL_AudioStream *SDL_OpenAudioDeviceStream(SDL_AudioDeviceID devid, const SDL_Au
         SDL_assert(device != NULL);
         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) {
             stream = SDL_CreateAudioStream(&device->spec, spec);
         } else {