Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _KIT_KMIXERPRIVATE_H
- #define _KIT_KMIXERPRIVATE_H
- #include "../../include/kit_sdl2/kit_kmixer.h"
- //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) //(SSE4.1)
- #define _AVX_MASK (1<<1)
- #define _AVX2_MASK (1<<0)
- //for debugging/testing
- #define _ENABLE_SSE SDL_TRUE
- #define _ENABLE_SSE2 SDL_TRUE
- #define _ENABLE_SSE3 SDL_TRUE
- #define _ENABLE_SSE41 SDL_TRUE
- #define _ENABLE_AVX SDL_TRUE
- #define _ENABLE_AVX2 SDL_TRUE
- //#define _KIT_KMIXER_DEBUG
- #define _DEV_MAGIC_NUM (0x0076654472786D6B) //="kmxrDev\x00"
- #define _CHECK_IF_DEVICE_IS_VALID(_value)\
- _IF_SDLERR_R(device->_magic.num!=_DEV_MAGIC_NUM,_value,;,"device is invalid")
- //bitmask of a Uint64's MSB
- #define U64_MSB ((Uint64)0xFF<<56)
- //ones' complement of U64_MSB
- #define U64_MSBC (~U64_MSB)
- //converts strings to unsigned ints
- //(with the power of technically undefined behavior! :D
- // if fast inverse square root can do it, then so can i)
- #define U32_STR(_s) (*(Uint32*)(_s))
- #define U64_STR(_s) (*(Uint64*)(_s))
- #define _PRINT_AUDIO_SPEC(_spec) { \
- SDL_Log(".freq =%i",_spec.freq); \
- SDL_Log(".format =%X",_spec.format); \
- SDL_Log(".channels=%u",_spec.channels); \
- SDL_Log(".silence =%u",_spec.silence); \
- SDL_Log(".samples =%u",_spec.samples); \
- SDL_Log(".size =%u",_spec.size); \
- SDL_Log(".callback=%p",_spec.callback); \
- SDL_Log(".userdata=%p",_spec.userdata); }
- #define _PRINT_AUDIO_SPEC_P(_spec) { \
- SDL_Log("->freq =%i",_spec->freq); \
- SDL_Log("->format =%X",_spec->format); \
- SDL_Log("->channels=%u",_spec->channels); \
- SDL_Log("->silence =%u",_spec->silence); \
- SDL_Log("->samples =%u",_spec->samples); \
- SDL_Log("->size =%u",_spec->size); \
- SDL_Log("->callback=%p",_spec->callback); \
- SDL_Log("->userdata=%p",_spec->userdata); }
- /* ++++++++++++ */
- /* +kit_kmixer+ */
- /* ++++++++++++ */
- struct _kit_kmixerGlobals_t {
- SDL_mutex* lock;
- int threadPoolSize, cores, capabilities;
- int init;
- };
- extern struct _kit_kmixerGlobals_t _kit_kmixerGlobals;
- typedef union {
- void* ptr;
- Uint8* u_8;
- Sint16* i16;
- Sint32* i32;
- float* f32;
- } _mono_samples;
- //(stores left and right ear components of a stereo stream)
- typedef struct { Uint8 l,r; } _stereo_samples_u_8;
- typedef struct { Sint16 l,r; } _stereo_samples_i16;
- typedef struct { Sint32 l,r; } _stereo_samples_i32;
- typedef struct { float l,r; } _stereo_samples_f32;
- typedef union {
- void* ptr;
- _stereo_samples_u_8* u_8;
- _stereo_samples_i16* i16;
- _stereo_samples_i32* i32;
- _stereo_samples_f32* f32;
- } _stereo_samples;
- /* ------------ */
- /* -kit_kmixer- */
- /* ------------ */
- /* +++++++++++++++++ */
- /* +kit_kmixerVoice+ */
- /* +++++++++++++++++ */
- typedef union {
- void* v;
- _mono_samples m;
- _stereo_samples s;
- } _kit_kmixerVoiceBuffer;
- typedef union {
- void* v;
- float* m;
- _stereo_samples_f32* s;
- } _kit_kmixerVoiceBufferF;
- typedef struct _kit_kmixerVoice _kit_kmixerVoice;
- struct _kit_kmixerVoice { //128B
- //lock is compared with NULL to check if voice is valid
- SDL_mutex* lock; //to make sure a voice doesn't get deleted while it's processing
- kit_coreVector* inputs; //list of input voice indexes, if any (can be NULL)
- kit_coreVector* inputRefs; //list of input voice references, if any (can be NULL)
- _kit_kmixerVoice* output; //reference to output voice struct
- _kit_kmixerVoiceBufferF bufferInput; //input buffer (or the mixing stage's output)
- _kit_kmixerVoiceBuffer bufferUser; //buffer to be filled in or modified by the user
- _kit_kmixerVoiceBufferF bufferConvert; //sometimes used for buffer conversion (always stereo size)
- _kit_kmixerVoiceBufferF bufferOutput; //final output buffer (or the mixing stage's input)
- kit_kmixerVoiceSpec spec; //contains info for bufferUser, given by the user
- Uint32 chainStage; //the voice's current position in the processing chain
- Uint32 index; //index of this specific voice in the device's voice list
- //volume can actually be <0, but for volL it will override applyVolume to SDL_FALSE,
- //and for volR, volR would then be set to volL
- float volL; //left ear volume (or total volume if mono); 0.0 -> 1.0
- float volR; //right ear volume (ignored if mono); 0.0 -> 1.0
- SDL_bool applyVolume; //if SDL_TRUE, apply volume when mixing voice's output
- SDL_bool stereoOutput; //output is mono if SDL_FALSE, stereo if SDL_TRUE
- };
- extern int _kit_kmixerVoiceProc(void* data);
- extern void _kit_kmixerVoiceMix(_kit_kmixerVoice* ovoice, kit_coreVector* ivoices);
- /* ----------------- */
- /* -kit_kmixerVoice- */
- /* ----------------- */
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement