Add functions to set a soundfont's sample data

This commit is contained in:
Chris Robinson 2013-12-19 04:19:03 -08:00
parent 03a6bf22a5
commit 1bd828603e
5 changed files with 94 additions and 1 deletions

View File

@ -284,6 +284,9 @@ static const ALCfunction alcFunctions[] = {
DECL(alGenSoundfontsSOFT),
DECL(alDeleteSoundfontsSOFT),
DECL(alIsSoundfontSOFT),
DECL(alSoundfontSamplesSOFT),
DECL(alSoundfontMapSamplesSOFT),
DECL(alSoundfontUnmapSamplesSOFT),
DECL(alGenPresetsSOFT),
DECL(alDeletePresetsSOFT),
DECL(alIsPresetSOFT),

View File

@ -429,6 +429,8 @@ void ALsoundfont_Construct(ALsoundfont *self)
self->Samples = NULL;
self->NumSamples = 0;
self->Mapped = AL_FALSE;
self->id = 0;
}

View File

@ -41,6 +41,9 @@
typedef void (AL_APIENTRY*LPALGENSOUNDFONTSSOFT)(ALsizei n, ALuint *ids);
typedef void (AL_APIENTRY*LPALDELETESOUNDFONTSSOFT)(ALsizei n, const ALuint *ids);
typedef ALboolean (AL_APIENTRY*LPALISSOUNDFONTSOFT)(ALuint id);
typedef void (AL_APIENTRY*LPALSOUNDFONTSAMPLESSOFT)(ALuint sfid, ALenum type, ALsizei count, const ALvoid *samples);
typedef ALvoid* (AL_APIENTRY*LPALSOUNDFONTMAPSAMPLESSOFT)(ALuint sfid, ALsizei offset, ALsizei length);
typedef void (AL_APIENTRY*LPALSOUNDFONTUNMAPSAMPLESSOFT)(ALuint sfid);
typedef void (AL_APIENTRY*LPALGENPRESETSSOFT)(ALsizei n, ALuint *ids);
typedef void (AL_APIENTRY*LPALDELETEPRESETSSOFT)(ALsizei n, const ALuint *ids);
typedef ALboolean (AL_APIENTRY*LPALISPRESETSOFT)(ALuint id);
@ -61,6 +64,10 @@ typedef void (AL_APIENTRY*LPALGETINTEGER64VSOFT)(ALenum pname, ALint64SOFT *valu
AL_API void AL_APIENTRY alGenSoundfontsSOFT(ALsizei n, ALuint *ids);
AL_API void AL_APIENTRY alDeleteSoundfontsSOFT(ALsizei n, const ALuint *ids);
AL_API ALboolean AL_APIENTRY alIsSoundfontSOFT(ALuint id);
AL_API ALvoid AL_APIENTRY alSoundfontSamplesSOFT(ALuint sfid, ALenum type, ALsizei count, const ALvoid *samples);
AL_API ALvoid* AL_APIENTRY alSoundfontMapSamplesSOFT(ALuint sfid, ALsizei offset, ALsizei length);
AL_API ALvoid AL_APIENTRY alSoundfontUnmapSamplesSOFT(ALuint sfid);
AL_API void AL_APIENTRY alGenPresetsSOFT(ALsizei n, ALuint *ids);
AL_API void AL_APIENTRY alDeletePresetsSOFT(ALsizei n, const ALuint *ids);
AL_API ALboolean AL_APIENTRY alIsPresetSOFT(ALuint id);

View File

@ -117,6 +117,8 @@ typedef struct ALsoundfont {
ALshort *Samples;
ALint NumSamples;
volatile ALenum Mapped;
ALuint id;
} ALsoundfont;

View File

@ -83,7 +83,7 @@ AL_API ALvoid AL_APIENTRY alDeleteSoundfontsSOFT(ALsizei n, const ALuint *ids)
/* Check for valid soundfont ID */
if((sfont=LookupSfont(device, ids[i])) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
if(sfont->ref != 0)
if(sfont->Mapped != AL_FALSE || sfont->ref != 0)
SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done);
}
@ -119,6 +119,85 @@ AL_API ALboolean AL_APIENTRY alIsSoundfontSOFT(ALuint id)
return ret;
}
AL_API ALvoid AL_APIENTRY alSoundfontSamplesSOFT(ALuint sfid, ALenum type, ALsizei count, const ALvoid *samples)
{
ALCdevice *device;
ALCcontext *context;
ALsoundfont *sfont;
context = GetContextRef();
if(!context) return;
device = context->Device;
if(!(sfont=LookupSfont(device, sfid)))
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
if(type != AL_SHORT_SOFT)
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
if(count <= 0)
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
// TODO: Lock and check ref count
{
void *temp = realloc(sfont->Samples, count * sizeof(ALshort));
if(!temp)
SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done);
sfont->Samples = temp;
sfont->NumSamples = count;
if(samples)
memcpy(sfont->Samples, samples, count * sizeof(ALshort));
}
done:
ALCcontext_DecRef(context);
}
AL_API ALvoid* AL_APIENTRY alSoundfontMapSamplesSOFT(ALuint sfid, ALsizei offset, ALsizei length)
{
ALCdevice *device;
ALCcontext *context;
ALsoundfont *sfont;
ALvoid *ptr = NULL;
context = GetContextRef();
if(!context) return NULL;
device = context->Device;
if(!(sfont=LookupSfont(device, sfid)))
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
if(offset < 0 || (ALuint)offset > sfont->NumSamples*sizeof(ALshort))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
if(length <= 0 || (ALuint)length > (sfont->NumSamples*sizeof(ALshort) - offset))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
if(ExchangeInt(&sfont->Mapped, AL_TRUE) == AL_TRUE)
SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done);
ptr = (ALbyte*)sfont->Samples + offset;
done:
ALCcontext_DecRef(context);
return ptr;
}
AL_API ALvoid AL_APIENTRY alSoundfontUnmapSamplesSOFT(ALuint sfid)
{
ALCdevice *device;
ALCcontext *context;
ALsoundfont *sfont;
context = GetContextRef();
if(!context) return;
device = context->Device;
if(!(sfont=LookupSfont(device, sfid)))
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
if(ExchangeInt(&sfont->Mapped, AL_FALSE) == AL_FALSE)
SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done);
done:
ALCcontext_DecRef(context);
}
/* ReleaseALSoundfonts
*