SDL-1.2: OS/2: moved DosSetPriority stuff from toplevel SDL_RunAudio() to driver

From 4c66df94f472bd41833641820299bb8f7d871b90 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Sun, 28 Feb 2021 17:33:02 +0300
Subject: [PATCH] OS/2: moved DosSetPriority stuff from toplevel SDL_RunAudio()
 to driver

also did a clean-up / tidy-up in DART code.
---
 src/audio/SDL_audio.c     |  36 +----
 src/audio/dart/SDL_dart.c | 296 ++++++++++++++++++--------------------
 src/audio/dart/SDL_dart.h |   1 +
 3 files changed, 146 insertions(+), 187 deletions(-)

diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 04ecebbf..450a53f4 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -28,12 +28,6 @@
 #include "SDL_audiomem.h"
 #include "SDL_sysaudio.h"
 
-#ifdef __OS2__
-/* We'll need the DosSetPriority() API! */
-#define INCL_DOSPROCESS
-#include <os2.h>
-#endif
-
 /* Available audio drivers */
 static AudioBootStrap *bootstrap[] = {
 #if SDL_AUDIO_DRIVER_PULSE
@@ -156,27 +150,6 @@ int SDLCALL SDL_RunAudio(void *audiop)
 		stream_len = audio->spec.size;
 	}
 
-#ifdef __OS2__
-        /* Increase the priority of this thread to make sure that
-           the audio will be continuous all the time! */
-#ifdef USE_DOSSETPRIORITY
-        if (SDL_getenv("SDL_USE_TIMECRITICAL_AUDIO"))
-        {
-#ifdef DEBUG_BUILD
-          printf("[SDL_RunAudio] : Setting priority to TimeCritical+0! (TID%d)\n", SDL_ThreadID());
-#endif
-          DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0);
-        }
-        else
-        {
-#ifdef DEBUG_BUILD
-          printf("[SDL_RunAudio] : Setting priority to ForegroundServer+0! (TID%d)\n", SDL_ThreadID());
-#endif
-          DosSetPriority(PRTYS_THREAD, PRTYC_FOREGROUNDSERVER, 0, 0);
-        }
-#endif
-#endif
-
 	/* Loop, filling the audio buffers */
 	while ( audio->enabled ) {
 
@@ -231,11 +204,6 @@ int SDLCALL SDL_RunAudio(void *audiop)
 		audio->WaitDone(audio);
 	}
 
-#ifdef __OS2__
-#ifdef DEBUG_BUILD
-        printf("[SDL_RunAudio] : Task exiting. (TID%d)\n", SDL_ThreadID());
-#endif
-#endif
 	return(0);
 }
 
