ModPlug Central

OpenMPT => Development Corner => Topic started by: bass on December 20, 2015, 21:02:55

Title: XM amiga period calculation
Post by: bass on December 20, 2015, 21:02:55
Hi,

I´m trying to implement the XM format for my player and I have a question about the format.
In the document of Triton, the period for amiga frequence is calculated like this:

Period = (PeriodTab[(Note MOD 12)*8 + FineTune/16]*(1-Frac(FineTune/16)) +
        PeriodTab[(Note MOD 12)*8 + FineTune/16]*(Frac(FineTune/16)))
       *16/2^(Note DIV 12);

There are some errors in this formula, I think. One is, that I get negative values for PeriodTab when Finetune is negative. Should I take the first value in the PeriodTab then? Is there an easier formula for this perhaps?

Thx!
Title: Re: XM amiga period calculation
Post by: Saga Musix on December 20, 2015, 23:51:56
Treating finetune to be 0...255 instead of -128...127 should probably help with the negative values.
I think the formula in the FT2 docs should be correct but you can double-check by looking at what OpenMPT does in Snd_fx.cpp (https://source.openmpt.org/browse/openmpt/trunk/OpenMPT/soundlib/Snd_fx.cpp), namely in GetPeriodFromNote and GetFreqFromPeriod in the MOD_TYPE_XM cases. There are some gotchas documented there that are not obvious at all from any documentation, and they result in very weird behaviour in frequency calculation that is supported by few XM players.