Add alLoadSoundfontSOFT to load a soundfont via callback
Some hefty caveats: This function is not thread-safe. In particular, the current context affecting the thread must not be changed, and the provided soundfont must not be altered while the function is executing. Ideally, this will be fixed. Error handling is poor. Some RIFF structure errors may not be caught (e.g. sub- chunks with sizes greater than the parent chunk allows for), and generated AL errors are ignored, possibly leading to resource leaks in certain situations. These should be fixed in time. There is minimal error checking on the provided soundfont ID. It does not ensure a valid ID has been provided, nor does it ensure the provided soundfont can be modified. These short-comings should be fixed eventually. Proper cleanup is the responsibility of the caller. The caller must get the preset objects from the soundfont before deleting it, and the fontsound objects from each preset before deleting them, to make sure all resources are properly deleted.
This commit is contained in:
@@ -314,6 +314,7 @@ static const ALCfunction alcFunctions[] = {
|
||||
DECL(alMidiGainSOFT),
|
||||
DECL(alGetInteger64SOFT),
|
||||
DECL(alGetInteger64vSOFT),
|
||||
DECL(alLoadSoundfontSOFT),
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
@@ -9,6 +9,18 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef size_t (*ReaderCb)(void *ptr, size_t size, void *stream);
|
||||
typedef struct Reader {
|
||||
ReaderCb cb;
|
||||
void *ptr;
|
||||
int error;
|
||||
} Reader;
|
||||
#define READ(x_, buf_, len_) ((x_)->cb((buf_), (len_), (x_)->ptr))
|
||||
#define READERR(x_) ((x_)->error)
|
||||
|
||||
ALboolean loadSf2(Reader *stream, ALuint sfid);
|
||||
|
||||
|
||||
struct MidiSynthVtable;
|
||||
|
||||
typedef struct MidiSynth {
|
||||
|
||||
+1283
File diff suppressed because it is too large
Load Diff
@@ -562,6 +562,7 @@ ENDIF()
|
||||
|
||||
SET(ALC_OBJS ${ALC_OBJS}
|
||||
Alc/midi/base.c
|
||||
Alc/midi/sf2load.c
|
||||
Alc/midi/dummy.c
|
||||
Alc/midi/fluidsynth.c
|
||||
)
|
||||
|
||||
@@ -91,6 +91,7 @@ typedef void (AL_APIENTRY*LPALMIDIRESETSOFT)(void);
|
||||
typedef void (AL_APIENTRY*LPALMIDIGAINSOFT)(ALfloat value);
|
||||
typedef ALint64SOFT (AL_APIENTRY*LPALGETINTEGER64SOFT)(ALenum pname);
|
||||
typedef void (AL_APIENTRY*LPALGETINTEGER64VSOFT)(ALenum pname, ALint64SOFT *values);
|
||||
typedef void (AL_APIENTRY*LPALLOADSOUNDFONTSOFT)(ALuint id, size_t(*cb)(ALvoid*,size_t,ALvoid*), ALvoid *user);
|
||||
#ifdef AL_ALEXT_PROTOTYPES
|
||||
AL_API void AL_APIENTRY alGenSoundfontsSOFT(ALsizei n, ALuint *ids);
|
||||
AL_API void AL_APIENTRY alDeleteSoundfontsSOFT(ALsizei n, const ALuint *ids);
|
||||
@@ -128,6 +129,7 @@ AL_API void AL_APIENTRY alMidiResetSOFT(void);
|
||||
AL_API void AL_APIENTRY alMidiGainSOFT(ALfloat value);
|
||||
AL_API ALint64SOFT AL_APIENTRY alGetInteger64SOFT(ALenum pname);
|
||||
AL_API void AL_APIENTRY alGetInteger64vSOFT(ALenum pname, ALint64SOFT *values);
|
||||
AL_API void AL_APIENTRY alLoadSoundfontSOFT(ALuint id, size_t(*cb)(ALvoid*,size_t,ALvoid*), ALvoid *user);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -83,6 +83,16 @@ done:
|
||||
ALCcontext_DecRef(context);
|
||||
}
|
||||
|
||||
AL_API void AL_APIENTRY alLoadSoundfontSOFT(ALuint id, size_t(*cb)(ALvoid*,size_t,ALvoid*), ALvoid *user)
|
||||
{
|
||||
Reader reader;
|
||||
reader.cb = cb;
|
||||
reader.ptr = user;
|
||||
reader.error = 0;
|
||||
loadSf2(&reader, id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
AL_API void AL_APIENTRY alMidiEventSOFT(ALuint64SOFT time, ALenum event, ALsizei channel, ALsizei param1, ALsizei param2)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user