@@ -223,9 +223,9 @@ SDL_AudioDetectDevices_Default(void)
223223 SDL_assert (current_audio .impl .OnlyHasDefaultOutputDevice );
224224 SDL_assert (current_audio .impl .OnlyHasDefaultCaptureDevice || !current_audio .impl .HasCaptureSupport );
225225
226- SDL_AddAudioDevice (SDL_FALSE , DEFAULT_OUTPUT_DEVNAME , (void * ) ((size_t ) 0x1 ));
226+ SDL_AddAudioDevice (SDL_FALSE , DEFAULT_OUTPUT_DEVNAME , NULL , (void * ) ((size_t ) 0x1 ));
227227 if (current_audio .impl .HasCaptureSupport ) {
228- SDL_AddAudioDevice (SDL_TRUE , DEFAULT_INPUT_DEVNAME , (void * ) ((size_t ) 0x2 ));
228+ SDL_AddAudioDevice (SDL_TRUE , DEFAULT_INPUT_DEVNAME , NULL , (void * ) ((size_t ) 0x2 ));
229229 }
230230}
231231
@@ -377,7 +377,7 @@ finish_audio_entry_points_init(void)
377377/* device hotplug support... */
378378
379379static int
380- add_audio_device (const char * name , void * handle , SDL_AudioDeviceItem * * devices , int * devCount )
380+ add_audio_device (const char * name , SDL_AudioSpec * spec , void * handle , SDL_AudioDeviceItem * * devices , int * devCount )
381381{
382382 int retval = -1 ;
383383 SDL_AudioDeviceItem * item ;
@@ -400,6 +400,11 @@ add_audio_device(const char *name, void *handle, SDL_AudioDeviceItem **devices,
400400
401401 item -> dupenum = 0 ;
402402 item -> name = item -> original_name ;
403+ if (spec != NULL ) {
404+ SDL_memcpy (& item -> spec , spec , sizeof (SDL_AudioSpec ));
405+ } else {
406+ SDL_zero (item -> spec );
407+ }
403408 item -> handle = handle ;
404409
405410 SDL_LockMutex (current_audio .detectionLock );
@@ -437,16 +442,16 @@ add_audio_device(const char *name, void *handle, SDL_AudioDeviceItem **devices,
437442}
438443
439444static SDL_INLINE int
440- add_capture_device (const char * name , void * handle )
445+ add_capture_device (const char * name , SDL_AudioSpec * spec , void * handle )
441446{
442447 SDL_assert (current_audio .impl .HasCaptureSupport );
443- return add_audio_device (name , handle , & current_audio .inputDevices , & current_audio .inputDeviceCount );
448+ return add_audio_device (name , spec , handle , & current_audio .inputDevices , & current_audio .inputDeviceCount );
444449}
445450
446451static SDL_INLINE int
447- add_output_device (const char * name , void * handle )
452+ add_output_device (const char * name , SDL_AudioSpec * spec , void * handle )
448453{
449- return add_audio_device (name , handle , & current_audio .outputDevices , & current_audio .outputDeviceCount );
454+ return add_audio_device (name , spec , handle , & current_audio .outputDevices , & current_audio .outputDeviceCount );
450455}
451456
452457static void
@@ -472,9 +477,9 @@ free_device_list(SDL_AudioDeviceItem **devices, int *devCount)
472477
473478/* The audio backends call this when a new device is plugged in. */
474479void
475- SDL_AddAudioDevice (const int iscapture , const char * name , void * handle )
480+ SDL_AddAudioDevice (const int iscapture , const char * name , SDL_AudioSpec * spec , void * handle )
476481{
477- const int device_index = iscapture ? add_capture_device (name , handle ) : add_output_device (name , handle );
482+ const int device_index = iscapture ? add_capture_device (name , spec , handle ) : add_output_device (name , spec , handle );
478483 if (device_index != -1 ) {
479484 /* Post the event, if desired */
480485 if (SDL_GetEventState (SDL_AUDIODEVICEADDED ) == SDL_ENABLE ) {
@@ -1112,6 +1117,44 @@ SDL_GetAudioDeviceName(int index, int iscapture)
11121117}
11131118
11141119
1120+ int
1121+ SDL_GetAudioDeviceSpec (int index , int iscapture , SDL_AudioSpec * spec )
1122+ {
1123+ if (spec == NULL ) {
1124+ return SDL_InvalidParamError ("spec" );
1125+ }
1126+
1127+ SDL_zerop (spec );
1128+
1129+ if (!SDL_WasInit (SDL_INIT_AUDIO )) {
1130+ return SDL_SetError ("Audio subsystem is not initialized" );
1131+ }
1132+
1133+ if (iscapture && !current_audio .impl .HasCaptureSupport ) {
1134+ return SDL_SetError ("No capture support" );
1135+ }
1136+
1137+ if (index >= 0 ) {
1138+ SDL_AudioDeviceItem * item ;
1139+ int i ;
1140+
1141+ SDL_LockMutex (current_audio .detectionLock );
1142+ item = iscapture ? current_audio .inputDevices : current_audio .outputDevices ;
1143+ i = iscapture ? current_audio .inputDeviceCount : current_audio .outputDeviceCount ;
1144+ if (index < i ) {
1145+ for (i -- ; i > index ; i -- , item = item -> next ) {
1146+ SDL_assert (item != NULL );
1147+ }
1148+ SDL_assert (item != NULL );
1149+ SDL_memcpy (spec , & item -> spec , sizeof (SDL_AudioSpec ));
1150+ }
1151+ SDL_UnlockMutex (current_audio .detectionLock );
1152+ }
1153+
1154+ return 0 ;
1155+ }
1156+
1157+
11151158static void
11161159close_audio_device (SDL_AudioDevice * device )
11171160{
0 commit comments