src/audio/winmm/SDL_winmm.c
changeset 5593 ab22ca13c47f
parent 5588 57bfc2a2a452
child 6044 35448a5ea044
     1.1 --- a/src/audio/winmm/SDL_winmm.c	Thu Aug 04 01:07:09 2011 -0400
     1.2 +++ b/src/audio/winmm/SDL_winmm.c	Thu Aug 04 00:31:11 2011 -0400
     1.3 @@ -33,89 +33,33 @@
     1.4  #include "win_ce_semaphore.h"
     1.5  #endif
     1.6  
     1.7 -
     1.8 -/* !!! FIXME: this is a cut and paste of SDL_FreeUnixAudioDevices(),
     1.9 - * !!! FIXME:  which is more proof this needs to be managed in SDL_audio.c
    1.10 - * !!! FIXME:  and not in drivers.
    1.11 - */
    1.12 -static void
    1.13 -FreeWaveOutAudioDevices(char ***devices, int *devCount)
    1.14 -{
    1.15 -    int i = *devCount;
    1.16 -    if ((i > 0) && (*devices != NULL)) {
    1.17 -        while (i--) {
    1.18 -            SDL_free((*devices)[i]);
    1.19 -        }
    1.20 -    }
    1.21 -
    1.22 -    if (*devices != NULL) {
    1.23 -        SDL_free(*devices);
    1.24 -    }
    1.25 -
    1.26 -    *devices = NULL;
    1.27 -    *devCount = 0;
    1.28 +#define DETECT_DEV_IMPL(typ, capstyp) \
    1.29 +static void DetectWave##typ##Devs(SDL_AddAudioDevice addfn) { \
    1.30 +    const UINT devcount = wave##typ##GetNumDevs(); \
    1.31 +    capstyp caps; \
    1.32 +    UINT i; \
    1.33 +    for (i = 0; i < devcount; i++) { \
    1.34 +        if (wave##typ##GetDevCaps(i,&caps,sizeof(caps))==MMSYSERR_NOERROR) { \
    1.35 +            char *name = WIN_StringToUTF8(caps.szPname); \
    1.36 +            if (name != NULL) { \
    1.37 +                addfn(name); \
    1.38 +                SDL_free(name); \
    1.39 +            } \
    1.40 +        } \
    1.41 +    } \
    1.42  }
    1.43  
    1.44 -static char **outputDevices = NULL;
    1.45 -static int outputDeviceCount = 0;
    1.46 -static char **inputDevices = NULL;
    1.47 -static int inputDeviceCount = 0;
    1.48 +DETECT_DEV_IMPL(Out, WAVEOUTCAPS)
    1.49 +DETECT_DEV_IMPL(In, WAVEINCAPS)
    1.50  
    1.51 -static int
    1.52 -DetectWaveOutDevices(void)
    1.53 -{
    1.54 -    UINT i;
    1.55 -    const UINT devcount = waveOutGetNumDevs();
    1.56 -    WAVEOUTCAPS caps;
    1.57 -    FreeWaveOutAudioDevices(&outputDevices, &outputDeviceCount);
    1.58 -    outputDevices = (const char **) SDL_malloc(sizeof (char *) * devcount);
    1.59 -    for (i = 0; i < devcount; i++) {
    1.60 -        if (waveOutGetDevCaps(i, &caps, sizeof (caps)) == MMSYSERR_NOERROR) {
    1.61 -            outputDevices[outputDeviceCount] = WIN_StringToUTF8(caps.szPname);
    1.62 -            if (outputDevices[outputDeviceCount] != NULL) {
    1.63 -                outputDeviceCount++;
    1.64 -            }
    1.65 -        }
    1.66 -    }
    1.67 -    return outputDeviceCount;
    1.68 -}
    1.69 -
    1.70 -static int
    1.71 -DetectWaveInDevices(void)
    1.72 +static void
    1.73 +WINMM_DetectDevices(int iscapture, SDL_AddAudioDevice addfn)
    1.74  {
    1.75 -    UINT i;
    1.76 -    const UINT devcount = waveInGetNumDevs();
    1.77 -    WAVEINCAPS caps;
    1.78 -    FreeWaveInAudioDevices(&inputDevices, &inputDeviceCount);
    1.79 -    inputDevices = (const char **) SDL_malloc(sizeof (char *) * devcount);
    1.80 -    for (i = 0; i < devcount; i++) {
    1.81 -        if (waveInGetDevCaps(i, &caps, sizeof (caps)) == MMSYSERR_NOERROR) {
    1.82 -            inputDevices[inputDeviceCount] = WIN_StringToUTF8(caps.szPname);
    1.83 -            if (inputDevices[inputDeviceCount] != NULL) {
    1.84 -                inputDeviceCount++;
    1.85 -            }
    1.86 -        }
    1.87 +    if (iscapture) {
    1.88 +        DetectWaveInDevs(addfn);
    1.89 +    } else {
    1.90 +        DetectWaveOutDevs(addfn);
    1.91      }
    1.92 -    return inputDeviceCount;
    1.93 -}
    1.94 -
    1.95 -static int
    1.96 -WINMM_DetectDevices(int iscapture)
    1.97 -{
    1.98 -    return (iscapture) ? DetectWaveInDevices() : DetectWaveOutDevices();
    1.99 -}
   1.100 -
   1.101 -static const char *
   1.102 -WINMM_GetDeviceName(int index, int iscapture)
   1.103 -{
   1.104 -    if ((iscapture) && (index < inputDeviceCount)) {
   1.105 -        return inputDevices[index];
   1.106 -    } else if ((!iscapture) && (index < outputDeviceCount)) {
   1.107 -        return outputDevices[index];
   1.108 -    }
   1.109 -
   1.110 -    SDL_SetError("No such device");
   1.111 -    return NULL;
   1.112  }
   1.113  
   1.114  static void CALLBACK
   1.115 @@ -448,7 +392,6 @@
   1.116  {
   1.117      /* Set the function pointers */
   1.118      impl->DetectDevices = WINMM_DetectDevices;
   1.119 -    impl->GetDeviceName = WINMM_GetDeviceName;
   1.120      impl->OpenDevice = WINMM_OpenDevice;
   1.121      impl->PlayDevice = WINMM_PlayDevice;
   1.122      impl->WaitDevice = WINMM_WaitDevice;