diff options
-rw-r--r-- | Alc/ALc.c | 2 | ||||
-rw-r--r-- | Alc/midi/base.c | 94 | ||||
-rw-r--r-- | Alc/midi/base.h | 2 | ||||
-rw-r--r-- | OpenAL32/Include/alMidi.h | 2 | ||||
-rw-r--r-- | OpenAL32/alSoundfont.c | 100 |
5 files changed, 102 insertions, 98 deletions
@@ -1950,7 +1950,7 @@ static ALCvoid FreeDevice(ALCdevice *device) } if(device->DefaultSfont) - MidiSynth_deleteSoundfont(device, device->DefaultSfont); + ALsoundfont_deleteSoundfont(device->DefaultSfont, device); device->DefaultSfont = NULL; if(device->BufferMap.size > 0) diff --git a/Alc/midi/base.c b/Alc/midi/base.c index cf677841..0a88c909 100644 --- a/Alc/midi/base.c +++ b/Alc/midi/base.c @@ -1,7 +1,6 @@ #include "config.h" -#include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> @@ -24,9 +23,6 @@ #define SYSEX_EVENT (0xF0) -static size_t read_file(ALvoid *buf, size_t bytes, ALvoid *ptr); - - void InitEvtQueue(EvtQueue *queue) { queue->events = NULL; @@ -154,88 +150,6 @@ void MidiSynth_Destruct(MidiSynth *self) ResetEvtQueue(&self->EventQueue); } -ALsoundfont *MidiSynth_getDefSoundfont(ALCcontext *context) -{ - ALCdevice *device = context->Device; - const char *fname; - - if(device->DefaultSfont) - return device->DefaultSfont; - - device->DefaultSfont = calloc(1, sizeof(device->DefaultSfont[0])); - ALsoundfont_Construct(device->DefaultSfont); - - fname = getenv("ALSOFT_SOUNDFONT"); - if((fname && fname[0]) || ConfigValueStr("midi", "soundfont", &fname)) - { - FILE *f; - - f = fopen(fname, "rb"); - if(f == NULL) - ERR("Failed to open %s\n", fname); - else - { - Reader reader; - reader.cb = read_file; - reader.ptr = f; - reader.error = 0; - TRACE("Loading %s\n", fname); - loadSf2(&reader, device->DefaultSfont, context); - fclose(f); - } - } - - return device->DefaultSfont; -} - -void MidiSynth_deleteSoundfont(ALCdevice *device, ALsoundfont *sfont) -{ - ALsfpreset **presets; - ALsizei num_presets; - ALsizei i; - - presets = ExchangePtr((XchgPtr*)&sfont->Presets, NULL); - num_presets = ExchangeInt(&sfont->NumPresets, 0); - - for(i = 0;i < num_presets;i++) - { - ALsfpreset *preset = presets[i]; - ALfontsound **sounds; - ALsizei num_sounds; - ALboolean deleting; - ALsizei j; - - sounds = ExchangePtr((XchgPtr*)&preset->Sounds, NULL); - num_sounds = ExchangeInt(&preset->NumSounds, 0); - DeletePreset(preset, device); - preset = NULL; - - for(j = 0;j < num_sounds;j++) - DecrementRef(&sounds[j]->ref); - /* Some fontsounds may not be immediately deletable because they're - * linked to another fontsound. When those fontsounds are deleted - * they should become deletable, so use a loop until all fontsounds - * are deleted. */ - do { - deleting = AL_FALSE; - for(j = 0;j < num_sounds;j++) - { - if(sounds[j] && sounds[j]->ref == 0) - { - deleting = AL_TRUE; - RemoveFontsound(device, sounds[j]->id); - ALfontsound_Destruct(sounds[j]); - free(sounds[j]); - sounds[j] = NULL; - } - } - } while(deleting); - free(sounds); - } - - ALsoundfont_Destruct(sfont); - free(sfont); -} ALenum MidiSynth_selectSoundfonts(MidiSynth *self, ALCcontext *context, ALsizei count, const ALuint *ids) { @@ -252,7 +166,7 @@ ALenum MidiSynth_selectSoundfonts(MidiSynth *self, ALCcontext *context, ALsizei for(i = 0;i < count;i++) { if(ids[i] == 0) - sfonts[i] = MidiSynth_getDefSoundfont(context); + sfonts[i] = ALsoundfont_getDefSoundfont(context); else if(!(sfonts[i]=LookupSfont(device, ids[i]))) { free(sfonts); @@ -361,9 +275,3 @@ ALenum MidiSynth_insertSysExEvent(MidiSynth *self, ALuint64 time, const ALbyte * return AL_NO_ERROR; } - - -static size_t read_file(ALvoid *buf, size_t bytes, ALvoid *ptr) -{ - return fread(buf, 1, bytes, (FILE*)ptr); -} diff --git a/Alc/midi/base.h b/Alc/midi/base.h index 25bd35dd..ec2627cc 100644 --- a/Alc/midi/base.h +++ b/Alc/midi/base.h @@ -52,8 +52,6 @@ typedef struct MidiSynth { void MidiSynth_Construct(MidiSynth *self, ALCdevice *device); void MidiSynth_Destruct(MidiSynth *self); -struct ALsoundfont *MidiSynth_getDefSoundfont(ALCcontext *context); -void MidiSynth_deleteSoundfont(ALCdevice *device, struct ALsoundfont *sfont); ALenum MidiSynth_selectSoundfonts(MidiSynth *self, ALCcontext *context, ALsizei count, const ALuint *ids); inline void MidiSynth_setGain(MidiSynth *self, ALfloat gain) { self->Gain = gain; } inline ALfloat MidiSynth_getGain(const MidiSynth *self) { return self->Gain; } diff --git a/OpenAL32/Include/alMidi.h b/OpenAL32/Include/alMidi.h index 998f6e92..25bed250 100644 --- a/OpenAL32/Include/alMidi.h +++ b/OpenAL32/Include/alMidi.h @@ -152,6 +152,8 @@ typedef struct ALsoundfont { void ALsoundfont_Construct(ALsoundfont *self); void ALsoundfont_Destruct(ALsoundfont *self); +ALsoundfont *ALsoundfont_getDefSoundfont(ALCcontext *context); +void ALsoundfont_deleteSoundfont(ALsoundfont *self, ALCdevice *device); inline struct ALsoundfont *LookupSfont(ALCdevice *device, ALuint id) { return (struct ALsoundfont*)LookupUIntMapKey(&device->SfontMap, id); } diff --git a/OpenAL32/alSoundfont.c b/OpenAL32/alSoundfont.c index 04b5e525..17812610 100644 --- a/OpenAL32/alSoundfont.c +++ b/OpenAL32/alSoundfont.c @@ -1,6 +1,7 @@ #include "config.h" +#include <stdio.h> #include <stdlib.h> #include <string.h> @@ -15,6 +16,12 @@ extern inline struct ALsoundfont *LookupSfont(ALCdevice *device, ALuint id); extern inline struct ALsoundfont *RemoveSfont(ALCdevice *device, ALuint id); +void ALsoundfont_Construct(ALsoundfont *self); +void ALsoundfont_Destruct(ALsoundfont *self); +void ALsoundfont_deleteSoundfont(ALsoundfont *self, ALCdevice *device); +ALsoundfont *ALsoundfont_getDefSoundfont(ALCcontext *context); +static size_t ALsoundfont_read(ALvoid *buf, size_t bytes, ALvoid *ptr); + AL_API void AL_APIENTRY alGenSoundfontsSOFT(ALsizei n, ALuint *ids) { @@ -95,7 +102,7 @@ AL_API ALvoid AL_APIENTRY alDeleteSoundfontsSOFT(ALsizei n, const ALuint *ids) MidiSynth *synth = device->Synth; WriteLock(&synth->Lock); if(device->DefaultSfont != NULL) - MidiSynth_deleteSoundfont(device, device->DefaultSfont); + ALsoundfont_deleteSoundfont(device->DefaultSfont, device); device->DefaultSfont = NULL; WriteUnlock(&synth->Lock); continue; @@ -237,7 +244,7 @@ AL_API void AL_APIENTRY alGetSoundfontivSOFT(ALuint id, ALenum param, ALint *val device = context->Device; if(id == 0) - sfont = MidiSynth_getDefSoundfont(context); + sfont = ALsoundfont_getDefSoundfont(context); else if(!(sfont=LookupSfont(device, id))) SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); switch(param) @@ -411,6 +418,95 @@ void ALsoundfont_Destruct(ALsoundfont *self) self->NumSamples = 0; } +ALsoundfont *ALsoundfont_getDefSoundfont(ALCcontext *context) +{ + ALCdevice *device = context->Device; + const char *fname; + + if(device->DefaultSfont) + return device->DefaultSfont; + + device->DefaultSfont = calloc(1, sizeof(device->DefaultSfont[0])); + ALsoundfont_Construct(device->DefaultSfont); + + fname = getenv("ALSOFT_SOUNDFONT"); + if((fname && fname[0]) || ConfigValueStr("midi", "soundfont", &fname)) + { + FILE *f; + + f = fopen(fname, "rb"); + if(f == NULL) + ERR("Failed to open %s\n", fname); + else + { + Reader reader; + reader.cb = ALsoundfont_read; + reader.ptr = f; + reader.error = 0; + TRACE("Loading %s\n", fname); + loadSf2(&reader, device->DefaultSfont, context); + fclose(f); + } + } + + return device->DefaultSfont; +} + +void ALsoundfont_deleteSoundfont(ALsoundfont *self, ALCdevice *device) +{ + ALsfpreset **presets; + ALsizei num_presets; + ALsizei i; + + presets = ExchangePtr((XchgPtr*)&self->Presets, NULL); + num_presets = ExchangeInt(&self->NumPresets, 0); + + for(i = 0;i < num_presets;i++) + { + ALsfpreset *preset = presets[i]; + ALfontsound **sounds; + ALsizei num_sounds; + ALboolean deleting; + ALsizei j; + + sounds = ExchangePtr((XchgPtr*)&preset->Sounds, NULL); + num_sounds = ExchangeInt(&preset->NumSounds, 0); + DeletePreset(preset, device); + preset = NULL; + + for(j = 0;j < num_sounds;j++) + DecrementRef(&sounds[j]->ref); + /* Some fontsounds may not be immediately deletable because they're + * linked to another fontsound. When those fontsounds are deleted + * they should become deletable, so use a loop until all fontsounds + * are deleted. */ + do { + deleting = AL_FALSE; + for(j = 0;j < num_sounds;j++) + { + if(sounds[j] && sounds[j]->ref == 0) + { + deleting = AL_TRUE; + RemoveFontsound(device, sounds[j]->id); + ALfontsound_Destruct(sounds[j]); + free(sounds[j]); + sounds[j] = NULL; + } + } + } while(deleting); + free(sounds); + } + + ALsoundfont_Destruct(self); + free(self); +} + + +static size_t ALsoundfont_read(ALvoid *buf, size_t bytes, ALvoid *ptr) +{ + return fread(buf, 1, bytes, (FILE*)ptr); +} + /* ReleaseALSoundfonts * |