Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "../include/kit_sdl2/kit_kmixer.h"
- #include "../_private/include/_kit_privmacro.h"
- #include "../_private/include/_kit_kmixerPrivate.h"
- /*
- VoiceProcess:
- convert data type to float
- convert mono to stereo, or vice versa
- */
- //include intrinsic functions
- #include <immintrin.h>
- //bitmasks for _kit_kmixerGlobals.capabilities
- #define _SSE_MASK (1<<5)
- #define _SSE2_MASK (1<<4)
- #define _SSE3_MASK (1<<3)
- #define _SSE41_MASK (1<<2)
- #define _AVX_MASK (1<<1)
- #define _AVX2_MASK (1<<0)
- //for visual clarity during ProcChannels
- //(this could also just be an enum probably, but w/e)
- #define _M_to_M (0) // mono->mono
- #define _M_to_S (1) // mono->stereo
- #define _S_to_M (2) //stereo->mono
- #define _S_to_S (3) //stereo->stereo
- //used to multiply an int by the inverse of an int to get a normalized float
- //(input 8-bit samples will be unsigned, so -=0x80 to convert them to signed first)
- const float invi8 =1.0f/0x7f;
- const float invi16=1.0f/0x7fff;
- const float invi32=1.0f/0x7fffffff;
- //stores left and right ear components of a stereo stream
- struct _stereo_u8 { Uint8 l,r; };
- struct _stereo_i16 { Sint16 l,r; };
- struct _stereo_i32 { Sint32 l,r; };
- struct _stereo_f32 { float l,r; };
- static inline void _kit_kmixerVoiceProcType(void* dataIn, void* dataOut, Uint32 numSamples,
- SDL_AudioFormat type, int channelInfo)
- {
- }
- //assumes f32
- void _kit_kmixerVoiceProcChannels(void* dataIn, void* dataOut, Uint32 sampleFrames, int channelInfo){
- Uint32 sizeIn,sizeOut; sizeIn=sizeOut=sampleFrames*sizeof(float);
- __m128 sse0,sse1,sse2; //__m256 avx0,avx1;
- float *dataInM=dataIn, *dataOutM=dataOut;
- struct _stereo_f32 *dataOutS=dataOut;
- if(_kit_kmixerGlobals.capabilities&_AVX_MASK){ switch(channelInfo){ //has >=AVX1
- //TBD
- case _M_to_M:
- case _M_to_S: sizeOut<<=1;
- case _S_to_M: sizeIn<<=1;
- case _S_to_S: sizeIn=sizeOut<<=1;
- }} else if(_kit_kmixerGlobals.capabilities&_SSE3_MASK && channelInfo==_S_to_M){ //(requires SSE3's "hadd")
- //TBD
- } else if(_kit_kmixerGlobals.capabilities&_SSE_MASK){ switch(channelInfo){ //has >=SSE1
- case _M_to_S: sizeOut<<=1; for(Uint32 i=0,o=-16; i<sizeIn; i+=16){
- sse0=_mm_loadu_ps(dataIn+i);
- sse1=_mm_unpacklo_ps(sse0,sse0);
- _mm_storeu_ps(dataOut+(o+=16),sse1);
- sse1=_mm_unpackhi_ps(sse0,sse0);
- _mm_storeu_ps(dataOut+(o+=16),sse0);
- } break;
- case _S_to_M: sizeIn <<=1; for(Uint32 i=-16,o=0; o<sizeOut; o+=8){ //assumes no hadd available
- sse0=_mm_loadu_ps(dataIn+(i+=16));
- sse1=_mm_shuffle_ps(sse0,sse0, _MM_SHUFFLE(2,3,0,1));
- sse2=_mm_add_ps(sse0,sse1);
- sse0=_mm_shuffle_ps(sse2,sse2, _MM_SHUFFLE(3,1,2,0));
- _mm_storel_pi(dataOut+o,sse0);
- } break;
- case _S_to_S: sizeIn=sizeOut<<=1;
- case _M_to_M: for(Uint32 io=0; io<sizeOut; io+=16) _mm_storeu_ps( dataOut+io, _mm_loadu_ps(dataIn+io) );
- }} else { switch(channelInfo){ //potato mode
- case _M_to_S: for(Uint32 i=0; i<sampleFrames; ++i){ dataOutS[i].l=dataOutS[i].r=dataInM[i]; } break;
- case _S_to_M: for(Uint32 i=0; i<sampleFrames; ++i){ dataOutM[i]=(dataOutS[i].l+dataOutS[i].r)*.5f; } break;
- case _S_to_S: sampleFrames<<=1; //multiply mono by 2 to make length of stereo
- case _M_to_M: for(Uint32 i=0; i<sampleFrames; ++i){ dataOutM[i]=dataInM[i]; }
- }}
- }
- int _kit_kmixerVoiceProc(void* data){
- return 0;
- }
- void _kit_kmixerVoiceMix()
- {
- }
Advertisement
Comments
-
- https://www.reddit.com/r/BlueBeetleHqFre/
- https://www.reddit.com/r/Strayshqfre
- https://www.reddit.com/r/HauntingQueenMaryHqf
- https://www.reddit.com/r/TheMoonhqfre
- https://www.reddit.com/r/BackontheStriphqf
Add Comment
Please, Sign In to add comment
Advertisement