AL_API ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint value) { ALCcontext *Context; ALCdevice *Device; ALfilter *ALFilter; Context = GetContextRef(); if(!Context) return; Device = Context->Device; if((ALFilter=LookupFilter(Device, filter)) == NULL) alSetError(Context, AL_INVALID_NAME); else { if(param == AL_FILTER_TYPE) { if(value == AL_FILTER_NULL || value == AL_FILTER_LOWPASS) InitFilterParams(ALFilter, value); else alSetError(Context, AL_INVALID_VALUE); } else { /* Call the appropriate handler */ ALfilter_SetParami(ALFilter, Context, param, value); } } ALCcontext_DecRef(Context); }
ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint iValue) { ALCcontext *Context; Context = alcGetCurrentContext(); SuspendContext(Context); if (filter && alIsFilter(filter)) { ALfilter *ALFilter = (ALfilter*)ALTHUNK_LOOKUPENTRY(filter); switch(param) { case AL_FILTER_TYPE: if(iValue == AL_FILTER_NULL || iValue == AL_FILTER_LOWPASS) InitFilterParams(ALFilter, iValue); else alSetError(AL_INVALID_VALUE); break; default: alSetError(AL_INVALID_ENUM); break; } } else alSetError(AL_INVALID_NAME); ProcessContext(Context); }
AL_API ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint iValue) { ALCcontext *Context; ALCdevice *Device; ALfilter *ALFilter; Context = GetContextSuspended(); if(!Context) return; Device = Context->Device; if((ALFilter=LookupFilter(Device->FilterMap, filter)) != NULL) { switch(param) { case AL_FILTER_TYPE: if(iValue == AL_FILTER_NULL || iValue == AL_FILTER_LOWPASS) InitFilterParams(ALFilter, iValue); else alSetError(Context, AL_INVALID_VALUE); break; default: alSetError(Context, AL_INVALID_ENUM); break; } } else alSetError(Context, AL_INVALID_NAME); ProcessContext(Context); }
AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters) { ALCcontext *Context; ALsizei i=0; Context = GetContextSuspended(); if(!Context) return; if (n > 0) { ALCdevice *device = Context->Device; // Check that enough memory has been allocted in the 'filters' array for n Filters if (!IsBadWritePtr((void*)filters, n * sizeof(ALuint))) { ALenum err; while(i < n) { ALfilter *filter = calloc(1, sizeof(ALfilter)); if(!filter) { alSetError(Context, AL_OUT_OF_MEMORY); alDeleteFilters(i, filters); break; } filter->filter = ALTHUNK_ADDENTRY(filter); err = InsertUIntMapEntry(&device->FilterMap, filter->filter, filter); if(err != AL_NO_ERROR) { ALTHUNK_REMOVEENTRY(filter->filter); memset(filter, 0, sizeof(ALfilter)); free(filter); alSetError(Context, err); alDeleteFilters(i, filters); break; } filters[i++] = filter->filter; InitFilterParams(filter, AL_FILTER_NULL); } } } ProcessContext(Context); }
AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters) { ALCcontext *Context; ALsizei i; Context = GetContextRef(); if(!Context) return; if(n < 0 || IsBadWritePtr((void*)filters, n * sizeof(ALuint))) alSetError(Context, AL_INVALID_VALUE); else { ALCdevice *device = Context->Device; ALenum err; for(i = 0;i < n;i++) { ALfilter *filter = calloc(1, sizeof(ALfilter)); if(!filter) { alSetError(Context, AL_OUT_OF_MEMORY); alDeleteFilters(i, filters); break; } InitFilterParams(filter, AL_FILTER_NULL); err = NewThunkEntry(&filter->filter); if(err == AL_NO_ERROR) err = InsertUIntMapEntry(&device->FilterMap, filter->filter, filter); if(err != AL_NO_ERROR) { FreeThunkEntry(filter->filter); memset(filter, 0, sizeof(ALfilter)); free(filter); alSetError(Context, err); alDeleteFilters(i, filters); break; } filters[i] = filter->filter; } } ALCcontext_DecRef(Context); }
AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters) { ALCcontext *Context; ALsizei i=0; Context = GetContextSuspended(); if(!Context) return; if(n < 0 || IsBadWritePtr((void*)filters, n * sizeof(ALuint))) alSetError(Context, AL_INVALID_VALUE); else { ALCdevice *device = Context->Device; ALenum err; while(i < n) { ALfilter *filter = alCalloc(1, sizeof(ALfilter)); if(!filter) { alSetError(Context, AL_OUT_OF_MEMORY); alDeleteFilters(i, filters); break; } filter->filter = ALTHUNK_ADDENTRY(filter); err = InsertUIntMapEntry(&device->FilterMap, filter->filter, filter); if(err != AL_NO_ERROR) { ALTHUNK_REMOVEENTRY(filter->filter); memset(filter, 0, sizeof(ALfilter)); alFree(filter); alSetError(Context, err); alDeleteFilters(i, filters); break; } filters[i++] = filter->filter; InitFilterParams(filter, AL_FILTER_NULL); } } ProcessContext(Context); }
AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters) { ALCcontext *Context; ALsizei cur = 0; Context = GetContextRef(); if(!Context) return; al_try { ALCdevice *device = Context->Device; ALenum err; CHECK_VALUE(Context, n >= 0); for(cur = 0;cur < n;cur++) { ALfilter *filter = calloc(1, sizeof(ALfilter)); if(!filter) al_throwerr(Context, AL_OUT_OF_MEMORY); InitFilterParams(filter, AL_FILTER_NULL); err = NewThunkEntry(&filter->id); if(err == AL_NO_ERROR) err = InsertUIntMapEntry(&device->FilterMap, filter->id, filter); if(err != AL_NO_ERROR) { FreeThunkEntry(filter->id); memset(filter, 0, sizeof(ALfilter)); free(filter); al_throwerr(Context, err); } filters[cur] = filter->id; } } al_catchany() { if(cur > 0) alDeleteFilters(cur, filters); } al_endtry; ALCcontext_DecRef(Context); }
ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters) { ALCcontext *Context; ALsizei i; Context = alcGetCurrentContext(); SuspendContext(Context); if (n > 0) { // Check that enough memory has been allocted in the 'filters' array for n Filters if (!IsBadWritePtr((void*)filters, n * sizeof(ALuint))) { ALfilter **list = &g_FilterList; while(*list) list = &(*list)->next; i = 0; while(i < n) { *list = calloc(1, sizeof(ALfilter)); if(!(*list)) { // We must have run out or memory alDeleteFilters(i, filters); alSetError(AL_OUT_OF_MEMORY); break; } filters[i] = (ALuint)ALTHUNK_ADDENTRY(*list); (*list)->filter = filters[i]; InitFilterParams(*list, AL_FILTER_NULL); g_FilterCount++; i++; list = &(*list)->next; } } } ProcessContext(Context); }
AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters) { 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++) { ALfilter *filter = calloc(1, sizeof(ALfilter)); if(!filter) { alDeleteFilters(cur, filters); SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done); } InitFilterParams(filter, AL_FILTER_NULL); err = NewThunkEntry(&filter->id); if(err == AL_NO_ERROR) err = InsertUIntMapEntry(&device->FilterMap, filter->id, filter); if(err != AL_NO_ERROR) { FreeThunkEntry(filter->id); memset(filter, 0, sizeof(ALfilter)); free(filter); alDeleteFilters(cur, filters); SET_ERROR_AND_GOTO(context, err, done); } filters[cur] = filter->id; } done: ALCcontext_DecRef(context); }
static ALfilter *AllocFilter(ALCcontext *context) { ALCdevice *device = context->Device; FilterSubList *sublist, *subend; ALfilter *filter = NULL; ALsizei lidx = 0; ALsizei slidx; almtx_lock(&device->FilterLock); sublist = VECTOR_BEGIN(device->FilterList); subend = VECTOR_END(device->FilterList); for(;sublist != subend;++sublist) { if(sublist->FreeMask) { slidx = CTZ64(sublist->FreeMask); filter = sublist->Filters + slidx; break; } ++lidx; } if(UNLIKELY(!filter)) { const FilterSubList empty_sublist = { 0, NULL }; /* Don't allocate so many list entries that the 32-bit ID could * overflow... */ if(UNLIKELY(VECTOR_SIZE(device->FilterList) >= 1<<25)) { almtx_unlock(&device->FilterLock); alSetError(context, AL_OUT_OF_MEMORY, "Too many filters allocated"); return NULL; } lidx = (ALsizei)VECTOR_SIZE(device->FilterList); VECTOR_PUSH_BACK(device->FilterList, empty_sublist); sublist = &VECTOR_BACK(device->FilterList); sublist->FreeMask = ~U64(0); sublist->Filters = al_calloc(16, sizeof(ALfilter)*64); if(UNLIKELY(!sublist->Filters)) { VECTOR_POP_BACK(device->FilterList); almtx_unlock(&device->FilterLock); alSetError(context, AL_OUT_OF_MEMORY, "Failed to allocate filter batch"); return NULL; } slidx = 0; filter = sublist->Filters + slidx; } memset(filter, 0, sizeof(*filter)); InitFilterParams(filter, AL_FILTER_NULL); /* Add 1 to avoid filter ID 0. */ filter->id = ((lidx<<6) | slidx) + 1; sublist->FreeMask &= ~(U64(1)<<slidx); almtx_unlock(&device->FilterLock); return filter; }