Skip to content

Commit

Permalink
[Fix] Fix inconsistency in length calculation and actual playback len…
Browse files Browse the repository at this point in the history
…gth in libopenmpt with tempo commands below 32 BPM in various formats (MDL, MED among others).

[Imp] MED: Allow tempo parameters < 32 BPM in OpenMPT. libopenmpt already supported them.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@21286 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Jul 25, 2024
1 parent bcac180 commit e771394
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 0 additions & 4 deletions soundlib/Load_med.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,6 @@ static std::pair<EffectCommand, ModCommand::PARAM> ConvertMEDEffect(ModCommand &
return {CMD_XPARAM, static_cast<ModCommand::PARAM>(tempo & 0xFF)};
}
}
#ifdef MODPLUG_TRACKER
if(m.param < 0x20)
m.param = 0x20;
#endif // MODPLUG_TRACKER
} else switch(param)
{
case 0xF1: // Play note twice
Expand Down
10 changes: 8 additions & 2 deletions soundlib/Snd_fx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ static uint32 GetLinearSlideUpTable (const CSoundFile *sndFile, uint32 i) {
static uint32 GetFineLinearSlideDownTable(const CSoundFile *sndFile, uint32 i) { MPT_ASSERT(i < std::size(FineLinearSlideDownTable)); return sndFile->m_playBehaviour[kPeriodsAreHertz] ? FineLinearSlideDownTable[i] : FineLinearSlideUpTable[i]; }
static uint32 GetFineLinearSlideUpTable (const CSoundFile *sndFile, uint32 i) { MPT_ASSERT(i < std::size(FineLinearSlideDownTable)); return sndFile->m_playBehaviour[kPeriodsAreHertz] ? FineLinearSlideUpTable[i] : FineLinearSlideDownTable[i]; }

// Minimum parameter of tempo command that is considered to be a BPM rather than a tempo slide
static constexpr TEMPO GetMinimumTempoParam(MODTYPE modType)
{
return (modType & (MOD_TYPE_MDL | MOD_TYPE_MED | MOD_TYPE_XM | MOD_TYPE_MOD)) ? TEMPO(1, 0) : TEMPO(32, 0);
}


////////////////////////////////////////////////////////////
// Length
Expand Down Expand Up @@ -754,7 +760,7 @@ std::vector<GetLengthType> CSoundFile::GetLength(enmGetLengthResetMode adjustMod
}

const auto &specs = GetModSpecifications();
if(tempo.GetInt() >= 0x20)
if(tempo >= GetMinimumTempoParam(GetType()))
{
#if MPT_MSVC_BEFORE(2019, 0)
// Work-around for VS2017 /std:c++17 /permissive-
Expand Down Expand Up @@ -6351,7 +6357,7 @@ void CSoundFile::SetTempo(TEMPO param, bool setFromUI)
const CModSpecifications &specs = GetModSpecifications();

// Anything lower than the minimum tempo is considered to be a tempo slide
const TEMPO minTempo = (GetType() & (MOD_TYPE_MDL | MOD_TYPE_MED | MOD_TYPE_MOD)) ? TEMPO(1, 0) : TEMPO(32, 0);
const TEMPO minTempo = GetMinimumTempoParam(GetType());

if(setFromUI)
{
Expand Down

0 comments on commit e771394

Please sign in to comment.