Handle fontsound sample types using explicit enum values

Uses AL_MONO_SOFT, AL_RIGHT_SOFT, and AL_LEFT_SOFT. "Linked" samples types
aren't explicitly supported due to being under-defined in the SF2 spec, nor are
ROM samples currently.
This commit is contained in:
Chris Robinson
2014-01-15 22:18:07 -08:00
parent 9ebeae6228
commit e118ac93a0
4 changed files with 45 additions and 15 deletions
+12 -1
View File
@@ -124,6 +124,17 @@ static int getSf2LoopMode(ALenum mode)
return 0;
}
static int getSampleType(ALenum type)
{
switch(type)
{
case AL_MONO_SOFT: return FLUID_SAMPLETYPE_MONO;
case AL_RIGHT_SOFT: return FLUID_SAMPLETYPE_RIGHT;
case AL_LEFT_SOFT: return FLUID_SAMPLETYPE_LEFT;
}
return FLUID_SAMPLETYPE_MONO;
}
typedef struct FSample {
DERIVE_FROM_TYPE(fluid_sample_t);
@@ -144,7 +155,7 @@ static void FSample_Construct(FSample *self, ALfontsound *sound, ALsoundfont *sf
sample->samplerate = sound->SampleRate;
sample->origpitch = sound->PitchKey;
sample->pitchadj = sound->PitchCorrection;
sample->sampletype = sound->SampleType;
sample->sampletype = getSampleType(sound->SampleType);
sample->valid = 1;
sample->data = sfont->Samples;
+29 -12
View File
@@ -772,6 +772,20 @@ static ALenum getLoopMode(int mode)
return AL_NONE;
}
static ALenum getSampleType(int type)
{
if(type == 1) return AL_MONO_SOFT;
if(type == 2) return AL_RIGHT_SOFT;
if(type == 4) return AL_LEFT_SOFT;
if(type == 8)
{
WARN("Sample type \"linked\" ignored; pretending mono\n");
return AL_MONO_SOFT;
}
ERR("Unhandled sample type: 0x%04x\n", type);
return AL_MONO_SOFT;
}
static void fillZone(ALfontsound *sound, ALCcontext *context, const GenModList *zone)
{
static const ALenum Gen2Param[60] = {
@@ -998,6 +1012,7 @@ static void processInstrument(ALfontsound ***sounds, ALsizei *sounds_size, ALCco
if(gen->mGenerator == 53)
{
const SampleHeader *samp;
ALfontsound *sound;
if(gen->mAmount >= sfont->shdr_size-1)
{
@@ -1019,19 +1034,21 @@ static void processInstrument(ALfontsound ***sounds, ALsizei *sounds_size, ALCco
if(!checkZone(&lzone, preset, inst, samp))
break;
/* Ignore ROM samples for now. */
if((samp->mSampleType&0x8000))
break;
(*sounds)[*sounds_size] = NewFontsound(context);
ALfontsound_setPropi((*sounds)[*sounds_size], context, AL_SAMPLE_START_SOFT, samp->mStart);
ALfontsound_setPropi((*sounds)[*sounds_size], context, AL_SAMPLE_END_SOFT, samp->mEnd);
ALfontsound_setPropi((*sounds)[*sounds_size], context, AL_SAMPLE_LOOP_START_SOFT, samp->mStartloop);
ALfontsound_setPropi((*sounds)[*sounds_size], context, AL_SAMPLE_LOOP_END_SOFT, samp->mEndloop);
ALfontsound_setPropi((*sounds)[*sounds_size], context, AL_SAMPLE_RATE_SOFT, samp->mSampleRate);
ALfontsound_setPropi((*sounds)[*sounds_size], context, AL_BASE_KEY_SOFT, samp->mOriginalKey);
ALfontsound_setPropi((*sounds)[*sounds_size], context, AL_KEY_CORRECTION_SOFT, samp->mCorrection);
if(samp->mSampleType == 1 || samp->mSampleType == 2 || samp->mSampleType == 4)
ALfontsound_setPropi((*sounds)[*sounds_size], context, AL_SAMPLE_TYPE_SOFT, samp->mSampleType);
fillZone((*sounds)[*sounds_size], context, &lzone);
(*sounds_size)++;
sound = NewFontsound(context);
(*sounds)[(*sounds_size)++] = sound;
ALfontsound_setPropi(sound, context, AL_SAMPLE_START_SOFT, samp->mStart);
ALfontsound_setPropi(sound, context, AL_SAMPLE_END_SOFT, samp->mEnd);
ALfontsound_setPropi(sound, context, AL_SAMPLE_LOOP_START_SOFT, samp->mStartloop);
ALfontsound_setPropi(sound, context, AL_SAMPLE_LOOP_END_SOFT, samp->mEndloop);
ALfontsound_setPropi(sound, context, AL_SAMPLE_RATE_SOFT, samp->mSampleRate);
ALfontsound_setPropi(sound, context, AL_BASE_KEY_SOFT, samp->mOriginalKey);
ALfontsound_setPropi(sound, context, AL_KEY_CORRECTION_SOFT, samp->mCorrection);
ALfontsound_setPropi(sound, context, AL_SAMPLE_TYPE_SOFT, getSampleType(samp->mSampleType&0x7fff));
fillZone(sound, context, &lzone);
break;
}
+2
View File
@@ -127,6 +127,8 @@
#define AL_EXCLUSIVE_CLASS_SOFT 0x0039
#define AL_LOOP_CONTINUOUS_SOFT 0x0001
#define AL_LOOP_UNTIL_RELEASE_SOFT 0x0003
#define AL_RIGHT_SOFT 0x0002
#define AL_LEFT_SOFT 0x0004
#define AL_FORMAT_TYPE_SOFT 0x1991
#define AL_NOTEOFF_SOFT 0x0080
#define AL_NOTEON_SOFT 0x0090
+2 -2
View File
@@ -572,7 +572,7 @@ static void ALfontsound_Construct(ALfontsound *self)
self->SampleRate = 0;
self->PitchKey = 0;
self->PitchCorrection = 0;
self->SampleType = AL_NONE;
self->SampleType = AL_MONO_SOFT;
self->Link = NULL;
InitUIntMap(&self->ModulatorMap, ~0);
@@ -781,7 +781,7 @@ void ALfontsound_setPropi(ALfontsound *self, ALCcontext *context, ALenum param,
break;
case AL_SAMPLE_TYPE_SOFT:
if(!(value >= 1 && value <= 4))
if(!(value == AL_MONO_SOFT || value == AL_RIGHT_SOFT || value == AL_LEFT_SOFT))
SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
self->SampleType = value;
break;