Skip to content

Commit

Permalink
Merged revision(s) 20376 from trunk/OpenMPT:
Browse files Browse the repository at this point in the history
[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.
........


git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.30@20378 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Mar 16, 2024
1 parent 6bf20fd commit a430ae9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion soundlib/plugins/dmo/DMOUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ namespace DMO
// 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;
Expand Down

0 comments on commit a430ae9

Please sign in to comment.