aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2013-12-25 19:13:59 -0800
committerChris Robinson <[email protected]>2013-12-25 19:13:59 -0800
commit94ddc5cb1889a42c9ffe98b79e431b596a9563df (patch)
treeb513f8c94347fb697775e286c735ee79dcc201dd /OpenAL32
parentcb3f82a4bf50aef28353629f2f7d6f45b5d420dc (diff)
Add a new fontsound object type
This is basically a combined preset and intrument zone with sample header.
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/Include/alMain.h11
-rw-r--r--OpenAL32/Include/alMidi.h39
-rw-r--r--OpenAL32/alFontsound.c134
3 files changed, 184 insertions, 0 deletions
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 <stdlib.h>
+#include <string.h>
+
+#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);
+ }
+}