Use mini/maxi/clampi and minu/maxu/clampu to replace min/max calls

This commit is contained in:
Chris Robinson 2011-08-16 18:33:10 -07:00
parent a96f817738
commit 04dad28228
7 changed files with 41 additions and 34 deletions

View File

@ -152,7 +152,7 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
ALSource->SampleSize;
maxstep -= ResamplerPadding[ALSource->Resampler] +
ResamplerPrePadding[ALSource->Resampler] + 1;
maxstep = min(maxstep, INT_MAX>>FRACTIONBITS);
maxstep = mini(maxstep, INT_MAX>>FRACTIONBITS);
Pitch = Pitch * ALBuffer->Frequency / Frequency;
if(Pitch > (ALfloat)maxstep)
@ -677,7 +677,7 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
ALSource->SampleSize;
maxstep -= ResamplerPadding[ALSource->Resampler] +
ResamplerPrePadding[ALSource->Resampler] + 1;
maxstep = min(maxstep, INT_MAX>>FRACTIONBITS);
maxstep = mini(maxstep, INT_MAX>>FRACTIONBITS);
Pitch = Pitch * ALBuffer->Frequency / Frequency;
if(Pitch > (ALfloat)maxstep)
@ -975,7 +975,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
while(size > 0)
{
/* Setup variables */
SamplesToDo = min(size, BUFFERSIZE);
SamplesToDo = minu(size, BUFFERSIZE);
/* Clear mixing buffer */
memset(device->DryBuffer, 0, SamplesToDo*MAXCHANNELS*sizeof(ALfloat));

View File

@ -65,7 +65,7 @@ static void CalcEvIndices(ALfloat ev, ALuint *evidx, ALfloat *evmu)
{
ev = (M_PI/2.0f + ev) * (ELEV_COUNT-1) / M_PI;
evidx[0] = (ALuint)ev;
evidx[1] = minF(evidx[0] + 1, ELEV_COUNT-1);
evidx[1] = minu(evidx[0] + 1, ELEV_COUNT-1);
*evmu = ev - evidx[0];
}

View File

@ -150,7 +150,7 @@ static void Mix_Hrtf_##T##_##sampler(ALsource *Source, ALCdevice *Device, \
ALuint *RESTRICT TargetDelay = Source->Params.HrtfDelay[i]; \
ALfloat *RESTRICT History = Source->HrtfHistory[i]; \
ALfloat (*RESTRICT Values)[2] = Source->HrtfValues[i]; \
ALint Counter = __max(Source->HrtfCounter, OutPos) - OutPos; \
ALint Counter = maxu(Source->HrtfCounter, OutPos) - OutPos; \
ALuint Offset = Source->HrtfOffset + OutPos; \
ALfloat Coeffs[HRIR_LENGTH][2]; \
ALuint Delay[2]; \
@ -612,7 +612,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
else
{
DataSize = (BufferPrePadding-DataPosInt)*FrameSize;
DataSize = min(BufferSize, DataSize);
DataSize = minu(BufferSize, DataSize);
memset(&SrcData[SrcDataSize], 0, DataSize);
SrcDataSize += DataSize;
@ -624,7 +624,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
/* Copy what's left to play in the source buffer, and clear the
* rest of the temp buffer */
DataSize = ALBuffer->size - pos;
DataSize = min(BufferSize, DataSize);
DataSize = minu(BufferSize, DataSize);
memcpy(&SrcData[SrcDataSize], &Data[pos], DataSize);
SrcDataSize += DataSize;
@ -653,7 +653,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
else
{
DataSize = (BufferPrePadding-DataPosInt)*FrameSize;
DataSize = min(BufferSize, DataSize);
DataSize = minu(BufferSize, DataSize);
memset(&SrcData[SrcDataSize], 0, DataSize);
SrcDataSize += DataSize;
@ -665,7 +665,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
/* Copy what's left of this loop iteration, then copy repeats
* of the loop section */
DataSize = LoopEnd*FrameSize - pos;
DataSize = min(BufferSize, DataSize);
DataSize = minu(BufferSize, DataSize);
memcpy(&SrcData[SrcDataSize], &Data[pos], DataSize);
SrcDataSize += DataSize;
@ -674,7 +674,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
DataSize = (LoopEnd-LoopStart) * FrameSize;
while(BufferSize > 0)
{
DataSize = min(BufferSize, DataSize);
DataSize = minu(BufferSize, DataSize);
memcpy(&SrcData[SrcDataSize], &Data[LoopStart*FrameSize], DataSize);
SrcDataSize += DataSize;
@ -697,7 +697,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
{
if(!BufferListIter->prev && !Looping)
{
ALuint DataSize = min(BufferSize, pos);
ALuint DataSize = minu(BufferSize, pos);
memset(&SrcData[SrcDataSize], 0, DataSize);
SrcDataSize += DataSize;
@ -744,7 +744,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
DataSize -= pos;
pos -= pos;
DataSize = min(BufferSize, DataSize);
DataSize = minu(BufferSize, DataSize);
memcpy(&SrcData[SrcDataSize], Data, DataSize);
SrcDataSize += DataSize;
BufferSize -= DataSize;
@ -770,7 +770,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
DataSize64 -= DataPosFrac;
BufferSize = (ALuint)((DataSize64+(increment-1)) / increment);
BufferSize = min(BufferSize, (SamplesToDo-OutPos));
BufferSize = minu(BufferSize, (SamplesToDo-OutPos));
SrcData += BufferPrePadding*FrameSize;
Source->Params.DoMix(Source, Device, SrcData, &DataPosInt, &DataPosFrac,
@ -837,7 +837,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
Source->HrtfOffset += OutPos;
if(State == AL_PLAYING)
{
Source->HrtfCounter = __max(Source->HrtfCounter, OutPos) - OutPos;
Source->HrtfCounter = maxu(Source->HrtfCounter, OutPos) - OutPos;
Source->HrtfMoving = AL_TRUE;
}
else

View File

@ -431,7 +431,7 @@ static HRESULT DoReset(ALCdevice *device)
device->NumUpdates = (device->NumUpdates*device->UpdateSize + min_len/2) /
min_len;
device->NumUpdates = __max(device->NumUpdates, 2);
device->NumUpdates = maxu(device->NumUpdates, 2);
device->UpdateSize = min_len;
hr = IAudioClient_Initialize(data->client, AUDCLNT_SHAREMODE_SHARED,

View File

@ -1121,7 +1121,7 @@ static ALCboolean pulse_open_capture(ALCdevice *device, const ALCchar *device_na
data->attr.prebuf = -1;
data->attr.maxlength = data->samples * data->frame_size;
data->attr.tlength = -1;
data->attr.fragsize = min(data->samples, 50 * device->Frequency / 1000) *
data->attr.fragsize = minu(data->samples, 50*device->Frequency/1000) *
data->frame_size;
data->spec.rate = device->Frequency;

View File

@ -134,6 +134,20 @@ static __inline ALfloat maxF(ALfloat a, ALfloat b)
static __inline ALfloat clampF(ALfloat val, ALfloat mn, ALfloat mx)
{ return minF(mx, maxF(mn, val)); }
static __inline ALuint minu(ALuint a, ALuint b)
{ return ((a > b) ? b : a); }
static __inline ALuint maxu(ALuint a, ALuint b)
{ return ((a > b) ? a : b); }
static __inline ALuint clampu(ALuint val, ALuint min, ALuint max)
{ return minu(max, maxu(min, val)); }
static __inline ALint mini(ALint a, ALint b)
{ return ((a > b) ? b : a); }
static __inline ALint maxi(ALint a, ALint b)
{ return ((a > b) ? a : b); }
static __inline ALint clampi(ALint val, ALint min, ALint max)
{ return mini(max, maxi(min, val)); }
static __inline ALdouble lerp(ALdouble val1, ALdouble val2, ALdouble mu)
{

View File

@ -982,11 +982,11 @@ static ALmulaw EncodeMuLaw(ALshort val)
{
/* -32768 doesn't properly negate on a short; it results in itself.
* So clamp to -32767 */
val = max(val, -32767);
val = maxi(val, -32767);
val = -val;
}
val = min(val, muLawClip);
val = mini(val, muLawClip);
val += muLawBias;
exp = muLawCompressTable[(val>>7) & 0xff];
@ -1010,8 +1010,7 @@ static void DecodeIMA4Block(ALshort *dst, const ALima4 *src, ALint numchans)
index[c] |= *(src++) << 8;
index[c] = (index[c]^0x8000) - 32768;
index[c] = max(0, index[c]);
index[c] = min(index[c], 88);
index[c] = clampi(index[c], 0, 88);
dst[c] = sample[c];
}
@ -1035,12 +1034,10 @@ static void DecodeIMA4Block(ALshort *dst, const ALima4 *src, ALint numchans)
code[c] >>= 4;
sample[c] += IMA4Codeword[nibble] * IMAStep_size[index[c]] / 8;
sample[c] = max(-32768, sample[c]);
sample[c] = min(sample[c], 32767);
sample[c] = clampi(sample[c], -32768, 32767);
index[c] += IMA4Index_adjust[nibble];
index[c] = max(0, index[c]);
index[c] = min(index[c], 88);
index[c] = clampi(index[c], 0, 88);
dst[j*numchans + c] = sample[c];
}
@ -1065,16 +1062,14 @@ static void EncodeIMA4Block(ALima4 *dst, const ALshort *src, ALint *sample, ALin
diff = -diff;
}
diff = min(step*2, diff);
diff = mini(step*2, diff);
nibble |= (diff*8/step - 1) / 2;
sample[c] += IMA4Codeword[nibble] * step / 8;
sample[c] = max(-32768, sample[c]);
sample[c] = min(sample[c], 32767);
sample[c] = clampi(sample[c], -32768, 32767);
index[c] += IMA4Index_adjust[nibble];
index[c] = max(0, index[c]);
index[c] = min(index[c], 88);
index[c] = clampi(index[c], 0, 88);
*(dst++) = sample[c] & 0xff;
*(dst++) = (sample[c]>>8) & 0xff;
@ -1100,16 +1095,14 @@ static void EncodeIMA4Block(ALima4 *dst, const ALshort *src, ALint *sample, ALin
diff = -diff;
}
diff = min(step*2, diff);
diff = mini(step*2, diff);
nibble |= (diff*8/step - 1) / 2;
sample[c] += IMA4Codeword[nibble] * step / 8;
sample[c] = max(-32768, sample[c]);
sample[c] = min(sample[c], 32767);
sample[c] = clampi(sample[c], -32768, 32767);
index[c] += IMA4Index_adjust[nibble];
index[c] = max(0, index[c]);
index[c] = min(index[c], 88);
index[c] = clampi(index[c], 0, 88);
if(!(k&1)) *dst = nibble;
else *(dst++) |= nibble<<4;