Skip to content

Commit

Permalink
- clamp the loop end point to the sample size for sound effects so th…
Browse files Browse the repository at this point in the history
…at bogus values do not render the loop start ineffective.
  • Loading branch information
coelckers committed Apr 22, 2017
1 parent dc3df4e commit 882279d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/sound/oalsound.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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!
}


Expand Down

0 comments on commit 882279d

Please sign in to comment.