summaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-06-29 02:04:05 -0700
committerChris Robinson <[email protected]>2014-06-29 02:04:05 -0700
commit8176d2c058d1744c25a2a520ec9b6882decb4f3f (patch)
treef287f5298208999e2f9ef32dea96608a83e20847 /Alc
parent389a2f7b4bcffa5cfbe17e8057c8541b0e442bf8 (diff)
Load soundfont samples into an ALbuffer
Also remove ALsoundfont's now-unneeded sample storage functions and struct fields.
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALc.c4
-rw-r--r--Alc/midi/fluidsynth.c4
-rw-r--r--Alc/midi/sf2load.c25
-rw-r--r--Alc/mixer.c30
4 files changed, 36 insertions, 27 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 0af8fc9d..e21cd8ed 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -293,10 +293,6 @@ static const ALCfunction alcFunctions[] = {
DECL(alGenSoundfontsSOFT),
DECL(alDeleteSoundfontsSOFT),
DECL(alIsSoundfontSOFT),
- DECL(alSoundfontSamplesSOFT),
- DECL(alGetSoundfontSamplesSOFT),
- DECL(alSoundfontMapSamplesSOFT),
- DECL(alSoundfontUnmapSamplesSOFT),
DECL(alGetSoundfontivSOFT),
DECL(alSoundfontPresetsSOFT),
DECL(alGenPresetsSOFT),
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;
}
diff --git a/Alc/mixer.c b/Alc/mixer.c
index a1502488..7141a8ae 100644
--- a/Alc/mixer.c
+++ b/Alc/mixer.c
@@ -121,7 +121,7 @@ DECL_TEMPLATE(ALfloat)
#undef DECL_TEMPLATE
-static void LoadData(ALfloat *dst, const ALvoid *src, ALuint srcstep, enum FmtType srctype, ALuint samples)
+static void LoadSamples(ALfloat *dst, const ALvoid *src, ALuint srcstep, enum FmtType srctype, ALuint samples)
{
switch(srctype)
{
@@ -137,7 +137,7 @@ static void LoadData(ALfloat *dst, const ALvoid *src, ALuint srcstep, enum FmtTy
}
}
-static void SilenceData(ALfloat *dst, ALuint samples)
+static void SilenceSamples(ALfloat *dst, ALuint samples)
{
ALuint i;
for(i = 0;i < samples;i++)
@@ -265,7 +265,7 @@ ALvoid MixSource(ALactivesource *src, ALCdevice *Device, ALuint SamplesToDo)
DataSize = BufferPrePadding - DataPosInt;
DataSize = minu(SrcBufferSize - SrcDataSize, DataSize);
- SilenceData(&SrcData[SrcDataSize], DataSize);
+ SilenceSamples(&SrcData[SrcDataSize], DataSize);
SrcDataSize += DataSize;
pos = 0;
@@ -275,11 +275,11 @@ ALvoid MixSource(ALactivesource *src, ALCdevice *Device, ALuint SamplesToDo)
* rest of the temp buffer */
DataSize = minu(SrcBufferSize - SrcDataSize, ALBuffer->SampleLen - pos);
- LoadData(&SrcData[SrcDataSize], &Data[(pos*NumChannels + chan)*SampleSize],
- NumChannels, ALBuffer->FmtType, DataSize);
+ LoadSamples(&SrcData[SrcDataSize], &Data[(pos*NumChannels + chan)*SampleSize],
+ NumChannels, ALBuffer->FmtType, DataSize);
SrcDataSize += DataSize;
- SilenceData(&SrcData[SrcDataSize], SrcBufferSize - SrcDataSize);
+ SilenceSamples(&SrcData[SrcDataSize], SrcBufferSize - SrcDataSize);
SrcDataSize += SrcBufferSize - SrcDataSize;
}
else
@@ -302,7 +302,7 @@ ALvoid MixSource(ALactivesource *src, ALCdevice *Device, ALuint SamplesToDo)
DataSize = BufferPrePadding - DataPosInt;
DataSize = minu(SrcBufferSize - SrcDataSize, DataSize);
- SilenceData(&SrcData[SrcDataSize], DataSize);
+ SilenceSamples(&SrcData[SrcDataSize], DataSize);
SrcDataSize += DataSize;
pos = 0;
@@ -313,8 +313,8 @@ ALvoid MixSource(ALactivesource *src, ALCdevice *Device, ALuint SamplesToDo)
DataSize = LoopEnd - pos;
DataSize = minu(SrcBufferSize - SrcDataSize, DataSize);
- LoadData(&SrcData[SrcDataSize], &Data[(pos*NumChannels + chan)*SampleSize],
- NumChannels, ALBuffer->FmtType, DataSize);
+ LoadSamples(&SrcData[SrcDataSize], &Data[(pos*NumChannels + chan)*SampleSize],
+ NumChannels, ALBuffer->FmtType, DataSize);
SrcDataSize += DataSize;
DataSize = LoopEnd-LoopStart;
@@ -322,8 +322,8 @@ ALvoid MixSource(ALactivesource *src, ALCdevice *Device, ALuint SamplesToDo)
{
DataSize = minu(SrcBufferSize - SrcDataSize, DataSize);
- LoadData(&SrcData[SrcDataSize], &Data[(LoopStart*NumChannels + chan)*SampleSize],
- NumChannels, ALBuffer->FmtType, DataSize);
+ LoadSamples(&SrcData[SrcDataSize], &Data[(LoopStart*NumChannels + chan)*SampleSize],
+ NumChannels, ALBuffer->FmtType, DataSize);
SrcDataSize += DataSize;
}
}
@@ -353,7 +353,7 @@ ALvoid MixSource(ALactivesource *src, ALCdevice *Device, ALuint SamplesToDo)
{
ALuint DataSize = minu(SrcBufferSize - SrcDataSize, pos);
- SilenceData(&SrcData[SrcDataSize], DataSize);
+ SilenceSamples(&SrcData[SrcDataSize], DataSize);
SrcDataSize += DataSize;
pos = 0;
@@ -390,8 +390,8 @@ ALvoid MixSource(ALactivesource *src, ALCdevice *Device, ALuint SamplesToDo)
pos -= pos;
DataSize = minu(SrcBufferSize - SrcDataSize, DataSize);
- LoadData(&SrcData[SrcDataSize], Data, NumChannels,
- ALBuffer->FmtType, DataSize);
+ LoadSamples(&SrcData[SrcDataSize], Data, NumChannels,
+ ALBuffer->FmtType, DataSize);
SrcDataSize += DataSize;
}
}
@@ -400,7 +400,7 @@ ALvoid MixSource(ALactivesource *src, ALCdevice *Device, ALuint SamplesToDo)
tmpiter = Source->queue;
else if(!tmpiter)
{
- SilenceData(&SrcData[SrcDataSize], SrcBufferSize - SrcDataSize);
+ SilenceSamples(&SrcData[SrcDataSize], SrcBufferSize - SrcDataSize);
SrcDataSize += SrcBufferSize - SrcDataSize;
}
}