@@ -530,8 +498,8 @@ int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
 	if ( obtained != NULL ) {
 		SDL_memcpy(obtained, &audio->spec, sizeof(audio->spec));
 	} else if ( desired->freq != audio->spec.freq ||
-                    desired->format != audio->spec.format ||
-	            desired->channels != audio->spec.channels ) {
+		    desired->format != audio->spec.format ||
+		    desired->channels != audio->spec.channels ) {
 		/* Build an audio conversion block */
 		if ( SDL_BuildAudioCVT(&audio->convert,
 			desired->format, desired->channels,
diff --git a/src/audio/dart/SDL_dart.c b/src/audio/dart/SDL_dart.c
index af0151e3..b1439b21 100644
--- a/src/audio/dart/SDL_dart.c
+++ b/src/audio/dart/SDL_dart.c
@@ -29,51 +29,43 @@
 #include "SDL_dart.h"
 
 // Buffer states:
-#define BUFFER_EMPTY       0
-#define BUFFER_USED        1
+#define BUFFER_EMPTY    0
+#define BUFFER_USED     1
 
 typedef struct _tMixBufferDesc {
-  int              iBufferUsage;      // BUFFER_EMPTY or BUFFER_USED
-  SDL_AudioDevice *pSDLAudioDevice;
+  int               iBufferUsage;   // BUFFER_EMPTY or BUFFER_USED
+  SDL_AudioDevice * pSDLAudioDevice;
 } tMixBufferDesc, *pMixBufferDesc;
 
 
 //---------------------------------------------------------------------
 // DARTEventFunc
 //
-// This function is called by DART, when an event occures, like end of 
+// This function is called by DART, when an event occures, like end of
 // playback of a buffer, etc...
 //---------------------------------------------------------------------
-LONG APIENTRY DARTEventFunc(ULONG ulStatus,
-			    PMCI_MIX_BUFFER pBuffer,
-			    ULONG ulFlags)
+static LONG APIENTRY DARTEventFunc(ULONG status, PMCI_MIX_BUFFER pBuffer, ULONG flags)
 {
-  if (ulFlags & MIX_WRITE_COMPLETE)
-  { // Playback of buffer completed!
+  (void) status;
 
-    // Get pointer to buffer description
-    pMixBufferDesc pBufDesc;
-
-    if (pBuffer)
-    {
-      pBufDesc = (pMixBufferDesc) (*pBuffer).ulUserParm;
-
-      if (pBufDesc)
-      {
+  if (flags & MIX_WRITE_COMPLETE) { // Playback of buffer completed!
+    if (pBuffer) {
+      // Get pointer to buffer description
+      pMixBufferDesc pBufDesc = (pMixBufferDesc) (*pBuffer).ulUserParm;
+      if (pBufDesc) {
         SDL_AudioDevice *pSDLAudioDevice = pBufDesc->pSDLAudioDevice;
         // Set the buffer to be empty
         pBufDesc->iBufferUsage = BUFFER_EMPTY;
         // And notify DART feeder thread that it will have to work a bit.
         if (pSDLAudioDevice)
-        DosPostEventSem(pSDLAudioDevice->hidden->hevAudioBufferPlayed);
+          DosPostEventSem(pSDLAudioDevice->hidden->hevAudioBufferPlayed);
       }
     }
   }
   return TRUE;
 }
 
-
-int DART_OpenAudio(_THIS, SDL_AudioSpec *spec)
+static int DART_OpenAudio(_THIS, SDL_AudioSpec *spec)
 {
   Uint16 test_format = SDL_FirstAudioFormat(spec->format);
   int valid_datatype = 0;
@@ -88,7 +80,7 @@ int DART_OpenAudio(_THIS, SDL_AudioSpec *spec)
   int iBufSize;
   int iOpenMode;
   int iSilence;
-  int rc;
+  int i, j, rc;
 
   // First thing is to try to open a given DART device!
   SDL_memset(&AmpOpenParms, 0, sizeof(MCI_AMP_OPEN_PARMS));
@@ -96,13 +88,13 @@ int DART_OpenAudio(_THIS, SDL_AudioSpec *spec)
   AmpOpenParms.pszDeviceType = (PSZ) (MCI_DEVTYPE_AUDIO_AMPMIX | (iDeviceOrd << 16));
 
   iOpenMode = MCI_WAIT | MCI_OPEN_TYPE_ID;
-  if (bOpenShared) iOpenMode |= MCI_OPEN_SHAREABLE;
+  if (bOpenShared)
+    iOpenMode |= MCI_OPEN_SHAREABLE;
+
+  rc = mciSendCommand(0, MCI_OPEN, iOpenMode, &AmpOpenParms, 0);
+  if (rc != MCIERR_SUCCESS) // No audio available??
+    return -1;
 
-  rc = mciSendCommand( 0, MCI_OPEN,
-                       iOpenMode,
-		       (PVOID) &AmpOpenParms, 0);
-  if (rc!=MCIERR_SUCCESS) // No audio available??
-    return (-1);
   // Save the device ID we got from DART!
   // We will use this in the next calls!
   iDeviceOrd = AmpOpenParms.usDeviceID;
@@ -111,26 +103,26 @@ int DART_OpenAudio(_THIS, SDL_AudioSpec *spec)
   if (spec->channels > 2)
     spec->channels = 2;  // !!! FIXME: more than stereo support in OS/2?
 
-  while ((!valid_datatype) && (test_format)) {
+  while (!valid_datatype && test_format) {
     spec->format = test_format;
     valid_datatype = 1;
     switch (test_format) {
-      case AUDIO_U8:
-        // Unsigned 8 bit audio data
-        iSilence = 0x80;
-        iBits = 8;
-        break;
-
-      case AUDIO_S16LSB:
-        // Signed 16 bit audio data
-        iSilence = 0x00;
-        iBits = 16;
-        break;
-
-      default:
-        valid_datatype = 0;
-        test_format = SDL_NextAudioFormat();
-        break;
+    case AUDIO_U8:
+      // Unsigned 8 bit audio data
+      iSilence = 0x80;
+      iBits = 8;
+      break;
+
+    case AUDIO_S16LSB:
+      // Signed 16 bit audio data
+      iSilence = 0x00;
+      iBits = 16;
+      break;
+
+    default:
+      valid_datatype = 0;
+      test_format = SDL_NextAudioFormat();
+      break;
     }
   }
 
@@ -138,7 +130,7 @@ int DART_OpenAudio(_THIS, SDL_AudioSpec *spec)
     // Close DART, and exit with error code!
     mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
     SDL_SetError("Unsupported audio format");
-    return (-1);
+    return -1;
   }
 
   iFreq = spec->freq;
@@ -159,99 +151,101 @@ int DART_OpenAudio(_THIS, SDL_AudioSpec *spec)
   rc = mciSendCommand (iDeviceOrd, MCI_MIXSETUP,
                        MCI_WAIT | MCI_MIXSETUP_QUERYMODE,
                        &(_this->hidden->MixSetupParms), 0);
-  if (rc!=MCIERR_SUCCESS)
-  { // The device cannot handle this format!
+  if (rc != MCIERR_SUCCESS) {
+    // The device cannot handle this format!
     // Close DART, and exit with error code!
     mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
     SDL_SetError("Audio device doesn't support requested audio format");
-    return(-1);
+    return -1;
   }
   // The device can handle this format, so initialize!
   rc = mciSendCommand(iDeviceOrd, MCI_MIXSETUP,
                       MCI_WAIT | MCI_MIXSETUP_INIT,
                       &(_this->hidden->MixSetupParms), 0);
-  if (rc!=MCIERR_SUCCESS)
-  { // The device could not be opened!
+  if (rc != MCIERR_SUCCESS) {
+    // The device could not be opened!
     // Close DART, and exit with error code!
     mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
     SDL_SetError("Audio device could not be set up");
-    return(-1);
+    return -1;
   }
+
   // Ok, the device is initialized.
   // Now we should allocate buffers. For this, we need a place where
   // the buffer descriptors will be:
   _this->hidden->pMixBuffers = (MCI_MIX_BUFFER *) SDL_malloc(sizeof(MCI_MIX_BUFFER)*iNumBufs);
-  if (!(_this->hidden->pMixBuffers))
-  { // Not enough memory!
+  if (!_this->hidden->pMixBuffers) {
+    // Not enough memory!
     // Close DART, and exit with error code!
     mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
     SDL_OutOfMemory();
-    return(-1);
+    return -1;
   }
+
   // Now that we have the place for buffer list, we can ask DART for the
   // buffers!
   _this->hidden->BufferParms.ulNumBuffers = iNumBufs;               // Number of buffers
   _this->hidden->BufferParms.ulBufferSize = iBufSize;               // each with this size
   _this->hidden->BufferParms.pBufList = _this->hidden->pMixBuffers; // getting descriptorts into this list
+
   // Allocate buffers!
   rc = mciSendCommand(iDeviceOrd, MCI_BUFFER,
                       MCI_WAIT | MCI_ALLOCATE_MEMORY,
                       &(_this->hidden->BufferParms), 0);
-  if ((rc!=MCIERR_SUCCESS) || (iNumBufs != _this->hidden->BufferParms.ulNumBuffers) || (_this->hidden->BufferParms.ulBufferSize==0))
+  if (rc != MCIERR_SUCCESS || iNumBufs != _this->hidden->BufferParms.ulNumBuffers ||
+      _this->hidden->BufferParms.ulBufferSize == 0)
   { // Could not allocate memory!
     // Close DART, and exit with error code!
     SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
     mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
     SDL_SetError("DART could not allocate buffers");
-    return(-1);
+    return -1;
   }
+
   // Ok, we have all the buffers allocated, let's mark them!
-  {
-    int i;
-    for (i=0; i<iNumBufs; i++)
-    {
-      pMixBufferDesc pBufferDesc = (pMixBufferDesc) SDL_malloc(sizeof(tMixBufferDesc));;
-      // Check if this buffer was really allocated by DART
-      if ((!(_this->hidden->pMixBuffers[i].pBuffer)) || (!pBufferDesc))
-      { // Wrong buffer!
-        // Close DART, and exit with error code!
-        // Free buffer descriptions
-        { int j;
-          for (j=0; j<i; j++) SDL_free((void *)(_this->hidden->pMixBuffers[j].ulUserParm));
-        }
-        // and cleanup
-        mciSendCommand(iDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0);
-        SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
-        mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
-        SDL_SetError("Error at internal buffer check");
-        return(-1);
-      }
-      pBufferDesc->iBufferUsage = BUFFER_EMPTY;
-      pBufferDesc->pSDLAudioDevice = _this;
-
-      _this->hidden->pMixBuffers[i].ulBufferLength = _this->hidden->BufferParms.ulBufferSize;
-      _this->hidden->pMixBuffers[i].ulUserParm = (ULONG) pBufferDesc; // User parameter: Description of buffer
-      _this->hidden->pMixBuffers[i].ulFlags = 0; // Some stuff should be flagged here for DART, like end of
-                                            // audio data, but as we will continously send
-                                            // audio data, there will be no end.:)
-      SDL_memset(_this->hidden->pMixBuffers[i].pBuffer, iSilence, iBufSize);
+  for (i = 0; i < iNumBufs; i++) {
+    pMixBufferDesc pBufferDesc = (pMixBufferDesc) SDL_malloc(sizeof(tMixBufferDesc));;
+    // Check if this buffer was really allocated by DART
+    if (!_this->hidden->pMixBuffers[i].pBuffer || !pBufferDesc) {
+      // Wrong buffer!
+      // Close DART, and exit with error code!
+      // Free buffer descriptions
+      for (j = 0; j < i; j++)
+        SDL_free((void *)(_this->hidden->pMixBuffers[j].ulUserParm));
+      // and cleanup
+      mciSendCommand(iDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0);
+      SDL_free(_this->hidden->pMixBuffers);
+      _this->hidden->pMixBuffers = NULL;
+      mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
+      SDL_SetError("Error at internal buffer check");
+      return -1;
     }
+    pBufferDesc->iBufferUsage = BUFFER_EMPTY;
+    pBufferDesc->pSDLAudioDevice = _this;
+
+    _this->hidden->pMixBuffers[i].ulBufferLength = _this->hidden->BufferParms.ulBufferSize;
+    _this->hidden->pMixBuffers[i].ulUserParm = (ULONG) pBufferDesc; // User parameter: Description of buffer
+    _this->hidden->pMixBuffers[i].ulFlags = 0; // Some stuff should be flagged here for DART, like end of
+                                               //  audio data, but as we will continously send audio data,
+                                               //  there will be no end. :)
+    SDL_memset(_this->hidden->pMixBuffers[i].pBuffer, iSilence, iBufSize);
   }
+
   _this->hidden->iNextFreeBuffer = 0;
   _this->hidden->iLastPlayedBuf = -1;
+
   // Create event semaphore
   if (DosCreateEventSem(NULL, &(_this->hidden->hevAudioBufferPlayed), 0, FALSE)!=NO_ERROR)
   {
     // Could not create event semaphore!
-    {
-      int i;
-      for (i=0; i<iNumBufs; i++) SDL_free((void *)(_this->hidden->pMixBuffers[i].ulUserParm));
-    }
+    for (i = 0; i < iNumBufs; i++)
+      SDL_free((void *)(_this->hidden->pMixBuffers[i].ulUserParm));
     mciSendCommand(iDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0);
-    SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
+    SDL_free(_this->hidden->pMixBuffers);
+    _this->hidden->pMixBuffers = NULL;
     mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
     SDL_SetError("Could not create event semaphore");
-    return(-1);
+    return -1;
   }
 
   // Store the new settings in global variables
@@ -262,17 +256,24 @@ int DART_OpenAudio(_THIS, SDL_AudioSpec *spec)
   _this->hidden->iCurrNumBufs = iNumBufs;
   _this->hidden->iCurrBufSize = iBufSize;
 
-  return (0);
+  return 0;
 }
 
-
-void DART_ThreadInit(_THIS)
+static void DART_ThreadInit(_THIS)
 {
-  /* nothing. */
+#ifdef USE_DOSSETPRIORITY
+  /* Increase the priority of this thread to make sure that
+     the audio will be continuous all the time! */
+  if (SDL_getenv("SDL_USE_TIMECRITICAL_AUDIO")) {
+    DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0);
+  } else {
+    DosSetPriority(PRTYS_THREAD, PRTYC_FOREGROUNDSERVER, 0, 0);
+  }
+#endif
 }
 
 /* This function waits until it is possible to write a full sound buffer */
-void DART_WaitAudio(_THIS)
+static void DART_WaitAudio(_THIS)
 {
   int i;
   pMixBufferDesc pBufDesc;
@@ -280,8 +281,7 @@ void DART_WaitAudio(_THIS)
 
   DosResetEventSem(_this->hidden->hevAudioBufferPlayed, &ulPostCount);
   // If there is already an empty buffer, then return now!
-  for (i=0; i<_this->hidden->iCurrNumBufs; i++)
-  {
+  for (i = 0; i < _this->hidden->iCurrNumBufs; i++) {
     pBufDesc = (pMixBufferDesc) _this->hidden->pMixBuffers[i].ulUserParm;
     if (pBufDesc->iBufferUsage == BUFFER_EMPTY)
       return;
@@ -290,7 +290,7 @@ void DART_WaitAudio(_THIS)
   DosWaitEventSem(_this->hidden->hevAudioBufferPlayed, 1000); // Wait max 1 sec!!! Important!
 }
 
-void DART_PlayAudio(_THIS)
+static void DART_PlayAudio(_THIS)
 {
   int iFreeBuf = _this->hidden->iNextFreeBuffer;
   pMixBufferDesc pBufDesc;
@@ -306,36 +306,36 @@ void DART_PlayAudio(_THIS)
   _this->hidden->iNextFreeBuffer = iFreeBuf;
 }
 
-Uint8 *DART_GetAudioBuf(_THIS)
+static Uint8 *DART_GetAudioBuf(_THIS)
 {
   int iFreeBuf;
   Uint8 *pResult;
   pMixBufferDesc pBufDesc;
 
-  if (_this)
-  {
-    if (_this->hidden)
-    {
-      iFreeBuf = _this->hidden->iNextFreeBuffer;
-      pBufDesc = (pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].ulUserParm;
-      
-      if (pBufDesc)
-      {
-        if (pBufDesc->iBufferUsage == BUFFER_EMPTY)
-        {
-          pResult = _this->hidden->pMixBuffers[iFreeBuf].pBuffer;
-          return pResult; 
-        }
-      } else
-        printf("[DART_GetAudioBuf] : ERROR! pBufDesc = %p\n", pBufDesc);
-    } else
-      printf("[DART_GetAudioBuf] : ERROR! _this->hidden = %p\n", _this->hidden);
-  } else
-    printf("[DART_GetAudioBuf] : ERROR! _this = %p\n", _this);
+  if (!_this || !_this->hidden) {
+    #ifdef DEBUG_BUILD
+    printf("[DART_GetAudioBuf]: ERROR! NULL param\n");
+    #endif
+    return NULL;
+  }
+
+  iFreeBuf = _this->hidden->iNextFreeBuffer;
+  pBufDesc = (pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].ulUserParm;
+  if (!pBufDesc) {
+    #ifdef DEBUG_BUILD
+    printf("[DART_GetAudioBuf]: ERROR! NULL pBufDesc\n");
+    #endif
+    return NULL;
+  }
+
+  if (pBufDesc->iBufferUsage == BUFFER_EMPTY) {
+    pResult = _this->hidden->pMixBuffers[iFreeBuf].pBuffer;
+    return pResult;
+  }
   return NULL;
 }
 
-void DART_WaitDone(_THIS)
+static void DART_WaitDone(_THIS)
 {
   pMixBufferDesc pBufDesc;
   ULONG ulPostCount;
@@ -343,36 +343,32 @@ void DART_WaitDone(_THIS)
 
   pBufDesc = (pMixBufferDesc) _this->hidden->pMixBuffers[_this->hidden->iLastPlayedBuf].ulUserParm;
   rc = NO_ERROR;
-  while ((pBufDesc->iBufferUsage != BUFFER_EMPTY) && (rc==NO_ERROR))
-  {
+  while (pBufDesc->iBufferUsage != BUFFER_EMPTY && rc == NO_ERROR) {
     DosResetEventSem(_this->hidden->hevAudioBufferPlayed, &ulPostCount);
     rc = DosWaitEventSem(_this->hidden->hevAudioBufferPlayed, 1000); // 1 sec timeout! Important!
   }
 }
 
-void DART_CloseAudio(_THIS)
+static void DART_CloseAudio(_THIS)
 {
   MCI_GENERIC_PARMS GenericParms;
-  int rc;
+  int i, rc;
 
   // Stop DART playback
   rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_STOP, MCI_WAIT, &GenericParms, 0);
-  if (rc!=MCIERR_SUCCESS)
-  {
-#ifdef SFX_DEBUG_BUILD
+  if (rc != MCIERR_SUCCESS) {
+    #ifdef DEBUG_BUILD
     printf("Could not stop DART playback!\n");
     fflush(stdout);
-#endif
+    #endif
   }
 
   // Close event semaphore
   DosCloseEventSem(_this->hidden->hevAudioBufferPlayed);
 
   // Free memory of buffer descriptions
-  {
-    int i;
-    for (i=0; i<_this->hidden->iCurrNumBufs; i++) SDL_free((void *)(_this->hidden->pMixBuffers[i].ulUserParm));
-  }
+  for (i = 0; i < _this->hidden->iCurrNumBufs; i++)
+    SDL_free((void *)(_this->hidden->pMixBuffers[i].ulUserParm));
 
   // Deallocate buffers
   rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0);
@@ -386,37 +382,32 @@ void DART_CloseAudio(_THIS)
 
 /* Audio driver bootstrap functions */
 
-int Audio_Available(void)
+static int DART_Available(void)
 {
-  return(1);
+  return 1;
 }
 
-void Audio_DeleteDevice(SDL_AudioDevice *device)
+static void DART_DeleteDevice(SDL_AudioDevice *device)
 {
   SDL_free(device->hidden);
   SDL_free(device);
 }
 
-SDL_AudioDevice *Audio_CreateDevice(int devindex)
+static SDL_AudioDevice *DART_CreateDevice(int devindex)
 {
   SDL_AudioDevice *this;
 
   /* Initialize all variables that we clean on shutdown */
-  this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
-  if ( this )
-  {
-    SDL_memset(this, 0, (sizeof *this));
+  this = (SDL_AudioDevice *)SDL_calloc(1, sizeof(SDL_AudioDevice));
+  if (this) {
     this->hidden = (struct SDL_PrivateAudioData *)
-      SDL_malloc((sizeof *this->hidden));
+                SDL_calloc(1, sizeof(struct SDL_PrivateAudioData));
   }
-  if ( (this == NULL) || (this->hidden == NULL) )
-  {
+  if (this == NULL || this->hidden == NULL) {
     SDL_OutOfMemory();
-    if ( this )
-      SDL_free(this);
-    return(0);
+    if (this) SDL_free(this);
+    return NULL;
   }
-  SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 
   /* Set the function pointers */
   this->OpenAudio = DART_OpenAudio;
@@ -427,13 +418,12 @@ SDL_AudioDevice *Audio_CreateDevice(int devindex)
   this->WaitDone = DART_WaitDone;
   this->CloseAudio = DART_CloseAudio;
 
-  this->free = Audio_DeleteDevice;
+  this->free = DART_DeleteDevice;
 
   return this;
 }
 
 AudioBootStrap DART_bootstrap = {
 	"dart", "OS/2 Direct Audio RouTines (DART)",
-	Audio_Available, Audio_CreateDevice
+	DART_Available, DART_CreateDevice
 };
-
diff --git a/src/audio/dart/SDL_dart.h b/src/audio/dart/SDL_dart.h
index 68c27bd9..2eb34336 100644
--- a/src/audio/dart/SDL_dart.h
+++ b/src/audio/dart/SDL_dart.h
@@ -30,6 +30,7 @@
 #define INCL_DOSMISC
 #define INCL_DOSERRORS
 
+#define INCL_DOSPROCESS
 #define INCL_OS2MM
 #define INCL_MMIOOS2
 #define INCL_MCIOS2