From: <sv...@op...> - 2024-09-09 18:12:27
|
Author: sagamusix Date: Mon Sep 9 20:12:14 2024 New Revision: 21577 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=21577 Log: [Fix] PTM: PolyTracker uses square root panning like FT2, and has a bug where the leftmost and rightmost positions play the sample without any attenuation on the left and right channels. Fixes bass balance in "BugFixed (The Song)" by Vic (https://www.un4seen.com/forum/?topic=15448.msg143684#msg143684). Modified: trunk/OpenMPT/soundlib/Load_ptm.cpp trunk/OpenMPT/soundlib/Sndmix.cpp Modified: trunk/OpenMPT/soundlib/Load_ptm.cpp ============================================================================== --- trunk/OpenMPT/soundlib/Load_ptm.cpp Mon Sep 9 12:37:58 2024 (r21576) +++ trunk/OpenMPT/soundlib/Load_ptm.cpp Mon Sep 9 20:12:14 2024 (r21577) @@ -175,6 +175,7 @@ m_modFormat.madeWithTracker = MPT_UFORMAT("PolyTracker {}.{}")(fileHeader.versionHi.get(), mpt::ufmt::hex0<2>(fileHeader.versionLo.get())); m_modFormat.charset = mpt::Charset::CP437; + SetMixLevels(MixLevels::CompatibleFT2); m_SongFlags = SONG_ITCOMPATGXX | SONG_ITOLDEFFECTS; m_nSamples = std::min(static_cast<SAMPLEINDEX>(fileHeader.numSamples), static_cast<SAMPLEINDEX>(MAX_SAMPLES - 1)); ReadOrderFromArray(Order(), fileHeader.orders, fileHeader.numOrders, 0xFF, 0xFE); @@ -265,8 +266,7 @@ { case CMD_PANNING8: // Don't be surprised about the strange formula, this is directly translated from original disassembly... - m.command = CMD_S3MCMDEX; - m.param = 0x80 | ((std::max<uint8>(m.param >> 3, 1u) - 1u) & 0x0F); + m.SetEffectCommand(CMD_S3MCMDEX, static_cast<ModCommand::PARAM>(0x80 | ((std::max<uint8>(m.param >> 3, 1u) - 1u) & 0x0F))); break; case CMD_GLOBALVOLUME: m.param = std::min(m.param, uint8(0x40)) * 2u; @@ -277,8 +277,7 @@ } if(b & 0x80) { - m.volcmd = VOLCMD_VOLUME; - m.vol = file.ReadUint8(); + m.SetVolumeCommand(VOLCMD_VOLUME, file.ReadUint8()); } } } Modified: trunk/OpenMPT/soundlib/Sndmix.cpp ============================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp Mon Sep 9 12:37:58 2024 (r21576) +++ trunk/OpenMPT/soundlib/Sndmix.cpp Mon Sep 9 20:12:14 2024 (r21577) @@ -2484,15 +2484,10 @@ { int32 pan = (m_MixerSettings.gnChannels >= 2) ? Clamp(chn.nRealPan, 0, 256) : 128; - int32 realvol; - if(m_PlayConfig.getUseGlobalPreAmp()) - { - realvol = (chn.nRealVolume * kChnMasterVol) / 128; - } else - { - // Extra attenuation required here if we're bypassing pre-amp. - realvol = (chn.nRealVolume * kChnMasterVol) / 256; - } + int32 realvol = (chn.nRealVolume * kChnMasterVol) / 128; + // Extra attenuation required here if we're bypassing pre-amp. + if(!m_PlayConfig.getUseGlobalPreAmp()) + realvol /= 2; const PanningMode panningMode = m_PlayConfig.getPanningMode(); if(panningMode == PanningMode::SoftPanning || (panningMode == PanningMode::Undetermined && (m_MixerSettings.MixerFlags & SNDMIX_SOFTPANNING))) @@ -2513,10 +2508,19 @@ // you can never truly achieve 100% right panning in FT2, only 100% left. // Test case: FT2PanLaw.xm LimitMax(pan, 255); - const int panL = pan > 0 ? XMPanningTable[256 - pan] : 65536; - const int panR = XMPanningTable[pan]; - chn.newLeftVol = (realvol * panL) / 65536; - chn.newRightVol = (realvol * panR) / 65536; + + // PolyTracker also uses square root panning, but there's a bug where the leftmost and rightmost pan positions play the sample centered, without any attenuation. + if(GetType() == MOD_TYPE_PTM && (pan == 0 || pan == 255)) + { + chn.newLeftVol = realvol; + chn.newRightVol = realvol; + } else + { + const int panL = pan > 0 ? XMPanningTable[256 - pan] : 65536; + const int panR = XMPanningTable[pan]; + chn.newLeftVol = (realvol * panL) / 65536; + chn.newRightVol = (realvol * panR) / 65536; + } } else { chn.newLeftVol = (realvol * (256 - pan)) / 256; |