Minor fixes in dsp driver. SDL-ryan-multiple-audio-device
authorRyan C. Gordon <icculus@icculus.org>
Sat, 07 Oct 2006 07:53:26 +0000
branchSDL-ryan-multiple-audio-device
changeset 3826 5b483ce86357
parent 3825 76c5a414b996
child 3827 1806fd1acba4
Minor fixes in dsp driver.
src/audio/dsp/SDL_dspaudio.c
--- a/src/audio/dsp/SDL_dspaudio.c	Sat Oct 07 07:25:30 2006 +0000
+++ b/src/audio/dsp/SDL_dspaudio.c	Sat Oct 07 07:53:26 2006 +0000
@@ -189,6 +189,7 @@
     /* Open the audio device */
     this->hidden->audio_fd = open(devname, flags, 0);
     if (this->hidden->audio_fd < 0) {
+        DSP_CloseDevice(this);
         SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
         return 0;
     }
@@ -196,12 +197,12 @@
 
     /* Make the file descriptor use blocking writes with fcntl() */
     {
-        long flags;
-        flags = fcntl(this->hidden->audio_fd, F_GETFL);
-        flags &= ~O_NONBLOCK;
-        if (fcntl(this->hidden->audio_fd, F_SETFL, flags) < 0) {
+        long ctlflags;
+        ctlflags = fcntl(this->hidden->audio_fd, F_GETFL);
+        ctlflags &= ~O_NONBLOCK;
+        if (fcntl(this->hidden->audio_fd, F_SETFL, ctlflags) < 0) {
+            DSP_CloseDevice(this);
             SDL_SetError("Couldn't set audio blocking mode");
-            DSP_CloseDevice(this);
             return 0;
         }
     }
@@ -209,8 +210,8 @@
     /* Get a list of supported hardware formats */
     if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) {
         perror("SNDCTL_DSP_GETFMTS");
+        DSP_CloseDevice(this);
         SDL_SetError("Couldn't get audio format list");
-        DSP_CloseDevice(this);
         return 0;
     }
 
@@ -267,8 +268,8 @@
         }
     }
     if (format == 0) {
+        DSP_CloseDevice(this);
         SDL_SetError("Couldn't find any hardware audio formats");
-        DSP_CloseDevice(this);
         return 0;
     }
     this->spec.format = test_format;
@@ -278,8 +279,8 @@
     if ( (ioctl(this->hidden->audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) ||
          (value != format) ) {
         perror("SNDCTL_DSP_SETFMT");
+        DSP_CloseDevice(this);
         SDL_SetError("Couldn't set audio format");
-        DSP_CloseDevice(this);
         return 0;
     }
 
@@ -287,8 +288,8 @@
     value = this->spec.channels;
     if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0) {
         perror("SNDCTL_DSP_CHANNELS");
+        DSP_CloseDevice(this);
         SDL_SetError("Cannot set the number of channels");
-        DSP_CloseDevice(this);
         return 0;
     }
     this->spec.channels = value;
@@ -297,8 +298,8 @@
     value = this->spec.freq;
     if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_SPEED, &value) < 0) {
         perror("SNDCTL_DSP_SPEED");
+        DSP_CloseDevice(this);
         SDL_SetError("Couldn't set audio frequency");
-        DSP_CloseDevice(this);
         return 0;
     }
     this->spec.freq = value;
@@ -309,8 +310,8 @@
     /* Determine the power of two of the fragment size */
     for (frag_spec = 0; (0x01U << frag_spec) < this->spec.size; ++frag_spec);
     if ((0x01U << frag_spec) != this->spec.size) {
+        DSP_CloseDevice(this);
         SDL_SetError("Fragment size must be a power of two");
-        DSP_CloseDevice(this);
         return 0;
     }
     frag_spec |= 0x00020000;    /* two fragments, for low latency */
@@ -339,6 +340,7 @@
     this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
     if (this->hidden->mixbuf == NULL) {
         DSP_CloseDevice(this);
+        SDL_OutOfMemory();
         return 0;
     }
     SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);