Advertisement
Kitomas

kit_sdl2_kmixer.c as of 2023-10-12

Oct 12th, 2023
1,140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.59 KB | None | 0 0
  1. #include "../include/kit_sdl2/kit_kmixer.h"
  2. #include "../_private/include/_kit_privmacro.h"
  3. #include "../_private/include/_kit_coreAllPrivate.h"
  4. #include "../_private/include/_kit_kmixerAllPrivate.h"
  5.  
  6.  
  7.  
  8.  
  9. #if defined(_KIT_KMIXER_DEBUG) || defined(_KIT_ALL_DEBUG)
  10. const SDL_bool kit_kmixerIsDebug=SDL_TRUE;
  11. #else
  12. const SDL_bool kit_kmixerIsDebug=SDL_FALSE;
  13. #endif
  14.  
  15.  
  16.  
  17.  
  18. struct _kit_kmixerGlobals_t _kit_kmixerGlobals;
  19.  
  20.  
  21.  
  22.  
  23. int kit_kmixerInit(int numDeviceThreads){
  24.   if(!_kit_coreGlobals.init){ SDL_SetError("core not initialized!"); return -1; }
  25.  
  26.   if(_kit_kmixerGlobals.init){ SDL_SetError("kmixer is initialized!"); return 1; }
  27.   if(SDL_InitSubSystem(SDL_INIT_AUDIO)<0) return -2;
  28.  
  29.   _kit_kmixerGlobals.lock=SDL_CreateMutex();
  30.   if(_kit_kmixerGlobals.lock == NULL) return -3;
  31.   if(SDL_LockMutex(_kit_kmixerGlobals.lock)<0) return -4;
  32.  
  33.   if(numDeviceThreads>0) _kit_kmixerGlobals.numDeviceThreads = numDeviceThreads;
  34.   else { //MAX is used here so 0 is functionally identical to -1
  35.     int fraction = MAX(SDL_abs(numDeviceThreads),1);
  36.     _kit_kmixerGlobals.numDeviceThreads = MAX(_kit_coreGlobals.cores/fraction,1);
  37.   }
  38.  
  39.   _kit_kmixerGlobals.init = 1;
  40.   if(SDL_UnlockMutex(_kit_kmixerGlobals.lock)<0) return -5;
  41.   return 0;
  42. }
  43.  
  44.  
  45.  
  46. int kit_kmixerQuit(){
  47.   if(!_kit_kmixerGlobals.init){ SDL_SetError("kmixer not initialized!"); return 1; }
  48.   if(SDL_LockMutex(_kit_kmixerGlobals.lock)<0) return -1;
  49.  
  50.   _kit_kmixerGlobals.init=0;
  51.   if(SDL_UnlockMutex(_kit_kmixerGlobals.lock)<0) return -2;
  52.   SDL_DestroyMutex(_kit_kmixerGlobals.lock);
  53.   SDL_QuitSubSystem(SDL_INIT_AUDIO);
  54.   return 0;
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement