AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects) { ALCcontext *Context; ALeffect *ALEffect; ALsizei i; Context = alcGetCurrentContext(); SuspendContext(Context); if (n >= 0) { // Check that all effects are valid for (i = 0; i < n; i++) { if (!alIsEffect(effects[i])) { alSetError(AL_INVALID_NAME); break; } } if (i == n) { // All effects are valid for (i = 0; i < n; i++) { // Recheck that the effect is valid, because there could be duplicated names if (effects[i] && alIsEffect(effects[i])) { ALeffect **list; ALEffect = ((ALeffect*)ALTHUNK_LOOKUPENTRY(effects[i])); // Remove Source from list of Sources list = &g_EffectList; while(*list && *list != ALEffect) list = &(*list)->next; if(*list) *list = (*list)->next; ALTHUNK_REMOVEENTRY(ALEffect->effect); memset(ALEffect, 0, sizeof(ALeffect)); free(ALEffect); g_EffectCount--; } } } } else alSetError(AL_INVALID_VALUE); ProcessContext(Context); }
ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters) { ALCcontext *Context; ALfilter *ALFilter; ALsizei i; Context = alcGetCurrentContext(); SuspendContext(Context); if (n >= 0) { // Check that all filters are valid for (i = 0; i < n; i++) { if (!alIsFilter(filters[i])) { alSetError(AL_INVALID_NAME); break; } } if (i == n) { // All filters are valid for (i = 0; i < n; i++) { // Recheck that the filter is valid, because there could be duplicated names if (filters[i] && alIsFilter(filters[i])) { ALfilter **list; ALFilter = ((ALfilter*)ALTHUNK_LOOKUPENTRY(filters[i])); // Remove Source from list of Sources list = &g_FilterList; while(*list && *list != ALFilter) list = &(*list)->next; if(*list) *list = (*list)->next; ALTHUNK_REMOVEENTRY(ALFilter->filter); memset(ALFilter, 0, sizeof(ALfilter)); free(ALFilter); g_FilterCount--; } } } } else alSetError(AL_INVALID_VALUE); ProcessContext(Context); }
/* * alGenDatabuffersEXT(ALsizei n, ALuint *puiBuffers) * * Generates n AL Databuffers, and stores the Databuffers Names in the array pointed to by puiBuffers */ AL_API ALvoid AL_APIENTRY alGenDatabuffersEXT(ALsizei n,ALuint *puiBuffers) { ALCcontext *Context; ALsizei i=0; Context = GetContextSuspended(); if(!Context) return; /* Check that we are actually generation some Databuffers */ if(n > 0) { ALCdevice *device = Context->Device; /* Check the pointer is valid (and points to enough memory to store * Databuffer Names) */ if(!IsBadWritePtr((void*)puiBuffers, n * sizeof(ALuint))) { ALenum err; /* Create all the new Databuffers */ while(i < n) { ALdatabuffer *buffer = calloc(1, sizeof(ALdatabuffer)); if(!buffer) { alSetError(Context, AL_OUT_OF_MEMORY); alDeleteDatabuffersEXT(i, puiBuffers); break; } buffer->databuffer = ALTHUNK_ADDENTRY(buffer); err = InsertUIntMapEntry(&device->DatabufferMap, buffer->databuffer, buffer); if(err != AL_NO_ERROR) { ALTHUNK_REMOVEENTRY(buffer->databuffer); memset(buffer, 0, sizeof(ALdatabuffer)); free(buffer); alSetError(Context, err); alDeleteDatabuffersEXT(i, puiBuffers); break; } puiBuffers[i++] = buffer->databuffer; buffer->state = UNMAPPED; } } else alSetError(Context, AL_INVALID_VALUE); } ProcessContext(Context); }
AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots) { ALCcontext *Context; ALeffectslot *EffectSlot; ALboolean SlotsValid = AL_FALSE; ALsizei i; Context = GetContextSuspended(); if(!Context) return; if(n < 0) alSetError(Context, AL_INVALID_VALUE); else { SlotsValid = AL_TRUE; // Check that all effectslots are valid for(i = 0;i < n;i++) { if((EffectSlot=LookupEffectSlot(Context->EffectSlotMap, effectslots[i])) == NULL) { alSetError(Context, AL_INVALID_NAME); SlotsValid = AL_FALSE; break; } else if(EffectSlot->refcount > 0) { alSetError(Context, AL_INVALID_NAME); SlotsValid = AL_FALSE; break; } } } if(SlotsValid) { // All effectslots are valid for(i = 0;i < n;i++) { // Recheck that the effectslot is valid, because there could be duplicated names if((EffectSlot=LookupEffectSlot(Context->EffectSlotMap, effectslots[i])) == NULL) continue; ALEffect_Destroy(EffectSlot->EffectState); RemoveUIntMapKey(&Context->EffectSlotMap, EffectSlot->effectslot); ALTHUNK_REMOVEENTRY(EffectSlot->effectslot); memset(EffectSlot, 0, sizeof(ALeffectslot)); free(EffectSlot); } } ProcessContext(Context); }
AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters) { ALCcontext *Context; ALCdevice *device; ALfilter *ALFilter; ALboolean Failed; ALsizei i; Context = GetContextSuspended(); if(!Context) return; Failed = AL_TRUE; device = Context->Device; if(n < 0) alSetError(Context, AL_INVALID_VALUE); else { Failed = AL_FALSE; // Check that all filters are valid for(i = 0;i < n;i++) { if(!filters[i]) continue; if(LookupFilter(device->FilterMap, filters[i]) == NULL) { alSetError(Context, AL_INVALID_NAME); Failed = AL_TRUE; break; } } } if(!Failed) { // All filters are valid for(i = 0;i < n;i++) { // Recheck that the filter is valid, because there could be duplicated names if((ALFilter=LookupFilter(device->FilterMap, filters[i])) == NULL) continue; RemoveUIntMapKey(&device->FilterMap, ALFilter->filter); ALTHUNK_REMOVEENTRY(ALFilter->filter); memset(ALFilter, 0, sizeof(ALfilter)); free(ALFilter); } } ProcessContext(Context); }
ALvoid ReleaseALEffects(ALCdevice *device) { ALsizei i; for(i = 0;i < device->EffectMap.size;i++) { ALeffect *temp = device->EffectMap.array[i].value; device->EffectMap.array[i].value = NULL; // Release effect structure ALTHUNK_REMOVEENTRY(temp->effect); memset(temp, 0, sizeof(ALeffect)); free(temp); } }
ALvoid ReleaseALFilters(ALCdevice *device) { ALsizei i; for(i = 0;i < device->FilterMap.size;i++) { ALfilter *temp = device->FilterMap.array[i].value; device->FilterMap.array[i].value = NULL; // Release filter structure ALTHUNK_REMOVEENTRY(temp->filter); memset(temp, 0, sizeof(ALfilter)); free(temp); } }
/* * alGenBuffers(ALsizei n, ALuint *puiBuffers) * * Generates n AL Buffers, and stores the Buffers Names in the array pointed to by puiBuffers */ AL_API ALvoid AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers) { ALCcontext *Context; ALsizei i=0; Context = GetContextSuspended(); if(!Context) return; // Check that we are actually generation some Buffers if(n > 0) { ALCdevice *device = Context->Device; ALenum err; // Check the pointer is valid (and points to enough memory to store Buffer Names) if(IsBadWritePtr((void*)buffers, n * sizeof(ALuint))) alSetError(Context, AL_INVALID_VALUE); else { // Create all the new Buffers while(i < n) { ALbuffer *buffer = calloc(1, sizeof(ALbuffer)); if(!buffer) { alSetError(Context, AL_OUT_OF_MEMORY); alDeleteBuffers(i, buffers); break; } buffer->buffer = (ALuint)ALTHUNK_ADDENTRY(buffer); err = InsertUIntMapEntry(&device->BufferMap, buffer->buffer, buffer); if(err != AL_NO_ERROR) { ALTHUNK_REMOVEENTRY(buffer->buffer); memset(buffer, 0, sizeof(ALbuffer)); free(buffer); alSetError(Context, err); alDeleteBuffers(i, buffers); break; } buffers[i++] = buffer->buffer; } } } 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); }
ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context) { ALsizei pos; for(pos = 0;pos < Context->EffectSlotMap.size;pos++) { ALeffectslot *temp = Context->EffectSlotMap.array[pos].value; Context->EffectSlotMap.array[pos].value = NULL; // Release effectslot structure ALEffect_Destroy(temp->EffectState); ALTHUNK_REMOVEENTRY(temp->effectslot); memset(temp, 0, sizeof(ALeffectslot)); free(temp); } }
/* * ReleaseALDatabuffers() * * INTERNAL FN : Called by DLLMain on exit to destroy any buffers that still exist */ ALvoid ReleaseALDatabuffers(ALCdevice *device) { ALsizei i; for(i = 0;i < device->DatabufferMap.size;i++) { ALdatabuffer *temp = device->DatabufferMap.array[i].value; device->DatabufferMap.array[i].value = NULL; // Release buffer data free(temp->data); // Release Buffer structure ALTHUNK_REMOVEENTRY(temp->databuffer); memset(temp, 0, sizeof(ALdatabuffer)); free(temp); } }
ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context) { while(Context->AuxiliaryEffectSlot) { ALeffectslot *temp = Context->AuxiliaryEffectSlot; Context->AuxiliaryEffectSlot = Context->AuxiliaryEffectSlot->next; // Release effectslot structure if(temp->EffectState) ALEffect_Destroy(temp->EffectState); ALTHUNK_REMOVEENTRY(temp->effectslot); memset(temp, 0, sizeof(ALeffectslot)); free(temp); } Context->AuxiliaryEffectSlotCount = 0; }
AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects) { ALCcontext *Context; ALsizei i=0; Context = GetContextSuspended(); if(!Context) return; if(n < 0 || IsBadWritePtr((void*)effects, n * sizeof(ALuint))) alSetError(Context, AL_INVALID_VALUE); else { ALCdevice *device = Context->Device; ALenum err; while(i < n) { ALeffect *effect = calloc(1, sizeof(ALeffect)); if(!effect) { alSetError(Context, AL_OUT_OF_MEMORY); alDeleteEffects(i, effects); break; } effect->effect = ALTHUNK_ADDENTRY(effect); err = InsertUIntMapEntry(&device->EffectMap, effect->effect, effect); if(err != AL_NO_ERROR) { ALTHUNK_REMOVEENTRY(effect->effect); memset(effect, 0, sizeof(ALeffect)); free(effect); alSetError(Context, err); alDeleteEffects(i, effects); break; } effects[i++] = effect->effect; InitEffectParams(effect, AL_EFFECT_NULL); } } 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 || 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); }
ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context) { #ifdef _DEBUG if(Context->AuxiliaryEffectSlotCount > 0) AL_PRINT("alcDestroyContext(): %d AuxiliaryEffectSlot(s) NOT deleted\n", Context->AuxiliaryEffectSlotCount); #endif while(Context->AuxiliaryEffectSlot) { ALeffectslot *temp = Context->AuxiliaryEffectSlot; Context->AuxiliaryEffectSlot = Context->AuxiliaryEffectSlot->next; // Release effectslot structure free(temp->ReverbBuffer); ALTHUNK_REMOVEENTRY(temp->effectslot); memset(temp, 0, sizeof(ALeffectslot)); free(temp); } Context->AuxiliaryEffectSlotCount = 0; }
ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots) { ALCcontext *Context; ALeffectslot *ALAuxiliaryEffectSlot; ALsizei i; Context = GetContextSuspended(); if(!Context) return; if (n >= 0) { // Check that all effectslots are valid for (i = 0; i < n; i++) { if (!alIsAuxiliaryEffectSlot(effectslots[i])) { alSetError(AL_INVALID_NAME); break; } else { ALAuxiliaryEffectSlot = (ALeffectslot*)ALTHUNK_LOOKUPENTRY(effectslots[i]); if(ALAuxiliaryEffectSlot->refcount > 0) { alSetError(AL_INVALID_NAME); break; } } } if (i == n) { // All effectslots are valid for (i = 0; i < n; i++) { // Recheck that the effectslot is valid, because there could be duplicated names if (alIsAuxiliaryEffectSlot(effectslots[i])) { ALeffectslot **list; ALAuxiliaryEffectSlot = ((ALeffectslot*)ALTHUNK_LOOKUPENTRY(effectslots[i])); // Remove Source from list of Sources list = &Context->AuxiliaryEffectSlot; while(*list && *list != ALAuxiliaryEffectSlot) list = &(*list)->next; if(*list) *list = (*list)->next; ALTHUNK_REMOVEENTRY(ALAuxiliaryEffectSlot->effectslot); if(ALAuxiliaryEffectSlot->EffectState) ALEffect_Destroy(ALAuxiliaryEffectSlot->EffectState); memset(ALAuxiliaryEffectSlot, 0, sizeof(ALeffectslot)); free(ALAuxiliaryEffectSlot); Context->AuxiliaryEffectSlotCount--; } } } } else alSetError(AL_INVALID_VALUE); ProcessContext(Context); }
/* * alDeleteBuffers(ALsizei n, ALuint *puiBuffers) * * Deletes the n AL Buffers pointed to by puiBuffers */ AL_API ALvoid AL_APIENTRY alDeleteBuffers(ALsizei n, const ALuint *puiBuffers) { ALCcontext *Context; ALbuffer *ALBuf; ALsizei i; Context = GetContextSuspended(); if(!Context) return; // Check we are actually Deleting some Buffers if(n < 0) alSetError(Context, AL_INVALID_VALUE); else { ALCdevice *device = Context->Device; ALboolean bFailed = AL_FALSE; // Check that all the buffers are valid and can actually be deleted for (i = 0; i < n; i++) { if(!puiBuffers[i]) continue; // Check for valid Buffer ID (can be NULL buffer) if((ALBuf=LookupBuffer(device->BufferMap, puiBuffers[i])) != NULL) { if(ALBuf->refcount != 0) { // Buffer still in use, cannot be deleted alSetError(Context, AL_INVALID_OPERATION); bFailed = AL_TRUE; break; } } else { // Invalid Buffer alSetError(Context, AL_INVALID_NAME); bFailed = AL_TRUE; break; } } // If all the Buffers were valid (and have Reference Counts of 0), then we can delete them if (!bFailed) { for (i = 0; i < n; i++) { if((ALBuf=LookupBuffer(device->BufferMap, puiBuffers[i])) != NULL) { // Release the memory used to store audio data free(ALBuf->data); // Release buffer structure RemoveUIntMapKey(&device->BufferMap, ALBuf->buffer); ALTHUNK_REMOVEENTRY(ALBuf->buffer); memset(ALBuf, 0, sizeof(ALbuffer)); free(ALBuf); } } } } ProcessContext(Context); }
/* * alDeleteBuffers(ALsizei n, ALuint *puiBuffers) * * Deletes the n AL Buffers pointed to by puiBuffers */ ALAPI ALvoid ALAPIENTRY alDeleteBuffers(ALsizei n, const ALuint *puiBuffers) { ALCcontext *Context; ALbuffer *ALBuf; ALsizei i; ALboolean bFailed = AL_FALSE; Context = alcGetCurrentContext(); SuspendContext(Context); // Check we are actually Deleting some Buffers if (n >= 0) { // Check that all the buffers are valid and can actually be deleted for (i = 0; i < n; i++) { // Check for valid Buffer ID (can be NULL buffer) if (alIsBuffer(puiBuffers[i])) { // If not the NULL buffer, check that the reference count is 0 ALBuf = ((ALbuffer *)ALTHUNK_LOOKUPENTRY(puiBuffers[i])); if (ALBuf) { if (ALBuf->refcount != 0) { // Buffer still in use, cannot be deleted alSetError(AL_INVALID_OPERATION); bFailed = AL_TRUE; } } } else { // Invalid Buffer alSetError(AL_INVALID_NAME); bFailed = AL_TRUE; } } // If all the Buffers were valid (and have Reference Counts of 0), then we can delete them if (!bFailed) { for (i = 0; i < n; i++) { if (puiBuffers[i] && alIsBuffer(puiBuffers[i])) { ALbuffer **list = &g_pBuffers; ALBuf=((ALbuffer *)ALTHUNK_LOOKUPENTRY(puiBuffers[i])); while(*list && *list != ALBuf) list = &(*list)->next; if(*list) *list = (*list)->next; // Release the memory used to store audio data free(ALBuf->data); // Release buffer structure ALTHUNK_REMOVEENTRY(puiBuffers[i]); memset(ALBuf, 0, sizeof(ALbuffer)); g_uiBufferCount--; free(ALBuf); } } } } else alSetError(AL_INVALID_VALUE); ProcessContext(Context); return; }
AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots) { ALCcontext *Context; ALCdevice *Device; Context = GetContextSuspended(); if(!Context) return; Device = Context->Device; if(n < 0 || IsBadWritePtr((void*)effectslots, n * sizeof(ALuint))) alSetError(Context, AL_INVALID_VALUE); else if((ALuint)n > Device->AuxiliaryEffectSlotMax - Context->EffectSlotMap.size) alSetError(Context, AL_INVALID_VALUE); else { ALenum err; ALsizei i, j; i = 0; while(i < n) { ALeffectslot *slot = calloc(1, sizeof(ALeffectslot)); if(!slot || !(slot->EffectState=NoneCreate())) { free(slot); // We must have run out or memory alSetError(Context, AL_OUT_OF_MEMORY); alDeleteAuxiliaryEffectSlots(i, effectslots); break; } slot->effectslot = (ALuint)ALTHUNK_ADDENTRY(slot); err = InsertUIntMapEntry(&Context->EffectSlotMap, slot->effectslot, slot); if(err != AL_NO_ERROR) { ALTHUNK_REMOVEENTRY(slot->effectslot); ALEffect_Destroy(slot->EffectState); free(slot); alSetError(Context, err); alDeleteAuxiliaryEffectSlots(i, effectslots); break; } effectslots[i++] = slot->effectslot; slot->Gain = int2ALfp(1); slot->AuxSendAuto = AL_TRUE; for(j = 0;j < BUFFERSIZE;j++) slot->WetBuffer[j] = int2ALfp(0); for(j = 0;j < 1;j++) { slot->ClickRemoval[j] = int2ALfp(0); slot->PendingClicks[j] = int2ALfp(0); } slot->refcount = 0; } } ProcessContext(Context); }
/* * alDatabeleteBuffersEXT(ALsizei n, ALuint *puiBuffers) * * Deletes the n AL Databuffers pointed to by puiBuffers */ AL_API ALvoid AL_APIENTRY alDeleteDatabuffersEXT(ALsizei n, const ALuint *puiBuffers) { ALCcontext *Context; ALdatabuffer *ALBuf; ALsizei i; ALboolean bFailed = AL_FALSE; Context = GetContextSuspended(); if(!Context) return; /* Check we are actually Deleting some Databuffers */ if(n >= 0) { ALCdevice *device = Context->Device; /* Check that all the databuffers are valid and can actually be * deleted */ for(i = 0;i < n;i++) { if(!puiBuffers[i]) continue; /* Check for valid Buffer ID */ if((ALBuf=LookupDatabuffer(device->DatabufferMap, puiBuffers[i])) != NULL) { if(ALBuf->state != UNMAPPED) { /* Databuffer still in use, cannot be deleted */ alSetError(Context, AL_INVALID_OPERATION); bFailed = AL_TRUE; break; } } else { /* Invalid Databuffer */ alSetError(Context, AL_INVALID_NAME); bFailed = AL_TRUE; break; } } /* If all the Databuffers were valid (and unmapped), then we can * delete them */ if(!bFailed) { for(i = 0;i < n;i++) { if((ALBuf=LookupDatabuffer(device->DatabufferMap, puiBuffers[i])) != NULL) { if(ALBuf == Context->SampleSource) Context->SampleSource = NULL; if(ALBuf == Context->SampleSink) Context->SampleSink = NULL; // Release the memory used to store audio data free(ALBuf->data); // Release buffer structure RemoveUIntMapKey(&device->DatabufferMap, ALBuf->databuffer); ALTHUNK_REMOVEENTRY(puiBuffers[i]); memset(ALBuf, 0, sizeof(ALdatabuffer)); free(ALBuf); } } } } else alSetError(Context, AL_INVALID_VALUE); ProcessContext(Context); }