BeOS audio now works in 1.3 branch. SDL-ryan-multiple-audio-device
authorRyan C. Gordon <icculus@icculus.org>
Sun, 08 Oct 2006 01:39:01 +0000
branchSDL-ryan-multiple-audio-device
changeset 3837 7c9663fb0860
parent 3836 7dc7327cd626
child 3838 45e566003276
BeOS audio now works in 1.3 branch.
configure.in
include/SDL_config.h.in
src/audio/SDL_audio.c
src/audio/baudio/SDL_beaudio.cc
--- a/configure.in	Sun Oct 08 00:55:30 2006 +0000
+++ b/configure.in	Sun Oct 08 01:39:01 2006 +0000
@@ -2242,7 +2242,7 @@
         CheckBeGL
         # Set up files for the audio library
         if test x$enable_audio = xyes; then
-            AC_DEFINE(SDL_AUDIO_DRIVER_BAUDIO)
+            AC_DEFINE(SDL_AUDIO_DRIVER_BEOSAUDIO)
             SOURCES="$SOURCES $srcdir/src/audio/baudio/*.cc"
             have_audio=yes
         fi
--- a/include/SDL_config.h.in	Sun Oct 08 00:55:30 2006 +0000
+++ b/include/SDL_config.h.in	Sun Oct 08 01:39:01 2006 +0000
@@ -154,7 +154,7 @@
 #undef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
 #undef SDL_AUDIO_DRIVER_ARTS
 #undef SDL_AUDIO_DRIVER_ARTS_DYNAMIC
-#undef SDL_AUDIO_DRIVER_BAUDIO
+#undef SDL_AUDIO_DRIVER_BEOSAUDIO
 #undef SDL_AUDIO_DRIVER_BSD
 #undef SDL_AUDIO_DRIVER_COREAUDIO
 #undef SDL_AUDIO_DRIVER_DART
--- a/src/audio/SDL_audio.c	Sun Oct 08 00:55:30 2006 +0000
+++ b/src/audio/SDL_audio.c	Sun Oct 08 01:39:01 2006 +0000
@@ -56,7 +56,7 @@
 extern AudioBootStrap DSOUND_bootstrap;
 extern AudioBootStrap WAVEOUT_bootstrap;
 extern AudioBootStrap PAUDIO_bootstrap;
-extern AudioBootStrap BAUDIO_bootstrap;
+extern AudioBootStrap BEOSAUDIO_bootstrap;
 extern AudioBootStrap COREAUDIO_bootstrap;
 extern AudioBootStrap SNDMGR_bootstrap;
 extern AudioBootStrap MINTAUDIO_GSXB_bootstrap;
@@ -110,8 +110,8 @@
 #if SDL_AUDIO_DRIVER_PAUDIO
     &PAUDIO_bootstrap,
 #endif
-#if SDL_AUDIO_DRIVER_BAUDIO
-    &BAUDIO_bootstrap,
+#if SDL_AUDIO_DRIVER_BEOSAUDIO
+    &BEOSAUDIO_bootstrap,
 #endif
 #if SDL_AUDIO_DRIVER_COREAUDIO
     &COREAUDIO_bootstrap,
--- a/src/audio/baudio/SDL_beaudio.cc	Sun Oct 08 00:55:30 2006 +0000
+++ b/src/audio/baudio/SDL_beaudio.cc	Sun Oct 08 01:39:01 2006 +0000
@@ -39,7 +39,7 @@
 }
 
 
-static int BEAUDIO_Available(void)
+static int BEOSAUDIO_Available(void)
 {
     return 1;  /* Always available on BeOS. */
 }
@@ -79,7 +79,7 @@
 }
 
 static void
