src/audio/dummy/SDL_dummyaudio.c
branchSDL-ryan-multiple-audio-device
changeset 3784 37c9c4590689
parent 1895 c121d94672cb
child 3792 866c310e2cb5
     1.1 --- a/src/audio/dummy/SDL_dummyaudio.c	Sun Oct 01 05:21:40 2006 +0000
     1.2 +++ b/src/audio/dummy/SDL_dummyaudio.c	Sun Oct 01 05:24:03 2006 +0000
     1.3 @@ -37,7 +37,7 @@
     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 int DUMMYAUD_OpenAudio(_THIS, const char *devname, int iscapture);
     1.9  static void DUMMYAUD_WaitAudio(_THIS);
    1.10  static void DUMMYAUD_PlayAudio(_THIS);
    1.11  static Uint8 *DUMMYAUD_GetAudioBuf(_THIS);
    1.12 @@ -47,6 +47,8 @@
    1.13  static int
    1.14  DUMMYAUD_Available(void)
    1.15  {
    1.16 +    /* !!! FIXME: check this at a higher level... */
    1.17 +    /* only ever use this driver if explicitly requested. */
    1.18      const char *envr = SDL_getenv("SDL_AUDIODRIVER");
    1.19      if (envr && (SDL_strcmp(envr, DUMMYAUD_DRIVER_NAME) == 0)) {
    1.20          return (1);
    1.21 @@ -54,49 +56,22 @@
    1.22      return (0);
    1.23  }
    1.24  
    1.25 -static void
    1.26 -DUMMYAUD_DeleteDevice(SDL_AudioDevice * device)
    1.27 +static int
    1.28 +DUMMYAUD_Init(SDL_AudioDriverImpl *impl)
    1.29  {
    1.30 -    SDL_free(device->hidden);
    1.31 -    SDL_free(device);
    1.32 -}
    1.33 -
    1.34 -static SDL_AudioDevice *
    1.35 -DUMMYAUD_CreateDevice(int devindex)
    1.36 -{
    1.37 -    SDL_AudioDevice *this;
    1.38 +    /* Set the function pointers */
    1.39 +    impl->OpenAudio = DUMMYAUD_OpenAudio;
    1.40 +    impl->WaitAudio = DUMMYAUD_WaitAudio;
    1.41 +    impl->PlayAudio = DUMMYAUD_PlayAudio;
    1.42 +    impl->GetAudioBuf = DUMMYAUD_GetAudioBuf;
    1.43 +    impl->CloseAudio = DUMMYAUD_CloseAudio;
    1.44  
    1.45 -    /* Initialize all variables that we clean on shutdown */
    1.46 -    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
    1.47 -    if (this) {
    1.48 -        SDL_memset(this, 0, (sizeof *this));
    1.49 -        this->hidden = (struct SDL_PrivateAudioData *)
    1.50 -            SDL_malloc((sizeof *this->hidden));
    1.51 -    }
    1.52 -    if ((this == NULL) || (this->hidden == NULL)) {
    1.53 -        SDL_OutOfMemory();
    1.54 -        if (this) {
    1.55 -            SDL_free(this);
    1.56 -        }
    1.57 -        return (0);
    1.58 -    }
    1.59 -    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
    1.60 -
    1.61 -    /* Set the function pointers */
    1.62 -    this->OpenAudio = DUMMYAUD_OpenAudio;
    1.63 -    this->WaitAudio = DUMMYAUD_WaitAudio;
    1.64 -    this->PlayAudio = DUMMYAUD_PlayAudio;
    1.65 -    this->GetAudioBuf = DUMMYAUD_GetAudioBuf;
    1.66 -    this->CloseAudio = DUMMYAUD_CloseAudio;
    1.67 -
    1.68 -    this->free = DUMMYAUD_DeleteDevice;
    1.69 -
    1.70 -    return this;
    1.71 +    return 1;
    1.72  }
    1.73  
    1.74  AudioBootStrap DUMMYAUD_bootstrap = {
    1.75      DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver",
    1.76 -    DUMMYAUD_Available, DUMMYAUD_CreateDevice
    1.77 +    DUMMYAUD_Available, DUMMYAUD_Init
    1.78  };
    1.79  
    1.80  /* This function waits until it is possible to write a full sound buffer */
    1.81 @@ -129,23 +104,35 @@
    1.82          SDL_FreeAudioMem(this->hidden->mixbuf);
    1.83          this->hidden->mixbuf = NULL;
    1.84      }
    1.85 +    SDL_free(this->hidden);
    1.86 +    this->hidden = NULL;
    1.87  }
    1.88  
    1.89  static int
    1.90 -DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec * spec)
    1.91 +DUMMYAUD_OpenAudio(_THIS, const char *devname, int iscapture)
    1.92  {
    1.93      float bytes_per_sec = 0.0f;
    1.94  
    1.95 +    /* Initialize all variables that we clean on shutdown */
    1.96 +    this->hidden = (struct SDL_PrivateAudioData *)
    1.97 +                    SDL_malloc((sizeof *this->hidden));
    1.98 +    if (this->hidden == NULL) {
    1.99 +        SDL_OutOfMemory();
   1.100 +        return 0;
   1.101 +    }
   1.102 +    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
   1.103 +
   1.104      /* Allocate mixing buffer */
   1.105 -    this->hidden->mixlen = spec->size;
   1.106 +    this->hidden->mixlen = this->spec.size;
   1.107      this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
   1.108      if (this->hidden->mixbuf == NULL) {
   1.109 -        return (-1);
   1.110 +        DUMMYAUD_CloseAudio(this);
   1.111 +        return 0;
   1.112      }
   1.113 -    SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
   1.114 +    SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
   1.115  
   1.116 -    bytes_per_sec = (float) (((spec->format & 0xFF) / 8) *
   1.117 -                             spec->channels * spec->freq);
   1.118 +    bytes_per_sec = (float) (SDL_AUDIO_BITSIZE(this->spec.format) / 8) *
   1.119 +                             this->spec.channels * this->spec.freq;
   1.120  
   1.121      /*
   1.122       * We try to make this request more audio at the correct rate for
   1.123 @@ -156,10 +143,10 @@
   1.124       */
   1.125      this->hidden->initial_calls = 2;
   1.126      this->hidden->write_delay =
   1.127 -        (Uint32) ((((float) spec->size) / bytes_per_sec) * 1000.0f);
   1.128 +        (Uint32) ((((float) this->spec.size) / bytes_per_sec) * 1000.0f);
   1.129  
   1.130      /* We're ready to rock and roll. :-) */
   1.131 -    return (0);
   1.132 +    return 1;
   1.133  }
   1.134  
   1.135  /* vi: set ts=4 sw=4 expandtab: */