src/audio/dummy/SDL_dummyaudio.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1538 b1f8c14f0df5
child 1668 4da1ee79c9af
     1.1 --- a/src/audio/dummy/SDL_dummyaudio.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/src/audio/dummy/SDL_dummyaudio.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -37,120 +37,129 @@
     1.4  #define DUMMYAUD_DRIVER_NAME         "dummy"
     1.5  
     1.6  /* Audio driver functions */
     1.7 -static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec);
     1.8 -static void DUMMYAUD_WaitAudio(_THIS);
     1.9 -static void DUMMYAUD_PlayAudio(_THIS);
    1.10 -static Uint8 *DUMMYAUD_GetAudioBuf(_THIS);
    1.11 -static void DUMMYAUD_CloseAudio(_THIS);
    1.12 +static int DUMMYAUD_OpenAudio (_THIS, SDL_AudioSpec * spec);
    1.13 +static void DUMMYAUD_WaitAudio (_THIS);
    1.14 +static void DUMMYAUD_PlayAudio (_THIS);
    1.15 +static Uint8 *DUMMYAUD_GetAudioBuf (_THIS);
    1.16 +static void DUMMYAUD_CloseAudio (_THIS);
    1.17  
    1.18  /* Audio driver bootstrap functions */
    1.19 -static int DUMMYAUD_Available(void)
    1.20 +static int
    1.21 +DUMMYAUD_Available (void)
    1.22  {
    1.23 -	const char *envr = SDL_getenv("SDL_AUDIODRIVER");
    1.24 -	if (envr && (SDL_strcmp(envr, DUMMYAUD_DRIVER_NAME) == 0)) {
    1.25 -		return(1);
    1.26 -	}
    1.27 -	return(0);
    1.28 +    const char *envr = SDL_getenv ("SDL_AUDIODRIVER");
    1.29 +    if (envr && (SDL_strcmp (envr, DUMMYAUD_DRIVER_NAME) == 0)) {
    1.30 +        return (1);
    1.31 +    }
    1.32 +    return (0);
    1.33  }
    1.34  
    1.35 -static void DUMMYAUD_DeleteDevice(SDL_AudioDevice *device)
    1.36 +static void
    1.37 +DUMMYAUD_DeleteDevice (SDL_AudioDevice * device)
    1.38  {
    1.39 -	SDL_free(device->hidden);
    1.40 -	SDL_free(device);
    1.41 +    SDL_free (device->hidden);
    1.42 +    SDL_free (device);
    1.43  }
    1.44  
    1.45 -static SDL_AudioDevice *DUMMYAUD_CreateDevice(int devindex)
    1.46 +static SDL_AudioDevice *
    1.47 +DUMMYAUD_CreateDevice (int devindex)
    1.48  {
    1.49 -	SDL_AudioDevice *this;
    1.50 +    SDL_AudioDevice *this;
    1.51  
    1.52 -	/* Initialize all variables that we clean on shutdown */
    1.53 -	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
    1.54 -	if ( this ) {
    1.55 -		SDL_memset(this, 0, (sizeof *this));
    1.56 -		this->hidden = (struct SDL_PrivateAudioData *)
    1.57 -				SDL_malloc((sizeof *this->hidden));
    1.58 -	}
    1.59 -	if ( (this == NULL) || (this->hidden == NULL) ) {
    1.60 -		SDL_OutOfMemory();
    1.61 -		if ( this ) {
    1.62 -			SDL_free(this);
    1.63 -		}
    1.64 -		return(0);
    1.65 -	}
    1.66 -	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
    1.67 +    /* Initialize all variables that we clean on shutdown */
    1.68 +    this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice));
    1.69 +    if (this) {
    1.70 +        SDL_memset (this, 0, (sizeof *this));
    1.71 +        this->hidden = (struct SDL_PrivateAudioData *)
    1.72 +            SDL_malloc ((sizeof *this->hidden));
    1.73 +    }
    1.74 +    if ((this == NULL) || (this->hidden == NULL)) {
    1.75 +        SDL_OutOfMemory ();
    1.76 +        if (this) {
    1.77 +            SDL_free (this);
    1.78 +        }
    1.79 +        return (0);
    1.80 +    }
    1.81 +    SDL_memset (this->hidden, 0, (sizeof *this->hidden));
    1.82  
    1.83 -	/* Set the function pointers */
    1.84 -	this->OpenAudio = DUMMYAUD_OpenAudio;
    1.85 -	this->WaitAudio = DUMMYAUD_WaitAudio;
    1.86 -	this->PlayAudio = DUMMYAUD_PlayAudio;
    1.87 -	this->GetAudioBuf = DUMMYAUD_GetAudioBuf;
    1.88 -	this->CloseAudio = DUMMYAUD_CloseAudio;
    1.89 +    /* Set the function pointers */
    1.90 +    this->OpenAudio = DUMMYAUD_OpenAudio;
    1.91 +    this->WaitAudio = DUMMYAUD_WaitAudio;
    1.92 +    this->PlayAudio = DUMMYAUD_PlayAudio;
    1.93 +    this->GetAudioBuf = DUMMYAUD_GetAudioBuf;
    1.94 +    this->CloseAudio = DUMMYAUD_CloseAudio;
    1.95  
    1.96 -	this->free = DUMMYAUD_DeleteDevice;
    1.97 +    this->free = DUMMYAUD_DeleteDevice;
    1.98  
    1.99 -	return this;
   1.100 +    return this;
   1.101  }
   1.102  
   1.103  AudioBootStrap DUMMYAUD_bootstrap = {
   1.104 -	DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver",
   1.105 -	DUMMYAUD_Available, DUMMYAUD_CreateDevice
   1.106 +    DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver",
   1.107 +    DUMMYAUD_Available, DUMMYAUD_CreateDevice
   1.108  };
   1.109  
   1.110  /* This function waits until it is possible to write a full sound buffer */
   1.111 -static void DUMMYAUD_WaitAudio(_THIS)
   1.112 +static void
   1.113 +DUMMYAUD_WaitAudio (_THIS)
   1.114  {
   1.115 -	/* Don't block on first calls to simulate initial fragment filling. */
   1.116 -	if (this->hidden->initial_calls)
   1.117 -		this->hidden->initial_calls--;
   1.118 -	else
   1.119 -		SDL_Delay(this->hidden->write_delay);
   1.120 +    /* Don't block on first calls to simulate initial fragment filling. */
   1.121 +    if (this->hidden->initial_calls)
   1.122 +        this->hidden->initial_calls--;
   1.123 +    else
   1.124 +        SDL_Delay (this->hidden->write_delay);
   1.125  }
   1.126  
   1.127 -static void DUMMYAUD_PlayAudio(_THIS)
   1.128 +static void
   1.129 +DUMMYAUD_PlayAudio (_THIS)
   1.130  {
   1.131 -	/* no-op...this is a null driver. */
   1.132 +    /* no-op...this is a null driver. */
   1.133  }
   1.134  
   1.135 -static Uint8 *DUMMYAUD_GetAudioBuf(_THIS)
   1.136 +static Uint8 *
   1.137 +DUMMYAUD_GetAudioBuf (_THIS)
   1.138  {
   1.139 -	return(this->hidden->mixbuf);
   1.140 +    return (this->hidden->mixbuf);
   1.141  }
   1.142  
   1.143 -static void DUMMYAUD_CloseAudio(_THIS)
   1.144 +static void
   1.145 +DUMMYAUD_CloseAudio (_THIS)
   1.146  {
   1.147 -	if ( this->hidden->mixbuf != NULL ) {
   1.148 -		SDL_FreeAudioMem(this->hidden->mixbuf);
   1.149 -		this->hidden->mixbuf = NULL;
   1.150 -	}
   1.151 +    if (this->hidden->mixbuf != NULL) {
   1.152 +        SDL_FreeAudioMem (this->hidden->mixbuf);
   1.153 +        this->hidden->mixbuf = NULL;
   1.154 +    }
   1.155  }
   1.156  
   1.157 -static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec)
   1.158 +static int
   1.159 +DUMMYAUD_OpenAudio (_THIS, SDL_AudioSpec * spec)
   1.160  {
   1.161 -	float bytes_per_sec = 0.0f;
   1.162 +    float bytes_per_sec = 0.0f;
   1.163  
   1.164 -	/* Allocate mixing buffer */
   1.165 -	this->hidden->mixlen = spec->size;
   1.166 -	this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
   1.167 -	if ( this->hidden->mixbuf == NULL ) {
   1.168 -		return(-1);
   1.169 -	}
   1.170 -	SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
   1.171 +    /* Allocate mixing buffer */
   1.172 +    this->hidden->mixlen = spec->size;
   1.173 +    this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem (this->hidden->mixlen);
   1.174 +    if (this->hidden->mixbuf == NULL) {
   1.175 +        return (-1);
   1.176 +    }
   1.177 +    SDL_memset (this->hidden->mixbuf, spec->silence, spec->size);
   1.178  
   1.179 -	bytes_per_sec = (float) (((spec->format & 0xFF) / 8) *
   1.180 -	                   spec->channels * spec->freq);
   1.181 +    bytes_per_sec = (float) (((spec->format & 0xFF) / 8) *
   1.182 +                             spec->channels * spec->freq);
   1.183  
   1.184 -	/*
   1.185 -	 * We try to make this request more audio at the correct rate for
   1.186 -	 *  a given audio spec, so timing stays fairly faithful.
   1.187 -	 * Also, we have it not block at all for the first two calls, so
   1.188 -	 *  it seems like we're filling two audio fragments right out of the
   1.189 -	 *  gate, like other SDL drivers tend to do.
   1.190 -	 */
   1.191 -	this->hidden->initial_calls = 2;
   1.192 -	this->hidden->write_delay =
   1.193 -	               (Uint32) ((((float) spec->size) / bytes_per_sec) * 1000.0f);
   1.194 +    /*
   1.195 +     * We try to make this request more audio at the correct rate for
   1.196 +     *  a given audio spec, so timing stays fairly faithful.
   1.197 +     * Also, we have it not block at all for the first two calls, so
   1.198 +     *  it seems like we're filling two audio fragments right out of the
   1.199 +     *  gate, like other SDL drivers tend to do.
   1.200 +     */
   1.201 +    this->hidden->initial_calls = 2;
   1.202 +    this->hidden->write_delay =
   1.203 +        (Uint32) ((((float) spec->size) / bytes_per_sec) * 1000.0f);
   1.204  
   1.205 -	/* We're ready to rock and roll. :-) */
   1.206 -	return(0);
   1.207 +    /* We're ready to rock and roll. :-) */
   1.208 +    return (0);
   1.209  }
   1.210  
   1.211 +/* vi: set ts=4 sw=4 expandtab: */