diff --git a/Source/Core/AudioCommon/DPL2Decoder.cpp b/Source/Core/AudioCommon/DPL2Decoder.cpp index 0c9fd65400..399541c1c9 100644 --- a/Source/Core/AudioCommon/DPL2Decoder.cpp +++ b/Source/Core/AudioCommon/DPL2Decoder.cpp @@ -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); diff --git a/Source/Core/Common/MathUtil.h b/Source/Core/Common/MathUtil.h index fd798d7451..599701ca16 100644 --- a/Source/Core/Common/MathUtil.h +++ b/Source/Core/Common/MathUtil.h @@ -14,12 +14,12 @@ namespace MathUtil { template -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; } diff --git a/Source/Core/Core/DSP/DSPAccelerator.cpp b/Source/Core/Core/DSP/DSPAccelerator.cpp index 0db54078ef..bd21086a9c 100644 --- a/Source/Core/Core/DSP/DSPAccelerator.cpp +++ b/Source/Core/Core/DSP/DSPAccelerator.cpp @@ -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; diff --git a/Source/Core/Core/HW/AudioInterface.cpp b/Source/Core/Core/HW/AudioInterface.cpp index 6ef12134c1..42203a951b 100644 --- a/Source/Core/Core/HW/AudioInterface.cpp +++ b/Source/Core/Core/HW/AudioInterface.cpp @@ -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++; diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/UCode_AX.cpp b/Source/Core/Core/HW/DSPHLE/UCodes/UCode_AX.cpp index b9649dda0c..5502335083 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/UCode_AX.cpp +++ b/Source/Core/Core/HW/DSPHLE/UCodes/UCode_AX.cpp @@ -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); diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/UCode_AXWii.cpp b/Source/Core/Core/HW/DSPHLE/UCodes/UCode_AXWii.cpp index 553f3bc3d0..4a82082def 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/UCode_AXWii.cpp +++ b/Source/Core/Core/HW/DSPHLE/UCodes/UCode_AXWii.cpp @@ -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); } } diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/UCode_AX_Voice.h b/Source/Core/Core/HW/DSPHLE/UCodes/UCode_AX_Voice.h index 6baf134482..1c08113af2 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/UCode_AX_Voice.h +++ b/Source/Core/Core/HW/DSPHLE/UCodes/UCode_AX_Voice.h @@ -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; diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/UCode_Zelda_ADPCM.cpp b/Source/Core/Core/HW/DSPHLE/UCodes/UCode_Zelda_ADPCM.cpp index a66228a2c3..2f9d03e9b0 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/UCode_Zelda_ADPCM.cpp +++ b/Source/Core/Core/HW/DSPHLE/UCodes/UCode_Zelda_ADPCM.cpp @@ -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; diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/UCode_Zelda_Voice.cpp b/Source/Core/Core/HW/DSPHLE/UCodes/UCode_Zelda_Voice.cpp index 20ffe61ff8..d013ef6d16 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/UCode_Zelda_Voice.cpp +++ b/Source/Core/Core/HW/DSPHLE/UCodes/UCode_Zelda_Voice.cpp @@ -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; diff --git a/Source/Core/Core/HW/StreamADPCM.cpp b/Source/Core/Core/HW/StreamADPCM.cpp index 992ce37b2f..4dc910948d 100644 --- a/Source/Core/Core/HW/StreamADPCM.cpp +++ b/Source/Core/Core/HW/StreamADPCM.cpp @@ -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; }