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 38265b483ce86357
parent 3825 76c5a414b996
child 3827 1806fd1acba4
Minor fixes in dsp driver.
src/audio/dsp/SDL_dspaudio.c
     1.1 --- a/src/audio/dsp/SDL_dspaudio.c	Sat Oct 07 07:25:30 2006 +0000
     1.2 +++ b/src/audio/dsp/SDL_dspaudio.c	Sat Oct 07 07:53:26 2006 +0000
     1.3 @@ -189,6 +189,7 @@
     1.4      /* Open the audio device */
     1.5      this->hidden->audio_fd = open(devname, flags, 0);
     1.6      if (this->hidden->audio_fd < 0) {
     1.7 +        DSP_CloseDevice(this);
     1.8          SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
     1.9          return 0;
    1.10      }
    1.11 @@ -196,12 +197,12 @@
    1.12  
    1.13      /* Make the file descriptor use blocking writes with fcntl() */
    1.14      {
    1.15 -        long flags;
    1.16 -        flags = fcntl(this->hidden->audio_fd, F_GETFL);
    1.17 -        flags &= ~O_NONBLOCK;
    1.18 -        if (fcntl(this->hidden->audio_fd, F_SETFL, flags) < 0) {
    1.19 +        long ctlflags;
    1.20 +        ctlflags = fcntl(this->hidden->audio_fd, F_GETFL);
    1.21 +        ctlflags &= ~O_NONBLOCK;
    1.22 +        if (fcntl(this->hidden->audio_fd, F_SETFL, ctlflags) < 0) {
    1.23 +            DSP_CloseDevice(this);
    1.24              SDL_SetError("Couldn't set audio blocking mode");
    1.25 -            DSP_CloseDevice(this);
    1.26              return 0;
    1.27          }
    1.28      }
    1.29 @@ -209,8 +210,8 @@
    1.30      /* Get a list of supported hardware formats */
    1.31      if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) {
    1.32          perror("SNDCTL_DSP_GETFMTS");
    1.33 +        DSP_CloseDevice(this);
    1.34          SDL_SetError("Couldn't get audio format list");
    1.35 -        DSP_CloseDevice(this);
    1.36          return 0;
    1.37      }
    1.38  
    1.39 @@ -267,8 +268,8 @@
    1.40          }
    1.41      }
    1.42      if (format == 0) {
    1.43 +        DSP_CloseDevice(this);
    1.44          SDL_SetError("Couldn't find any hardware audio formats");
    1.45 -        DSP_CloseDevice(this);
    1.46          return 0;
    1.47      }
    1.48      this->spec.format = test_format;
    1.49 @@ -278,8 +279,8 @@
    1.50      if ( (ioctl(this->hidden->audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) ||
    1.51           (value != format) ) {
    1.52          perror("SNDCTL_DSP_SETFMT");
    1.53 +        DSP_CloseDevice(this);
    1.54          SDL_SetError("Couldn't set audio format");
    1.55 -        DSP_CloseDevice(this);
    1.56          return 0;
    1.57      }
    1.58  
    1.59 @@ -287,8 +288,8 @@
    1.60      value = this->spec.channels;
    1.61      if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0) {
    1.62          perror("SNDCTL_DSP_CHANNELS");
    1.63 +        DSP_CloseDevice(this);
    1.64          SDL_SetError("Cannot set the number of channels");
    1.65 -        DSP_CloseDevice(this);
    1.66          return 0;
    1.67      }
    1.68      this->spec.channels = value;
    1.69 @@ -297,8 +298,8 @@
    1.70      value = this->spec.freq;
    1.71      if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_SPEED, &value) < 0) {
    1.72          perror("SNDCTL_DSP_SPEED");
    1.73 +        DSP_CloseDevice(this);
    1.74          SDL_SetError("Couldn't set audio frequency");
    1.75 -        DSP_CloseDevice(this);
    1.76          return 0;
    1.77      }
    1.78      this->spec.freq = value;
    1.79 @@ -309,8 +310,8 @@
    1.80      /* Determine the power of two of the fragment size */
    1.81      for (frag_spec = 0; (0x01U << frag_spec) < this->spec.size; ++frag_spec);
    1.82      if ((0x01U << frag_spec) != this->spec.size) {
    1.83 +        DSP_CloseDevice(this);
    1.84          SDL_SetError("Fragment size must be a power of two");
    1.85 -        DSP_CloseDevice(this);
    1.86          return 0;
    1.87      }
    1.88      frag_spec |= 0x00020000;    /* two fragments, for low latency */
    1.89 @@ -339,6 +340,7 @@
    1.90      this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
    1.91      if (this->hidden->mixbuf == NULL) {
    1.92          DSP_CloseDevice(this);
    1.93 +        SDL_OutOfMemory();
    1.94          return 0;
    1.95      }
    1.96      SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);