- clamp the loop end point to the sample size for sound effects so that bogus values do not render the loop start ineffective.

This commit is contained in:
Christoph Oelckers 2017-04-22 15:49:39 +02:00
parent dc3df4e897
commit 882279d600

View file

@ -1218,15 +1218,16 @@ std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int
if(!decoder) return std::make_pair(retval, true);
decoder->getInfo(&srate, &chans, &type);
int samplesize = 1;
if(chans == ChannelConfig_Mono || monoize)
{
if(type == SampleType_UInt8) format = AL_FORMAT_MONO8;
if(type == SampleType_Int16) format = AL_FORMAT_MONO16;
if(type == SampleType_UInt8) format = AL_FORMAT_MONO8, samplesize = 1;
if(type == SampleType_Int16) format = AL_FORMAT_MONO16, samplesize = 2;
}
else if(chans == ChannelConfig_Stereo)
{
if(type == SampleType_UInt8) format = AL_FORMAT_STEREO8;
if(type == SampleType_Int16) format = AL_FORMAT_STEREO16;
if(type == SampleType_UInt8) format = AL_FORMAT_STEREO8, samplesize = 2;
if(type == SampleType_Int16) format = AL_FORMAT_STEREO16, samplesize = 4;
}
if(format == AL_NONE)
@ -1282,13 +1283,14 @@ std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int
if (!startass) loop_start = Scale(loop_start, srate, 1000);
if (!endass) loop_end = Scale(loop_end, srate, 1000);
if (loop_start < 0) loop_start = 0;
if (loop_end >= data.Size() / samplesize) loop_end = data.Size() / samplesize - 1;
if ((loop_start > 0 || loop_end > 0) && loop_end > loop_start && AL.SOFT_loop_points)
{
ALint loops[2] = { static_cast<ALint>(loop_start), static_cast<ALint>(loop_end) };
DPrintf(DMSG_NOTIFY, "Setting loop points %d -> %d\n", loops[0], loops[1]);
alBufferiv(buffer, AL_LOOP_POINTS_SOFT, loops);
getALError();
// no console messages here, please!
}