src/audio/baudio/SDL_beaudio.cc
branchSDL-ryan-multiple-audio-device
changeset 3837 7c9663fb0860
parent 3830 29e83f221c62
child 3846 66fb40445587
     1.1 --- a/src/audio/baudio/SDL_beaudio.cc	Sun Oct 08 00:55:30 2006 +0000
     1.2 +++ b/src/audio/baudio/SDL_beaudio.cc	Sun Oct 08 01:39:01 2006 +0000
     1.3 @@ -39,7 +39,7 @@
     1.4  }
     1.5  
     1.6  
     1.7 -static int BEAUDIO_Available(void)
     1.8 +static int BEOSAUDIO_Available(void)
     1.9  {
    1.10      return 1;  /* Always available on BeOS. */
    1.11  }
    1.12 @@ -79,7 +79,7 @@
    1.13  }
    1.14  
    1.15  static void
    1.16 -BEAUDIO_CloseDevice(_THIS)
    1.17 +BEOSAUDIO_CloseDevice(_THIS)
    1.18  {
    1.19      if (_this->hidden != NULL) {
    1.20          if (_this->hidden->audio_obj) {
    1.21 @@ -90,18 +90,15 @@
    1.22  
    1.23          delete _this->hidden;
    1.24          _this->hidden = NULL;
    1.25 -
    1.26 -        /* Quit the Be Application, if there's nothing left to do */
    1.27 -        SDL_QuitBeApp();
    1.28      }
    1.29  }
    1.30  
    1.31  static int
    1.32 -BEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
    1.33 +BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
    1.34  {
    1.35      int valid_datatype = 0;
    1.36      media_raw_audio_format format;
    1.37 -    SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
    1.38 +    SDL_AudioFormat test_format = SDL_FirstAudioFormat(_this->spec.format);
    1.39  
    1.40      /* Initialize all variables that we clean on shutdown */
    1.41      _this->hidden = new SDL_PrivateAudioData;
    1.42 @@ -111,19 +108,14 @@
    1.43      }
    1.44      SDL_memset(_this->hidden, 0, (sizeof *_this->hidden));
    1.45  
    1.46 -    /* Initialize the Be Application, if it's not already started */
    1.47 -    if (SDL_InitBeApp() < 0) {
    1.48 -        return 0;
    1.49 -    }
    1.50 -
    1.51      /* Parse the audio format and fill the Be raw audio format */
    1.52      SDL_memset(&format, '\0', sizeof(media_raw_audio_format));
    1.53      format.byte_order = B_MEDIA_LITTLE_ENDIAN;
    1.54 -    format.frame_rate = (float) this->spec.freq;
    1.55 -    format.channel_count = this->spec.channels;  /* !!! FIXME: support > 2? */
    1.56 +    format.frame_rate = (float) _this->spec.freq;
    1.57 +    format.channel_count = _this->spec.channels;  /* !!! FIXME: support > 2? */
    1.58      while ((!valid_datatype) && (test_format)) {
    1.59          valid_datatype = 1;
    1.60 -        this->spec.format = test_format;
    1.61 +        _this->spec.format = test_format;
    1.62          switch (test_format) {
    1.63              case AUDIO_S8:
    1.64                  format.format = media_raw_audio_format::B_AUDIO_CHAR;
    1.65 @@ -167,15 +159,16 @@
    1.66          }
    1.67      }
    1.68  
    1.69 -    format.buffer_size = this->spec.samples;
    1.70 +    format.buffer_size = _this->spec.samples;
    1.71  
    1.72      if (!valid_datatype) {  /* shouldn't happen, but just in case... */
    1.73 +        BEOSAUDIO_CloseDevice(_this);
    1.74          SDL_SetError("Unsupported audio format");
    1.75          return 0;
    1.76      }
    1.77  
    1.78      /* Calculate the final parameters for this audio specification */
    1.79 -    SDL_CalculateAudioSpec(&this->spec);
    1.80 +    SDL_CalculateAudioSpec(&_this->spec);
    1.81  
    1.82      /* Subscribe to the audio stream (creates a new thread) */
    1.83      sigset_t omask;
    1.84 @@ -187,6 +180,7 @@
    1.85      if (_this->hidden->audio_obj->Start() == B_NO_ERROR) {
    1.86          _this->hidden->audio_obj->SetHasData(true);
    1.87      } else {
    1.88 +        BEOSAUDIO_CloseDevice(_this);
    1.89          SDL_SetError("Unable to start Be audio");
    1.90          return 0;
    1.91      }
    1.92 @@ -195,22 +189,35 @@
    1.93      return 1;
    1.94  }
    1.95  
    1.96 +static void
    1.97 +BEOSAUDIO_Deinitialize(void)
    1.98 +{
    1.99 +    SDL_QuitBeApp();
   1.100 +}
   1.101 +
   1.102  static int
   1.103 -BEAUDIO_Init(SDL_AudioDriverImpl *impl)
   1.104 +BEOSAUDIO_Init(SDL_AudioDriverImpl *impl)
   1.105  {
   1.106 +    /* Initialize the Be Application, if it's not already started */
   1.107 +    if (SDL_InitBeApp() < 0) {
   1.108 +        return 0;
   1.109 +    }
   1.110 +
   1.111      /* Set the function pointers */
   1.112 -    impl->OpenDevice = DSP_OpenDevice;
   1.113 -    impl->CloseDevice = DSP_CloseDevice;
   1.114 +    impl->OpenDevice = BEOSAUDIO_OpenDevice;
   1.115 +    impl->CloseDevice = BEOSAUDIO_CloseDevice;
   1.116 +    impl->Deinitialize = BEOSAUDIO_Deinitialize;
   1.117      impl->ProvidesOwnCallbackThread = 1;
   1.118      impl->OnlyHasDefaultOutputDevice = 1;
   1.119  
   1.120      return 1;
   1.121  }
   1.122  
   1.123 -
   1.124 -AudioBootStrap BEAUDIO_bootstrap = {
   1.125 +extern "C" { extern AudioBootStrap BEOSAUDIO_bootstrap; }
   1.126 +AudioBootStrap BEOSAUDIO_bootstrap = {
   1.127      "baudio", "BeOS BSoundPlayer",
   1.128 -    BEAUDIO_Available, BEAUDIO_Init, 0
   1.129 +    BEOSAUDIO_Available, BEOSAUDIO_Init, 0
   1.130  };
   1.131  
   1.132  /* vi: set ts=4 sw=4 expandtab: */
   1.133 +