Store 4 modulators per map entry

This commit is contained in:
Chris Robinson 2014-07-06 09:06:35 -07:00
parent dc76013126
commit 8dec92531b
3 changed files with 31 additions and 24 deletions

View File

@ -171,14 +171,16 @@ static void FSample_Construct(FSample *self, ALfontsound *sound)
self->Sound = sound; self->Sound = sound;
self->NumMods = 0; self->NumMods = 0;
self->Mods = calloc(sound->ModulatorMap.size, sizeof(self->Mods[0])); self->Mods = calloc(sound->ModulatorMap.size*4, sizeof(fluid_mod_t[4]));
if(self->Mods) if(self->Mods)
{ {
ALsizei i, j; ALsizei i, j, k;
for(i = j = 0;i < sound->ModulatorMap.size;i++) for(i = j = 0;i < sound->ModulatorMap.size;i++)
{ {
ALsfmodulator *mod = sound->ModulatorMap.array[i].value; ALsfmodulator *mod = sound->ModulatorMap.array[i].value;
for(k = 0;k < 4;k++,mod++)
{
if(mod->Dest == AL_NONE) if(mod->Dest == AL_NONE)
continue; continue;
fluid_mod_set_source1(&self->Mods[j], getGenInput(mod->Source[0].Input), fluid_mod_set_source1(&self->Mods[j], getGenInput(mod->Source[0].Input),
@ -191,6 +193,7 @@ static void FSample_Construct(FSample *self, ALfontsound *sound)
fluid_mod_set_dest(&self->Mods[j], getSf2Gen(mod->Dest)); fluid_mod_set_dest(&self->Mods[j], getSf2Gen(mod->Dest));
self->Mods[j++].next = NULL; self->Mods[j++].next = NULL;
} }
}
self->NumMods = j; self->NumMods = j;
} }
} }
@ -260,7 +263,6 @@ static void FPreset_Destruct(FPreset *self)
static ALboolean FPreset_canDelete(FPreset *self) static ALboolean FPreset_canDelete(FPreset *self)
{ {
ALsizei i; ALsizei i;
for(i = 0;i < self->NumSamples;i++) for(i = 0;i < self->NumSamples;i++)
{ {
if(fluid_sample_refcount(STATIC_CAST(fluid_sample_t, &self->Samples[i])) != 0) if(fluid_sample_refcount(STATIC_CAST(fluid_sample_t, &self->Samples[i])) != 0)
@ -300,8 +302,7 @@ static int FPreset_noteOn(fluid_preset_t *preset, fluid_synth_t *synth, int chan
continue; continue;
voice = fluid_synth_alloc_voice(synth, STATIC_CAST(fluid_sample_t, sample), channel, key, vel); voice = fluid_synth_alloc_voice(synth, STATIC_CAST(fluid_sample_t, sample), channel, key, vel);
if(voice == NULL) if(voice == NULL) return FLUID_FAILED;
return FLUID_FAILED;
fluid_voice_gen_set(voice, GEN_MODLFOTOPITCH, sound->ModLfoToPitch); fluid_voice_gen_set(voice, GEN_MODLFOTOPITCH, sound->ModLfoToPitch);
fluid_voice_gen_set(voice, GEN_VIBLFOTOPITCH, sound->VibratoLfoToPitch); fluid_voice_gen_set(voice, GEN_VIBLFOTOPITCH, sound->VibratoLfoToPitch);

View File

@ -87,6 +87,7 @@ typedef struct ALfontsound {
ALenum SampleType; ALenum SampleType;
struct ALfontsound *Link; struct ALfontsound *Link;
/* NOTE: Each map entry contains *four* (4) ALsfmodulator objects. */
UIntMap ModulatorMap; UIntMap ModulatorMap;
ALuint id; ALuint id;

View File

@ -25,9 +25,11 @@ void ALfontsound_setModStagei(ALfontsound *self, ALCcontext *context, ALsizei st
static void ALfontsound_getModStagei(ALfontsound *self, ALCcontext *context, ALsizei stage, ALenum param, ALint *values); static void ALfontsound_getModStagei(ALfontsound *self, ALCcontext *context, ALsizei stage, ALenum param, ALint *values);
static inline struct ALsfmodulator *LookupModulator(ALfontsound *sound, ALuint id) static inline struct ALsfmodulator *LookupModulator(ALfontsound *sound, ALuint id)
{ return (struct ALsfmodulator*)LookupUIntMapKey(&sound->ModulatorMap, id); } {
static inline struct ALsfmodulator *RemoveModulator(ALfontsound *sound, ALuint id) ALsfmodulator *mod = LookupUIntMapKey(&sound->ModulatorMap, id>>2);
{ return (struct ALsfmodulator*)RemoveUIntMapKey(&sound->ModulatorMap, id); } if(mod) mod += id&3;
return mod;
}
AL_API void AL_APIENTRY alGenFontsoundsSOFT(ALsizei n, ALuint *ids) AL_API void AL_APIENTRY alGenFontsoundsSOFT(ALsizei n, ALuint *ids)
@ -846,15 +848,18 @@ static ALsfmodulator *ALfontsound_getModStage(ALfontsound *self, ALsizei stage)
{ {
static const ALsfmodulator moddef = { static const ALsfmodulator moddef = {
{ { AL_ONE_SOFT, AL_UNORM_SOFT, AL_LINEAR_SOFT }, { { AL_ONE_SOFT, AL_UNORM_SOFT, AL_LINEAR_SOFT },
{ AL_ONE_SOFT, AL_UNORM_SOFT, AL_LINEAR_SOFT } { AL_ONE_SOFT, AL_UNORM_SOFT, AL_LINEAR_SOFT } },
},
0, 0,
AL_LINEAR_SOFT, AL_LINEAR_SOFT,
AL_NONE AL_NONE
}; };
ret = malloc(sizeof(*ret)); ret = malloc(sizeof(ALsfmodulator[4]));
*ret = moddef; ret[0] = moddef;
InsertUIntMapEntry(&self->ModulatorMap, stage, ret); ret[1] = moddef;
ret[2] = moddef;
ret[3] = moddef;
InsertUIntMapEntry(&self->ModulatorMap, stage>>2, ret);
ret += stage&3;
} }
return ret; return ret;
} }