Browse code

Removed my clamp function to use the C++17 one.

Naram Qashat authored on 2021/04/06 00:05:39
Showing 4 changed files
... ...
@@ -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
+			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
+			std::clamp(realPan, 0, 127);
591 591
 
592 592
 			cr &= ~SOUND_PAN(0x7F);
593 593
 			cr |= SOUND_PAN(realPan);
... ...
@@ -243,7 +243,7 @@ target_compile_definitions(in_xsf_framework PUBLIC
243 243
 target_compile_options(in_xsf_framework PUBLIC
244 244
 	$<$<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>
245 245
 	$<$<CXX_COMPILER_ID:GNU>:-Wlogical-op>
246
-	$<$<CXX_COMPILER_ID:MSVC>:/W4 /wd4244 /wd6258 /wd26451 /wd28159>)
246
+	$<$<CXX_COMPILER_ID:MSVC>:/W4 /wd4244 /wd4834 /wd6258 /wd26451 /wd28159>)
247 247
 target_include_directories(in_xsf_framework PUBLIC
248 248
 	${CMAKE_CURRENT_SOURCE_DIR}
249 249
 	${CMAKE_CURRENT_SOURCE_DIR}/winamp
... ...
@@ -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
+				std::clamp(s1, static_cast<double>(std::numeric_limits<std::int16_t>::min()), static_cast<double>(std::numeric_limits<std::int16_t>::max()));
171
+				std::clamp(s2, static_cast<double>(std::numeric_limits<std::int16_t>::min()), static_cast<double>(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
+			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()));
185
+			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()));
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
 		}