-BEAUDIO_CloseDevice(_THIS)
+BEOSAUDIO_CloseDevice(_THIS)
 {
     if (_this->hidden != NULL) {
         if (_this->hidden->audio_obj) {
@@ -90,18 +90,15 @@
 
         delete _this->hidden;
         _this->hidden = NULL;
-
-        /* Quit the Be Application, if there's nothing left to do */
-        SDL_QuitBeApp();
     }
 }
 
 static int
-BEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
+BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
 {
     int valid_datatype = 0;
     media_raw_audio_format format;
-    SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
+    SDL_AudioFormat test_format = SDL_FirstAudioFormat(_this->spec.format);
 
     /* Initialize all variables that we clean on shutdown */
     _this->hidden = new SDL_PrivateAudioData;
@@ -111,19 +108,14 @@
     }
     SDL_memset(_this->hidden, 0, (sizeof *_this->hidden));
 
-    /* Initialize the Be Application, if it's not already started */
-    if (SDL_InitBeApp() < 0) {
-        return 0;
-    }
-
     /* Parse the audio format and fill the Be raw audio format */
     SDL_memset(&format, '\0', sizeof(media_raw_audio_format));
     format.byte_order = B_MEDIA_LITTLE_ENDIAN;
-    format.frame_rate = (float) this->spec.freq;
-    format.channel_count = this->spec.channels;  /* !!! FIXME: support > 2? */
+    format.frame_rate = (float) _this->spec.freq;
+    format.channel_count = _this->spec.channels;  /* !!! FIXME: support > 2? */
     while ((!valid_datatype) && (test_format)) {
         valid_datatype = 1;
-        this->spec.format = test_format;
+        _this->spec.format = test_format;
         switch (test_format) {
             case AUDIO_S8:
                 format.format = media_raw_audio_format::B_AUDIO_CHAR;
@@ -167,15 +159,16 @@
         }
     }
 
-    format.buffer_size = this->spec.samples;
+    format.buffer_size = _this->spec.samples;
 
     if (!valid_datatype) {  /* shouldn't happen, but just in case... */
+        BEOSAUDIO_CloseDevice(_this);
         SDL_SetError("Unsupported audio format");
         return 0;
     }
 
     /* Calculate the final parameters for this audio specification */
-    SDL_CalculateAudioSpec(&this->spec);
+    SDL_CalculateAudioSpec(&_this->spec);
 
     /* Subscribe to the audio stream (creates a new thread) */
     sigset_t omask;
@@ -187,6 +180,7 @@
     if (_this->hidden->audio_obj->Start() == B_NO_ERROR) {
         _this->hidden->audio_obj->SetHasData(true);
     } else {
+        BEOSAUDIO_CloseDevice(_this);
         SDL_SetError("Unable to start Be audio");
         return 0;
     }
@@ -195,22 +189,35 @@
     return 1;
 }
 
+static void
+BEOSAUDIO_Deinitialize(void)
+{
+    SDL_QuitBeApp();
+}
+
 static int
-BEAUDIO_Init(SDL_AudioDriverImpl *impl)
+BEOSAUDIO_Init(SDL_AudioDriverImpl *impl)
 {
+    /* Initialize the Be Application, if it's not already started */
+    if (SDL_InitBeApp() < 0) {
+        return 0;
+    }
+
     /* Set the function pointers */
-    impl->OpenDevice = DSP_OpenDevice;
-    impl->CloseDevice = DSP_CloseDevice;
+    impl->OpenDevice = BEOSAUDIO_OpenDevice;
+    impl->CloseDevice = BEOSAUDIO_CloseDevice;
+    impl->Deinitialize = BEOSAUDIO_Deinitialize;
     impl->ProvidesOwnCallbackThread = 1;
     impl->OnlyHasDefaultOutputDevice = 1;
 
     return 1;
 }
 
-
-AudioBootStrap BEAUDIO_bootstrap = {
+extern "C" { extern AudioBootStrap BEOSAUDIO_bootstrap; }
+AudioBootStrap BEOSAUDIO_bootstrap = {
     "baudio", "BeOS BSoundPlayer",
-    BEAUDIO_Available, BEAUDIO_Init, 0
+    BEOSAUDIO_Available, BEOSAUDIO_Init, 0
 };
 
 /* vi: set ts=4 sw=4 expandtab: */
+