diff options
author | Chris Robinson <[email protected]> | 2014-06-29 02:04:05 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-06-29 02:04:05 -0700 |
commit | 8176d2c058d1744c25a2a520ec9b6882decb4f3f (patch) | |
tree | f287f5298208999e2f9ef32dea96608a83e20847 /Alc/midi | |
parent | 389a2f7b4bcffa5cfbe17e8057c8541b0e442bf8 (diff) |
Load soundfont samples into an ALbuffer
Also remove ALsoundfont's now-unneeded sample storage functions and struct
fields.
Diffstat (limited to 'Alc/midi')
-rw-r--r-- | Alc/midi/fluidsynth.c | 4 | ||||
-rw-r--r-- | Alc/midi/sf2load.c | 25 |
2 files changed, 21 insertions, 8 deletions
diff --git a/Alc/midi/fluidsynth.c b/Alc/midi/fluidsynth.c index d10c1be8..582da06d 100644 --- a/Alc/midi/fluidsynth.c +++ b/Alc/midi/fluidsynth.c @@ -218,7 +218,7 @@ static int FPreset_getPreset(fluid_preset_t *preset); static int FPreset_getBank(fluid_preset_t *preset); static int FPreset_noteOn(fluid_preset_t *preset, fluid_synth_t *synth, int channel, int key, int velocity); -static void FPreset_Construct(FPreset *self, ALsfpreset *preset, fluid_sfont_t *parent, ALsoundfont *sfont) +static void FPreset_Construct(FPreset *self, ALsfpreset *preset, fluid_sfont_t *parent) { STATIC_CAST(fluid_preset_t, self)->data = self; STATIC_CAST(fluid_preset_t, self)->sfont = parent; @@ -386,7 +386,7 @@ static void FSfont_Construct(FSfont *self, ALsoundfont *sfont) ALsizei i; self->NumPresets = sfont->NumPresets; for(i = 0;i < self->NumPresets;i++) - FPreset_Construct(&self->Presets[i], sfont->Presets[i], STATIC_CAST(fluid_sfont_t, self), sfont); + FPreset_Construct(&self->Presets[i], sfont->Presets[i], STATIC_CAST(fluid_sfont_t, self)); } } diff --git a/Alc/midi/sf2load.c b/Alc/midi/sf2load.c index 2bc94133..44d19a8a 100644 --- a/Alc/midi/sf2load.c +++ b/Alc/midi/sf2load.c @@ -897,7 +897,7 @@ static void fillZone(ALfontsound *sound, ALCcontext *context, const GenModList * } } -static void processInstrument(ALfontsound ***sounds, ALsizei *sounds_size, ALCcontext *context, InstrumentHeader *inst, const PresetHeader *preset, const Soundfont *sfont, const GenModList *pzone) +static void processInstrument(ALfontsound ***sounds, ALsizei *sounds_size, ALCcontext *context, ALbuffer *buffer, InstrumentHeader *inst, const PresetHeader *preset, const Soundfont *sfont, const GenModList *pzone) { const Generator *gen, *gen_end; const Modulator *mod, *mod_end; @@ -990,6 +990,7 @@ static void processInstrument(ALfontsound ***sounds, ALsizei *sounds_size, ALCco sound = NewFontsound(context); (*sounds)[(*sounds_size)++] = sound; + ALfontsound_setPropi(sound, context, AL_BUFFER, buffer->id); 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); @@ -1015,6 +1016,7 @@ ALboolean loadSf2(Reader *stream, ALsoundfont *soundfont, ALCcontext *context) { ALsfpreset **presets = NULL; ALsizei presets_size = 0; + ALbuffer *buffer = NULL; ALuint ltype; Soundfont sfont; RiffHdr riff; @@ -1099,6 +1101,7 @@ ALboolean loadSf2(Reader *stream, ALsoundfont *soundfont, ALCcontext *context) { ALbyte *ptr; RiffHdr smpl; + ALenum err; RiffHdr_read(&smpl, stream); if(smpl.mCode != FOURCC('s','m','p','l')) @@ -1108,11 +1111,14 @@ ALboolean loadSf2(Reader *stream, ALsoundfont *soundfont, ALCcontext *context) if(smpl.mSize > list.mSize) ERROR_GOTO(error, "Invalid Format, sample chunk size mismatch\n"); - if(!(ptr=realloc(soundfont->Samples, smpl.mSize))) + buffer = NewBuffer(context); + if(!buffer) SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, error); - soundfont->Samples = (ALshort*)ptr; - soundfont->NumSamples = smpl.mSize/2; + /* Sample rate it unimportant, the individual fontsounds will specify it. */ + if((err=LoadData(buffer, 22050, AL_MONO16_SOFT, smpl.mSize/2, UserFmtMono, UserFmtShort, NULL, 1, AL_FALSE)) != AL_NO_ERROR) + SET_ERROR_AND_GOTO(context, err, error); + ptr = buffer->data; if(IS_LITTLE_ENDIAN) READ(stream, ptr, smpl.mSize); else @@ -1310,8 +1316,10 @@ ALboolean loadSf2(Reader *stream, ALsoundfont *soundfont, ALCcontext *context) ERR("Generator %ld has invalid instrument ID (%d of %d)\n", (long)(gen-sfont.pgen), gen->mAmount, sfont.inst_size-1); else - processInstrument(&sounds, &sounds_size, context, - &sfont.inst[gen->mAmount], &sfont.phdr[i], &sfont, &lzone); + processInstrument( + &sounds, &sounds_size, context, buffer, &sfont.inst[gen->mAmount], + &sfont.phdr[i], &sfont, &lzone + ); break; } GenModList_insertGen(&lzone, gen, AL_TRUE); @@ -1346,6 +1354,9 @@ ALboolean loadSf2(Reader *stream, ALsoundfont *soundfont, ALCcontext *context) free(presets); Soundfont_Destruct(&sfont); + /* If the buffer ends up unused, delete it. */ + if(ReadRef(&buffer->ref) == 0) + DeleteBuffer(context->Device, buffer->id); return AL_TRUE; @@ -1359,6 +1370,8 @@ error: } Soundfont_Destruct(&sfont); + if(buffer) + DeleteBuffer(context->Device, buffer->id); return AL_FALSE; } |