Skip to content

Commit

Permalink
Merged revision(s) 20660-20662 from trunk/OpenMPT:
Browse files Browse the repository at this point in the history
[Fix] S3M: In mono mode, the ratio between sample and OPL volume was incorrect (https://bugs.openmpt.org/view.php?id=1774).
........
[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).
........


git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.30@20664 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Apr 27, 2024
1 parent 11975ee commit ce85dfd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
17 changes: 10 additions & 7 deletions soundlib/Load_s3m.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,15 +432,18 @@ bool CSoundFile::ReadS3M(FileReader &file, ModLoadingFlags loadFlags)
else
m_nSamplePreAmp = std::max(fileHeader.masterVolume & 0x7F, 0x10); // Bit 7 = Stereo (we always use stereo)

const bool isStereo = (fileHeader.masterVolume & 0x80) != 0 || m_dwLastSavedWithVersion;
if(!isStereo)
m_nSamplePreAmp = Util::muldivr_unsigned(m_nSamplePreAmp, 8, 11);

// Approximately as loud as in DOSBox and a real SoundBlaster 16
m_nVSTiVolume = 36;
if(isSchism && schismDateVersion < SchismVersionFromDate<2018, 11, 12>::date)
m_nVSTiVolume = 64;

const bool isStereo = (fileHeader.masterVolume & 0x80) != 0 || m_dwLastSavedWithVersion;
if(!isStereo)
{
m_nSamplePreAmp = Util::muldivr_unsigned(m_nSamplePreAmp, 8, 11);
m_nVSTiVolume = Util::muldivr_unsigned(m_nVSTiVolume, 8, 11);
}

// Channel setup
m_nChannels = 4;
std::bitset<32> isAdlibChannel;
Expand Down Expand Up @@ -484,8 +487,7 @@ bool CSoundFile::ReadS3M(FileReader &file, ModLoadingFlags loadFlags)
// Read extended channel panning
if(fileHeader.usePanningTable == S3MFileHeader::idPanning)
{
uint8 pan[32];
file.ReadArray(pan);
const auto pan = file.ReadArray<uint8, 32>();
for(CHANNELINDEX i = 0; i < 32; i++)
{
if((pan[i] & 0x20) != 0 && (!isST3 || !isAdlibChannel[i]))
Expand Down Expand Up @@ -818,7 +820,8 @@ bool CSoundFile::SaveS3M(std::ostream &f) const

// Write patterns
enum class S3MChannelType : uint8 { kUnused = 0, kPCM = 1, kAdlib = 2 };
FlagSet<S3MChannelType> channelType[32] = { S3MChannelType::kUnused };
std::array<FlagSet<S3MChannelType>, 32> channelType;
channelType.fill(S3MChannelType::kUnused);
bool globalCmdOnMutedChn = false;
for(PATTERNINDEX pat = 0; pat < writePatterns; pat++)
{
Expand Down
11 changes: 6 additions & 5 deletions soundlib/opal.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@


#include <cstdint>
#include "../common/mptBaseUtils.h"



Expand Down Expand Up @@ -574,9 +575,9 @@ void Opal::Sample(int16_t *left, int16_t *right) {
}

// 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;
}
Expand Down Expand Up @@ -606,14 +607,14 @@ void Opal::Output(int16_t &left, int16_t &right) {
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++;

Expand Down

0 comments on commit ce85dfd

Please sign in to comment.