Patched to compile. SDL-ryan-multiple-audio-device
authorRyan C. Gordon
Fri, 06 Oct 2006 04:49:48 +0000
branchSDL-ryan-multiple-audio-device
changeset 3817103bbe13f5eb
parent 3816 9d070c1a45fa
child 3818 49eadd6e8962
Patched to compile.
src/audio/dma/SDL_dmaaudio.c
src/audio/dsp/SDL_dspaudio.c
     1.1 --- a/src/audio/dma/SDL_dmaaudio.c	Fri Oct 06 04:46:58 2006 +0000
     1.2 +++ b/src/audio/dma/SDL_dmaaudio.c	Fri Oct 06 04:49:48 2006 +0000
     1.3 @@ -218,9 +218,26 @@
     1.4  }
     1.5  
     1.6  
     1.7 +static void
     1.8 +DMA_CloseDevice(_THIS)
     1.9 +{
    1.10 +    if (this->hidden != NULL) {
    1.11 +        if (dma_buf != NULL) {
    1.12 +            munmap(dma_buf, dma_len);
    1.13 +            dma_buf = NULL;
    1.14 +        }
    1.15 +        if (audio_fd >= 0) {
    1.16 +            close(audio_fd);
    1.17 +            audio_fd = -1;
    1.18 +        }
    1.19 +        SDL_free(this->hidden);
    1.20 +        this->hidden = NULL;
    1.21 +    }
    1.22 +}
    1.23 +
    1.24  
    1.25  static int
    1.26 -open_device_internal(_THIS, const char *devname, int iscapture)
    1.27 +DMA_OpenDevice(_THIS, const char *devname, int iscapture)
    1.28  {
    1.29      const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
    1.30      int format;
    1.31 @@ -249,10 +266,10 @@
    1.32      }
    1.33      SDL_memset(this->hidden, 0, (sizeof *this->hidden));
    1.34  
    1.35 -
    1.36      /* Open the audio device */
    1.37      audio_fd = open(devname, flags, 0);
    1.38      if (audio_fd < 0) {
    1.39 +        DMA_CloseDevice(this);
    1.40          SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
    1.41          return 0;
    1.42      }
    1.43 @@ -261,6 +278,7 @@
    1.44  
    1.45      /* Get a list of supported hardware formats */
    1.46      if (ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) {
    1.47 +        DMA_CloseDevice(this);
    1.48          SDL_SetError("Couldn't get audio format list");
    1.49          return 0;
    1.50      }
    1.51 @@ -312,6 +330,7 @@
    1.52          }
    1.53      }
    1.54      if (format == 0) {
    1.55 +        DMA_CloseDevice(this);
    1.56          SDL_SetError("Couldn't find any hardware audio formats");
    1.57          return 0;
    1.58      }
    1.59 @@ -320,6 +339,7 @@
    1.60      /* Set the audio format */
    1.61      value = format;
    1.62      if ((ioctl(audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) || (value != format)) {
    1.63 +        DMA_CloseDevice(this);
    1.64          SDL_SetError("Couldn't set audio format");
    1.65          return 0;
    1.66      }
    1.67 @@ -338,12 +358,14 @@
    1.68         once we know what format and channels are supported
    1.69       */
    1.70      if (DMA_ReopenAudio(this, devname, format, stereo) < 0) {
    1.71 +        DMA_CloseDevice(this);
    1.72          /* Error is set by DMA_ReopenAudio() */
    1.73          return 0;
    1.74      }
    1.75  
    1.76      /* Memory map the audio buffer */
    1.77      if (ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info) < 0) {
    1.78 +        DMA_CloseDevice(this);
    1.79          SDL_SetError("Couldn't get OSPACE parameters");
    1.80          return 0;
    1.81      }
    1.82 @@ -355,6 +377,7 @@
    1.83      dma_buf = (Uint8 *) mmap(NULL, dma_len, PROT_WRITE, MAP_SHARED,
    1.84                               audio_fd, 0);
    1.85      if (dma_buf == MAP_FAILED) {
    1.86 +        DMA_CloseDevice(this);
    1.87          SDL_SetError("DMA memory map failed");
    1.88          dma_buf = NULL;
    1.89          return 0;
    1.90 @@ -376,6 +399,7 @@
    1.91      ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &value);
    1.92      value = PCM_ENABLE_OUTPUT;
    1.93      if (ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &value) < 0) {
    1.94 +        DMA_CloseDevice(this);
    1.95          SDL_SetError("Couldn't trigger audio output");
    1.96          return 0;
    1.97      }
    1.98 @@ -387,17 +411,6 @@
    1.99      return 1;
   1.100  }
   1.101  
   1.102 -static int
   1.103 -DMA_OpenDevice(_THIS, const char *devname, int iscapture)
   1.104 -{
   1.105 -    int retval = open_device_internal(this, devname, iscapture);
   1.106 -    if (!retval)
   1.107 -        DMA_CloseDevice(this);  /* !!! FIXME: do this at higher level. */
   1.108 -    return retval;
   1.109 -}
   1.110 -
   1.111 -
   1.112 -
   1.113  
   1.114  /* This function waits until it is possible to write a full sound buffer */
   1.115  static void
   1.116 @@ -505,22 +518,6 @@
   1.117      return (dma_buf + (filling * this->spec.size));
   1.118  }
   1.119  
   1.120 -static void
   1.121 -DMA_CloseDevice(_THIS)
   1.122 -{
   1.123 -    if (this->hidden != NULL) {
   1.124 -        if (dma_buf != NULL) {
   1.125 -            munmap(dma_buf, dma_len);
   1.126 -            dma_buf = NULL;
   1.127 -        }
   1.128 -        if (audio_fd >= 0) {
   1.129 -            close(audio_fd);
   1.130 -            audio_fd = -1;
   1.131 -        }
   1.132 -        SDL_free(this->hidden);
   1.133 -        this->hidden = NULL;
   1.134 -    }
   1.135 -}
   1.136  
   1.137  static int
   1.138  DMA_Init(SDL_AudioDriverImpl *impl)
     2.1 --- a/src/audio/dsp/SDL_dspaudio.c	Fri Oct 06 04:46:58 2006 +0000
     2.2 +++ b/src/audio/dsp/SDL_dspaudio.c	Fri Oct 06 04:49:48 2006 +0000
     2.3 @@ -140,6 +140,24 @@
     2.4  }
     2.5  
     2.6  
     2.7 +static void
     2.8 +DSP_CloseDevice(_THIS)
     2.9 +{
    2.10 +    if (this->hidden != NULL) {
    2.11 +        if (this->hidden->mixbuf != NULL) {
    2.12 +            SDL_FreeAudioMem(this->hidden->mixbuf);
    2.13 +            this->hidden->mixbuf = NULL;
    2.14 +        }
    2.15 +        if (this->hidden->audio_fd >= 0) {
    2.16 +            close(this->hidden->audio_fd);
    2.17 +            this->hidden->audio_fd = -1;
    2.18 +        }
    2.19 +        SDL_free(this->hidden);
    2.20 +        this->hidden = NULL;
    2.21 +    }
    2.22 +}
    2.23 +
    2.24 +
    2.25  static int
    2.26  DSP_OpenDevice(_THIS, const char *devname, int iscapture)
    2.27  {
    2.28 @@ -352,23 +370,6 @@
    2.29      return (this->hidden->mixbuf);
    2.30  }
    2.31  
    2.32 -static void
    2.33 -DSP_CloseDevice(_THIS)
    2.34 -{
    2.35 -    if (this->hidden != NULL) {
    2.36 -        if (this->hidden->mixbuf != NULL) {
    2.37 -            SDL_FreeAudioMem(this->hidden->mixbuf);
    2.38 -            this->hidden->mixbuf = NULL;
    2.39 -        }
    2.40 -        if (this->hidden->audio_fd >= 0) {
    2.41 -            close(this->hidden->audio_fd);
    2.42 -            this->hidden->audio_fd = -1;
    2.43 -        }
    2.44 -        SDL_free(this->hidden);
    2.45 -        this->hidden = NULL;
    2.46 -    }
    2.47 -}
    2.48 -
    2.49  static int
    2.50  DSP_Init(SDL_AudioDriverImpl *impl)
    2.51  {