Revert "Removed my clamp function to use the C++17 one."
This reverts commit 781afb69fea3ab7399fa53320e986f1ea09994e2.
--- a/src/in_ncsf/SSEQPlayer/Channel.cpp
+++ b/src/in_ncsf/SSEQPlayer/Channel.cpp
@@ -563,7 +563,7 @@
if (bModulation && this->modType == 1)
totalVol += modParam;
totalVol += AMPL_K;
- std::clamp(totalVol, 0, AMPL_K);
+ clamp(totalVol, 0, AMPL_K);
cr &= ~(SOUND_VOL(0x7F) | SOUND_VOLDIV(3));
cr |= SOUND_VOL(static_cast<int>(getvoltbl[totalVol]));
@@ -587,7 +587,7 @@
if (bModulation && this->modType == 2)
realPan += modParam;
realPan += 64;
- std::clamp(realPan, 0, 127);
+ clamp(realPan, 0, 127);
cr &= ~SOUND_PAN(0x7F);
cr |= SOUND_PAN(realPan);
--- a/src/in_xsf_framework/CMakeLists.txt
+++ b/src/in_xsf_framework/CMakeLists.txt
@@ -243,7 +243,7 @@
target_compile_options(in_xsf_framework PUBLIC
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:-Wall -Wctor-dtor-privacy -Wold-style-cast -Wextra -Wno-div-by-zero -Wfloat-equal -Wshadow -Winit-self -Wcast-qual -Wunreachable-code -Woverloaded-virtual -Wno-long-long -Wno-switch>
$<$<CXX_COMPILER_ID:GNU>:-Wlogical-op>
- $<$<CXX_COMPILER_ID:MSVC>:/W4 /wd4244 /wd4834 /wd6258 /wd26451 /wd28159>)
+ $<$<CXX_COMPILER_ID:MSVC>:/W4 /wd4244 /wd6258 /wd26451 /wd28159>)
target_include_directories(in_xsf_framework PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/winamp
--- a/src/in_xsf_framework/XSFCommon.h
+++ b/src/in_xsf_framework/XSFCommon.h
@@ -51,6 +51,15 @@
return value + 1;
}
+// Clamp a value between a minimum and maximum value
+template<typename T1, typename T2> inline void clamp(T1 &valueToClamp, const T2 &minValue, const T2 &maxValue)
+{
+ if (valueToClamp < minValue)
+ valueToClamp = minValue;
+ else if (valueToClamp > maxValue)
+ valueToClamp = maxValue;
+}
+
inline void CopyToString(const std::wstring &src, wchar_t *dst)
{
std::wcscpy(dst, src.c_str());
--- a/src/in_xsf_framework/XSFPlayer.cpp
+++ b/src/in_xsf_framework/XSFPlayer.cpp
@@ -167,8 +167,8 @@
double s1 = bufLong[2 * ofs] * scale, s2 = bufLong[2 * ofs + 1] * scale;
if (!this->uses32BitSamplesClampedTo16Bit)
{
- std::clamp(s1, static_cast<double>(std::numeric_limits<std::int16_t>::min()), static_cast<double>(std::numeric_limits<std::int16_t>::max()));
- std::clamp(s2, static_cast<double>(std::numeric_limits<std::int16_t>::min()), static_cast<double>(std::numeric_limits<std::int16_t>::max()));
+ clamp(s1, std::numeric_limits<std::int16_t>::min(), std::numeric_limits<std::int16_t>::max());
+ clamp(s2, std::numeric_limits<std::int16_t>::min(), std::numeric_limits<std::int16_t>::max());
}
bufLong[2 * ofs] = static_cast<std::int32_t>(s1);
bufLong[2 * ofs + 1] = static_cast<std::int32_t>(s2);
@@ -181,8 +181,8 @@
for (unsigned ofs = 0; ofs < bufsize; ++ofs)
{
std::int32_t s1 = bufLong[2 * ofs], s2 = bufLong[2 * ofs + 1];
- std::clamp(s1, static_cast<std::int32_t>(std::numeric_limits<std::int16_t>::min()), static_cast<std::int32_t>(std::numeric_limits<std::int16_t>::max()));
- std::clamp(s2, static_cast<std::int32_t>(std::numeric_limits<std::int16_t>::min()), static_cast<std::int32_t>(std::numeric_limits<std::int16_t>::max()));
+ clamp(s1, std::numeric_limits<std::int16_t>::min(), std::numeric_limits<std::int16_t>::max());
+ clamp(s2, std::numeric_limits<std::int16_t>::min(), std::numeric_limits<std::int16_t>::max());
bufShort[2 * ofs] = static_cast<std::int16_t>(s1);
bufShort[2 * ofs + 1] = static_cast<std::int16_t>(s2);
}