Change the modified parameter in the Clamp function to be a pointer.

Makes it easier to identify the one being modified.
This commit is contained in:
Lioncash 2014-02-05 04:04:35 -05:00
parent 6b87a0ef20
commit 249b00c469
10 changed files with 24 additions and 24 deletions

View file

@ -123,7 +123,7 @@ float* design_fir(unsigned int *n, float* fc, float opt)
// Sanity check
if(*n==0) return NULL;
MathUtil::Clamp(fc[0],float(0.001),float(1));
MathUtil::Clamp(&fc[0],float(0.001),float(1));
float *w=(float*)calloc(sizeof(float),*n);

View file

@ -14,12 +14,12 @@
namespace MathUtil
{
template<class T>
inline void Clamp(T& val, const T& min, const T& max)
inline void Clamp(T* val, const T& min, const T& max)
{
if (val < min)
val = min;
else if (val > max)
val = max;
if (*val < min)
*val = min;
else if (*val > max)
*val = max;
}

View file

@ -37,7 +37,7 @@ static s16 ADPCM_Step(u32& _rSamplePos)
// 0x400 = 0.5 in 11-bit fixed point
int val = (scale * temp) + ((0x400 + coef1 * (s16)g_dsp.ifx_regs[DSP_YN1] + coef2 * (s16)g_dsp.ifx_regs[DSP_YN2]) >> 11);
MathUtil::Clamp(val, -0x7FFF, 0x7FFF);
MathUtil::Clamp(&val, -0x7FFF, 0x7FFF);
g_dsp.ifx_regs[DSP_YN2] = g_dsp.ifx_regs[DSP_YN1];
g_dsp.ifx_regs[DSP_YN1] = val;

View file

@ -339,11 +339,11 @@ unsigned int Callback_GetStreaming(short* _pDestBuffer, unsigned int _numSamples
if (i % 3)
{
pcm_l = (((pcm_l + (int)pcm[pos*2]) / 2 * lvolume) >> 8) + (int)(*_pDestBuffer);
MathUtil::Clamp(pcm_l, -32767, 32767);
MathUtil::Clamp(&pcm_l, -32767, 32767);
*_pDestBuffer++ = pcm_l;
pcm_r = (((pcm_r + (int)pcm[pos*2+1]) / 2 * rvolume) >> 8) + (int)(*_pDestBuffer);
MathUtil::Clamp(pcm_r, -32767, 32767);
MathUtil::Clamp(&pcm_r, -32767, 32767);
*_pDestBuffer++ = pcm_r;
}
pcm_l = pcm[pos*2];
@ -373,11 +373,11 @@ unsigned int Callback_GetStreaming(short* _pDestBuffer, unsigned int _numSamples
pcm_l = (pcm_l * lvolume >> 8) + (int)(*_pDestBuffer);
MathUtil::Clamp(pcm_l, -32767, 32767);
MathUtil::Clamp(&pcm_l, -32767, 32767);
*_pDestBuffer++ = pcm_l;
pcm_r = (pcm_r * lvolume >> 8) + (int)(*_pDestBuffer);
MathUtil::Clamp(pcm_r, -32767, 32767);
MathUtil::Clamp(&pcm_r, -32767, 32767);
*_pDestBuffer++ = pcm_r;
frac += ratio;
@ -387,11 +387,11 @@ unsigned int Callback_GetStreaming(short* _pDestBuffer, unsigned int _numSamples
else //1:1 no resampling
{
pcm_l = (((int)pcm[pos*2] * lvolume) >> 8) + (int)(*_pDestBuffer);
MathUtil::Clamp(pcm_l, -32767, 32767);
MathUtil::Clamp(&pcm_l, -32767, 32767);
*_pDestBuffer++ = pcm_l;
pcm_r = (((int)pcm[pos*2+1] * rvolume) >> 8) + (int)(*_pDestBuffer);
MathUtil::Clamp(pcm_r, -32767, 32767);
MathUtil::Clamp(&pcm_r, -32767, 32767);
*_pDestBuffer++ = pcm_r;
pos++;

View file

@ -560,8 +560,8 @@ void CUCode_AX::OutputSamples(u32 lr_addr, u32 surround_addr)
int left = m_samples_left[i];
int right = m_samples_right[i];
MathUtil::Clamp(left, -32767, 32767);
MathUtil::Clamp(right, -32767, 32767);
MathUtil::Clamp(&left, -32767, 32767);
MathUtil::Clamp(&right, -32767, 32767);
buffer[2 * i + 0] = Common::swap16(right);
buffer[2 * i + 1] = Common::swap16(left);

View file

@ -618,8 +618,8 @@ void CUCode_AXWii::OutputSamples(u32 lr_addr, u32 surround_addr, u16 volume,
left = ((s64)left * volume_ramp[i]) >> 15;
right = ((s64)right * volume_ramp[i]) >> 15;
MathUtil::Clamp(left, -32767, 32767);
MathUtil::Clamp(right, -32767, 32767);
MathUtil::Clamp(&left, -32767, 32767);
MathUtil::Clamp(&right, -32767, 32767);
m_samples_left[i] = left;
m_samples_right[i] = right;
@ -654,7 +654,7 @@ void CUCode_AXWii::OutputWMSamples(u32* addresses)
for (u32 j = 0; j < 3 * 6; ++j)
{
int sample = in[j];
MathUtil::Clamp(sample, -32767, 32767);
MathUtil::Clamp(&sample, -32767, 32767);
out[j] = Common::swap16((u16)sample);
}
}

View file

@ -217,7 +217,7 @@ u16 AcceleratorGetSample()
temp -= 16;
int val = (scale * temp) + ((0x400 + coef1 * acc_pb->adpcm.yn1 + coef2 * acc_pb->adpcm.yn2) >> 11);
MathUtil::Clamp(val, -0x7FFF, 0x7FFF);
MathUtil::Clamp(&val, -0x7FFF, 0x7FFF);
acc_pb->adpcm.yn2 = acc_pb->adpcm.yn1;
acc_pb->adpcm.yn1 = val;

View file

@ -56,7 +56,7 @@ void CUCode_Zelda::AFCdecodebuffer(const s16 *coef, const char *src, signed shor
{
int sample = delta * nibbles[i] + ((int)hist * coef[idx * 2]) + ((int)hist2 * coef[idx * 2 + 1]);
sample >>= 11;
MathUtil::Clamp(sample, -32768, 32767);
MathUtil::Clamp(&sample, -32768, 32767);
out[i] = sample;
hist2 = hist;
hist = (short)sample;

View file

@ -781,10 +781,10 @@ void CUCode_Zelda::MixAdd(short *_Buffer, int _Size)
s32 left = (s32)_Buffer[0] + m_LeftBuffer[i];
s32 right = (s32)_Buffer[1] + m_RightBuffer[i];
MathUtil::Clamp(left, -32768, 32767);
MathUtil::Clamp(&left, -32768, 32767);
_Buffer[0] = (short)left;
MathUtil::Clamp(right, -32768, 32767);
MathUtil::Clamp(&right, -32768, 32767);
_Buffer[1] = (short)right;
_Buffer += 2;

View file

@ -32,7 +32,7 @@ s16 ADPDecodeSample(s32 bits, s32 q, s32& hist1, s32& hist2)
break;
}
hist = (hist + 0x20) >> 6;
MathUtil::Clamp(hist, -0x200000, 0x1fffff);
MathUtil::Clamp(&hist, -0x200000, 0x1fffff);
s32 cur = (((s16)(bits << 12) >> (q & 0xf)) << 6) + hist;
@ -40,7 +40,7 @@ s16 ADPDecodeSample(s32 bits, s32 q, s32& hist1, s32& hist2)
hist1 = cur;
cur >>= 6;
MathUtil::Clamp(cur, -0x8000, 0x7fff);
MathUtil::Clamp(&cur, -0x8000, 0x7fff);
return (s16)cur;
}