Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _KIT_KMIXERVOICEPRIVATE_H
- #define _KIT_KMIXERVOICEPRIVATE_H
- #include "../../include/kit_sdl2/kit_core.h"
- #include "_kit_kmixerPrivate.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- 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_kmixerDevice* device; //reference to the voice's device
- Uint32 output; //index of output voice
- Uint32 timeStamp; //result of SDL_GetTicks() at the time of voice creation
- kit_acodecPCMSamples bufferInput; //input buffer (aka the mixing stage's output)
- kit_acodecPCMSamples bufferUser; //buffer to be filled in or modified by the user
- kit_acodecPCMSamples bufferConvert; //sometimes used for buffer conversion (always stereo size)
- kit_acodecPCMSamples bufferOutput; //final output buffer (aka a mixing stage 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
- //volL can actually be <0, but it will be MAX()'d to 0 anyway
- //if volR <0, volR would then be set to whatever volL is after the MAX()
- 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 stereoOutput; //output is mono if SDL_FALSE, stereo if SDL_TRUE
- };
- extern int _kit_kmixerVoiceProc(void* data);
- extern int _kit_kmixerVoiceMix(void* data);
- extern int _kit_kmixerVoiceRebuildOrd(kit_kmixerDevice* device);
- static inline int _kit_kmixerVoiceAddFillSpec(kit_kmixerDevice* device,
- kit_kmixerVoiceSpec* vspec)
- {
- _kit_kmixerVoice* voice0 = device->_raw->data;
- vspec->freq = voice0->spec.freq;
- vspec->samples = voice0->spec.samples;
- vspec->_size = voice0->spec.samples<<vspec->stereo;
- switch(vspec->format){
- case AUDIO_F32: SDL_FALLTHROUGH;
- case AUDIO_S32: vspec->_size *= 2; SDL_FALLTHROUGH;
- case AUDIO_S16: vspec->_size *= 2; SDL_FALLTHROUGH;
- case AUDIO_U8 : break;
- default: _IS_SDLERR(;,"spec's format is invalid"); }
- /*!err*/ return 0;
- _error_: return -1;
- }
- static inline int _kit_kmixerVoiceAddFillVoice(kit_kmixerVoiceSpec* vspec,
- _kit_kmixerVoice* voiceO,
- _kit_kmixerVoice* voiceI)
- {
- kit_coreMemset(voiceI, 0, sizeof(_kit_kmixerVoice));
- Uint32 stereo_f32_size = sizeof(float)*vspec->samples*2;
- Uint32 bufferUser_size = vspec->_size;
- Uint32 bufferOutput_size = (sizeof(float)*vspec->samples)<<voiceO->spec.stereo;
- voiceI->lock = SDL_CreateMutex();
- _IF_GOTO_ERROR(voiceI->lock==NULL,;)
- voiceI->inputs = NULL; //created when the first input is added
- //voiceI->device = <handled inside VoiceAdd>
- voiceI->output = voiceO->index;
- voiceI->timeStamp = SDL_GetTicks();
- voiceI->bufferInput.data = SDL_malloc(stereo_f32_size);
- voiceI->bufferUser.data = SDL_malloc(bufferUser_size);
- voiceI->bufferConvert.data = SDL_malloc(stereo_f32_size);
- voiceI->bufferOutput.data = SDL_malloc(bufferOutput_size);
- voiceI->spec = *vspec;
- //voiceI->chainStage = <handled inside VoiceAddInput>
- //voiceI->index = <handled inside VoiceAdd>
- voiceI->volL = 1.0f;
- voiceI->volR = (voiceI->spec.stereo) ? 1.0f : -1.0f;
- voiceI->stereoOutput = voiceO->spec.stereo;
- /*!err*/ return 0;
- _error_: return -1;
- }
- #ifdef __cplusplus
- }
- #endif
- #endif /* _KIT_KMIXERVOICEPRIVATE_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement