diff options
author | Chris Robinson <[email protected]> | 2014-06-29 00:47:29 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-06-29 00:47:29 -0700 |
commit | 389a2f7b4bcffa5cfbe17e8057c8541b0e442bf8 (patch) | |
tree | 238deea1698705473073b3aafd0494c08c9dd1f2 /OpenAL32/alFontsound.c | |
parent | d19e42a723231d63da777d51a3b036683b42e702 (diff) |
Store and use an ALbuffer for samples in an ALfontsound
The fontsound still maintains its own start, end, and loop offsets, so that the
same buffer may be shared between multiple/all fontsounds. Ideally a single
buffer should be used for all fontsounds to avoid memory fragmentation and help
CPU caching, although higher quality soundfonts may need more memory than a
single buffer can hold.
Diffstat (limited to 'OpenAL32/alFontsound.c')
-rw-r--r-- | OpenAL32/alFontsound.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/OpenAL32/alFontsound.c b/OpenAL32/alFontsound.c index c4d49e92..80a7562e 100644 --- a/OpenAL32/alFontsound.c +++ b/OpenAL32/alFontsound.c @@ -8,6 +8,7 @@ #include "alMidi.h" #include "alError.h" #include "alThunk.h" +#include "alBuffer.h" #include "midi/base.h" @@ -257,6 +258,10 @@ AL_API void AL_APIENTRY alGetFontsoundivSOFT(ALuint id, ALenum param, ALint *val SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); switch(param) { + case AL_BUFFER: + values[0] = (sound->Buffer ? sound->Buffer->id : 0); + break; + case AL_MOD_LFO_TO_PITCH_SOFT: values[0] = sound->ModLfoToPitch; break; @@ -510,6 +515,8 @@ static void ALfontsound_Construct(ALfontsound *self) { InitRef(&self->ref, 0); + self->Buffer = NULL; + self->MinKey = 0; self->MaxKey = 127; self->MinVelocity = 0; @@ -587,6 +594,9 @@ void ALfontsound_Destruct(ALfontsound *self) FreeThunkEntry(self->id); self->id = 0; + if(self->Buffer) + DecrementRef(&self->Buffer->ref); + self->Buffer = NULL; if(self->Link) DecrementRef(&self->Link->ref); self->Link = NULL; @@ -602,9 +612,26 @@ void ALfontsound_Destruct(ALfontsound *self) void ALfontsound_setPropi(ALfontsound *self, ALCcontext *context, ALenum param, ALint value) { ALfontsound *link; + ALbuffer *buffer; switch(param) { + case AL_BUFFER: + buffer = value ? LookupBuffer(context->Device, value) : NULL; + if(value && !buffer) + SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE); + else if(buffer) + { + /* Buffer must have a non-0 length, and must be mono. */ + if(buffer->SampleLen <= 0 || buffer->FmtChannels != FmtMono) + SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE); + } + + if(buffer) IncrementRef(&buffer->ref); + if((buffer=ExchangePtr((XchgPtr*)&self->Buffer, buffer)) != NULL) + DecrementRef(&buffer->ref); + break; + case AL_MOD_LFO_TO_PITCH_SOFT: self->ModLfoToPitch = value; break; |