Skip to content

Commit

Permalink
Merged revision(s) 20957 from trunk/OpenMPT:
Browse files Browse the repository at this point in the history
[Fix] DTM: Finetune needs to be handled separately for correct period calculation. Fixes the slides in AMAI.DTM by Yerzmyey (libopenmpt only).
........


git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.30@20978 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Jun 8, 2024
1 parent e37c657 commit e4dcb25
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
23 changes: 10 additions & 13 deletions soundlib/Load_dtm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ struct DTMSample
// In revolution to come.dtm, the file header says samples rate is 24512 Hz, but samples say it's 50000 Hz
// Digital Home Studio ignores the header setting in 2.04-/2.06-style modules
mptSmp.nC5Speed = (formatVersion == DTM_PT_PATTERN_FORMAT && forcedSampleRate > 0) ? forcedSampleRate : sampleRate;
int32 transposeAmount = MOD2XMFineTune(finetune);
int32 transposeAmount = 0;
#ifdef MODPLUG_TRACKER
transposeAmount = MOD2XMFineTune(finetune);
#else
mptSmp.nFineTune = MOD2XMFineTune(finetune);
#endif
if(formatVersion == DTM_206_PATTERN_FORMAT && transpose > 0 && transpose != 48)
{
// Digital Home Studio applies this unconditionally, but some old songs sound wrong then (delirium.dtm).
Expand Down Expand Up @@ -437,26 +442,18 @@ bool CSoundFile::ReadDTM(FileReader &file, ModLoadingFlags loadFlags)
{
m->note = note + NOTE_MIN + 12;
if(position.rem)
{
m->command = CMD_MODCMDEX;
m->param = 0xD0 | static_cast<ModCommand::PARAM>(std::min(position.rem, 15));
}
m->SetEffectCommand(CMD_MODCMDEX, static_cast<ModCommand::PARAM>(0xD0 | std::min(position.rem, 15)));
} else if(note & 0x80)
{
// Lower 7 bits contain note, probably intended for MIDI-like note-on/note-off events
if(position.rem)
{
m->command = CMD_MODCMDEX;
m->param = 0xC0 | static_cast<ModCommand::PARAM>(std::min(position.rem, 15));
} else
{
m->SetEffectCommand(CMD_MODCMDEX, static_cast<ModCommand::PARAM>(0xC0 |std::min(position.rem, 15)));
else
m->note = NOTE_NOTECUT;
}
}
if(volume)
{
m->volcmd = VOLCMD_VOLUME;
m->vol = std::min(volume, uint8(64)); // Volume can go up to 255, but we do not support over-amplification at the moment.
m->SetVolumeCommand(VOLCMD_VOLUME, std::min(volume, uint8(64))); // Volume can go up to 255, but we do not support over-amplification at the moment.
}
if(instr)
{
Expand Down
11 changes: 8 additions & 3 deletions soundlib/Snd_fx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5990,11 +5990,16 @@ uint32 CSoundFile::GetPeriodFromNote(uint32 note, int32 nFineTune, uint32 nC5Spe
note -= NOTE_MIN;
if(!UseFinetuneAndTranspose())
{
if(GetType() & (MOD_TYPE_MDL | MOD_TYPE_DTM))
if(GetType() == MOD_TYPE_MDL)
{
// MDL uses non-linear slides, but their effectiveness does not depend on the middle-C frequency.
MPT_ASSERT(!PeriodsAreFrequencies());
return (FreqS3MTable[note % 12u] << 4) >> (note / 12);
} else if(GetType() == MOD_TYPE_DTM)
{
// Similar to MDL, but finetune is factored in and we don't transpose everything by an octave
MPT_ASSERT(!PeriodsAreFrequencies());
return (ProTrackerTunedPeriods[XM2MODFineTune(nFineTune) * 12u + note % 12u] << 5) >> (note / 12u);
}
if(!nC5Speed)
nC5Speed = 8363;
Expand Down Expand Up @@ -6110,7 +6115,7 @@ uint32 CSoundFile::GetFreqFromPeriod(uint32 period, uint32 c5speed, int32 nPerio
{
// We only really use c5speed for the finetune pattern command. All samples in 669 files have the same middle-C speed (imported as 8363 Hz).
return (period + c5speed - 8363) << FREQ_FRACBITS;
} else if(GetType() & (MOD_TYPE_MDL | MOD_TYPE_DTM))
} else if(GetType() == MOD_TYPE_MDL)
{
MPT_ASSERT(!PeriodsAreFrequencies());
LimitMax(period, Util::MaxValueOfType(period) >> 8);
Expand All @@ -6124,7 +6129,7 @@ uint32 CSoundFile::GetFreqFromPeriod(uint32 period, uint32 c5speed, int32 nPerio
// Input is already a frequency in Hertz, not a period.
static_assert(FREQ_FRACBITS <= 8, "Check this shift operator");
return uint32(((uint64(period) << 8) + nPeriodFrac) >> (8 - FREQ_FRACBITS));
} else if(m_SongFlags[SONG_LINEARSLIDES])
} else if(m_SongFlags[SONG_LINEARSLIDES] || GetType() == MOD_TYPE_DTM)
{
if(!c5speed)
c5speed = 8363;
Expand Down

0 comments on commit e4dcb25

Please sign in to comment.