src/audio/winmm/SDL_winmm.c
changeset 8585 2d08b56cbfa9
parent 8149 681eb46b8ac4
child 9394 bb28e5281770
equal deleted inserted replaced
8584:58a69af25ccc 8585:2d08b56cbfa9
    96 }
    96 }
    97 
    97 
    98 static int
    98 static int
    99 SetMMerror(char *function, MMRESULT code)
    99 SetMMerror(char *function, MMRESULT code)
   100 {
   100 {
   101     size_t len;
   101     int len;
   102     char errbuf[MAXERRORLENGTH];
   102     char errbuf[MAXERRORLENGTH];
   103     wchar_t werrbuf[MAXERRORLENGTH];
   103     wchar_t werrbuf[MAXERRORLENGTH];
   104 
   104 
   105     SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function);
   105     SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function);
   106     len = SDL_strlen(errbuf);
   106     len = SDL_static_cast(int, SDL_strlen(errbuf));
   107 
   107 
   108     waveOutGetErrorText(code, werrbuf, MAXERRORLENGTH - len);
   108     waveOutGetErrorText(code, werrbuf, MAXERRORLENGTH - len);
   109     WideCharToMultiByte(CP_ACP, 0, werrbuf, -1, errbuf + len,
   109     WideCharToMultiByte(CP_ACP, 0, werrbuf, -1, errbuf + len,
   110                         MAXERRORLENGTH - len, NULL, NULL);
   110                         MAXERRORLENGTH - len, NULL, NULL);
   111 
   111 
   194         this->hidden = NULL;
   194         this->hidden = NULL;
   195     }
   195     }
   196 }
   196 }
   197 
   197 
   198 static SDL_bool
   198 static SDL_bool
   199 PrepWaveFormat(_THIS, UINT_PTR devId, WAVEFORMATEX *pfmt, const int iscapture)
   199 PrepWaveFormat(_THIS, UINT devId, WAVEFORMATEX *pfmt, const int iscapture)
   200 {
   200 {
   201     SDL_zerop(pfmt);
   201     SDL_zerop(pfmt);
   202 
   202 
   203     if (SDL_AUDIO_ISFLOAT(this->spec.format)) {
   203     if (SDL_AUDIO_ISFLOAT(this->spec.format)) {
   204         pfmt->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
   204         pfmt->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
   224 {
   224 {
   225     SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
   225     SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
   226     int valid_datatype = 0;
   226     int valid_datatype = 0;
   227     MMRESULT result;
   227     MMRESULT result;
   228     WAVEFORMATEX waveformat;
   228     WAVEFORMATEX waveformat;
   229     UINT_PTR devId = WAVE_MAPPER;  /* WAVE_MAPPER == choose system's default */
   229     UINT devId = WAVE_MAPPER;  /* WAVE_MAPPER == choose system's default */
   230     char *utf8 = NULL;
   230     char *utf8 = NULL;
   231     int i;
   231     UINT i;
   232 
   232 
   233     if (devname != NULL) {  /* specific device requested? */
   233     if (devname != NULL) {  /* specific device requested? */
   234         if (iscapture) {
   234         if (iscapture) {
   235             const int devcount = (int) waveInGetNumDevs();
   235             const UINT devcount = waveInGetNumDevs();
   236             WAVEINCAPS caps;
   236             WAVEINCAPS caps;
   237             for (i = 0; (i < devcount) && (devId == WAVE_MAPPER); i++) {
   237             for (i = 0; (i < devcount) && (devId == WAVE_MAPPER); i++) {
   238                 result = waveInGetDevCaps(i, &caps, sizeof (caps));
   238                 result = waveInGetDevCaps(i, &caps, sizeof (caps));
   239                 if (result != MMSYSERR_NOERROR)
   239                 if (result != MMSYSERR_NOERROR)
   240                     continue;
   240                     continue;
   241                 else if ((utf8 = WIN_StringToUTF8(caps.szPname)) == NULL)
   241                 else if ((utf8 = WIN_StringToUTF8(caps.szPname)) == NULL)
   242                     continue;
   242                     continue;
   243                 else if (SDL_strcmp(devname, utf8) == 0)
   243                 else if (SDL_strcmp(devname, utf8) == 0)
   244                     devId = (UINT_PTR) i;
   244                     devId = i;
   245                 SDL_free(utf8);
   245                 SDL_free(utf8);
   246             }
   246             }
   247         } else {
   247         } else {
   248             const int devcount = (int) waveOutGetNumDevs();
   248             const UINT devcount = waveOutGetNumDevs();
   249             WAVEOUTCAPS caps;
   249             WAVEOUTCAPS caps;
   250             for (i = 0; (i < devcount) && (devId == WAVE_MAPPER); i++) {
   250             for (i = 0; (i < devcount) && (devId == WAVE_MAPPER); i++) {
   251                 result = waveOutGetDevCaps(i, &caps, sizeof (caps));
   251                 result = waveOutGetDevCaps(i, &caps, sizeof (caps));
   252                 if (result != MMSYSERR_NOERROR)
   252                 if (result != MMSYSERR_NOERROR)
   253                     continue;
   253                     continue;
   254                 else if ((utf8 = WIN_StringToUTF8(caps.szPname)) == NULL)
   254                 else if ((utf8 = WIN_StringToUTF8(caps.szPname)) == NULL)
   255                     continue;
   255                     continue;
   256                 else if (SDL_strcmp(devname, utf8) == 0)
   256                 else if (SDL_strcmp(devname, utf8) == 0)
   257                     devId = (UINT_PTR) i;
   257                     devId = i;
   258                 SDL_free(utf8);
   258                 SDL_free(utf8);
   259             }
   259             }
   260         }
   260         }
   261 
   261 
   262         if (devId == WAVE_MAPPER) {
   262         if (devId == WAVE_MAPPER) {