Advertisement
Kitomas

_kit_kmixerPrivate.h as of 2023-8-31

Sep 1st, 2023
839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.98 KB | None | 0 0
  1. #ifndef _KIT_KMIXERPRIVATE_H
  2. #define _KIT_KMIXERPRIVATE_H
  3.  
  4.  
  5.  
  6.  
  7. #include "../../include/kit_sdl2/kit_kmixer.h"
  8. //include intrinsic functions
  9. #include <immintrin.h>
  10.  
  11.  
  12.  
  13.  
  14. //bitmasks for _kit_kmixerGlobals.capabilities
  15. #define _SSE_MASK   (1<<5)
  16. #define _SSE2_MASK  (1<<4)
  17. #define _SSE3_MASK  (1<<3)
  18. #define _SSE41_MASK (1<<2) //(SSE4.1)
  19. #define _AVX_MASK   (1<<1)
  20. #define _AVX2_MASK  (1<<0)
  21.  
  22.  
  23.  
  24. //for debugging/testing
  25. #define _ENABLE_SSE   SDL_TRUE
  26. #define _ENABLE_SSE2  SDL_TRUE
  27. #define _ENABLE_SSE3  SDL_TRUE
  28. #define _ENABLE_SSE41 SDL_TRUE
  29. #define _ENABLE_AVX   SDL_TRUE
  30. #define _ENABLE_AVX2  SDL_TRUE
  31. //#define _KIT_KMIXER_DEBUG
  32.  
  33.  
  34.  
  35. #define _DEV_MAGIC_NUM (0x0076654472786D6B) //="kmxrDev\x00"
  36. #define _CHECK_IF_DEVICE_IS_VALID(_value)\
  37.   _IF_SDLERR_R(device->_magic.num!=_DEV_MAGIC_NUM,_value,;,"device is invalid")
  38.  
  39.  
  40. //bitmask of a Uint64's MSB
  41. #define U64_MSB  ((Uint64)0xFF<<56)
  42. //ones' complement of U64_MSB
  43. #define U64_MSBC (~U64_MSB)
  44. //converts strings to unsigned ints
  45.  //(with the power of technically undefined behavior! :D
  46.  // if fast inverse square root can do it, then so can i)
  47. #define U32_STR(_s) (*(Uint32*)(_s))
  48. #define U64_STR(_s) (*(Uint64*)(_s))
  49.  
  50.  
  51.  
  52. #define _PRINT_AUDIO_SPEC(_spec) {       \
  53.   SDL_Log(".freq    =%i",_spec.freq);     \
  54.   SDL_Log(".format  =%X",_spec.format);   \
  55.   SDL_Log(".channels=%u",_spec.channels); \
  56.   SDL_Log(".silence =%u",_spec.silence);  \
  57.   SDL_Log(".samples =%u",_spec.samples);  \
  58.   SDL_Log(".size    =%u",_spec.size);     \
  59.   SDL_Log(".callback=%p",_spec.callback); \
  60.   SDL_Log(".userdata=%p",_spec.userdata); }
  61.  
  62. #define _PRINT_AUDIO_SPEC_P(_spec) {      \
  63.   SDL_Log("->freq    =%i",_spec->freq);     \
  64.   SDL_Log("->format  =%X",_spec->format);   \
  65.   SDL_Log("->channels=%u",_spec->channels); \
  66.   SDL_Log("->silence =%u",_spec->silence);  \
  67.   SDL_Log("->samples =%u",_spec->samples);  \
  68.   SDL_Log("->size    =%u",_spec->size);     \
  69.   SDL_Log("->callback=%p",_spec->callback); \
  70.   SDL_Log("->userdata=%p",_spec->userdata); }
  71.  
  72.  
  73.  
  74.  
  75. /* ++++++++++++ */
  76. /* +kit_kmixer+ */
  77. /* ++++++++++++ */
  78.  
  79. struct _kit_kmixerGlobals_t {
  80.   SDL_mutex* lock;
  81.   int threadPoolSize, cores, capabilities;
  82.   int init;
  83. };
  84. extern struct _kit_kmixerGlobals_t _kit_kmixerGlobals;
  85.  
  86.  
  87. typedef union {
  88.   void*   ptr;
  89.   Uint8*  u_8;
  90.   Sint16* i16;
  91.   Sint32* i32;
  92.   float*  f32;
  93. } _mono_samples;
  94.  
  95.  
  96. //(stores left and right ear components of a stereo stream)
  97. typedef struct { Uint8  l,r; } _stereo_samples_u_8;
  98. typedef struct { Sint16 l,r; } _stereo_samples_i16;
  99. typedef struct { Sint32 l,r; } _stereo_samples_i32;
  100. typedef struct { float  l,r; } _stereo_samples_f32;
  101.  
  102. typedef union {
  103.   void*                ptr;
  104.   _stereo_samples_u_8* u_8;
  105.   _stereo_samples_i16* i16;
  106.   _stereo_samples_i32* i32;
  107.   _stereo_samples_f32* f32;
  108. } _stereo_samples;
  109.  
  110. /* ------------ */
  111. /* -kit_kmixer- */
  112. /* ------------ */
  113.  
  114.  
  115.  
  116.  
  117. /* +++++++++++++++++ */
  118. /* +kit_kmixerVoice+ */
  119. /* +++++++++++++++++ */
  120.  
  121. typedef union {
  122.   void*           v;
  123.   _mono_samples   m;
  124.   _stereo_samples s;
  125. } _kit_kmixerVoiceBuffer;
  126.  
  127. typedef union {
  128.   void*                v;
  129.   float*               m;
  130.   _stereo_samples_f32* s;
  131. } _kit_kmixerVoiceBufferF;
  132.  
  133.  
  134. typedef struct _kit_kmixerVoice _kit_kmixerVoice;
  135. struct _kit_kmixerVoice { //128B
  136.   //lock is compared with NULL to check if voice is valid
  137.   SDL_mutex*              lock; //to make sure a voice doesn't get deleted while it's processing
  138.   kit_coreVector*       inputs; //list of input voice indexes, if any (can be NULL)
  139.   kit_coreVector*    inputRefs; //list of input voice references, if any (can be NULL)
  140.   _kit_kmixerVoice*     output; //reference to output voice struct
  141.  
  142.   _kit_kmixerVoiceBufferF   bufferInput; //input buffer (or the mixing stage's output)
  143.   _kit_kmixerVoiceBuffer     bufferUser; //buffer to be filled in or modified by the user
  144.   _kit_kmixerVoiceBufferF bufferConvert; //sometimes used for buffer conversion (always stereo size)
  145.   _kit_kmixerVoiceBufferF  bufferOutput; //final output buffer (or the mixing stage's input)
  146.  
  147.   kit_kmixerVoiceSpec     spec; //contains info for bufferUser, given by the user
  148.  
  149.   Uint32            chainStage; //the voice's current position in the processing chain
  150.   Uint32                 index; //index of this specific voice in the device's voice list
  151.  
  152.   //volume can actually be <0, but for volL it will override applyVolume to SDL_FALSE,
  153.    //and for volR, volR would then be set to volL
  154.   float                   volL; //left ear volume (or total volume if mono); 0.0 -> 1.0
  155.   float                   volR; //right ear volume (ignored if mono); 0.0 -> 1.0
  156.  
  157.   SDL_bool         applyVolume; //if SDL_TRUE, apply volume when mixing voice's output
  158.   SDL_bool        stereoOutput; //output is mono if SDL_FALSE, stereo if SDL_TRUE
  159. };
  160.  
  161.  
  162.  
  163. extern int _kit_kmixerVoiceProc(void* data);
  164.  
  165.  
  166. extern void _kit_kmixerVoiceMix(_kit_kmixerVoice* ovoice, kit_coreVector* ivoices);
  167.  
  168. /* ----------------- */
  169. /* -kit_kmixerVoice- */
  170. /* ----------------- */
  171.  
  172.  
  173.  
  174.  
  175. #endif
  176.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement