(This time correctly, it doesn't clamp in-place like mine did.)
| ... | ... |
@@ -563,7 +563,7 @@ void Channel::Update() |
| 563 | 563 |
if (bModulation && this->modType == 1) |
| 564 | 564 |
totalVol += modParam; |
| 565 | 565 |
totalVol += AMPL_K; |
| 566 |
- clamp(totalVol, 0, AMPL_K); |
|
| 566 |
+ totalVol = std::clamp(totalVol, 0, AMPL_K); |
|
| 567 | 567 |
|
| 568 | 568 |
cr &= ~(SOUND_VOL(0x7F) | SOUND_VOLDIV(3)); |
| 569 | 569 |
cr |= SOUND_VOL(static_cast<int>(getvoltbl[totalVol])); |
| ... | ... |
@@ -587,7 +587,7 @@ void Channel::Update() |
| 587 | 587 |
if (bModulation && this->modType == 2) |
| 588 | 588 |
realPan += modParam; |
| 589 | 589 |
realPan += 64; |
| 590 |
- clamp(realPan, 0, 127); |
|
| 590 |
+ realPan = std::clamp(realPan, 0, 127); |
|
| 591 | 591 |
|
| 592 | 592 |
cr &= ~SOUND_PAN(0x7F); |
| 593 | 593 |
cr |= SOUND_PAN(realPan); |
| ... | ... |
@@ -51,15 +51,6 @@ template<typename T> inline typename std::enable_if_t<std::is_integral_v<T>, T> |
| 51 | 51 |
return value + 1; |
| 52 | 52 |
} |
| 53 | 53 |
|
| 54 |
-// Clamp a value between a minimum and maximum value |
|
| 55 |
-template<typename T1, typename T2> inline void clamp(T1 &valueToClamp, const T2 &minValue, const T2 &maxValue) |
|
| 56 |
-{
|
|
| 57 |
- if (valueToClamp < minValue) |
|
| 58 |
- valueToClamp = minValue; |
|
| 59 |
- else if (valueToClamp > maxValue) |
|
| 60 |
- valueToClamp = maxValue; |
|
| 61 |
-} |
|
| 62 |
- |
|
| 63 | 54 |
inline void CopyToString(const std::wstring &src, wchar_t *dst) |
| 64 | 55 |
{
|
| 65 | 56 |
std::wcscpy(dst, src.c_str()); |
| ... | ... |
@@ -167,8 +167,8 @@ bool XSFPlayer::FillBuffer(std::vector<std::uint8_t> &buf, unsigned &samplesWrit |
| 167 | 167 |
double s1 = bufLong[2 * ofs] * scale, s2 = bufLong[2 * ofs + 1] * scale; |
| 168 | 168 |
if (!this->uses32BitSamplesClampedTo16Bit) |
| 169 | 169 |
{
|
| 170 |
- clamp(s1, std::numeric_limits<std::int16_t>::min(), std::numeric_limits<std::int16_t>::max()); |
|
| 171 |
- clamp(s2, std::numeric_limits<std::int16_t>::min(), std::numeric_limits<std::int16_t>::max()); |
|
| 170 |
+ s1 = std::clamp<double>(s1, std::numeric_limits<std::int16_t>::min(), std::numeric_limits<std::int16_t>::max()); |
|
| 171 |
+ s2 = std::clamp<double>(s2, std::numeric_limits<std::int16_t>::min(), std::numeric_limits<std::int16_t>::max()); |
|
| 172 | 172 |
} |
| 173 | 173 |
bufLong[2 * ofs] = static_cast<std::int32_t>(s1); |
| 174 | 174 |
bufLong[2 * ofs + 1] = static_cast<std::int32_t>(s2); |
| ... | ... |
@@ -181,8 +181,8 @@ bool XSFPlayer::FillBuffer(std::vector<std::uint8_t> &buf, unsigned &samplesWrit |
| 181 | 181 |
for (unsigned ofs = 0; ofs < bufsize; ++ofs) |
| 182 | 182 |
{
|
| 183 | 183 |
std::int32_t s1 = bufLong[2 * ofs], s2 = bufLong[2 * ofs + 1]; |
| 184 |
- clamp(s1, std::numeric_limits<std::int16_t>::min(), std::numeric_limits<std::int16_t>::max()); |
|
| 185 |
- clamp(s2, std::numeric_limits<std::int16_t>::min(), std::numeric_limits<std::int16_t>::max()); |
|
| 184 |
+ s1 = std::clamp<std::int32_t>(s1, std::numeric_limits<std::int16_t>::min(), std::numeric_limits<std::int16_t>::max()); |
|
| 185 |
+ s2 = std::clamp<std::int32_t>(s2, std::numeric_limits<std::int16_t>::min(), std::numeric_limits<std::int16_t>::max()); |
|
| 186 | 186 |
bufShort[2 * ofs] = static_cast<std::int16_t>(s1); |
| 187 | 187 |
bufShort[2 * ofs + 1] = static_cast<std::int16_t>(s2); |
| 188 | 188 |
} |