From 389a2f7b4bcffa5cfbe17e8057c8541b0e442bf8 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 29 Jun 2014 00:47:29 -0700 Subject: Store and use an ALbuffer for samples in an ALfontsound The fontsound still maintains its own start, end, and loop offsets, so that the same buffer may be shared between multiple/all fontsounds. Ideally a single buffer should be used for all fontsounds to avoid memory fragmentation and help CPU caching, although higher quality soundfonts may need more memory than a single buffer can hold. --- Alc/midi/fluidsynth.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'Alc/midi') diff --git a/Alc/midi/fluidsynth.c b/Alc/midi/fluidsynth.c index b4788635..d10c1be8 100644 --- a/Alc/midi/fluidsynth.c +++ b/Alc/midi/fluidsynth.c @@ -144,7 +144,7 @@ typedef struct FSample { ALsizei NumMods; } FSample; -static void FSample_Construct(FSample *self, ALfontsound *sound, ALsoundfont *sfont) +static void FSample_Construct(FSample *self, ALfontsound *sound) { fluid_sample_t *sample = STATIC_CAST(fluid_sample_t, self); memset(sample->name, 0, sizeof(sample->name)); @@ -157,7 +157,7 @@ static void FSample_Construct(FSample *self, ALfontsound *sound, ALsoundfont *sf sample->pitchadj = sound->PitchCorrection; sample->sampletype = getSampleType(sound->SampleType); sample->valid = 1; - sample->data = sfont->Samples; + sample->data = sound->Buffer ? sound->Buffer->data : NULL; sample->amplitude_that_reaches_noise_floor_is_valid = 0; sample->amplitude_that_reaches_noise_floor = 0.0; @@ -240,7 +240,7 @@ static void FPreset_Construct(FPreset *self, ALsfpreset *preset, fluid_sfont_t * ALsizei i; self->NumSamples = preset->NumSounds; for(i = 0;i < self->NumSamples;i++) - FSample_Construct(&self->Samples[i], preset->Sounds[i], sfont); + FSample_Construct(&self->Samples[i], preset->Sounds[i]); } } @@ -294,6 +294,8 @@ static int FPreset_noteOn(fluid_preset_t *preset, fluid_synth_t *synth, int chan fluid_voice_t *voice; ALsizei m; + if(!STATIC_CAST(fluid_sample_t, sample)->data) + continue; if(!(key >= sound->MinKey && key <= sound->MaxKey && vel >= sound->MinVelocity && vel <= sound->MaxVelocity)) continue; -- cgit v1.2.3