Limit the source step to 10

This means the combination of the buffer frequency, source pitch, and
doppler shift can't exceed 10x the device playback frequency.

This is needed to keep the mixer from starving with a really high
increment, causing small DstBufferSize values that require a lot of
iterations.
This commit is contained in:
Chris Robinson 2013-07-02 06:57:27 -07:00
parent 61c6a38f04
commit 52096234e1
3 changed files with 6 additions and 23 deletions

View File

@ -279,14 +279,9 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
ALbuffer *ALBuffer;
if((ALBuffer=BufferListItem->buffer) != NULL)
{
ALsizei maxstep = BUFFERSIZE;
maxstep -= ResamplerPadding[Resampler] +
ResamplerPrePadding[Resampler] + 1;
maxstep = mini(maxstep, INT_MAX>>FRACTIONBITS);
Pitch = Pitch * ALBuffer->Frequency / Frequency;
if(Pitch > (ALfloat)maxstep)
ALSource->Params.Step = maxstep<<FRACTIONBITS;
if(Pitch > 10.0f)
ALSource->Params.Step = 10<<FRACTIONBITS;
else
{
ALSource->Params.Step = fastf2i(Pitch*FRACTIONONE);
@ -777,14 +772,9 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
{
/* Calculate fixed-point stepping value, based on the pitch, buffer
* frequency, and output frequency. */
ALsizei maxstep = BUFFERSIZE;
maxstep -= ResamplerPadding[Resampler] +
ResamplerPrePadding[Resampler] + 1;
maxstep = mini(maxstep, INT_MAX>>FRACTIONBITS);
Pitch = Pitch * ALBuffer->Frequency / Frequency;
if(Pitch > (ALfloat)maxstep)
ALSource->Params.Step = maxstep<<FRACTIONBITS;
if(Pitch > 10.0f)
ALSource->Params.Step = 10<<FRACTIONBITS;
else
{
ALSource->Params.Step = fastf2i(Pitch*FRACTIONONE);

View File

@ -577,15 +577,8 @@ enum DeviceType {
* more memory, while smaller values may need more iterations. The value needs
* to be a sensible size, however, as it constrains the max stepping value used
* for mixing, as well as the maximum number of samples per mixing iteration.
*
* The mixer requires being able to do two samplings per mixing loop. With the
* cubic resampler (which requires 3 padding samples), this limits a 2048
* buffer size to about 2044. This means that buffer_freq*source_pitch cannot
* exceed device_freq*2044 for a 32-bit buffer.
*/
#ifndef BUFFERSIZE
#define BUFFERSIZE 2048
#endif
#define BUFFERSIZE (2048u)
struct ALCdevice_struct

View File

@ -546,7 +546,7 @@ ALenum InitializeEffect(ALCdevice *Device, ALeffectslot *EffectSlot, ALeffect *e
ALenum InitEffectSlot(ALeffectslot *slot)
{
ALeffectStateFactory *factory;
ALint i, c;
ALuint i, c;
slot->EffectType = AL_EFFECT_NULL;