summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-08-16 18:33:10 -0700
committerChris Robinson <[email protected]>2011-08-16 18:33:10 -0700
commit04dad28228a694e681d722826615245466a3aa16 (patch)
tree54860fb951339bb4af88df4c620383323427a5fd
parenta96f8177387818d3ef69778e3f78a9ed251326c1 (diff)
Use mini/maxi/clampi and minu/maxu/clampu to replace min/max calls
-rw-r--r--Alc/ALu.c6
-rw-r--r--Alc/hrtf.c2
-rw-r--r--Alc/mixer.c20
-rw-r--r--Alc/mmdevapi.c2
-rw-r--r--Alc/pulseaudio.c2
-rw-r--r--OpenAL32/Include/alu.h14
-rw-r--r--OpenAL32/alBuffer.c29
7 files changed, 41 insertions, 34 deletions
diff --git a/Alc/ALu.c b/Alc/ALu.c
index aaf79fe3..a2352de9 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -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));
diff --git a/Alc/hrtf.c b/Alc/hrtf.c
index 226138a0..e1f02ce7 100644
--- a/Alc/hrtf.c
+++ b/Alc/hrtf.c
@@ -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];
}
diff --git a/Alc/mixer.c b/Alc/mixer.c
index d3f22b51..b589593f 100644
--- a/Alc/mixer.c
+++ b/Alc/mixer.c
@@ -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
diff --git a/Alc/mmdevapi.c b/Alc/mmdevapi.c
index d7d85a20..ba5a36d6 100644
--- a/Alc/mmdevapi.c
+++ b/Alc/mmdevapi.c
@@ -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,
diff --git a/Alc/pulseaudio.c b/Alc/pulseaudio.c
index c3561bed..5900d728 100644
--- a/Alc/pulseaudio.c
+++ b/Alc/pulseaudio.c
@@ -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;
diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h
index 65d8d3a7..45eb09c5 100644
--- a/OpenAL32/Include/alu.h
+++ b/OpenAL32/Include/alu.h
@@ -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)
{
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c
index 306d240d..267faad5 100644
--- a/OpenAL32/alBuffer.c
+++ b/OpenAL32/alBuffer.c
@@ -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;