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"
- void _kit_kmixerDeviceCallback(void* userdata, Uint8* _stream, int len){
- //kit_kmixerDevice* device=userdata;
- //_kit_kmixerVoiceBufferF stream={ .v=(void*)_stream };
- }
- int kit_kmixerDeviceClose(kit_kmixerDevice** device_p){
- return 0;
- }
- kit_kmixerDevice* kit_kmixerDeviceOpen(const char* deviceName,
- int isCapture, int allowedChanges,
- int freq, int stereo, Uint16 samples)
- {
- kit_kmixerDevice* device=SDL_malloc(sizeof(kit_kmixerDevice));
- _IF_GOTO_ERROR(device==NULL,;);
- memset(device, 0, sizeof(kit_kmixerDevice));
- device->_magic.num=0x0076654472786D6B; //="kmxrDev\x00"
- SDL_AudioSpec specWant, specHave;
- specWant.freq=freq;
- specWant.format=AUDIO_F32;
- specWant.channels=1+(stereo&1);
- specWant.samples=samples;
- specWant.callback=_kit_kmixerDeviceCallback;
- specWant.userdata=device;
- allowedChanges&=!SDL_AUDIO_ALLOW_FORMAT_CHANGE; //samples are always f32 internally
- device->_devID=SDL_OpenAudioDevice(deviceName,isCapture&1, &specWant,&specHave, allowedChanges);
- _IF_GOTO_ERROR(!device->_devID,;);
- _IF_SDLERR(specHave.channels>2,;,"specified audio device returned as neither mono nor stereo");
- device->spec=specHave;
- device->_lock=SDL_CreateMutex();
- _IF_GOTO_ERROR(device->_lock==NULL,;);
- device->_thread.cond=SDL_CreateCond();
- _IF_GOTO_ERROR(device->_thread.cond,;);
- device->_thread.queue=kit_coreVectorCreate(1,0,0,sizeof(kit_coreThread),*(Uint32*)"cTh\x00",NULL);
- _IF_GOTO_ERROR(device->_thread.queue==NULL,;);
- device->_thread.pool=kit_coreVectorCreate(_kit_kmixerGlobals.threadPoolSize,0,0,
- sizeof(kit_coreThread),*(Uint32*)"cTh\x00",NULL);
- _IF_GOTO_ERROR(device->_thread.pool==NULL,;);
- device->_voices.raw=kit_coreVectorCreate(1,0,0,sizeof(_kit_kmixerVoice),*(Uint32*)"kmV\x00",NULL);
- _IF_GOTO_ERROR(device->_voices.raw==NULL,;);
- device->_voices.ord=kit_coreVectorCreate(1,1,0,sizeof(_kit_kmixerVoice),*(Uint32*)"kmV\x00",NULL);
- _IF_GOTO_ERROR(device->_voices.ord==NULL,;);
- return device;
- _error_:
- if(device!=NULL){
- if(device->_voices.ord!=NULL) kit_coreVectorDestroy(&device->_voices.ord);
- if(device->_voices.raw!=NULL) kit_coreVectorDestroy(&device->_voices.raw);
- if(device->_thread.pool!=NULL) kit_coreVectorDestroy(&device->_thread.pool);
- if(device->_thread.queue!=NULL) kit_coreVectorDestroy(&device->_thread.queue);
- if(device->_thread.cond!=NULL) SDL_DestroyCond(device->_thread.cond);
- if(device->_lock!=NULL) SDL_DestroyMutex(device->_lock);
- if(device->_devID!=0) SDL_CloseAudioDevice(device->_devID);
- SDL_free(device);
- }
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement