Author: sagamusix
Date: Sun Apr 28 00:16:56 2024
New Revision: 20666
URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20666
Log:
Merged revision(s) 20662 from trunk/OpenMPT:
[Fix] Opal: With mix rates exceeding 131kHz, it was possible that the interpolated output overflowed. The new linear interpolation is based on OpenMPT's own mixer code, and may also be slightly faster because it divides by SampleRate only once (https://bugs.openmpt.org/view.php?id=1775).
........
Modified:
branches/OpenMPT-1.28/ (props changed)
branches/OpenMPT-1.28/soundlib/opal.h
Modified: branches/OpenMPT-1.28/soundlib/opal.h
==============================================================================
--- branches/OpenMPT-1.28/soundlib/opal.h Sun Apr 28 00:15:29 2024 (r20665)
+++ branches/OpenMPT-1.28/soundlib/opal.h Sun Apr 28 00:16:56 2024 (r20666)
@@ -21,6 +21,7 @@
#include <cstdint>
+#include "../common/mptBaseUtils.h"
@@ -563,9 +564,9 @@
}
// Mix with the partial accumulation
- int32_t omblend = SampleRate - SampleAccum;
- *left = static_cast<uint16_t>((LastOutput[0] * omblend + CurrOutput[0] * SampleAccum) / SampleRate);
- *right = static_cast<uint16_t>((LastOutput[1] * omblend + CurrOutput[1] * SampleAccum) / SampleRate);
+ const int32_t fract = Util::muldivr(SampleAccum, 65536, SampleRate);
+ *left = static_cast<int16_t>(LastOutput[0] + ((fract * (CurrOutput[0] - LastOutput[0])) / 65536));
+ *right = static_cast<int16_t>(LastOutput[1] + ((fract * (CurrOutput[1] - LastOutput[1])) / 65536));
SampleAccum += OPL3SampleRate;
}
@@ -595,14 +596,14 @@
else if (leftmix > 0x7FFF)
left = 0x7FFF;
else
- left = static_cast<uint16_t>(leftmix);
+ left = static_cast<int16_t>(leftmix);
if (rightmix < -0x8000)
right = -0x8000;
else if (rightmix > 0x7FFF)
right = 0x7FFF;
else
- right = static_cast<uint16_t>(rightmix);
+ right = static_cast<int16_t>(rightmix);
Clock++;
|