From 22982948cf951924c206b37e80c31532b75c5410 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 30 Jun 2014 00:10:40 -0700 Subject: Standardize some New/Delete methods --- OpenAL32/Include/alBuffer.h | 2 +- OpenAL32/Include/alMidi.h | 4 ++-- OpenAL32/alBuffer.c | 12 ++++++------ OpenAL32/alFontsound.c | 25 ++++++++++++++++--------- OpenAL32/alPreset.c | 7 +++---- OpenAL32/alSoundfont.c | 9 ++++----- 6 files changed, 32 insertions(+), 27 deletions(-) (limited to 'OpenAL32') diff --git a/OpenAL32/Include/alBuffer.h b/OpenAL32/Include/alBuffer.h index 3e93a883..557f2282 100644 --- a/OpenAL32/Include/alBuffer.h +++ b/OpenAL32/Include/alBuffer.h @@ -98,7 +98,7 @@ typedef struct ALbuffer { } ALbuffer; ALbuffer *NewBuffer(ALCcontext *context); -void DeleteBuffer(ALCdevice *device, ALuint bufid); +void DeleteBuffer(ALCdevice *device, ALbuffer *buffer); ALenum LoadData(ALbuffer *buffer, ALuint freq, ALenum NewFormat, ALsizei frames, enum UserFmtChannels SrcChannels, enum UserFmtType SrcType, const ALvoid *data, ALsizei align, ALboolean storesrc); diff --git a/OpenAL32/Include/alMidi.h b/OpenAL32/Include/alMidi.h index 03aa8253..76567db0 100644 --- a/OpenAL32/Include/alMidi.h +++ b/OpenAL32/Include/alMidi.h @@ -92,11 +92,11 @@ typedef struct ALfontsound { ALuint id; } ALfontsound; -void ALfontsound_Destruct(ALfontsound *self); void ALfontsound_setPropi(ALfontsound *self, ALCcontext *context, ALenum param, ALint value); void ALfontsound_setModStagei(ALfontsound *self, ALCcontext *context, ALsizei stage, ALenum param, ALint value); ALfontsound *NewFontsound(ALCcontext *context); +void DeleteFontsound(ALCdevice *device, ALfontsound *sound); inline struct ALfontsound *LookupFontsound(ALCdevice *device, ALuint id) { return (struct ALfontsound*)LookupUIntMapKey(&device->FontsoundMap, id); } @@ -124,7 +124,7 @@ typedef struct ALsfpreset { } ALsfpreset; ALsfpreset *NewPreset(ALCcontext *context); -void DeletePreset(ALsfpreset *preset, ALCdevice *device); +void DeletePreset(ALCdevice *device, ALsfpreset *preset); inline struct ALsfpreset *LookupPreset(ALCdevice *device, ALuint id) { return (struct ALsfpreset*)LookupUIntMapKey(&device->PresetMap, id); } diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c index b906da14..9f12128e 100644 --- a/OpenAL32/alBuffer.c +++ b/OpenAL32/alBuffer.c @@ -104,7 +104,10 @@ AL_API ALvoid AL_APIENTRY alDeleteBuffers(ALsizei n, const ALuint *buffers) } for(i = 0;i < n;i++) - DeleteBuffer(device, buffers[i]); + { + if((ALBuf=LookupBuffer(device, buffers[i])) != NULL) + DeleteBuffer(device, ALBuf); + } done: ALCcontext_DecRef(context); @@ -1294,12 +1297,9 @@ ALbuffer *NewBuffer(ALCcontext *context) return buffer; } -void DeleteBuffer(ALCdevice *device, ALuint bufid) +void DeleteBuffer(ALCdevice *device, ALbuffer *buffer) { - ALbuffer *buffer; - - if((buffer=RemoveBuffer(device, bufid)) == NULL) - return; + RemoveBuffer(device, buffer->id); FreeThunkEntry(buffer->id); free(buffer->data); diff --git a/OpenAL32/alFontsound.c b/OpenAL32/alFontsound.c index 80a7562e..8e28355a 100644 --- a/OpenAL32/alFontsound.c +++ b/OpenAL32/alFontsound.c @@ -15,9 +15,11 @@ extern inline struct ALfontsound *LookupFontsound(ALCdevice *device, ALuint id); extern inline struct ALfontsound *RemoveFontsound(ALCdevice *device, ALuint id); +extern inline struct ALsfmodulator *LookupModulator(ALfontsound *sound, ALuint id); +extern inline struct ALsfmodulator *RemoveModulator(ALfontsound *sound, ALuint id); static void ALfontsound_Construct(ALfontsound *self); -void ALfontsound_Destruct(ALfontsound *self); +static void ALfontsound_Destruct(ALfontsound *self); void ALfontsound_setPropi(ALfontsound *self, ALCcontext *context, ALenum param, ALint value); static ALsfmodulator *ALfontsound_getModStage(ALfontsound *self, ALsizei stage); void ALfontsound_setModStagei(ALfontsound *self, ALCcontext *context, ALsizei stage, ALenum param, ALint value); @@ -76,13 +78,8 @@ AL_API ALvoid AL_APIENTRY alDeleteFontsoundsSOFT(ALsizei n, const ALuint *ids) for(i = 0;i < n;i++) { - if((inst=RemoveFontsound(device, ids[i])) == NULL) - continue; - - ALfontsound_Destruct(inst); - - memset(inst, 0, sizeof(*inst)); - free(inst); + if((inst=LookupFontsound(device, ids[i])) == NULL) + DeleteFontsound(device, inst); } done: @@ -510,6 +507,16 @@ ALfontsound *NewFontsound(ALCcontext *context) return sound; } +void DeleteFontsound(ALCdevice *device, ALfontsound *sound) +{ + RemoveFontsound(device, sound->id); + + ALfontsound_Destruct(sound); + + memset(sound, 0, sizeof(*sound)); + free(sound); +} + static void ALfontsound_Construct(ALfontsound *self) { @@ -587,7 +594,7 @@ static void ALfontsound_Construct(ALfontsound *self) self->id = 0; } -void ALfontsound_Destruct(ALfontsound *self) +static void ALfontsound_Destruct(ALfontsound *self) { ALsizei i; diff --git a/OpenAL32/alPreset.c b/OpenAL32/alPreset.c index c7167d6b..a715c946 100644 --- a/OpenAL32/alPreset.c +++ b/OpenAL32/alPreset.c @@ -71,9 +71,8 @@ AL_API ALvoid AL_APIENTRY alDeletePresetsSOFT(ALsizei n, const ALuint *ids) for(i = 0;i < n;i++) { - if((preset=LookupPreset(device, ids[i])) == NULL) - continue; - DeletePreset(preset, device); + if((preset=LookupPreset(device, ids[i])) != NULL) + DeletePreset(device, preset); } done: @@ -282,7 +281,7 @@ ALsfpreset *NewPreset(ALCcontext *context) return preset; } -void DeletePreset(ALsfpreset *preset, ALCdevice *device) +void DeletePreset(ALCdevice *device, ALsfpreset *preset) { RemovePreset(device, preset->id); diff --git a/OpenAL32/alSoundfont.c b/OpenAL32/alSoundfont.c index 2f1629df..6ba4772c 100644 --- a/OpenAL32/alSoundfont.c +++ b/OpenAL32/alSoundfont.c @@ -357,7 +357,8 @@ void ALsoundfont_deleteSoundfont(ALsoundfont *self, ALCdevice *device) sounds = ExchangePtr((XchgPtr*)&preset->Sounds, NULL); num_sounds = ExchangeInt(&preset->NumSounds, 0); - DeletePreset(preset, device); + + DeletePreset(device, preset); preset = NULL; for(j = 0;j < num_sounds;j++) @@ -377,9 +378,7 @@ void ALsoundfont_deleteSoundfont(ALsoundfont *self, ALCdevice *device) buffer = sounds[j]->Buffer; else if(sounds[j]->Buffer) assert(sounds[j]->Buffer == buffer); - RemoveFontsound(device, sounds[j]->id); - ALfontsound_Destruct(sounds[j]); - free(sounds[j]); + DeleteFontsound(device, sounds[j]); sounds[j] = NULL; } } @@ -393,7 +392,7 @@ void ALsoundfont_deleteSoundfont(ALsoundfont *self, ALCdevice *device) if(buffer) { assert(ReadRef(&buffer->ref) == 0); - DeleteBuffer(device, buffer->id); + DeleteBuffer(device, buffer); } } -- cgit v1.2.3