1.1 --- a/src/audio/nas/SDL_nasaudio.c Mon May 29 03:53:21 2006 +0000
1.2 +++ b/src/audio/nas/SDL_nasaudio.c Mon May 29 04:04:35 2006 +0000
1.3 @@ -43,52 +43,52 @@
1.4 static struct SDL_PrivateAudioData *this2 = NULL;
1.5
1.6 /* Audio driver functions */
1.7 -static int NAS_OpenAudio (_THIS, SDL_AudioSpec * spec);
1.8 -static void NAS_WaitAudio (_THIS);
1.9 -static void NAS_PlayAudio (_THIS);
1.10 -static Uint8 *NAS_GetAudioBuf (_THIS);
1.11 -static void NAS_CloseAudio (_THIS);
1.12 +static int NAS_OpenAudio(_THIS, SDL_AudioSpec * spec);
1.13 +static void NAS_WaitAudio(_THIS);
1.14 +static void NAS_PlayAudio(_THIS);
1.15 +static Uint8 *NAS_GetAudioBuf(_THIS);
1.16 +static void NAS_CloseAudio(_THIS);
1.17
1.18 /* Audio driver bootstrap functions */
1.19
1.20 static int
1.21 -Audio_Available (void)
1.22 +Audio_Available(void)
1.23 {
1.24 - AuServer *aud = AuOpenServer ("", 0, NULL, 0, NULL, NULL);
1.25 + AuServer *aud = AuOpenServer("", 0, NULL, 0, NULL, NULL);
1.26 if (!aud)
1.27 return 0;
1.28
1.29 - AuCloseServer (aud);
1.30 + AuCloseServer(aud);
1.31 return 1;
1.32 }
1.33
1.34 static void
1.35 -Audio_DeleteDevice (SDL_AudioDevice * device)
1.36 +Audio_DeleteDevice(SDL_AudioDevice * device)
1.37 {
1.38 - SDL_free (device->hidden);
1.39 - SDL_free (device);
1.40 + SDL_free(device->hidden);
1.41 + SDL_free(device);
1.42 }
1.43
1.44 static SDL_AudioDevice *
1.45 -Audio_CreateDevice (int devindex)
1.46 +Audio_CreateDevice(int devindex)
1.47 {
1.48 SDL_AudioDevice *this;
1.49
1.50 /* Initialize all variables that we clean on shutdown */
1.51 - this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice));
1.52 + this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
1.53 if (this) {
1.54 - SDL_memset (this, 0, (sizeof *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 + SDL_malloc((sizeof *this->hidden));
1.59 }
1.60 if ((this == NULL) || (this->hidden == NULL)) {
1.61 - SDL_OutOfMemory ();
1.62 + SDL_OutOfMemory();
1.63 if (this) {
1.64 - SDL_free (this);
1.65 + SDL_free(this);
1.66 }
1.67 return (0);
1.68 }
1.69 - SDL_memset (this->hidden, 0, (sizeof *this->hidden));
1.70 + SDL_memset(this->hidden, 0, (sizeof *this->hidden));
1.71
1.72 /* Set the function pointers */
1.73 this->OpenAudio = NAS_OpenAudio;
1.74 @@ -109,60 +109,59 @@
1.75
1.76 /* This function waits until it is possible to write a full sound buffer */
1.77 static void
1.78 -NAS_WaitAudio (_THIS)
1.79 +NAS_WaitAudio(_THIS)
1.80 {
1.81 while (this->hidden->buf_free < this->hidden->mixlen) {
1.82 AuEvent ev;
1.83 - AuNextEvent (this->hidden->aud, AuTrue, &ev);
1.84 - AuDispatchEvent (this->hidden->aud, &ev);
1.85 + AuNextEvent(this->hidden->aud, AuTrue, &ev);
1.86 + AuDispatchEvent(this->hidden->aud, &ev);
1.87 }
1.88 }
1.89
1.90 static void
1.91 -NAS_PlayAudio (_THIS)
1.92 +NAS_PlayAudio(_THIS)
1.93 {
1.94 while (this->hidden->mixlen > this->hidden->buf_free) { /* We think the buffer is full? Yikes! Ask the server for events,
1.95 in the hope that some of them is LowWater events telling us more
1.96 of the buffer is free now than what we think. */
1.97 AuEvent ev;
1.98 - AuNextEvent (this->hidden->aud, AuTrue, &ev);
1.99 - AuDispatchEvent (this->hidden->aud, &ev);
1.100 + AuNextEvent(this->hidden->aud, AuTrue, &ev);
1.101 + AuDispatchEvent(this->hidden->aud, &ev);
1.102 }
1.103 this->hidden->buf_free -= this->hidden->mixlen;
1.104
1.105 /* Write the audio data */
1.106 - AuWriteElement (this->hidden->aud, this->hidden->flow, 0,
1.107 - this->hidden->mixlen, this->hidden->mixbuf, AuFalse,
1.108 - NULL);
1.109 + AuWriteElement(this->hidden->aud, this->hidden->flow, 0,
1.110 + this->hidden->mixlen, this->hidden->mixbuf, AuFalse, NULL);
1.111
1.112 this->hidden->written += this->hidden->mixlen;
1.113
1.114 #ifdef DEBUG_AUDIO
1.115 - fprintf (stderr, "Wrote %d bytes of audio data\n", this->hidden->mixlen);
1.116 + fprintf(stderr, "Wrote %d bytes of audio data\n", this->hidden->mixlen);
1.117 #endif
1.118 }
1.119
1.120 static Uint8 *
1.121 -NAS_GetAudioBuf (_THIS)
1.122 +NAS_GetAudioBuf(_THIS)
1.123 {
1.124 return (this->hidden->mixbuf);
1.125 }
1.126
1.127 static void
1.128 -NAS_CloseAudio (_THIS)
1.129 +NAS_CloseAudio(_THIS)
1.130 {
1.131 if (this->hidden->mixbuf != NULL) {
1.132 - SDL_FreeAudioMem (this->hidden->mixbuf);
1.133 + SDL_FreeAudioMem(this->hidden->mixbuf);
1.134 this->hidden->mixbuf = NULL;
1.135 }
1.136 if (this->hidden->aud) {
1.137 - AuCloseServer (this->hidden->aud);
1.138 + AuCloseServer(this->hidden->aud);
1.139 this->hidden->aud = 0;
1.140 }
1.141 }
1.142
1.143 static unsigned char
1.144 -sdlformat_to_auformat (unsigned int fmt)
1.145 +sdlformat_to_auformat(unsigned int fmt)
1.146 {
1.147 switch (fmt) {
1.148 case AUDIO_U8:
1.149 @@ -182,7 +181,7 @@
1.150 }
1.151
1.152 static AuBool
1.153 -event_handler (AuServer * aud, AuEvent * ev, AuEventHandlerRec * hnd)
1.154 +event_handler(AuServer * aud, AuEvent * ev, AuEventHandlerRec * hnd)
1.155 {
1.156 switch (ev->type) {
1.157 case AuEventTypeElementNotify:
1.158 @@ -193,7 +192,7 @@
1.159 case AuElementNotifyKindLowWater:
1.160 if (this2->buf_free >= 0) {
1.161 this2->really += event->num_bytes;
1.162 - gettimeofday (&this2->last_tv, 0);
1.163 + gettimeofday(&this2->last_tv, 0);
1.164 this2->buf_free += event->num_bytes;
1.165 } else {
1.166 this2->buf_free = event->num_bytes;
1.167 @@ -205,7 +204,7 @@
1.168 if (event->reason != AuReasonUser) {
1.169 if (this2->buf_free >= 0) {
1.170 this2->really += event->num_bytes;
1.171 - gettimeofday (&this2->last_tv, 0);
1.172 + gettimeofday(&this2->last_tv, 0);
1.173 this2->buf_free += event->num_bytes;
1.174 } else {
1.175 this2->buf_free = event->num_bytes;
1.176 @@ -220,22 +219,21 @@
1.177 }
1.178
1.179 static AuDeviceID
1.180 -find_device (_THIS, int nch)
1.181 +find_device(_THIS, int nch)
1.182 {
1.183 int i;
1.184 - for (i = 0; i < AuServerNumDevices (this->hidden->aud); i++) {
1.185 - if ((AuDeviceKind (AuServerDevice (this->hidden->aud, i)) ==
1.186 + for (i = 0; i < AuServerNumDevices(this->hidden->aud); i++) {
1.187 + if ((AuDeviceKind(AuServerDevice(this->hidden->aud, i)) ==
1.188 AuComponentKindPhysicalOutput) &&
1.189 - AuDeviceNumTracks (AuServerDevice (this->hidden->aud, i)) ==
1.190 - nch) {
1.191 - return AuDeviceIdentifier (AuServerDevice (this->hidden->aud, i));
1.192 + AuDeviceNumTracks(AuServerDevice(this->hidden->aud, i)) == nch) {
1.193 + return AuDeviceIdentifier(AuServerDevice(this->hidden->aud, i));
1.194 }
1.195 }
1.196 return AuNone;
1.197 }
1.198
1.199 static int
1.200 -NAS_OpenAudio (_THIS, SDL_AudioSpec * spec)
1.201 +NAS_OpenAudio(_THIS, SDL_AudioSpec * spec)
1.202 {
1.203 AuElement elms[3];
1.204 int buffer_size;
1.205 @@ -245,33 +243,32 @@
1.206
1.207 /* Try for a closest match on audio format */
1.208 format = 0;
1.209 - for (test_format = SDL_FirstAudioFormat (spec->format);
1.210 + for (test_format = SDL_FirstAudioFormat(spec->format);
1.211 !format && test_format;) {
1.212 - format = sdlformat_to_auformat (test_format);
1.213 + format = sdlformat_to_auformat(test_format);
1.214
1.215 if (format == AuNone) {
1.216 - test_format = SDL_NextAudioFormat ();
1.217 + test_format = SDL_NextAudioFormat();
1.218 }
1.219 }
1.220 if (format == 0) {
1.221 - SDL_SetError ("Couldn't find any hardware audio formats");
1.222 + SDL_SetError("Couldn't find any hardware audio formats");
1.223 return (-1);
1.224 }
1.225 spec->format = test_format;
1.226
1.227 - this->hidden->aud = AuOpenServer ("", 0, NULL, 0, NULL, NULL);
1.228 + this->hidden->aud = AuOpenServer("", 0, NULL, 0, NULL, NULL);
1.229 if (this->hidden->aud == 0) {
1.230 - SDL_SetError ("Couldn't open connection to NAS server");
1.231 + SDL_SetError("Couldn't open connection to NAS server");
1.232 return (-1);
1.233 }
1.234
1.235 - this->hidden->dev = find_device (this, spec->channels);
1.236 + this->hidden->dev = find_device(this, spec->channels);
1.237 if ((this->hidden->dev == AuNone)
1.238 - || (!(this->hidden->flow = AuCreateFlow (this->hidden->aud, NULL)))) {
1.239 - AuCloseServer (this->hidden->aud);
1.240 + || (!(this->hidden->flow = AuCreateFlow(this->hidden->aud, NULL)))) {
1.241 + AuCloseServer(this->hidden->aud);
1.242 this->hidden->aud = 0;
1.243 - SDL_SetError
1.244 - ("Couldn't find a fitting playback device on NAS server");
1.245 + SDL_SetError("Couldn't find a fitting playback device on NAS server");
1.246 return (-1);
1.247 }
1.248
1.249 @@ -283,32 +280,32 @@
1.250 buffer_size = 32768; /* So that the buffer won't get unmanageably big. */
1.251
1.252 /* Calculate the final parameters for this audio specification */
1.253 - SDL_CalculateAudioSpec (spec);
1.254 + SDL_CalculateAudioSpec(spec);
1.255
1.256 this2 = this->hidden;
1.257
1.258 - AuMakeElementImportClient (elms, spec->freq, format, spec->channels,
1.259 - AuTrue, buffer_size, buffer_size / 4, 0, NULL);
1.260 - AuMakeElementExportDevice (elms + 1, 0, this->hidden->dev, spec->freq,
1.261 - AuUnlimitedSamples, 0, NULL);
1.262 - AuSetElements (this->hidden->aud, this->hidden->flow, AuTrue, 2, elms,
1.263 - NULL);
1.264 - AuRegisterEventHandler (this->hidden->aud, AuEventHandlerIDMask, 0,
1.265 - this->hidden->flow, event_handler,
1.266 - (AuPointer) NULL);
1.267 + AuMakeElementImportClient(elms, spec->freq, format, spec->channels,
1.268 + AuTrue, buffer_size, buffer_size / 4, 0, NULL);
1.269 + AuMakeElementExportDevice(elms + 1, 0, this->hidden->dev, spec->freq,
1.270 + AuUnlimitedSamples, 0, NULL);
1.271 + AuSetElements(this->hidden->aud, this->hidden->flow, AuTrue, 2, elms,
1.272 + NULL);
1.273 + AuRegisterEventHandler(this->hidden->aud, AuEventHandlerIDMask, 0,
1.274 + this->hidden->flow, event_handler,
1.275 + (AuPointer) NULL);
1.276
1.277 - AuStartFlow (this->hidden->aud, this->hidden->flow, NULL);
1.278 + AuStartFlow(this->hidden->aud, this->hidden->flow, NULL);
1.279
1.280 /* Allocate mixing buffer */
1.281 this->hidden->mixlen = spec->size;
1.282 - this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem (this->hidden->mixlen);
1.283 + this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
1.284 if (this->hidden->mixbuf == NULL) {
1.285 return (-1);
1.286 }
1.287 - SDL_memset (this->hidden->mixbuf, spec->silence, spec->size);
1.288 + SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
1.289
1.290 /* Get the parent process id (we're the parent of the audio thread) */
1.291 - this->hidden->parent = getpid ();
1.292 + this->hidden->parent = getpid();
1.293
1.294 /* We're ready to rock and roll. :-) */
1.295 return (0);