ALbuffer *NewBuffer(ALCcontext *context) { ALCdevice *device = context->Device; ALbuffer *buffer; ALenum err; buffer = calloc(1, sizeof(ALbuffer)); if(!buffer) SET_ERROR_AND_RETURN_VALUE(context, AL_OUT_OF_MEMORY, NULL); RWLockInit(&buffer->lock); err = NewThunkEntry(&buffer->id); if(err == AL_NO_ERROR) err = InsertUIntMapEntry(&device->BufferMap, buffer->id, buffer); if(err != AL_NO_ERROR) { FreeThunkEntry(buffer->id); memset(buffer, 0, sizeof(ALbuffer)); free(buffer); SET_ERROR_AND_RETURN_VALUE(context, err, NULL); } return buffer; }
void InitUIntMap(UIntMap *map, ALsizei limit) { map->array = NULL; map->size = 0; map->maxsize = 0; map->limit = limit; RWLockInit(&map->lock); }
void InitUIntMap(UIntMap *map, ALsizei limit) { map->keys = NULL; map->values = NULL; map->size = 0; map->capacity = 0; map->limit = limit; RWLockInit(&map->lock); }
static void ALsoundfont_Construct(ALsoundfont *self) { InitRef(&self->ref, 0); self->Presets = NULL; self->NumPresets = 0; RWLockInit(&self->Lock); self->id = 0; }
static void MidiSynth_Construct(MidiSynth *self, ALCdevice *device) { InitEvtQueue(&self->EventQueue); RWLockInit(&self->Lock); self->Gain = 1.0f; self->State = AL_INITIAL; self->LastEvtTime = 0; self->NextEvtTime = UINT64_MAX; self->SamplesSinceLast = 0.0; self->SamplesToNext = 0.0; self->SamplesPerTick = (ALdouble)device->Frequency / TICKS_PER_SECOND; }
void MidiSynth_Construct(MidiSynth *self, ALCdevice *device) { InitEvtQueue(&self->EventQueue); RWLockInit(&self->Lock); self->Soundfonts = NULL; self->NumSoundfonts = 0; self->Gain = 1.0f; self->State = AL_INITIAL; self->ClockBase = 0; self->SamplesDone = 0; self->SampleRate = device->Frequency; }
AL_API ALvoid AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers) { ALCdevice *device; ALCcontext *context; ALsizei cur = 0; ALenum err; context = GetContextRef(); if(!context) return; if(!(n >= 0)) SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); device = context->Device; for(cur = 0; cur < n; cur++) { ALbuffer *buffer = calloc(1, sizeof(ALbuffer)); if(!buffer) { alDeleteBuffers(cur, buffers); SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done); } RWLockInit(&buffer->lock); err = NewThunkEntry(&buffer->id); if(err == AL_NO_ERROR) err = InsertUIntMapEntry(&device->BufferMap, buffer->id, buffer); if(err != AL_NO_ERROR) { FreeThunkEntry(buffer->id); memset(buffer, 0, sizeof(ALbuffer)); free(buffer); alDeleteBuffers(cur, buffers); SET_ERROR_AND_GOTO(context, err, done); } buffers[cur] = buffer->id; } done: ALCcontext_DecRef(context); }
void ThunkInit(void) { RWLockInit(&ThunkLock); ThunkArraySize = 1; ThunkArray = calloc(1, ThunkArraySize * sizeof(*ThunkArray)); }
void ThunkInit(void) { RWLockInit(&ThunkLock); ThunkArraySize = 1024; ThunkArray = al_calloc(16, ThunkArraySize * sizeof(*ThunkArray)); }