From 94ddc5cb1889a42c9ffe98b79e431b596a9563df Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 25 Dec 2013 19:13:59 -0800 Subject: Add a new fontsound object type This is basically a combined preset and intrument zone with sample header. --- OpenAL32/Include/alMain.h | 11 ++++ OpenAL32/Include/alMidi.h | 39 ++++++++++++++ OpenAL32/alFontsound.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 184 insertions(+) create mode 100644 OpenAL32/alFontsound.c (limited to 'OpenAL32') diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 5e3cdc4f..aafe6c90 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -60,6 +60,9 @@ typedef void (AL_APIENTRY*LPALGETPRESETIVSOFT)(ALuint id, ALenum param, ALint *v typedef void (AL_APIENTRY*LPALGENINSTRUMENTSSOFT)(ALsizei n, ALuint *ids); typedef void (AL_APIENTRY*LPALDELETEINSTRUMENTSSOFT)(ALsizei n, const ALuint *ids); typedef ALboolean (AL_APIENTRY*LPALISINSTRUMENTSOFT)(ALuint id); +typedef void (AL_APIENTRY*LPALGENFONTSOUNDSSOFT)(ALsizei n, ALuint *ids); +typedef void (AL_APIENTRY*LPALDELETEFONTSOUNDSSOFT)(ALsizei n, const ALuint *ids); +typedef ALboolean (AL_APIENTRY*LPALISFONTSOUNDSOFT)(ALuint id); typedef void (AL_APIENTRY*LPALMIDISOUNDFONTSOFT)(const char *filename); typedef void (AL_APIENTRY*LPALMIDIEVENTSOFT)(ALuint64SOFT time, ALenum event, ALsizei channel, ALsizei param1, ALsizei param2); typedef void (AL_APIENTRY*LPALMIDISYSEXSOFT)(ALuint64SOFT time, const ALbyte *data, ALsizei size); @@ -90,6 +93,11 @@ AL_API void AL_APIENTRY alGetPresetivSOFT(ALuint id, ALenum param, ALint *values AL_API void AL_APIENTRY alGenInstrumentsSOFT(ALsizei n, ALuint *ids); AL_API void AL_APIENTRY alDeleteInstrumentsSOFT(ALsizei n, const ALuint *ids); AL_API ALboolean AL_APIENTRY alIsInstrumentSOFT(ALuint id); + +AL_API void AL_APIENTRY alGenFontsoundsSOFT(ALsizei n, ALuint *ids); +AL_API void AL_APIENTRY alDeleteFontsoundsSOFT(ALsizei n, const ALuint *ids); +AL_API ALboolean AL_APIENTRY alIsFontsoundSOFT(ALuint id); + AL_API void AL_APIENTRY alMidiSoundfontSOFT(const char *filename); AL_API void AL_APIENTRY alMidiEventSOFT(ALuint64SOFT time, ALenum event, ALsizei channel, ALsizei param1, ALsizei param2); AL_API void AL_APIENTRY alMidiSysExSOFT(ALuint64SOFT time, const ALbyte *data, ALsizei size); @@ -472,6 +480,9 @@ struct ALCdevice_struct // Map of Instruments for this device UIntMap InstrumentMap; + // Map of Fontsounds for this device + UIntMap FontsoundMap; + /* MIDI synth engine */ struct MidiSynth *Synth; diff --git a/OpenAL32/Include/alMidi.h b/OpenAL32/Include/alMidi.h index b37a6546..374940c1 100644 --- a/OpenAL32/Include/alMidi.h +++ b/OpenAL32/Include/alMidi.h @@ -84,6 +84,45 @@ inline struct ALsfinstrument *RemoveInstrument(ALCdevice *device, ALuint id) void ReleaseALInstruments(ALCdevice *device); +typedef struct ALfontsound { + volatile RefCount ref; + + ALint MinKey, MaxKey; + ALint MinVelocity, MaxVelocity; + + ALsfgenerator *Generators; + ALsizei NumGenerators; + ALsizei GeneratorsMax; + + ALsfmodulator *Modulators; + ALsizei NumModulators; + ALsizei ModulatorsMax; + + ALuint Start; + ALuint End; + ALuint LoopStart; + ALuint LoopEnd; + ALuint SampleRate; + ALubyte PitchKey; + ALbyte PitchCorrection; + ALint SampleLink; + ALenum SampleType; + + ALuint id; +} ALfontsound; + +void ALfontsound_Construct(ALfontsound *self); +void ALfontsound_Destruct(ALfontsound *self); + + +inline struct ALfontsound *LookupFontsound(ALCdevice *device, ALuint id) +{ return (struct ALfontsound*)LookupUIntMapKey(&device->FontsoundMap, id); } +inline struct ALfontsound *RemoveFontsound(ALCdevice *device, ALuint id) +{ return (struct ALfontsound*)RemoveUIntMapKey(&device->FontsoundMap, id); } + +void ReleaseALFontsounds(ALCdevice *device); + + typedef struct ALsfpreset { volatile RefCount ref; diff --git a/OpenAL32/alFontsound.c b/OpenAL32/alFontsound.c new file mode 100644 index 00000000..bfb2e6da --- /dev/null +++ b/OpenAL32/alFontsound.c @@ -0,0 +1,134 @@ + +#include "config.h" + +#include +#include + +#include "alMain.h" +#include "alMidi.h" +#include "alError.h" +#include "alThunk.h" + +#include "midi/base.h" + + +extern inline struct ALfontsound *LookupFontsound(ALCdevice *device, ALuint id); +extern inline struct ALfontsound *RemoveFontsound(ALCdevice *device, ALuint id); + + +AL_API void AL_APIENTRY alGenFontsoundsSOFT(ALsizei n, ALuint *ids) +{ + 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++) + { + ALfontsound *inst = calloc(1, sizeof(ALfontsound)); + if(!inst) + { + alDeleteFontsoundsSOFT(cur, ids); + SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done); + } + ALfontsound_Construct(inst); + + err = NewThunkEntry(&inst->id); + if(err == AL_NO_ERROR) + err = InsertUIntMapEntry(&device->FontsoundMap, inst->id, inst); + if(err != AL_NO_ERROR) + { + ALfontsound_Destruct(inst); + memset(inst, 0, sizeof(*inst)); + free(inst); + + alDeleteFontsoundsSOFT(cur, ids); + SET_ERROR_AND_GOTO(context, err, done); + } + + ids[cur] = inst->id; + } + +done: + ALCcontext_DecRef(context); +} + +AL_API ALvoid AL_APIENTRY alDeleteFontsoundsSOFT(ALsizei n, const ALuint *ids) +{ + ALCdevice *device; + ALCcontext *context; + ALfontsound *inst; + ALsizei i; + + context = GetContextRef(); + if(!context) return; + + if(!(n >= 0)) + SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); + + device = context->Device; + for(i = 0;i < n;i++) + { + /* Check for valid ID */ + if((inst=LookupFontsound(device, ids[i])) == NULL) + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); + if(inst->ref != 0) + SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done); + } + + for(i = 0;i < n;i++) + { + if((inst=RemoveFontsound(device, ids[i])) == NULL) + continue; + + ALfontsound_Destruct(inst); + + memset(inst, 0, sizeof(*inst)); + free(inst); + } + +done: + ALCcontext_DecRef(context); +} + +AL_API ALboolean AL_APIENTRY alIsFontsoundSOFT(ALuint id) +{ + ALCcontext *context; + ALboolean ret; + + context = GetContextRef(); + if(!context) return AL_FALSE; + + ret = LookupFontsound(context->Device, id) ? AL_TRUE : AL_FALSE; + + ALCcontext_DecRef(context); + + return ret; +} + + +/* ReleaseALFontsounds + * + * Called to destroy any fontsounds that still exist on the device + */ +void ReleaseALFontsounds(ALCdevice *device) +{ + ALsizei i; + for(i = 0;i < device->FontsoundMap.size;i++) + { + ALfontsound *temp = device->FontsoundMap.array[i].value; + device->FontsoundMap.array[i].value = NULL; + + ALfontsound_Destruct(temp); + + memset(temp, 0, sizeof(*temp)); + free(temp); + } +} -- cgit v1.2.3