From: <sv...@op...> - 2024-03-16 20:57:07
|
Author: sagamusix Date: Sat Mar 16 21:56:54 2024 New Revision: 20376 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20376 Log: [Fix] Distortion DMO: The UB fix in r15730 did not correspond to the actually observed behaviour, thus causing the Distortion plugin to sound different in some situations. Modified: trunk/OpenMPT/soundlib/plugins/dmo/DMOUtils.cpp Modified: trunk/OpenMPT/soundlib/plugins/dmo/DMOUtils.cpp ============================================================================== --- trunk/OpenMPT/soundlib/plugins/dmo/DMOUtils.cpp Sat Mar 16 08:21:34 2024 (r20375) +++ trunk/OpenMPT/soundlib/plugins/dmo/DMOUtils.cpp Sat Mar 16 21:56:54 2024 (r20376) @@ -26,7 +26,12 @@ // Computes (log2(x) + 1) * 2 ^ (shiftL - shiftR) (x = -2^31...2^31) float logGain(float x, int32 shiftL, int32 shiftR) { - uint32 intSample = static_cast<uint32>(static_cast<int64>(x)); + uint32 intSample; + if(x <= static_cast<float>(int32_min) || x > static_cast<float>(int32_max)) + intSample = static_cast<uint32>(int32_min); + else + intSample = static_cast<uint32>(static_cast<int32>(x)); + const uint32 sign = intSample & 0x80000000; if(sign) intSample = (~intSample) + 1; |