Advertisement
Kitomas

kit_sdl2_kmixerVoice.c as of 8-18-23

Aug 18th, 2023
980
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.46 KB | None | 0 0
  1. #include "../include/kit_sdl2/kit_kmixer.h"
  2. #include "../_private/include/_kit_privmacro.h"
  3. #include "../_private/include/_kit_kmixerPrivate.h"
  4.  
  5. /*
  6. VoiceProcess:
  7.   convert data type to float
  8.   convert mono to stereo, or vice versa
  9. */
  10.  
  11. //include intrinsic functions
  12. #include <immintrin.h>
  13.  
  14.  
  15.  
  16.  
  17. //bitmasks for _kit_kmixerGlobals.capabilities
  18. #define _SSE_MASK   (1<<5)
  19. #define _SSE2_MASK  (1<<4)
  20. #define _SSE3_MASK  (1<<3)
  21. #define _SSE41_MASK (1<<2)
  22. #define _AVX_MASK   (1<<1)
  23. #define _AVX2_MASK  (1<<0)
  24.  
  25. //for visual clarity during ProcChannels
  26.  //(this could also just be an enum probably, but w/e)
  27. #define _M_to_M (0) //  mono->mono
  28. #define _M_to_S (1) //  mono->stereo
  29. #define _S_to_M (2) //stereo->mono
  30. #define _S_to_S (3) //stereo->stereo
  31.  
  32. //used to multiply an int by the inverse of an int to get a normalized float
  33. //(input 8-bit samples will be unsigned, so -=0x80 to convert them to signed first)
  34. const float invi8 =1.0f/0x7f;
  35. const float invi16=1.0f/0x7fff;
  36. const float invi32=1.0f/0x7fffffff;
  37.  
  38.  
  39. //stores left and right ear components of a stereo stream
  40. struct _stereo_u8  { Uint8  l,r; };
  41. struct _stereo_i16 { Sint16 l,r; };
  42. struct _stereo_i32 { Sint32 l,r; };
  43. struct _stereo_f32 { float  l,r; };
  44.  
  45.  
  46. static inline void _kit_kmixerVoiceProcType(void* dataIn, void* dataOut, Uint32 numSamples,
  47.                                             SDL_AudioFormat type, int channelInfo)
  48. {
  49.  
  50. }
  51.  
  52.  
  53. //assumes f32
  54. void _kit_kmixerVoiceProcChannels(void* dataIn, void* dataOut, Uint32 sampleFrames, int channelInfo){
  55.   Uint32 sizeIn,sizeOut; sizeIn=sizeOut=sampleFrames*sizeof(float);
  56.   __m128 sse0,sse1,sse2; //__m256 avx0,avx1;
  57.   float *dataInM=dataIn, *dataOutM=dataOut;
  58.   struct _stereo_f32     *dataOutS=dataOut;
  59.   if(_kit_kmixerGlobals.capabilities&_AVX_MASK){ switch(channelInfo){ //has >=AVX1
  60.     //TBD
  61.     case _M_to_M:
  62.     case _M_to_S: sizeOut<<=1;
  63.     case _S_to_M: sizeIn<<=1;
  64.     case _S_to_S: sizeIn=sizeOut<<=1;
  65.   }} else if(_kit_kmixerGlobals.capabilities&_SSE3_MASK && channelInfo==_S_to_M){ //(requires SSE3's "hadd")
  66.     //TBD
  67.   } else if(_kit_kmixerGlobals.capabilities&_SSE_MASK){ switch(channelInfo){ //has >=SSE1
  68.     case _M_to_S: sizeOut<<=1; for(Uint32 i=0,o=-16; i<sizeIn; i+=16){
  69.       sse0=_mm_loadu_ps(dataIn+i);
  70.       sse1=_mm_unpacklo_ps(sse0,sse0);
  71.            _mm_storeu_ps(dataOut+(o+=16),sse1);
  72.       sse1=_mm_unpackhi_ps(sse0,sse0);
  73.            _mm_storeu_ps(dataOut+(o+=16),sse0);
  74.     } break;
  75.     case _S_to_M: sizeIn <<=1; for(Uint32 i=-16,o=0; o<sizeOut; o+=8){ //assumes no hadd available
  76.       sse0=_mm_loadu_ps(dataIn+(i+=16));
  77.       sse1=_mm_shuffle_ps(sse0,sse0, _MM_SHUFFLE(2,3,0,1));
  78.       sse2=_mm_add_ps(sse0,sse1);
  79.       sse0=_mm_shuffle_ps(sse2,sse2, _MM_SHUFFLE(3,1,2,0));
  80.       _mm_storel_pi(dataOut+o,sse0);
  81.     } break;
  82.     case _S_to_S: sizeIn=sizeOut<<=1;
  83.     case _M_to_M: for(Uint32 io=0; io<sizeOut; io+=16) _mm_storeu_ps( dataOut+io, _mm_loadu_ps(dataIn+io) );
  84.   }} else { switch(channelInfo){ //potato mode
  85.     case _M_to_S: for(Uint32 i=0; i<sampleFrames; ++i){ dataOutS[i].l=dataOutS[i].r=dataInM[i]; } break;
  86.     case _S_to_M: for(Uint32 i=0; i<sampleFrames; ++i){ dataOutM[i]=(dataOutS[i].l+dataOutS[i].r)*.5f; } break;
  87.     case _S_to_S: sampleFrames<<=1; //multiply mono by 2 to make length of stereo
  88.     case _M_to_M: for(Uint32 i=0; i<sampleFrames; ++i){ dataOutM[i]=dataInM[i]; }
  89.   }}
  90. }
  91.  
  92.  
  93.  
  94. int _kit_kmixerVoiceProc(void* data){
  95.  
  96.   return 0;
  97. }
  98.  
  99.  
  100.  
  101. void _kit_kmixerVoiceMix()
  102. {
  103. }
  104.  
Advertisement
Comments
  • # Python 0.21 KB | 0 0
    1. https://www.reddit.com/r/BlueBeetleHqFre/
    2. https://www.reddit.com/r/Strayshqfre
    3. https://www.reddit.com/r/HauntingQueenMaryHqf
    4. https://www.reddit.com/r/TheMoonhqfre
    5. https://www.reddit.com/r/BackontheStriphqf
    6.  
Add Comment
Please, Sign In to add comment
Advertisement