src/audio/windx5/SDL_dx5audio.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
child 1701 442248d4e738
     1.1 --- a/src/audio/windx5/SDL_dx5audio.c	Mon May 29 03:53:21 2006 +0000
     1.2 +++ b/src/audio/windx5/SDL_dx5audio.c	Mon May 29 04:04:35 2006 +0000
     1.3 @@ -32,31 +32,31 @@
     1.4  //#define USE_POSITION_NOTIFY
     1.5  
     1.6  /* DirectX function pointers for audio */
     1.7 -HRESULT (WINAPI * DSoundCreate) (LPGUID, LPDIRECTSOUND *, LPUNKNOWN);
     1.8 +HRESULT(WINAPI * DSoundCreate) (LPGUID, LPDIRECTSOUND *, LPUNKNOWN);
     1.9  
    1.10  /* Audio driver functions */
    1.11 -static int DX5_OpenAudio (_THIS, SDL_AudioSpec * spec);
    1.12 -static void DX5_ThreadInit (_THIS);
    1.13 -static void DX5_WaitAudio_BusyWait (_THIS);
    1.14 +static int DX5_OpenAudio(_THIS, SDL_AudioSpec * spec);
    1.15 +static void DX5_ThreadInit(_THIS);
    1.16 +static void DX5_WaitAudio_BusyWait(_THIS);
    1.17  #ifdef USE_POSITION_NOTIFY
    1.18 -static void DX6_WaitAudio_EventWait (_THIS);
    1.19 +static void DX6_WaitAudio_EventWait(_THIS);
    1.20  #endif
    1.21 -static void DX5_PlayAudio (_THIS);
    1.22 -static Uint8 *DX5_GetAudioBuf (_THIS);
    1.23 -static void DX5_WaitDone (_THIS);
    1.24 -static void DX5_CloseAudio (_THIS);
    1.25 +static void DX5_PlayAudio(_THIS);
    1.26 +static Uint8 *DX5_GetAudioBuf(_THIS);
    1.27 +static void DX5_WaitDone(_THIS);
    1.28 +static void DX5_CloseAudio(_THIS);
    1.29  
    1.30  /* Audio driver bootstrap functions */
    1.31  
    1.32  static int
    1.33 -Audio_Available (void)
    1.34 +Audio_Available(void)
    1.35  {
    1.36      HINSTANCE DSoundDLL;
    1.37      int dsound_ok;
    1.38  
    1.39      /* Version check DSOUND.DLL (Is DirectX okay?) */
    1.40      dsound_ok = 0;
    1.41 -    DSoundDLL = LoadLibrary (TEXT ("DSOUND.DLL"));
    1.42 +    DSoundDLL = LoadLibrary(TEXT("DSOUND.DLL"));
    1.43      if (DSoundDLL != NULL) {
    1.44          /* We just use basic DirectSound, we're okay */
    1.45          /* Yay! */
    1.46 @@ -66,8 +66,8 @@
    1.47             in the audio - it sounds terrible.  Punt for now.
    1.48           */
    1.49          OSVERSIONINFO ver;
    1.50 -        ver.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
    1.51 -        GetVersionEx (&ver);
    1.52 +        ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    1.53 +        GetVersionEx(&ver);
    1.54          switch (ver.dwPlatformId) {
    1.55          case VER_PLATFORM_WIN32_NT:
    1.56              if (ver.dwMajorVersion > 4) {
    1.57 @@ -88,13 +88,12 @@
    1.58           * to fall back to the DIB driver. */
    1.59          if (dsound_ok) {
    1.60              /* DirectSoundCaptureCreate was added in DX5 */
    1.61 -            if (!GetProcAddress
    1.62 -                (DSoundDLL, TEXT ("DirectSoundCaptureCreate")))
    1.63 +            if (!GetProcAddress(DSoundDLL, TEXT("DirectSoundCaptureCreate")))
    1.64                  dsound_ok = 0;
    1.65  
    1.66          }
    1.67          /* Clean up.. */
    1.68 -        FreeLibrary (DSoundDLL);
    1.69 +        FreeLibrary(DSoundDLL);
    1.70      }
    1.71      return (dsound_ok);
    1.72  }
    1.73 @@ -103,67 +102,67 @@
    1.74  static HINSTANCE DSoundDLL = NULL;
    1.75  
    1.76  static void
    1.77 -DX5_Unload (void)
    1.78 +DX5_Unload(void)
    1.79  {
    1.80      if (DSoundDLL != NULL) {
    1.81 -        FreeLibrary (DSoundDLL);
    1.82 +        FreeLibrary(DSoundDLL);
    1.83          DSoundCreate = NULL;
    1.84          DSoundDLL = NULL;
    1.85      }
    1.86  }
    1.87  static int
    1.88 -DX5_Load (void)
    1.89 +DX5_Load(void)
    1.90  {
    1.91      int status;
    1.92  
    1.93 -    DX5_Unload ();
    1.94 -    DSoundDLL = LoadLibrary (TEXT ("DSOUND.DLL"));
    1.95 +    DX5_Unload();
    1.96 +    DSoundDLL = LoadLibrary(TEXT("DSOUND.DLL"));
    1.97      if (DSoundDLL != NULL) {
    1.98 -        DSoundCreate = (void *) GetProcAddress (DSoundDLL,
    1.99 -                                                TEXT ("DirectSoundCreate"));
   1.100 +        DSoundCreate = (void *) GetProcAddress(DSoundDLL,
   1.101 +                                               TEXT("DirectSoundCreate"));
   1.102      }
   1.103      if (DSoundDLL && DSoundCreate) {
   1.104          status = 0;
   1.105      } else {
   1.106 -        DX5_Unload ();
   1.107 +        DX5_Unload();
   1.108          status = -1;
   1.109      }
   1.110      return status;
   1.111  }
   1.112  
   1.113  static void
   1.114 -Audio_DeleteDevice (SDL_AudioDevice * device)
   1.115 +Audio_DeleteDevice(SDL_AudioDevice * device)
   1.116  {
   1.117 -    DX5_Unload ();
   1.118 -    SDL_free (device->hidden);
   1.119 -    SDL_free (device);
   1.120 +    DX5_Unload();
   1.121 +    SDL_free(device->hidden);
   1.122 +    SDL_free(device);
   1.123  }
   1.124  
   1.125  static SDL_AudioDevice *
   1.126 -Audio_CreateDevice (int devindex)
   1.127 +Audio_CreateDevice(int devindex)
   1.128  {
   1.129      SDL_AudioDevice *this;
   1.130  
   1.131      /* Load DirectX */
   1.132 -    if (DX5_Load () < 0) {
   1.133 +    if (DX5_Load() < 0) {
   1.134          return (NULL);
   1.135      }
   1.136  
   1.137      /* Initialize all variables that we clean on shutdown */
   1.138 -    this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice));
   1.139 +    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
   1.140      if (this) {
   1.141 -        SDL_memset (this, 0, (sizeof *this));
   1.142 +        SDL_memset(this, 0, (sizeof *this));
   1.143          this->hidden = (struct SDL_PrivateAudioData *)
   1.144 -            SDL_malloc ((sizeof *this->hidden));
   1.145 +            SDL_malloc((sizeof *this->hidden));
   1.146      }
   1.147      if ((this == NULL) || (this->hidden == NULL)) {
   1.148 -        SDL_OutOfMemory ();
   1.149 +        SDL_OutOfMemory();
   1.150          if (this) {
   1.151 -            SDL_free (this);
   1.152 +            SDL_free(this);
   1.153          }
   1.154          return (0);
   1.155      }
   1.156 -    SDL_memset (this->hidden, 0, (sizeof *this->hidden));
   1.157 +    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
   1.158  
   1.159      /* Set the function pointers */
   1.160      this->OpenAudio = DX5_OpenAudio;
   1.161 @@ -185,7 +184,7 @@
   1.162  };
   1.163  
   1.164  static void
   1.165 -SetDSerror (const char *function, int code)
   1.166 +SetDSerror(const char *function, int code)
   1.167  {
   1.168      static const char *error;
   1.169      static char errbuf[1024];
   1.170 @@ -227,15 +226,15 @@
   1.171          error = "Function not supported";
   1.172          break;
   1.173      default:
   1.174 -        SDL_snprintf (errbuf, SDL_arraysize (errbuf),
   1.175 -                      "%s: Unknown DirectSound error: 0x%x", function, code);
   1.176 +        SDL_snprintf(errbuf, SDL_arraysize(errbuf),
   1.177 +                     "%s: Unknown DirectSound error: 0x%x", function, code);
   1.178          break;
   1.179      }
   1.180      if (!errbuf[0]) {
   1.181 -        SDL_snprintf (errbuf, SDL_arraysize (errbuf), "%s: %s", function,
   1.182 -                      error);
   1.183 +        SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function,
   1.184 +                     error);
   1.185      }
   1.186 -    SDL_SetError ("%s", errbuf);
   1.187 +    SDL_SetError("%s", errbuf);
   1.188      return;
   1.189  }
   1.190  
   1.191 @@ -243,19 +242,19 @@
   1.192  static HWND mainwin = NULL;
   1.193  /* */
   1.194  void
   1.195 -DX5_SoundFocus (HWND hwnd)
   1.196 +DX5_SoundFocus(HWND hwnd)
   1.197  {
   1.198      mainwin = hwnd;
   1.199  }
   1.200  
   1.201  static void
   1.202 -DX5_ThreadInit (_THIS)
   1.203 +DX5_ThreadInit(_THIS)
   1.204  {
   1.205 -    SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_HIGHEST);
   1.206 +    SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
   1.207  }
   1.208  
   1.209  static void
   1.210 -DX5_WaitAudio_BusyWait (_THIS)
   1.211 +DX5_WaitAudio_BusyWait(_THIS)
   1.212  {
   1.213      DWORD status;
   1.214      DWORD cursor, junk;
   1.215 @@ -264,13 +263,13 @@
   1.216      /* Semi-busy wait, since we have no way of getting play notification
   1.217         on a primary mixing buffer located in hardware (DirectX 5.0)
   1.218       */
   1.219 -    result = IDirectSoundBuffer_GetCurrentPosition (mixbuf, &cursor, &junk);
   1.220 +    result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &cursor, &junk);
   1.221      if (result != DS_OK) {
   1.222          if (result == DSERR_BUFFERLOST) {
   1.223 -            IDirectSoundBuffer_Restore (mixbuf);
   1.224 +            IDirectSoundBuffer_Restore(mixbuf);
   1.225          }
   1.226  #ifdef DEBUG_SOUND
   1.227 -        SetDSerror ("DirectSound GetCurrentPosition", result);
   1.228 +        SetDSerror("DirectSound GetCurrentPosition", result);
   1.229  #endif
   1.230          return;
   1.231      }
   1.232 @@ -278,33 +277,33 @@
   1.233  
   1.234      while (cursor == playing) {
   1.235          /* FIXME: find out how much time is left and sleep that long */
   1.236 -        SDL_Delay (10);
   1.237 +        SDL_Delay(10);
   1.238  
   1.239          /* Try to restore a lost sound buffer */
   1.240 -        IDirectSoundBuffer_GetStatus (mixbuf, &status);
   1.241 +        IDirectSoundBuffer_GetStatus(mixbuf, &status);
   1.242          if ((status & DSBSTATUS_BUFFERLOST)) {
   1.243 -            IDirectSoundBuffer_Restore (mixbuf);
   1.244 -            IDirectSoundBuffer_GetStatus (mixbuf, &status);
   1.245 +            IDirectSoundBuffer_Restore(mixbuf);
   1.246 +            IDirectSoundBuffer_GetStatus(mixbuf, &status);
   1.247              if ((status & DSBSTATUS_BUFFERLOST)) {
   1.248                  break;
   1.249              }
   1.250          }
   1.251          if (!(status & DSBSTATUS_PLAYING)) {
   1.252 -            result = IDirectSoundBuffer_Play (mixbuf, 0, 0, DSBPLAY_LOOPING);
   1.253 +            result = IDirectSoundBuffer_Play(mixbuf, 0, 0, DSBPLAY_LOOPING);
   1.254              if (result == DS_OK) {
   1.255                  continue;
   1.256              }
   1.257  #ifdef DEBUG_SOUND
   1.258 -            SetDSerror ("DirectSound Play", result);
   1.259 +            SetDSerror("DirectSound Play", result);
   1.260  #endif
   1.261              return;
   1.262          }
   1.263  
   1.264          /* Find out where we are playing */
   1.265 -        result = IDirectSoundBuffer_GetCurrentPosition (mixbuf,
   1.266 -                                                        &cursor, &junk);
   1.267 +        result = IDirectSoundBuffer_GetCurrentPosition(mixbuf,
   1.268 +                                                       &cursor, &junk);
   1.269          if (result != DS_OK) {
   1.270 -            SetDSerror ("DirectSound GetCurrentPosition", result);
   1.271 +            SetDSerror("DirectSound GetCurrentPosition", result);
   1.272              return;
   1.273          }
   1.274          cursor /= mixlen;
   1.275 @@ -313,45 +312,45 @@
   1.276  
   1.277  #ifdef USE_POSITION_NOTIFY
   1.278  static void
   1.279 -DX6_WaitAudio_EventWait (_THIS)
   1.280 +DX6_WaitAudio_EventWait(_THIS)
   1.281  {
   1.282      DWORD status;
   1.283      HRESULT result;
   1.284  
   1.285      /* Try to restore a lost sound buffer */
   1.286 -    IDirectSoundBuffer_GetStatus (mixbuf, &status);
   1.287 +    IDirectSoundBuffer_GetStatus(mixbuf, &status);
   1.288      if ((status & DSBSTATUS_BUFFERLOST)) {
   1.289 -        IDirectSoundBuffer_Restore (mixbuf);
   1.290 -        IDirectSoundBuffer_GetStatus (mixbuf, &status);
   1.291 +        IDirectSoundBuffer_Restore(mixbuf);
   1.292 +        IDirectSoundBuffer_GetStatus(mixbuf, &status);
   1.293          if ((status & DSBSTATUS_BUFFERLOST)) {
   1.294              return;
   1.295          }
   1.296      }
   1.297      if (!(status & DSBSTATUS_PLAYING)) {
   1.298 -        result = IDirectSoundBuffer_Play (mixbuf, 0, 0, DSBPLAY_LOOPING);
   1.299 +        result = IDirectSoundBuffer_Play(mixbuf, 0, 0, DSBPLAY_LOOPING);
   1.300          if (result != DS_OK) {
   1.301  #ifdef DEBUG_SOUND
   1.302 -            SetDSerror ("DirectSound Play", result);
   1.303 +            SetDSerror("DirectSound Play", result);
   1.304  #endif
   1.305              return;
   1.306          }
   1.307      }
   1.308 -    WaitForSingleObject (audio_event, INFINITE);
   1.309 +    WaitForSingleObject(audio_event, INFINITE);
   1.310  }
   1.311  #endif /* USE_POSITION_NOTIFY */
   1.312  
   1.313  static void
   1.314 -DX5_PlayAudio (_THIS)
   1.315 +DX5_PlayAudio(_THIS)
   1.316  {
   1.317      /* Unlock the buffer, allowing it to play */
   1.318      if (locked_buf) {
   1.319 -        IDirectSoundBuffer_Unlock (mixbuf, locked_buf, mixlen, NULL, 0);
   1.320 +        IDirectSoundBuffer_Unlock(mixbuf, locked_buf, mixlen, NULL, 0);
   1.321      }
   1.322  
   1.323  }
   1.324  
   1.325  static Uint8 *
   1.326 -DX5_GetAudioBuf (_THIS)
   1.327 +DX5_GetAudioBuf(_THIS)
   1.328  {
   1.329      DWORD cursor, junk;
   1.330      HRESULT result;
   1.331 @@ -359,14 +358,14 @@
   1.332  
   1.333      /* Figure out which blocks to fill next */
   1.334      locked_buf = NULL;
   1.335 -    result = IDirectSoundBuffer_GetCurrentPosition (mixbuf, &cursor, &junk);
   1.336 +    result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &cursor, &junk);
   1.337      if (result == DSERR_BUFFERLOST) {
   1.338 -        IDirectSoundBuffer_Restore (mixbuf);
   1.339 -        result = IDirectSoundBuffer_GetCurrentPosition (mixbuf,
   1.340 -                                                        &cursor, &junk);
   1.341 +        IDirectSoundBuffer_Restore(mixbuf);
   1.342 +        result = IDirectSoundBuffer_GetCurrentPosition(mixbuf,
   1.343 +                                                       &cursor, &junk);
   1.344      }
   1.345      if (result != DS_OK) {
   1.346 -        SetDSerror ("DirectSound GetCurrentPosition", result);
   1.347 +        SetDSerror("DirectSound GetCurrentPosition", result);
   1.348          return (NULL);
   1.349      }
   1.350      cursor /= mixlen;
   1.351 @@ -375,53 +374,53 @@
   1.352      cursor *= mixlen;
   1.353  
   1.354      /* Lock the audio buffer */
   1.355 -    result = IDirectSoundBuffer_Lock (mixbuf, cursor, mixlen,
   1.356 -                                      (LPVOID *) & locked_buf, &rawlen, NULL,
   1.357 -                                      &junk, 0);
   1.358 +    result = IDirectSoundBuffer_Lock(mixbuf, cursor, mixlen,
   1.359 +                                     (LPVOID *) & locked_buf, &rawlen, NULL,
   1.360 +                                     &junk, 0);
   1.361      if (result == DSERR_BUFFERLOST) {
   1.362 -        IDirectSoundBuffer_Restore (mixbuf);
   1.363 -        result = IDirectSoundBuffer_Lock (mixbuf, cursor, mixlen,
   1.364 -                                          (LPVOID *) & locked_buf, &rawlen,
   1.365 -                                          NULL, &junk, 0);
   1.366 +        IDirectSoundBuffer_Restore(mixbuf);
   1.367 +        result = IDirectSoundBuffer_Lock(mixbuf, cursor, mixlen,
   1.368 +                                         (LPVOID *) & locked_buf, &rawlen,
   1.369 +                                         NULL, &junk, 0);
   1.370      }
   1.371      if (result != DS_OK) {
   1.372 -        SetDSerror ("DirectSound Lock", result);
   1.373 +        SetDSerror("DirectSound Lock", result);
   1.374          return (NULL);
   1.375      }
   1.376      return (locked_buf);
   1.377  }
   1.378  
   1.379  static void
   1.380 -DX5_WaitDone (_THIS)
   1.381 +DX5_WaitDone(_THIS)
   1.382  {
   1.383      Uint8 *stream;
   1.384  
   1.385      /* Wait for the playing chunk to finish */
   1.386 -    stream = this->GetAudioBuf (this);
   1.387 +    stream = this->GetAudioBuf(this);
   1.388      if (stream != NULL) {
   1.389 -        SDL_memset (stream, silence, mixlen);
   1.390 -        this->PlayAudio (this);
   1.391 +        SDL_memset(stream, silence, mixlen);
   1.392 +        this->PlayAudio(this);
   1.393      }
   1.394 -    this->WaitAudio (this);
   1.395 +    this->WaitAudio(this);
   1.396  
   1.397      /* Stop the looping sound buffer */
   1.398 -    IDirectSoundBuffer_Stop (mixbuf);
   1.399 +    IDirectSoundBuffer_Stop(mixbuf);
   1.400  }
   1.401  
   1.402  static void
   1.403 -DX5_CloseAudio (_THIS)
   1.404 +DX5_CloseAudio(_THIS)
   1.405  {
   1.406      if (sound != NULL) {
   1.407          if (mixbuf != NULL) {
   1.408              /* Clean up the audio buffer */
   1.409 -            IDirectSoundBuffer_Release (mixbuf);
   1.410 +            IDirectSoundBuffer_Release(mixbuf);
   1.411              mixbuf = NULL;
   1.412          }
   1.413          if (audio_event != NULL) {
   1.414 -            CloseHandle (audio_event);
   1.415 +            CloseHandle(audio_event);
   1.416              audio_event = NULL;
   1.417          }
   1.418 -        IDirectSound_Release (sound);
   1.419 +        IDirectSound_Release(sound);
   1.420          sound = NULL;
   1.421      }
   1.422  }
   1.423 @@ -431,9 +430,9 @@
   1.424     number of audio chunks available in the created buffer.
   1.425  */
   1.426  static int
   1.427 -CreatePrimary (LPDIRECTSOUND sndObj, HWND focus,
   1.428 -               LPDIRECTSOUNDBUFFER * sndbuf, WAVEFORMATEX * wavefmt,
   1.429 -               Uint32 chunksize)
   1.430 +CreatePrimary(LPDIRECTSOUND sndObj, HWND focus,
   1.431 +              LPDIRECTSOUNDBUFFER * sndbuf, WAVEFORMATEX * wavefmt,
   1.432 +              Uint32 chunksize)
   1.433  {
   1.434      HRESULT result;
   1.435      DSBUFFERDESC format;
   1.436 @@ -441,40 +440,40 @@
   1.437      int numchunks;
   1.438  
   1.439      /* Try to set primary mixing privileges */
   1.440 -    result = IDirectSound_SetCooperativeLevel (sndObj, focus,
   1.441 -                                               DSSCL_WRITEPRIMARY);
   1.442 +    result = IDirectSound_SetCooperativeLevel(sndObj, focus,
   1.443 +                                              DSSCL_WRITEPRIMARY);
   1.444      if (result != DS_OK) {
   1.445  #ifdef DEBUG_SOUND
   1.446 -        SetDSerror ("DirectSound SetCooperativeLevel", result);
   1.447 +        SetDSerror("DirectSound SetCooperativeLevel", result);
   1.448  #endif
   1.449          return (-1);
   1.450      }
   1.451  
   1.452      /* Try to create the primary buffer */
   1.453 -    SDL_memset (&format, 0, sizeof (format));
   1.454 -    format.dwSize = sizeof (format);
   1.455 +    SDL_memset(&format, 0, sizeof(format));
   1.456 +    format.dwSize = sizeof(format);
   1.457      format.dwFlags = (DSBCAPS_PRIMARYBUFFER | DSBCAPS_GETCURRENTPOSITION2);
   1.458      format.dwFlags |= DSBCAPS_STICKYFOCUS;
   1.459  #ifdef USE_POSITION_NOTIFY
   1.460      format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY;
   1.461  #endif
   1.462 -    result = IDirectSound_CreateSoundBuffer (sndObj, &format, sndbuf, NULL);
   1.463 +    result = IDirectSound_CreateSoundBuffer(sndObj, &format, sndbuf, NULL);
   1.464      if (result != DS_OK) {
   1.465  #ifdef DEBUG_SOUND
   1.466 -        SetDSerror ("DirectSound CreateSoundBuffer", result);
   1.467 +        SetDSerror("DirectSound CreateSoundBuffer", result);
   1.468  #endif
   1.469          return (-1);
   1.470      }
   1.471  
   1.472      /* Check the size of the fragment buffer */
   1.473 -    SDL_memset (&caps, 0, sizeof (caps));
   1.474 -    caps.dwSize = sizeof (caps);
   1.475 -    result = IDirectSoundBuffer_GetCaps (*sndbuf, &caps);
   1.476 +    SDL_memset(&caps, 0, sizeof(caps));
   1.477 +    caps.dwSize = sizeof(caps);
   1.478 +    result = IDirectSoundBuffer_GetCaps(*sndbuf, &caps);
   1.479      if (result != DS_OK) {
   1.480  #ifdef DEBUG_SOUND
   1.481 -        SetDSerror ("DirectSound GetCaps", result);
   1.482 +        SetDSerror("DirectSound GetCaps", result);
   1.483  #endif
   1.484 -        IDirectSoundBuffer_Release (*sndbuf);
   1.485 +        IDirectSoundBuffer_Release(*sndbuf);
   1.486          return (-1);
   1.487      }
   1.488      if ((chunksize > caps.dwBufferBytes) ||
   1.489 @@ -483,7 +482,7 @@
   1.490             -- this hopefully doesn't happen when 'chunksize' is a 
   1.491             power of 2.
   1.492           */
   1.493 -        IDirectSoundBuffer_Release (*sndbuf);
   1.494 +        IDirectSoundBuffer_Release(*sndbuf);
   1.495          SDL_SetError
   1.496              ("Primary buffer size is: %d, cannot break it into chunks of %d bytes\n",
   1.497               caps.dwBufferBytes, chunksize);
   1.498 @@ -492,12 +491,12 @@
   1.499      numchunks = (caps.dwBufferBytes / chunksize);
   1.500  
   1.501      /* Set the primary audio format */
   1.502 -    result = IDirectSoundBuffer_SetFormat (*sndbuf, wavefmt);
   1.503 +    result = IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt);
   1.504      if (result != DS_OK) {
   1.505  #ifdef DEBUG_SOUND
   1.506 -        SetDSerror ("DirectSound SetFormat", result);
   1.507 +        SetDSerror("DirectSound SetFormat", result);
   1.508  #endif
   1.509 -        IDirectSoundBuffer_Release (*sndbuf);
   1.510 +        IDirectSoundBuffer_Release(*sndbuf);
   1.511          return (-1);
   1.512      }
   1.513      return (numchunks);
   1.514 @@ -508,9 +507,9 @@
   1.515     number of audio chunks available in the created buffer.
   1.516  */
   1.517  static int
   1.518 -CreateSecondary (LPDIRECTSOUND sndObj, HWND focus,
   1.519 -                 LPDIRECTSOUNDBUFFER * sndbuf, WAVEFORMATEX * wavefmt,
   1.520 -                 Uint32 chunksize)
   1.521 +CreateSecondary(LPDIRECTSOUND sndObj, HWND focus,
   1.522 +                LPDIRECTSOUNDBUFFER * sndbuf, WAVEFORMATEX * wavefmt,
   1.523 +                Uint32 chunksize)
   1.524  {
   1.525      const int numchunks = 2;
   1.526      HRESULT result;
   1.527 @@ -520,23 +519,23 @@
   1.528  
   1.529      /* Try to set primary mixing privileges */
   1.530      if (focus) {
   1.531 -        result = IDirectSound_SetCooperativeLevel (sndObj,
   1.532 -                                                   focus, DSSCL_PRIORITY);
   1.533 +        result = IDirectSound_SetCooperativeLevel(sndObj,
   1.534 +                                                  focus, DSSCL_PRIORITY);
   1.535      } else {
   1.536 -        result = IDirectSound_SetCooperativeLevel (sndObj,
   1.537 -                                                   GetDesktopWindow (),
   1.538 -                                                   DSSCL_NORMAL);
   1.539 +        result = IDirectSound_SetCooperativeLevel(sndObj,
   1.540 +                                                  GetDesktopWindow(),
   1.541 +                                                  DSSCL_NORMAL);
   1.542      }
   1.543      if (result != DS_OK) {
   1.544  #ifdef DEBUG_SOUND
   1.545 -        SetDSerror ("DirectSound SetCooperativeLevel", result);
   1.546 +        SetDSerror("DirectSound SetCooperativeLevel", result);
   1.547  #endif
   1.548          return (-1);
   1.549      }
   1.550  
   1.551      /* Try to create the secondary buffer */
   1.552 -    SDL_memset (&format, 0, sizeof (format));
   1.553 -    format.dwSize = sizeof (format);
   1.554 +    SDL_memset(&format, 0, sizeof(format));
   1.555 +    format.dwSize = sizeof(format);
   1.556      format.dwFlags = DSBCAPS_GETCURRENTPOSITION2;
   1.557  #ifdef USE_POSITION_NOTIFY
   1.558      format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY;
   1.559 @@ -549,34 +548,34 @@
   1.560      format.dwBufferBytes = numchunks * chunksize;
   1.561      if ((format.dwBufferBytes < DSBSIZE_MIN) ||
   1.562          (format.dwBufferBytes > DSBSIZE_MAX)) {
   1.563 -        SDL_SetError ("Sound buffer size must be between %d and %d",
   1.564 -                      DSBSIZE_MIN / numchunks, DSBSIZE_MAX / numchunks);
   1.565 +        SDL_SetError("Sound buffer size must be between %d and %d",
   1.566 +                     DSBSIZE_MIN / numchunks, DSBSIZE_MAX / numchunks);
   1.567          return (-1);
   1.568      }
   1.569      format.dwReserved = 0;
   1.570      format.lpwfxFormat = wavefmt;
   1.571 -    result = IDirectSound_CreateSoundBuffer (sndObj, &format, sndbuf, NULL);
   1.572 +    result = IDirectSound_CreateSoundBuffer(sndObj, &format, sndbuf, NULL);
   1.573      if (result != DS_OK) {
   1.574 -        SetDSerror ("DirectSound CreateSoundBuffer", result);
   1.575 +        SetDSerror("DirectSound CreateSoundBuffer", result);
   1.576          return (-1);
   1.577      }
   1.578 -    IDirectSoundBuffer_SetFormat (*sndbuf, wavefmt);
   1.579 +    IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt);
   1.580  
   1.581      /* Silence the initial audio buffer */
   1.582 -    result = IDirectSoundBuffer_Lock (*sndbuf, 0, format.dwBufferBytes,
   1.583 -                                      (LPVOID *) & pvAudioPtr1,
   1.584 -                                      &dwAudioBytes1,
   1.585 -                                      (LPVOID *) & pvAudioPtr2,
   1.586 -                                      &dwAudioBytes2, DSBLOCK_ENTIREBUFFER);
   1.587 +    result = IDirectSoundBuffer_Lock(*sndbuf, 0, format.dwBufferBytes,
   1.588 +                                     (LPVOID *) & pvAudioPtr1,
   1.589 +                                     &dwAudioBytes1,
   1.590 +                                     (LPVOID *) & pvAudioPtr2,
   1.591 +                                     &dwAudioBytes2, DSBLOCK_ENTIREBUFFER);
   1.592      if (result == DS_OK) {
   1.593          if (wavefmt->wBitsPerSample == 8) {
   1.594 -            SDL_memset (pvAudioPtr1, 0x80, dwAudioBytes1);
   1.595 +            SDL_memset(pvAudioPtr1, 0x80, dwAudioBytes1);
   1.596          } else {
   1.597 -            SDL_memset (pvAudioPtr1, 0x00, dwAudioBytes1);
   1.598 +            SDL_memset(pvAudioPtr1, 0x00, dwAudioBytes1);
   1.599          }
   1.600 -        IDirectSoundBuffer_Unlock (*sndbuf,
   1.601 -                                   (LPVOID) pvAudioPtr1, dwAudioBytes1,
   1.602 -                                   (LPVOID) pvAudioPtr2, dwAudioBytes2);
   1.603 +        IDirectSoundBuffer_Unlock(*sndbuf,
   1.604 +                                  (LPVOID) pvAudioPtr1, dwAudioBytes1,
   1.605 +                                  (LPVOID) pvAudioPtr2, dwAudioBytes2);
   1.606      }
   1.607  
   1.608      /* We're ready to go */
   1.609 @@ -586,7 +585,7 @@
   1.610  /* This function tries to set position notify events on the mixing buffer */
   1.611  #ifdef USE_POSITION_NOTIFY
   1.612  static int
   1.613 -CreateAudioEvent (_THIS)
   1.614 +CreateAudioEvent(_THIS)
   1.615  {
   1.616      LPDIRECTSOUNDNOTIFY notify;
   1.617      DSBPOSITIONNOTIFY *notify_positions;
   1.618 @@ -598,23 +597,23 @@
   1.619      notify = NULL;
   1.620  
   1.621      /* Query for the interface */
   1.622 -    result = IDirectSoundBuffer_QueryInterface (mixbuf,
   1.623 -                                                &IID_IDirectSoundNotify,
   1.624 -                                                (void *) &notify);
   1.625 +    result = IDirectSoundBuffer_QueryInterface(mixbuf,
   1.626 +                                               &IID_IDirectSoundNotify,
   1.627 +                                               (void *) &notify);
   1.628      if (result != DS_OK) {
   1.629          goto done;
   1.630      }
   1.631  
   1.632      /* Allocate the notify structures */
   1.633 -    notify_positions = (DSBPOSITIONNOTIFY *) SDL_malloc (NUM_BUFFERS *
   1.634 -                                                         sizeof
   1.635 -                                                         (*notify_positions));
   1.636 +    notify_positions = (DSBPOSITIONNOTIFY *) SDL_malloc(NUM_BUFFERS *
   1.637 +                                                        sizeof
   1.638 +                                                        (*notify_positions));
   1.639      if (notify_positions == NULL) {
   1.640          goto done;
   1.641      }
   1.642  
   1.643      /* Create the notify event */
   1.644 -    audio_event = CreateEvent (NULL, FALSE, FALSE, NULL);
   1.645 +    audio_event = CreateEvent(NULL, FALSE, FALSE, NULL);
   1.646      if (audio_event == NULL) {
   1.647          goto done;
   1.648      }
   1.649 @@ -624,28 +623,28 @@
   1.650          notify_positions[i].dwOffset = i * mixlen;
   1.651          notify_positions[i].hEventNotify = audio_event;
   1.652      }
   1.653 -    result = IDirectSoundNotify_SetNotificationPositions (notify,
   1.654 -                                                          NUM_BUFFERS,
   1.655 -                                                          notify_positions);
   1.656 +    result = IDirectSoundNotify_SetNotificationPositions(notify,
   1.657 +                                                         NUM_BUFFERS,
   1.658 +                                                         notify_positions);
   1.659      if (result == DS_OK) {
   1.660          retval = 0;
   1.661      }
   1.662    done:
   1.663      if (notify != NULL) {
   1.664 -        IDirectSoundNotify_Release (notify);
   1.665 +        IDirectSoundNotify_Release(notify);
   1.666      }
   1.667      return (retval);
   1.668  }
   1.669  #endif /* USE_POSITION_NOTIFY */
   1.670  
   1.671  static int
   1.672 -DX5_OpenAudio (_THIS, SDL_AudioSpec * spec)
   1.673 +DX5_OpenAudio(_THIS, SDL_AudioSpec * spec)
   1.674  {
   1.675      HRESULT result;
   1.676      WAVEFORMATEX waveformat;
   1.677  
   1.678      /* Set basic WAVE format parameters */
   1.679 -    SDL_memset (&waveformat, 0, sizeof (waveformat));
   1.680 +    SDL_memset(&waveformat, 0, sizeof(waveformat));
   1.681      waveformat.wFormatTag = WAVE_FORMAT_PCM;
   1.682  
   1.683      /* Determine the audio parameters from the AudioSpec */
   1.684 @@ -663,7 +662,7 @@
   1.685          waveformat.wBitsPerSample = 16;
   1.686          break;
   1.687      default:
   1.688 -        SDL_SetError ("Unsupported audio format");
   1.689 +        SDL_SetError("Unsupported audio format");
   1.690          return (-1);
   1.691      }
   1.692      waveformat.nChannels = spec->channels;
   1.693 @@ -674,12 +673,12 @@
   1.694          waveformat.nSamplesPerSec * waveformat.nBlockAlign;
   1.695  
   1.696      /* Update the fragment size as size in bytes */
   1.697 -    SDL_CalculateAudioSpec (spec);
   1.698 +    SDL_CalculateAudioSpec(spec);
   1.699  
   1.700      /* Open the audio device */
   1.701 -    result = DSoundCreate (NULL, &sound, NULL);
   1.702 +    result = DSoundCreate(NULL, &sound, NULL);
   1.703      if (result != DS_OK) {
   1.704 -        SetDSerror ("DirectSoundCreate", result);
   1.705 +        SetDSerror("DirectSoundCreate", result);
   1.706          return (-1);
   1.707      }
   1.708  
   1.709 @@ -687,23 +686,23 @@
   1.710      NUM_BUFFERS = -1;
   1.711  #ifdef USE_PRIMARY_BUFFER
   1.712      if (mainwin) {
   1.713 -        NUM_BUFFERS = CreatePrimary (sound, mainwin, &mixbuf,
   1.714 -                                     &waveformat, spec->size);
   1.715 +        NUM_BUFFERS = CreatePrimary(sound, mainwin, &mixbuf,
   1.716 +                                    &waveformat, spec->size);
   1.717      }
   1.718  #endif /* USE_PRIMARY_BUFFER */
   1.719      if (NUM_BUFFERS < 0) {
   1.720 -        NUM_BUFFERS = CreateSecondary (sound, mainwin, &mixbuf,
   1.721 -                                       &waveformat, spec->size);
   1.722 +        NUM_BUFFERS = CreateSecondary(sound, mainwin, &mixbuf,
   1.723 +                                      &waveformat, spec->size);
   1.724          if (NUM_BUFFERS < 0) {
   1.725              return (-1);
   1.726          }
   1.727  #ifdef DEBUG_SOUND
   1.728 -        fprintf (stderr, "Using secondary audio buffer\n");
   1.729 +        fprintf(stderr, "Using secondary audio buffer\n");
   1.730  #endif
   1.731      }
   1.732  #ifdef DEBUG_SOUND
   1.733      else
   1.734 -        fprintf (stderr, "Using primary audio buffer\n");
   1.735 +        fprintf(stderr, "Using primary audio buffer\n");
   1.736  #endif
   1.737  
   1.738      /* The buffer will auto-start playing in DX5_WaitAudio() */
   1.739 @@ -712,7 +711,7 @@
   1.740  
   1.741  #ifdef USE_POSITION_NOTIFY
   1.742      /* See if we can use DirectX 6 event notification */
   1.743 -    if (CreateAudioEvent (this) == 0) {
   1.744 +    if (CreateAudioEvent(this) == 0) {
   1.745          this->WaitAudio = DX6_WaitAudio_EventWait;
   1.746      } else {
   1.747          this->WaitAudio = DX5_WaitAudio_BusyWait;