src/audio/windx5/SDL_dx5audio.c
changeset 1895 c121d94672cb
parent 1877 9b02a5b97f79
child 2008 4ad1e863d100
     1.1 --- a/src/audio/windx5/SDL_dx5audio.c	Thu Jul 06 18:01:37 2006 +0000
     1.2 +++ b/src/audio/windx5/SDL_dx5audio.c	Mon Jul 10 21:04:37 2006 +0000
     1.3 @@ -32,10 +32,10 @@
     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 int DX5_OpenAudio(_THIS, SDL_AudioSpec * spec);
    1.13  static void DX5_ThreadInit(_THIS);
    1.14  static void DX5_WaitAudio_BusyWait(_THIS);
    1.15  #ifdef USE_POSITION_NOTIFY
    1.16 @@ -48,658 +48,686 @@
    1.17  
    1.18  /* Audio driver bootstrap functions */
    1.19  
    1.20 -static int Audio_Available(void)
    1.21 +static int
    1.22 +Audio_Available(void)
    1.23  {
    1.24 -	HINSTANCE DSoundDLL;
    1.25 -	int dsound_ok;
    1.26 +    HINSTANCE DSoundDLL;
    1.27 +    int dsound_ok;
    1.28  
    1.29 -	/* Version check DSOUND.DLL (Is DirectX okay?) */
    1.30 -	dsound_ok = 0;
    1.31 -	DSoundDLL = LoadLibrary(TEXT("DSOUND.DLL"));
    1.32 -	if ( DSoundDLL != NULL ) {
    1.33 -		/* We just use basic DirectSound, we're okay */
    1.34 -		/* Yay! */
    1.35 -		/* Unfortunately, the sound drivers on NT have
    1.36 -		   higher latencies than the audio buffers used
    1.37 -		   by many SDL applications, so there are gaps
    1.38 -		   in the audio - it sounds terrible.  Punt for now.
    1.39 -		 */
    1.40 -		OSVERSIONINFO ver;
    1.41 -		ver.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
    1.42 -		GetVersionEx(&ver);
    1.43 -		switch (ver.dwPlatformId) {
    1.44 -			case VER_PLATFORM_WIN32_NT:
    1.45 -				if ( ver.dwMajorVersion > 4 ) {
    1.46 -					/* Win2K */
    1.47 -					dsound_ok = 1;
    1.48 -				} else {
    1.49 -					/* WinNT */
    1.50 -					dsound_ok = 0;
    1.51 -				}
    1.52 -				break;
    1.53 -			default:
    1.54 -				/* Win95 or Win98 */
    1.55 -				dsound_ok = 1;
    1.56 -				break;
    1.57 -		}
    1.58 -		/* Now check for DirectX 5 or better - otherwise
    1.59 -		 * we will fail later in DX5_OpenAudio without a chance
    1.60 -		 * to fall back to the DIB driver. */
    1.61 -		if (dsound_ok) {
    1.62 -			/* DirectSoundCaptureCreate was added in DX5 */
    1.63 -			if (!GetProcAddress(DSoundDLL, TEXT("DirectSoundCaptureCreate")))
    1.64 -				dsound_ok = 0;
    1.65 +    /* Version check DSOUND.DLL (Is DirectX okay?) */
    1.66 +    dsound_ok = 0;
    1.67 +    DSoundDLL = LoadLibrary(TEXT("DSOUND.DLL"));
    1.68 +    if (DSoundDLL != NULL) {
    1.69 +        /* We just use basic DirectSound, we're okay */
    1.70 +        /* Yay! */
    1.71 +        /* Unfortunately, the sound drivers on NT have
    1.72 +           higher latencies than the audio buffers used
    1.73 +           by many SDL applications, so there are gaps
    1.74 +           in the audio - it sounds terrible.  Punt for now.
    1.75 +         */
    1.76 +        OSVERSIONINFO ver;
    1.77 +        ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    1.78 +        GetVersionEx(&ver);
    1.79 +        switch (ver.dwPlatformId) {
    1.80 +        case VER_PLATFORM_WIN32_NT:
    1.81 +            if (ver.dwMajorVersion > 4) {
    1.82 +                /* Win2K */
    1.83 +                dsound_ok = 1;
    1.84 +            } else {
    1.85 +                /* WinNT */
    1.86 +                dsound_ok = 0;
    1.87 +            }
    1.88 +            break;
    1.89 +        default:
    1.90 +            /* Win95 or Win98 */
    1.91 +            dsound_ok = 1;
    1.92 +            break;
    1.93 +        }
    1.94 +        /* Now check for DirectX 5 or better - otherwise
    1.95 +         * we will fail later in DX5_OpenAudio without a chance
    1.96 +         * to fall back to the DIB driver. */
    1.97 +        if (dsound_ok) {
    1.98 +            /* DirectSoundCaptureCreate was added in DX5 */
    1.99 +            if (!GetProcAddress(DSoundDLL, TEXT("DirectSoundCaptureCreate")))
   1.100 +                dsound_ok = 0;
   1.101  
   1.102 -		}
   1.103 -		/* Clean up.. */
   1.104 -		FreeLibrary(DSoundDLL);
   1.105 -	}
   1.106 -	return(dsound_ok);
   1.107 +        }
   1.108 +        /* Clean up.. */
   1.109 +        FreeLibrary(DSoundDLL);
   1.110 +    }
   1.111 +    return (dsound_ok);
   1.112  }
   1.113  
   1.114  /* Functions for loading the DirectX functions dynamically */
   1.115  static HINSTANCE DSoundDLL = NULL;
   1.116  
   1.117 -static void DX5_Unload(void)
   1.118 +static void
   1.119 +DX5_Unload(void)
   1.120  {
   1.121 -	if ( DSoundDLL != NULL ) {
   1.122 -		FreeLibrary(DSoundDLL);
   1.123 -		DSoundCreate = NULL;
   1.124 -		DSoundDLL = NULL;
   1.125 -	}
   1.126 +    if (DSoundDLL != NULL) {
   1.127 +        FreeLibrary(DSoundDLL);
   1.128 +        DSoundCreate = NULL;
   1.129 +        DSoundDLL = NULL;
   1.130 +    }
   1.131  }
   1.132 -static int DX5_Load(void)
   1.133 +static int
   1.134 +DX5_Load(void)
   1.135  {
   1.136 -	int status;
   1.137 +    int status;
   1.138  
   1.139 -	DX5_Unload();
   1.140 -	DSoundDLL = LoadLibrary(TEXT("DSOUND.DLL"));
   1.141 -	if ( DSoundDLL != NULL ) {
   1.142 -		DSoundCreate = (void *)GetProcAddress(DSoundDLL,
   1.143 -					TEXT("DirectSoundCreate"));
   1.144 -	}
   1.145 -	if ( DSoundDLL && DSoundCreate ) {
   1.146 -		status = 0;
   1.147 -	} else {
   1.148 -		DX5_Unload();
   1.149 -		status = -1;
   1.150 -	}
   1.151 -	return status;
   1.152 +    DX5_Unload();
   1.153 +    DSoundDLL = LoadLibrary(TEXT("DSOUND.DLL"));
   1.154 +    if (DSoundDLL != NULL) {
   1.155 +        DSoundCreate = (void *) GetProcAddress(DSoundDLL,
   1.156 +                                               TEXT("DirectSoundCreate"));
   1.157 +    }
   1.158 +    if (DSoundDLL && DSoundCreate) {
   1.159 +        status = 0;
   1.160 +    } else {
   1.161 +        DX5_Unload();
   1.162 +        status = -1;
   1.163 +    }
   1.164 +    return status;
   1.165  }
   1.166  
   1.167 -static void Audio_DeleteDevice(SDL_AudioDevice *device)
   1.168 +static void
   1.169 +Audio_DeleteDevice(SDL_AudioDevice * device)
   1.170  {
   1.171 -	DX5_Unload();
   1.172 -	SDL_free(device->hidden);
   1.173 -	SDL_free(device);
   1.174 +    DX5_Unload();
   1.175 +    SDL_free(device->hidden);
   1.176 +    SDL_free(device);
   1.177  }
   1.178  
   1.179 -static SDL_AudioDevice *Audio_CreateDevice(int devindex)
   1.180 +static SDL_AudioDevice *
   1.181 +Audio_CreateDevice(int devindex)
   1.182  {
   1.183 -	SDL_AudioDevice *this;
   1.184 +    SDL_AudioDevice *this;
   1.185  
   1.186 -	/* Load DirectX */
   1.187 -	if ( DX5_Load() < 0 ) {
   1.188 -		return(NULL);
   1.189 -	}
   1.190 +    /* Load DirectX */
   1.191 +    if (DX5_Load() < 0) {
   1.192 +        return (NULL);
   1.193 +    }
   1.194  
   1.195 -	/* Initialize all variables that we clean on shutdown */
   1.196 -	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
   1.197 -	if ( this ) {
   1.198 -		SDL_memset(this, 0, (sizeof *this));
   1.199 -		this->hidden = (struct SDL_PrivateAudioData *)
   1.200 -				SDL_malloc((sizeof *this->hidden));
   1.201 -	}
   1.202 -	if ( (this == NULL) || (this->hidden == NULL) ) {
   1.203 -		SDL_OutOfMemory();
   1.204 -		if ( this ) {
   1.205 -			SDL_free(this);
   1.206 -		}
   1.207 -		return(0);
   1.208 -	}
   1.209 -	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
   1.210 +    /* Initialize all variables that we clean on shutdown */
   1.211 +    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
   1.212 +    if (this) {
   1.213 +        SDL_memset(this, 0, (sizeof *this));
   1.214 +        this->hidden = (struct SDL_PrivateAudioData *)
   1.215 +            SDL_malloc((sizeof *this->hidden));
   1.216 +    }
   1.217 +    if ((this == NULL) || (this->hidden == NULL)) {
   1.218 +        SDL_OutOfMemory();
   1.219 +        if (this) {
   1.220 +            SDL_free(this);
   1.221 +        }
   1.222 +        return (0);
   1.223 +    }
   1.224 +    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
   1.225  
   1.226 -	/* Set the function pointers */
   1.227 -	this->OpenAudio = DX5_OpenAudio;
   1.228 -	this->ThreadInit = DX5_ThreadInit;
   1.229 -	this->WaitAudio = DX5_WaitAudio_BusyWait;
   1.230 -	this->PlayAudio = DX5_PlayAudio;
   1.231 -	this->GetAudioBuf = DX5_GetAudioBuf;
   1.232 -	this->WaitDone = DX5_WaitDone;
   1.233 -	this->CloseAudio = DX5_CloseAudio;
   1.234 +    /* Set the function pointers */
   1.235 +    this->OpenAudio = DX5_OpenAudio;
   1.236 +    this->ThreadInit = DX5_ThreadInit;
   1.237 +    this->WaitAudio = DX5_WaitAudio_BusyWait;
   1.238 +    this->PlayAudio = DX5_PlayAudio;
   1.239 +    this->GetAudioBuf = DX5_GetAudioBuf;
   1.240 +    this->WaitDone = DX5_WaitDone;
   1.241 +    this->CloseAudio = DX5_CloseAudio;
   1.242  
   1.243 -	this->free = Audio_DeleteDevice;
   1.244 +    this->free = Audio_DeleteDevice;
   1.245  
   1.246 -	return this;
   1.247 +    return this;
   1.248  }
   1.249  
   1.250  AudioBootStrap DSOUND_bootstrap = {
   1.251 -	"dsound", "Win95/98/2000 DirectSound",
   1.252 -	Audio_Available, Audio_CreateDevice
   1.253 +    "dsound", "Win95/98/2000 DirectSound",
   1.254 +    Audio_Available, Audio_CreateDevice
   1.255  };
   1.256  
   1.257 -static void SetDSerror(const char *function, int code)
   1.258 +static void
   1.259 +SetDSerror(const char *function, int code)
   1.260  {
   1.261 -	static const char *error;
   1.262 -	static char  errbuf[1024];
   1.263 +    static const char *error;
   1.264 +    static char errbuf[1024];
   1.265  
   1.266 -	errbuf[0] = 0;
   1.267 -	switch (code) {
   1.268 -		case E_NOINTERFACE:
   1.269 -			error = 
   1.270 -		"Unsupported interface\n-- Is DirectX 5.0 or later installed?";
   1.271 -			break;
   1.272 -		case DSERR_ALLOCATED:
   1.273 -			error = "Audio device in use";
   1.274 -			break;
   1.275 -		case DSERR_BADFORMAT:
   1.276 -			error = "Unsupported audio format";
   1.277 -			break;
   1.278 -		case DSERR_BUFFERLOST:
   1.279 -			error = "Mixing buffer was lost";
   1.280 -			break;
   1.281 -		case DSERR_CONTROLUNAVAIL:
   1.282 -			error = "Control requested is not available";
   1.283 -			break;
   1.284 -		case DSERR_INVALIDCALL:
   1.285 -			error = "Invalid call for the current state";
   1.286 -			break;
   1.287 -		case DSERR_INVALIDPARAM:
   1.288 -			error = "Invalid parameter";
   1.289 -			break;
   1.290 -		case DSERR_NODRIVER:
   1.291 -			error = "No audio device found";
   1.292 -			break;
   1.293 -		case DSERR_OUTOFMEMORY:
   1.294 -			error = "Out of memory";
   1.295 -			break;
   1.296 -		case DSERR_PRIOLEVELNEEDED:
   1.297 -			error = "Caller doesn't have priority";
   1.298 -			break;
   1.299 -		case DSERR_UNSUPPORTED:
   1.300 -			error = "Function not supported";
   1.301 -			break;
   1.302 -		default:
   1.303 -			SDL_snprintf(errbuf, SDL_arraysize(errbuf),
   1.304 -			         "%s: Unknown DirectSound error: 0x%x",
   1.305 -								function, code);
   1.306 -			break;
   1.307 -	}
   1.308 -	if ( ! errbuf[0] ) {
   1.309 -		SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error);
   1.310 -	}
   1.311 -	SDL_SetError("%s", errbuf);
   1.312 -	return;
   1.313 +    errbuf[0] = 0;
   1.314 +    switch (code) {
   1.315 +    case E_NOINTERFACE:
   1.316 +        error =
   1.317 +            "Unsupported interface\n-- Is DirectX 5.0 or later installed?";
   1.318 +        break;
   1.319 +    case DSERR_ALLOCATED:
   1.320 +        error = "Audio device in use";
   1.321 +        break;
   1.322 +    case DSERR_BADFORMAT:
   1.323 +        error = "Unsupported audio format";
   1.324 +        break;
   1.325 +    case DSERR_BUFFERLOST:
   1.326 +        error = "Mixing buffer was lost";
   1.327 +        break;
   1.328 +    case DSERR_CONTROLUNAVAIL:
   1.329 +        error = "Control requested is not available";
   1.330 +        break;
   1.331 +    case DSERR_INVALIDCALL:
   1.332 +        error = "Invalid call for the current state";
   1.333 +        break;
   1.334 +    case DSERR_INVALIDPARAM:
   1.335 +        error = "Invalid parameter";
   1.336 +        break;
   1.337 +    case DSERR_NODRIVER:
   1.338 +        error = "No audio device found";
   1.339 +        break;
   1.340 +    case DSERR_OUTOFMEMORY:
   1.341 +        error = "Out of memory";
   1.342 +        break;
   1.343 +    case DSERR_PRIOLEVELNEEDED:
   1.344 +        error = "Caller doesn't have priority";
   1.345 +        break;
   1.346 +    case DSERR_UNSUPPORTED:
   1.347 +        error = "Function not supported";
   1.348 +        break;
   1.349 +    default:
   1.350 +        SDL_snprintf(errbuf, SDL_arraysize(errbuf),
   1.351 +                     "%s: Unknown DirectSound error: 0x%x", function, code);
   1.352 +        break;
   1.353 +    }
   1.354 +    if (!errbuf[0]) {
   1.355 +        SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function,
   1.356 +                     error);
   1.357 +    }
   1.358 +    SDL_SetError("%s", errbuf);
   1.359 +    return;
   1.360  }
   1.361  
   1.362  /* DirectSound needs to be associated with a window */
   1.363  static HWND mainwin = NULL;
   1.364  /* */
   1.365 -void DX5_SoundFocus(HWND hwnd)
   1.366 +void
   1.367 +DX5_SoundFocus(HWND hwnd)
   1.368  {
   1.369 -	mainwin = hwnd;
   1.370 +    mainwin = hwnd;
   1.371  }
   1.372  
   1.373 -static void DX5_ThreadInit(_THIS)
   1.374 +static void
   1.375 +DX5_ThreadInit(_THIS)
   1.376  {
   1.377 -	SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
   1.378 +    SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
   1.379  }
   1.380  
   1.381 -static void DX5_WaitAudio_BusyWait(_THIS)
   1.382 +static void
   1.383 +DX5_WaitAudio_BusyWait(_THIS)
   1.384  {
   1.385 -	DWORD status;
   1.386 -	DWORD cursor, junk;
   1.387 -	HRESULT result;
   1.388 +    DWORD status;
   1.389 +    DWORD cursor, junk;
   1.390 +    HRESULT result;
   1.391  
   1.392 -	/* Semi-busy wait, since we have no way of getting play notification
   1.393 -	   on a primary mixing buffer located in hardware (DirectX 5.0)
   1.394 -	*/
   1.395 -	result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &junk, &cursor);
   1.396 -	if ( result != DS_OK ) {
   1.397 -		if ( result == DSERR_BUFFERLOST ) {
   1.398 -			IDirectSoundBuffer_Restore(mixbuf);
   1.399 -		}
   1.400 +    /* Semi-busy wait, since we have no way of getting play notification
   1.401 +       on a primary mixing buffer located in hardware (DirectX 5.0)
   1.402 +     */
   1.403 +    result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &junk, &cursor);
   1.404 +    if (result != DS_OK) {
   1.405 +        if (result == DSERR_BUFFERLOST) {
   1.406 +            IDirectSoundBuffer_Restore(mixbuf);
   1.407 +        }
   1.408  #ifdef DEBUG_SOUND
   1.409 -		SetDSerror("DirectSound GetCurrentPosition", result);
   1.410 +        SetDSerror("DirectSound GetCurrentPosition", result);
   1.411  #endif
   1.412 -		return;
   1.413 -	}
   1.414 +        return;
   1.415 +    }
   1.416  
   1.417 -	while ( (cursor/mixlen) == lastchunk ) {
   1.418 -		/* FIXME: find out how much time is left and sleep that long */
   1.419 -		SDL_Delay(1);
   1.420 +    while ((cursor / mixlen) == lastchunk) {
   1.421 +        /* FIXME: find out how much time is left and sleep that long */
   1.422 +        SDL_Delay(1);
   1.423  
   1.424 -		/* Try to restore a lost sound buffer */
   1.425 -		IDirectSoundBuffer_GetStatus(mixbuf, &status);
   1.426 -		if ( (status&DSBSTATUS_BUFFERLOST) ) {
   1.427 -			IDirectSoundBuffer_Restore(mixbuf);
   1.428 -			IDirectSoundBuffer_GetStatus(mixbuf, &status);
   1.429 -			if ( (status&DSBSTATUS_BUFFERLOST) ) {
   1.430 -				break;
   1.431 -			}
   1.432 -		}
   1.433 -		if ( ! (status&DSBSTATUS_PLAYING) ) {
   1.434 -			result = IDirectSoundBuffer_Play(mixbuf, 0, 0, DSBPLAY_LOOPING);
   1.435 -			if ( result == DS_OK ) {
   1.436 -				continue;
   1.437 -			}
   1.438 +        /* Try to restore a lost sound buffer */
   1.439 +        IDirectSoundBuffer_GetStatus(mixbuf, &status);
   1.440 +        if ((status & DSBSTATUS_BUFFERLOST)) {
   1.441 +            IDirectSoundBuffer_Restore(mixbuf);
   1.442 +            IDirectSoundBuffer_GetStatus(mixbuf, &status);
   1.443 +            if ((status & DSBSTATUS_BUFFERLOST)) {
   1.444 +                break;
   1.445 +            }
   1.446 +        }
   1.447 +        if (!(status & DSBSTATUS_PLAYING)) {
   1.448 +            result = IDirectSoundBuffer_Play(mixbuf, 0, 0, DSBPLAY_LOOPING);
   1.449 +            if (result == DS_OK) {
   1.450 +                continue;
   1.451 +            }
   1.452  #ifdef DEBUG_SOUND
   1.453 -			SetDSerror("DirectSound Play", result);
   1.454 +            SetDSerror("DirectSound Play", result);
   1.455  #endif
   1.456 -			return;
   1.457 -		}
   1.458 +            return;
   1.459 +        }
   1.460  
   1.461 -		/* Find out where we are playing */
   1.462 -		result = IDirectSoundBuffer_GetCurrentPosition(mixbuf,
   1.463 -								&junk, &cursor);
   1.464 -		if ( result != DS_OK ) {
   1.465 -			SetDSerror("DirectSound GetCurrentPosition", result);
   1.466 -			return;
   1.467 -		}
   1.468 -	}
   1.469 +        /* Find out where we are playing */
   1.470 +        result = IDirectSoundBuffer_GetCurrentPosition(mixbuf,
   1.471 +                                                       &junk, &cursor);
   1.472 +        if (result != DS_OK) {
   1.473 +            SetDSerror("DirectSound GetCurrentPosition", result);
   1.474 +            return;
   1.475 +        }
   1.476 +    }
   1.477  }
   1.478  
   1.479  #ifdef USE_POSITION_NOTIFY
   1.480 -static void DX6_WaitAudio_EventWait(_THIS)
   1.481 +static void
   1.482 +DX6_WaitAudio_EventWait(_THIS)
   1.483  {
   1.484 -	DWORD status;
   1.485 -	HRESULT result;
   1.486 +    DWORD status;
   1.487 +    HRESULT result;
   1.488  
   1.489 -	/* Try to restore a lost sound buffer */
   1.490 -	IDirectSoundBuffer_GetStatus(mixbuf, &status);
   1.491 -	if ( (status&DSBSTATUS_BUFFERLOST) ) {
   1.492 -		IDirectSoundBuffer_Restore(mixbuf);
   1.493 -		IDirectSoundBuffer_GetStatus(mixbuf, &status);
   1.494 -		if ( (status&DSBSTATUS_BUFFERLOST) ) {
   1.495 -			return;
   1.496 -		}
   1.497 -	}
   1.498 -	if ( ! (status&DSBSTATUS_PLAYING) ) {
   1.499 -		result = IDirectSoundBuffer_Play(mixbuf, 0, 0, DSBPLAY_LOOPING);
   1.500 -		if ( result != DS_OK ) {
   1.501 +    /* Try to restore a lost sound buffer */
   1.502 +    IDirectSoundBuffer_GetStatus(mixbuf, &status);
   1.503 +    if ((status & DSBSTATUS_BUFFERLOST)) {
   1.504 +        IDirectSoundBuffer_Restore(mixbuf);
   1.505 +        IDirectSoundBuffer_GetStatus(mixbuf, &status);
   1.506 +        if ((status & DSBSTATUS_BUFFERLOST)) {
   1.507 +            return;
   1.508 +        }
   1.509 +    }
   1.510 +    if (!(status & DSBSTATUS_PLAYING)) {
   1.511 +        result = IDirectSoundBuffer_Play(mixbuf, 0, 0, DSBPLAY_LOOPING);
   1.512 +        if (result != DS_OK) {
   1.513  #ifdef DEBUG_SOUND
   1.514 -			SetDSerror("DirectSound Play", result);
   1.515 +            SetDSerror("DirectSound Play", result);
   1.516  #endif
   1.517 -			return;
   1.518 -		}
   1.519 -	}
   1.520 -	WaitForSingleObject(audio_event, INFINITE);
   1.521 +            return;
   1.522 +        }
   1.523 +    }
   1.524 +    WaitForSingleObject(audio_event, INFINITE);
   1.525  }
   1.526  #endif /* USE_POSITION_NOTIFY */
   1.527  
   1.528 -static void DX5_PlayAudio(_THIS)
   1.529 +static void
   1.530 +DX5_PlayAudio(_THIS)
   1.531  {
   1.532 -	/* Unlock the buffer, allowing it to play */
   1.533 -	if ( locked_buf ) {
   1.534 -		IDirectSoundBuffer_Unlock(mixbuf, locked_buf, mixlen, NULL, 0);
   1.535 -	}
   1.536 +    /* Unlock the buffer, allowing it to play */
   1.537 +    if (locked_buf) {
   1.538 +        IDirectSoundBuffer_Unlock(mixbuf, locked_buf, mixlen, NULL, 0);
   1.539 +    }
   1.540  
   1.541  }
   1.542  
   1.543 -static Uint8 *DX5_GetAudioBuf(_THIS)
   1.544 +static Uint8 *
   1.545 +DX5_GetAudioBuf(_THIS)
   1.546  {
   1.547 -	DWORD   cursor, junk;
   1.548 -	HRESULT result;
   1.549 -	DWORD   rawlen;
   1.550 +    DWORD cursor, junk;
   1.551 +    HRESULT result;
   1.552 +    DWORD rawlen;
   1.553  
   1.554 -	/* Figure out which blocks to fill next */
   1.555 -	locked_buf = NULL;
   1.556 -	result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &junk, &cursor);
   1.557 -	if ( result == DSERR_BUFFERLOST ) {
   1.558 -		IDirectSoundBuffer_Restore(mixbuf);
   1.559 -		result = IDirectSoundBuffer_GetCurrentPosition(mixbuf,
   1.560 -								&junk, &cursor);
   1.561 -	}
   1.562 -	if ( result != DS_OK ) {
   1.563 -		SetDSerror("DirectSound GetCurrentPosition", result);
   1.564 -		return(NULL);
   1.565 -	}
   1.566 -	cursor /= mixlen;
   1.567 +    /* Figure out which blocks to fill next */
   1.568 +    locked_buf = NULL;
   1.569 +    result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &junk, &cursor);
   1.570 +    if (result == DSERR_BUFFERLOST) {
   1.571 +        IDirectSoundBuffer_Restore(mixbuf);
   1.572 +        result = IDirectSoundBuffer_GetCurrentPosition(mixbuf,
   1.573 +                                                       &junk, &cursor);
   1.574 +    }
   1.575 +    if (result != DS_OK) {
   1.576 +        SetDSerror("DirectSound GetCurrentPosition", result);
   1.577 +        return (NULL);
   1.578 +    }
   1.579 +    cursor /= mixlen;
   1.580  #ifdef DEBUG_SOUND
   1.581 -	/* Detect audio dropouts */
   1.582 -	{ DWORD spot = cursor;
   1.583 -	  if ( spot < lastchunk ) {
   1.584 -	    spot += NUM_BUFFERS;
   1.585 -	  }
   1.586 -	  if ( spot > lastchunk+1 ) {
   1.587 -	    fprintf(stderr, "Audio dropout, missed %d fragments\n",
   1.588 -	            (spot - (lastchunk+1)));
   1.589 -	  }
   1.590 -	}
   1.591 +    /* Detect audio dropouts */
   1.592 +    {
   1.593 +        DWORD spot = cursor;
   1.594 +        if (spot < lastchunk) {
   1.595 +            spot += NUM_BUFFERS;
   1.596 +        }
   1.597 +        if (spot > lastchunk + 1) {
   1.598 +            fprintf(stderr, "Audio dropout, missed %d fragments\n",
   1.599 +                    (spot - (lastchunk + 1)));
   1.600 +        }
   1.601 +    }
   1.602  #endif
   1.603 -	lastchunk = cursor;
   1.604 -	cursor = (cursor+1)%NUM_BUFFERS;
   1.605 -	cursor *= mixlen;
   1.606 +    lastchunk = cursor;
   1.607 +    cursor = (cursor + 1) % NUM_BUFFERS;
   1.608 +    cursor *= mixlen;
   1.609  
   1.610 -	/* Lock the audio buffer */
   1.611 -	result = IDirectSoundBuffer_Lock(mixbuf, cursor, mixlen,
   1.612 -				(LPVOID *)&locked_buf, &rawlen, NULL, &junk, 0);
   1.613 -	if ( result == DSERR_BUFFERLOST ) {
   1.614 -		IDirectSoundBuffer_Restore(mixbuf);
   1.615 -		result = IDirectSoundBuffer_Lock(mixbuf, cursor, mixlen,
   1.616 -				(LPVOID *)&locked_buf, &rawlen, NULL, &junk, 0);
   1.617 -	}
   1.618 -	if ( result != DS_OK ) {
   1.619 -		SetDSerror("DirectSound Lock", result);
   1.620 -		return(NULL);
   1.621 -	}
   1.622 -	return(locked_buf);
   1.623 +    /* Lock the audio buffer */
   1.624 +    result = IDirectSoundBuffer_Lock(mixbuf, cursor, mixlen,
   1.625 +                                     (LPVOID *) & locked_buf, &rawlen, NULL,
   1.626 +                                     &junk, 0);
   1.627 +    if (result == DSERR_BUFFERLOST) {
   1.628 +        IDirectSoundBuffer_Restore(mixbuf);
   1.629 +        result = IDirectSoundBuffer_Lock(mixbuf, cursor, mixlen,
   1.630 +                                         (LPVOID *) & locked_buf, &rawlen,
   1.631 +                                         NULL, &junk, 0);
   1.632 +    }
   1.633 +    if (result != DS_OK) {
   1.634 +        SetDSerror("DirectSound Lock", result);
   1.635 +        return (NULL);
   1.636 +    }
   1.637 +    return (locked_buf);
   1.638  }
   1.639  
   1.640 -static void DX5_WaitDone(_THIS)
   1.641 +static void
   1.642 +DX5_WaitDone(_THIS)
   1.643  {
   1.644 -	Uint8 *stream;
   1.645 +    Uint8 *stream;
   1.646  
   1.647 -	/* Wait for the playing chunk to finish */
   1.648 -	stream = this->GetAudioBuf(this);
   1.649 -	if ( stream != NULL ) {
   1.650 -		SDL_memset(stream, silence, mixlen);
   1.651 -		this->PlayAudio(this);
   1.652 -	}
   1.653 -	this->WaitAudio(this);
   1.654 +    /* Wait for the playing chunk to finish */
   1.655 +    stream = this->GetAudioBuf(this);
   1.656 +    if (stream != NULL) {
   1.657 +        SDL_memset(stream, silence, mixlen);
   1.658 +        this->PlayAudio(this);
   1.659 +    }
   1.660 +    this->WaitAudio(this);
   1.661  
   1.662 -	/* Stop the looping sound buffer */
   1.663 -	IDirectSoundBuffer_Stop(mixbuf);
   1.664 +    /* Stop the looping sound buffer */
   1.665 +    IDirectSoundBuffer_Stop(mixbuf);
   1.666  }
   1.667  
   1.668 -static void DX5_CloseAudio(_THIS)
   1.669 +static void
   1.670 +DX5_CloseAudio(_THIS)
   1.671  {
   1.672 -	if ( sound != NULL ) {
   1.673 -		if ( mixbuf != NULL ) {
   1.674 -			/* Clean up the audio buffer */
   1.675 -			IDirectSoundBuffer_Release(mixbuf);
   1.676 -			mixbuf = NULL;
   1.677 -		}
   1.678 -		if ( audio_event != NULL ) {
   1.679 -			CloseHandle(audio_event);
   1.680 -			audio_event = NULL;
   1.681 -		}
   1.682 -		IDirectSound_Release(sound);
   1.683 -		sound = NULL;
   1.684 -	}
   1.685 +    if (sound != NULL) {
   1.686 +        if (mixbuf != NULL) {
   1.687 +            /* Clean up the audio buffer */
   1.688 +            IDirectSoundBuffer_Release(mixbuf);
   1.689 +            mixbuf = NULL;
   1.690 +        }
   1.691 +        if (audio_event != NULL) {
   1.692 +            CloseHandle(audio_event);
   1.693 +            audio_event = NULL;
   1.694 +        }
   1.695 +        IDirectSound_Release(sound);
   1.696 +        sound = NULL;
   1.697 +    }
   1.698  }
   1.699  
   1.700  #ifdef USE_PRIMARY_BUFFER
   1.701  /* This function tries to create a primary audio buffer, and returns the
   1.702     number of audio chunks available in the created buffer.
   1.703  */
   1.704 -static int CreatePrimary(LPDIRECTSOUND sndObj, HWND focus, 
   1.705 -	LPDIRECTSOUNDBUFFER *sndbuf, WAVEFORMATEX *wavefmt, Uint32 chunksize)
   1.706 +static int
   1.707 +CreatePrimary(LPDIRECTSOUND sndObj, HWND focus,
   1.708 +              LPDIRECTSOUNDBUFFER * sndbuf, WAVEFORMATEX * wavefmt,
   1.709 +              Uint32 chunksize)
   1.710  {
   1.711 -	HRESULT result;
   1.712 -	DSBUFFERDESC format;
   1.713 -	DSBCAPS caps;
   1.714 -	int numchunks;
   1.715 +    HRESULT result;
   1.716 +    DSBUFFERDESC format;
   1.717 +    DSBCAPS caps;
   1.718 +    int numchunks;
   1.719  
   1.720 -	/* Try to set primary mixing privileges */
   1.721 -	result = IDirectSound_SetCooperativeLevel(sndObj, focus,
   1.722 -							DSSCL_WRITEPRIMARY);
   1.723 -	if ( result != DS_OK ) {
   1.724 +    /* Try to set primary mixing privileges */
   1.725 +    result = IDirectSound_SetCooperativeLevel(sndObj, focus,
   1.726 +                                              DSSCL_WRITEPRIMARY);
   1.727 +    if (result != DS_OK) {
   1.728  #ifdef DEBUG_SOUND
   1.729 -		SetDSerror("DirectSound SetCooperativeLevel", result);
   1.730 +        SetDSerror("DirectSound SetCooperativeLevel", result);
   1.731  #endif
   1.732 -		return(-1);
   1.733 -	}
   1.734 +        return (-1);
   1.735 +    }
   1.736  
   1.737 -	/* Try to create the primary buffer */
   1.738 -	SDL_memset(&format, 0, sizeof(format));
   1.739 -	format.dwSize = sizeof(format);
   1.740 -	format.dwFlags=(DSBCAPS_PRIMARYBUFFER|DSBCAPS_GETCURRENTPOSITION2);
   1.741 -	format.dwFlags |= DSBCAPS_STICKYFOCUS;
   1.742 +    /* Try to create the primary buffer */
   1.743 +    SDL_memset(&format, 0, sizeof(format));
   1.744 +    format.dwSize = sizeof(format);
   1.745 +    format.dwFlags = (DSBCAPS_PRIMARYBUFFER | DSBCAPS_GETCURRENTPOSITION2);
   1.746 +    format.dwFlags |= DSBCAPS_STICKYFOCUS;
   1.747  #ifdef USE_POSITION_NOTIFY
   1.748 -	format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY;
   1.749 +    format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY;
   1.750  #endif
   1.751 -	result = IDirectSound_CreateSoundBuffer(sndObj, &format, sndbuf, NULL);
   1.752 -	if ( result != DS_OK ) {
   1.753 +    result = IDirectSound_CreateSoundBuffer(sndObj, &format, sndbuf, NULL);
   1.754 +    if (result != DS_OK) {
   1.755  #ifdef DEBUG_SOUND
   1.756 -		SetDSerror("DirectSound CreateSoundBuffer", result);
   1.757 +        SetDSerror("DirectSound CreateSoundBuffer", result);
   1.758  #endif
   1.759 -		return(-1);
   1.760 -	}
   1.761 +        return (-1);
   1.762 +    }
   1.763  
   1.764 -	/* Check the size of the fragment buffer */
   1.765 -	SDL_memset(&caps, 0, sizeof(caps));
   1.766 -	caps.dwSize = sizeof(caps);
   1.767 -	result = IDirectSoundBuffer_GetCaps(*sndbuf, &caps);
   1.768 -	if ( result != DS_OK ) {
   1.769 +    /* Check the size of the fragment buffer */
   1.770 +    SDL_memset(&caps, 0, sizeof(caps));
   1.771 +    caps.dwSize = sizeof(caps);
   1.772 +    result = IDirectSoundBuffer_GetCaps(*sndbuf, &caps);
   1.773 +    if (result != DS_OK) {
   1.774  #ifdef DEBUG_SOUND
   1.775 -		SetDSerror("DirectSound GetCaps", result);
   1.776 +        SetDSerror("DirectSound GetCaps", result);
   1.777  #endif
   1.778 -		IDirectSoundBuffer_Release(*sndbuf);
   1.779 -		return(-1);
   1.780 -	}
   1.781 -	if ( (chunksize > caps.dwBufferBytes) ||
   1.782 -				((caps.dwBufferBytes%chunksize) != 0) ) {
   1.783 -		/* The primary buffer size is not a multiple of 'chunksize'
   1.784 -		   -- this hopefully doesn't happen when 'chunksize' is a 
   1.785 -		      power of 2.
   1.786 -		*/
   1.787 -		IDirectSoundBuffer_Release(*sndbuf);
   1.788 -		SDL_SetError(
   1.789 -"Primary buffer size is: %d, cannot break it into chunks of %d bytes\n",
   1.790 -					caps.dwBufferBytes, chunksize);
   1.791 -		return(-1);
   1.792 -	}
   1.793 -	numchunks = (caps.dwBufferBytes/chunksize);
   1.794 +        IDirectSoundBuffer_Release(*sndbuf);
   1.795 +        return (-1);
   1.796 +    }
   1.797 +    if ((chunksize > caps.dwBufferBytes) ||
   1.798 +        ((caps.dwBufferBytes % chunksize) != 0)) {
   1.799 +        /* The primary buffer size is not a multiple of 'chunksize'
   1.800 +           -- this hopefully doesn't happen when 'chunksize' is a 
   1.801 +           power of 2.
   1.802 +         */
   1.803 +        IDirectSoundBuffer_Release(*sndbuf);
   1.804 +        SDL_SetError
   1.805 +            ("Primary buffer size is: %d, cannot break it into chunks of %d bytes\n",
   1.806 +             caps.dwBufferBytes, chunksize);
   1.807 +        return (-1);
   1.808 +    }
   1.809 +    numchunks = (caps.dwBufferBytes / chunksize);
   1.810  
   1.811 -	/* Set the primary audio format */
   1.812 -	result = IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt);
   1.813 -	if ( result != DS_OK ) {
   1.814 +    /* Set the primary audio format */
   1.815 +    result = IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt);
   1.816 +    if (result != DS_OK) {
   1.817  #ifdef DEBUG_SOUND
   1.818 -		SetDSerror("DirectSound SetFormat", result);
   1.819 +        SetDSerror("DirectSound SetFormat", result);
   1.820  #endif
   1.821 -		IDirectSoundBuffer_Release(*sndbuf);
   1.822 -		return(-1);
   1.823 -	}
   1.824 -	return(numchunks);
   1.825 +        IDirectSoundBuffer_Release(*sndbuf);
   1.826 +        return (-1);
   1.827 +    }
   1.828 +    return (numchunks);
   1.829  }
   1.830  #endif /* USE_PRIMARY_BUFFER */
   1.831  
   1.832  /* This function tries to create a secondary audio buffer, and returns the
   1.833     number of audio chunks available in the created buffer.
   1.834  */
   1.835 -static int CreateSecondary(LPDIRECTSOUND sndObj, HWND focus,
   1.836 -	LPDIRECTSOUNDBUFFER *sndbuf, WAVEFORMATEX *wavefmt, Uint32 chunksize)
   1.837 +static int
   1.838 +CreateSecondary(LPDIRECTSOUND sndObj, HWND focus,
   1.839 +                LPDIRECTSOUNDBUFFER * sndbuf, WAVEFORMATEX * wavefmt,
   1.840 +                Uint32 chunksize)
   1.841  {
   1.842 -	const int numchunks = 8;
   1.843 -	HRESULT result;
   1.844 -	DSBUFFERDESC format;
   1.845 -	LPVOID pvAudioPtr1, pvAudioPtr2;
   1.846 -	DWORD  dwAudioBytes1, dwAudioBytes2;
   1.847 +    const int numchunks = 8;
   1.848 +    HRESULT result;
   1.849 +    DSBUFFERDESC format;
   1.850 +    LPVOID pvAudioPtr1, pvAudioPtr2;
   1.851 +    DWORD dwAudioBytes1, dwAudioBytes2;
   1.852  
   1.853 -	/* Try to set primary mixing privileges */
   1.854 -	if ( focus ) {
   1.855 -		result = IDirectSound_SetCooperativeLevel(sndObj,
   1.856 -					focus, DSSCL_PRIORITY);
   1.857 -	} else {
   1.858 -		result = IDirectSound_SetCooperativeLevel(sndObj,
   1.859 -					GetDesktopWindow(), DSSCL_NORMAL);
   1.860 -	}
   1.861 -	if ( result != DS_OK ) {
   1.862 +    /* Try to set primary mixing privileges */
   1.863 +    if (focus) {
   1.864 +        result = IDirectSound_SetCooperativeLevel(sndObj,
   1.865 +                                                  focus, DSSCL_PRIORITY);
   1.866 +    } else {
   1.867 +        result = IDirectSound_SetCooperativeLevel(sndObj,
   1.868 +                                                  GetDesktopWindow(),
   1.869 +                                                  DSSCL_NORMAL);
   1.870 +    }
   1.871 +    if (result != DS_OK) {
   1.872  #ifdef DEBUG_SOUND
   1.873 -		SetDSerror("DirectSound SetCooperativeLevel", result);
   1.874 +        SetDSerror("DirectSound SetCooperativeLevel", result);
   1.875  #endif
   1.876 -		return(-1);
   1.877 -	}
   1.878 +        return (-1);
   1.879 +    }
   1.880  
   1.881 -	/* Try to create the secondary buffer */
   1.882 -	SDL_memset(&format, 0, sizeof(format));
   1.883 -	format.dwSize = sizeof(format);
   1.884 -	format.dwFlags = DSBCAPS_GETCURRENTPOSITION2;
   1.885 +    /* Try to create the secondary buffer */
   1.886 +    SDL_memset(&format, 0, sizeof(format));
   1.887 +    format.dwSize = sizeof(format);
   1.888 +    format.dwFlags = DSBCAPS_GETCURRENTPOSITION2;
   1.889  #ifdef USE_POSITION_NOTIFY
   1.890 -	format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY;
   1.891 +    format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY;
   1.892  #endif
   1.893 -	if ( ! focus ) {
   1.894 -		format.dwFlags |= DSBCAPS_GLOBALFOCUS;
   1.895 -	} else {
   1.896 -		format.dwFlags |= DSBCAPS_STICKYFOCUS;
   1.897 -	}
   1.898 -	format.dwBufferBytes = numchunks*chunksize;
   1.899 -	if ( (format.dwBufferBytes < DSBSIZE_MIN) ||
   1.900 -	     (format.dwBufferBytes > DSBSIZE_MAX) ) {
   1.901 -		SDL_SetError("Sound buffer size must be between %d and %d",
   1.902 -				DSBSIZE_MIN/numchunks, DSBSIZE_MAX/numchunks);
   1.903 -		return(-1);
   1.904 -	}
   1.905 -	format.dwReserved = 0;
   1.906 -	format.lpwfxFormat = wavefmt;
   1.907 -	result = IDirectSound_CreateSoundBuffer(sndObj, &format, sndbuf, NULL);
   1.908 -	if ( result != DS_OK ) {
   1.909 -		SetDSerror("DirectSound CreateSoundBuffer", result);
   1.910 -		return(-1);
   1.911 -	}
   1.912 -	IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt);
   1.913 +    if (!focus) {
   1.914 +        format.dwFlags |= DSBCAPS_GLOBALFOCUS;
   1.915 +    } else {
   1.916 +        format.dwFlags |= DSBCAPS_STICKYFOCUS;
   1.917 +    }
   1.918 +    format.dwBufferBytes = numchunks * chunksize;
   1.919 +    if ((format.dwBufferBytes < DSBSIZE_MIN) ||
   1.920 +        (format.dwBufferBytes > DSBSIZE_MAX)) {
   1.921 +        SDL_SetError("Sound buffer size must be between %d and %d",
   1.922 +                     DSBSIZE_MIN / numchunks, DSBSIZE_MAX / numchunks);
   1.923 +        return (-1);
   1.924 +    }
   1.925 +    format.dwReserved = 0;
   1.926 +    format.lpwfxFormat = wavefmt;
   1.927 +    result = IDirectSound_CreateSoundBuffer(sndObj, &format, sndbuf, NULL);
   1.928 +    if (result != DS_OK) {
   1.929 +        SetDSerror("DirectSound CreateSoundBuffer", result);
   1.930 +        return (-1);
   1.931 +    }
   1.932 +    IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt);
   1.933  
   1.934 -	/* Silence the initial audio buffer */
   1.935 -	result = IDirectSoundBuffer_Lock(*sndbuf, 0, format.dwBufferBytes,
   1.936 -	                                 (LPVOID *)&pvAudioPtr1, &dwAudioBytes1,
   1.937 -	                                 (LPVOID *)&pvAudioPtr2, &dwAudioBytes2,
   1.938 -	                                 DSBLOCK_ENTIREBUFFER);
   1.939 -	if ( result == DS_OK ) {
   1.940 -		if ( wavefmt->wBitsPerSample == 8 ) {
   1.941 -			SDL_memset(pvAudioPtr1, 0x80, dwAudioBytes1);
   1.942 -		} else {
   1.943 -			SDL_memset(pvAudioPtr1, 0x00, dwAudioBytes1);
   1.944 -		}
   1.945 -		IDirectSoundBuffer_Unlock(*sndbuf,
   1.946 -		                          (LPVOID)pvAudioPtr1, dwAudioBytes1,
   1.947 -		                          (LPVOID)pvAudioPtr2, dwAudioBytes2);
   1.948 -	}
   1.949 +    /* Silence the initial audio buffer */
   1.950 +    result = IDirectSoundBuffer_Lock(*sndbuf, 0, format.dwBufferBytes,
   1.951 +                                     (LPVOID *) & pvAudioPtr1, &dwAudioBytes1,
   1.952 +                                     (LPVOID *) & pvAudioPtr2, &dwAudioBytes2,
   1.953 +                                     DSBLOCK_ENTIREBUFFER);
   1.954 +    if (result == DS_OK) {
   1.955 +        if (wavefmt->wBitsPerSample == 8) {
   1.956 +            SDL_memset(pvAudioPtr1, 0x80, dwAudioBytes1);
   1.957 +        } else {
   1.958 +            SDL_memset(pvAudioPtr1, 0x00, dwAudioBytes1);
   1.959 +        }
   1.960 +        IDirectSoundBuffer_Unlock(*sndbuf,
   1.961 +                                  (LPVOID) pvAudioPtr1, dwAudioBytes1,
   1.962 +                                  (LPVOID) pvAudioPtr2, dwAudioBytes2);
   1.963 +    }
   1.964  
   1.965 -	/* We're ready to go */
   1.966 -	return(numchunks);
   1.967 +    /* We're ready to go */
   1.968 +    return (numchunks);
   1.969  }
   1.970  
   1.971  /* This function tries to set position notify events on the mixing buffer */
   1.972  #ifdef USE_POSITION_NOTIFY
   1.973 -static int CreateAudioEvent(_THIS)
   1.974 +static int
   1.975 +CreateAudioEvent(_THIS)
   1.976  {
   1.977 -	LPDIRECTSOUNDNOTIFY notify;
   1.978 -	DSBPOSITIONNOTIFY *notify_positions;
   1.979 -	int i, retval;
   1.980 -	HRESULT result;
   1.981 +    LPDIRECTSOUNDNOTIFY notify;
   1.982 +    DSBPOSITIONNOTIFY *notify_positions;
   1.983 +    int i, retval;
   1.984 +    HRESULT result;
   1.985  
   1.986 -	/* Default to fail on exit */
   1.987 -	retval = -1;
   1.988 -	notify = NULL;
   1.989 +    /* Default to fail on exit */
   1.990 +    retval = -1;
   1.991 +    notify = NULL;
   1.992  
   1.993 -	/* Query for the interface */
   1.994 -	result = IDirectSoundBuffer_QueryInterface(mixbuf,
   1.995 -			&IID_IDirectSoundNotify, (void *)&notify);
   1.996 -	if ( result != DS_OK ) {
   1.997 -		goto done;
   1.998 -	}
   1.999 +    /* Query for the interface */
  1.1000 +    result = IDirectSoundBuffer_QueryInterface(mixbuf,
  1.1001 +                                               &IID_IDirectSoundNotify,
  1.1002 +                                               (void *) &notify);
  1.1003 +    if (result != DS_OK) {
  1.1004 +        goto done;
  1.1005 +    }
  1.1006  
  1.1007 -	/* Allocate the notify structures */
  1.1008 -	notify_positions = (DSBPOSITIONNOTIFY *)SDL_malloc(NUM_BUFFERS*
  1.1009 -					sizeof(*notify_positions));
  1.1010 -	if ( notify_positions == NULL ) {
  1.1011 -		goto done;
  1.1012 -	}
  1.1013 +    /* Allocate the notify structures */
  1.1014 +    notify_positions = (DSBPOSITIONNOTIFY *) SDL_malloc(NUM_BUFFERS *
  1.1015 +                                                        sizeof
  1.1016 +                                                        (*notify_positions));
  1.1017 +    if (notify_positions == NULL) {
  1.1018 +        goto done;
  1.1019 +    }
  1.1020  
  1.1021 -	/* Create the notify event */
  1.1022 -	audio_event = CreateEvent(NULL, FALSE, FALSE, NULL);
  1.1023 -	if ( audio_event == NULL ) {
  1.1024 -		goto done;
  1.1025 -	}
  1.1026 +    /* Create the notify event */
  1.1027 +    audio_event = CreateEvent(NULL, FALSE, FALSE, NULL);
  1.1028 +    if (audio_event == NULL) {
  1.1029 +        goto done;
  1.1030 +    }
  1.1031  
  1.1032 -	/* Set up the notify structures */
  1.1033 -	for ( i=0; i<NUM_BUFFERS; ++i ) {
  1.1034 -		notify_positions[i].dwOffset = i*mixlen;
  1.1035 -		notify_positions[i].hEventNotify = audio_event;
  1.1036 -	}
  1.1037 -	result = IDirectSoundNotify_SetNotificationPositions(notify,
  1.1038 -					NUM_BUFFERS, notify_positions);
  1.1039 -	if ( result == DS_OK ) {
  1.1040 -		retval = 0;
  1.1041 -	}
  1.1042 -done:
  1.1043 -	if ( notify != NULL ) {
  1.1044 -		IDirectSoundNotify_Release(notify);
  1.1045 -	}
  1.1046 -	return(retval);
  1.1047 +    /* Set up the notify structures */
  1.1048 +    for (i = 0; i < NUM_BUFFERS; ++i) {
  1.1049 +        notify_positions[i].dwOffset = i * mixlen;
  1.1050 +        notify_positions[i].hEventNotify = audio_event;
  1.1051 +    }
  1.1052 +    result = IDirectSoundNotify_SetNotificationPositions(notify,
  1.1053 +                                                         NUM_BUFFERS,
  1.1054 +                                                         notify_positions);
  1.1055 +    if (result == DS_OK) {
  1.1056 +        retval = 0;
  1.1057 +    }
  1.1058 +  done:
  1.1059 +    if (notify != NULL) {
  1.1060 +        IDirectSoundNotify_Release(notify);
  1.1061 +    }
  1.1062 +    return (retval);
  1.1063  }
  1.1064  #endif /* USE_POSITION_NOTIFY */
  1.1065  
  1.1066 -static int DX5_OpenAudio(_THIS, SDL_AudioSpec *spec)
  1.1067 +static int
  1.1068 +DX5_OpenAudio(_THIS, SDL_AudioSpec * spec)
  1.1069  {
  1.1070 -	HRESULT      result;
  1.1071 -	WAVEFORMATEX waveformat;
  1.1072 +    HRESULT result;
  1.1073 +    WAVEFORMATEX waveformat;
  1.1074  
  1.1075 -	/* Set basic WAVE format parameters */
  1.1076 -	SDL_memset(&waveformat, 0, sizeof(waveformat));
  1.1077 -	waveformat.wFormatTag = WAVE_FORMAT_PCM;
  1.1078 +    /* Set basic WAVE format parameters */
  1.1079 +    SDL_memset(&waveformat, 0, sizeof(waveformat));
  1.1080 +    waveformat.wFormatTag = WAVE_FORMAT_PCM;
  1.1081  
  1.1082 -	/* Determine the audio parameters from the AudioSpec */
  1.1083 -	switch ( spec->format & 0xFF ) {
  1.1084 -		case 8:
  1.1085 -			/* Unsigned 8 bit audio data */
  1.1086 -			spec->format = AUDIO_U8;
  1.1087 -			silence = 0x80;
  1.1088 -			waveformat.wBitsPerSample = 8;
  1.1089 -			break;
  1.1090 -		case 16:
  1.1091 -			/* Signed 16 bit audio data */
  1.1092 -			spec->format = AUDIO_S16;
  1.1093 -			silence = 0x00;
  1.1094 -			waveformat.wBitsPerSample = 16;
  1.1095 -			break;
  1.1096 -		default:
  1.1097 -			SDL_SetError("Unsupported audio format");
  1.1098 -			return(-1);
  1.1099 -	}
  1.1100 -	waveformat.nChannels = spec->channels;
  1.1101 -	waveformat.nSamplesPerSec = spec->freq;
  1.1102 -	waveformat.nBlockAlign =
  1.1103 -		waveformat.nChannels * (waveformat.wBitsPerSample/8);
  1.1104 -	waveformat.nAvgBytesPerSec = 
  1.1105 -		waveformat.nSamplesPerSec * waveformat.nBlockAlign;
  1.1106 +    /* Determine the audio parameters from the AudioSpec */
  1.1107 +    switch (spec->format & 0xFF) {
  1.1108 +    case 8:
  1.1109 +        /* Unsigned 8 bit audio data */
  1.1110 +        spec->format = AUDIO_U8;
  1.1111 +        silence = 0x80;
  1.1112 +        waveformat.wBitsPerSample = 8;
  1.1113 +        break;
  1.1114 +    case 16:
  1.1115 +        /* Signed 16 bit audio data */
  1.1116 +        spec->format = AUDIO_S16;
  1.1117 +        silence = 0x00;
  1.1118 +        waveformat.wBitsPerSample = 16;
  1.1119 +        break;
  1.1120 +    default:
  1.1121 +        SDL_SetError("Unsupported audio format");
  1.1122 +        return (-1);
  1.1123 +    }
  1.1124 +    waveformat.nChannels = spec->channels;
  1.1125 +    waveformat.nSamplesPerSec = spec->freq;
  1.1126 +    waveformat.nBlockAlign =
  1.1127 +        waveformat.nChannels * (waveformat.wBitsPerSample / 8);
  1.1128 +    waveformat.nAvgBytesPerSec =
  1.1129 +        waveformat.nSamplesPerSec * waveformat.nBlockAlign;
  1.1130  
  1.1131 -	/* Update the fragment size as size in bytes */
  1.1132 -	SDL_CalculateAudioSpec(spec);
  1.1133 +    /* Update the fragment size as size in bytes */
  1.1134 +    SDL_CalculateAudioSpec(spec);
  1.1135  
  1.1136 -	/* Open the audio device */
  1.1137 -	result = DSoundCreate(NULL, &sound, NULL);
  1.1138 -	if ( result != DS_OK ) {
  1.1139 -		SetDSerror("DirectSoundCreate", result);
  1.1140 -		return(-1);
  1.1141 -	}
  1.1142 +    /* Open the audio device */
  1.1143 +    result = DSoundCreate(NULL, &sound, NULL);
  1.1144 +    if (result != DS_OK) {
  1.1145 +        SetDSerror("DirectSoundCreate", result);
  1.1146 +        return (-1);
  1.1147 +    }
  1.1148  
  1.1149 -	/* Create the audio buffer to which we write */
  1.1150 -	NUM_BUFFERS = -1;
  1.1151 +    /* Create the audio buffer to which we write */
  1.1152 +    NUM_BUFFERS = -1;
  1.1153  #ifdef USE_PRIMARY_BUFFER
  1.1154 -	if ( mainwin ) {
  1.1155 -		NUM_BUFFERS = CreatePrimary(sound, mainwin, &mixbuf,
  1.1156 -						&waveformat, spec->size);
  1.1157 -	}
  1.1158 +    if (mainwin) {
  1.1159 +        NUM_BUFFERS = CreatePrimary(sound, mainwin, &mixbuf,
  1.1160 +                                    &waveformat, spec->size);
  1.1161 +    }
  1.1162  #endif /* USE_PRIMARY_BUFFER */
  1.1163 -	if ( NUM_BUFFERS < 0 ) {
  1.1164 -		NUM_BUFFERS = CreateSecondary(sound, mainwin, &mixbuf,
  1.1165 -						&waveformat, spec->size);
  1.1166 -		if ( NUM_BUFFERS < 0 ) {
  1.1167 -			return(-1);
  1.1168 -		}
  1.1169 +    if (NUM_BUFFERS < 0) {
  1.1170 +        NUM_BUFFERS = CreateSecondary(sound, mainwin, &mixbuf,
  1.1171 +                                      &waveformat, spec->size);
  1.1172 +        if (NUM_BUFFERS < 0) {
  1.1173 +            return (-1);
  1.1174 +        }
  1.1175  #ifdef DEBUG_SOUND
  1.1176 -		fprintf(stderr, "Using secondary audio buffer\n");
  1.1177 +        fprintf(stderr, "Using secondary audio buffer\n");
  1.1178  #endif
  1.1179 -	}
  1.1180 +    }
  1.1181  #ifdef DEBUG_SOUND
  1.1182 -	else
  1.1183 -		fprintf(stderr, "Using primary audio buffer\n");
  1.1184 +    else
  1.1185 +        fprintf(stderr, "Using primary audio buffer\n");
  1.1186  #endif
  1.1187  
  1.1188 -	/* The buffer will auto-start playing in DX5_WaitAudio() */
  1.1189 -	lastchunk = 0;
  1.1190 -	mixlen = spec->size;
  1.1191 +    /* The buffer will auto-start playing in DX5_WaitAudio() */
  1.1192 +    lastchunk = 0;
  1.1193 +    mixlen = spec->size;
  1.1194  
  1.1195  #ifdef USE_POSITION_NOTIFY
  1.1196 -	/* See if we can use DirectX 6 event notification */
  1.1197 -	if ( CreateAudioEvent(this) == 0 ) {
  1.1198 -		this->WaitAudio = DX6_WaitAudio_EventWait;
  1.1199 -	} else {
  1.1200 -		this->WaitAudio = DX5_WaitAudio_BusyWait;
  1.1201 -	}
  1.1202 +    /* See if we can use DirectX 6 event notification */
  1.1203 +    if (CreateAudioEvent(this) == 0) {
  1.1204 +        this->WaitAudio = DX6_WaitAudio_EventWait;
  1.1205 +    } else {
  1.1206 +        this->WaitAudio = DX5_WaitAudio_BusyWait;
  1.1207 +    }
  1.1208  #endif
  1.1209 -	return(0);
  1.1210 +    return (0);
  1.1211  }
  1.1212  
  1.1213 +/* vi: set ts=4 sw=4 expandtab: */