aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-01-15 22:18:07 -0800
committerChris Robinson <[email protected]>2014-01-15 22:18:07 -0800
commite118ac93a01c15adee8e6d81a99dda73a985c54d (patch)
treed0629a04fd04ffb8222f2a1001bd8761c8380318
parent9ebeae62285092712cc10642802711e7a24b1043 (diff)
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.
-rw-r--r--Alc/midi/fluidsynth.c13
-rw-r--r--Alc/midi/sf2load.c41
-rw-r--r--OpenAL32/Include/alMain.h2
-rw-r--r--OpenAL32/alFontsound.c4
4 files changed, 45 insertions, 15 deletions
diff --git a/Alc/midi/fluidsynth.c b/Alc/midi/fluidsynth.c
index c32d2fb1..0e3ddd6d 100644
--- a/Alc/midi/fluidsynth.c
+++ b/Alc/midi/fluidsynth.c
@@ -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;
diff --git a/Alc/midi/sf2load.c b/Alc/midi/sf2load.c
index 747b340f..40023301 100644
--- a/Alc/midi/sf2load.c
+++ b/Alc/midi/sf2load.c
@@ -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;
}
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 3394eab2..82105ab6 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -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
diff --git a/OpenAL32/alFontsound.c b/OpenAL32/alFontsound.c
index 4a195c21..3adb5783 100644
--- a/OpenAL32/alFontsound.c
+++ b/OpenAL32/alFontsound.c
@@ -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;