The XM module format description for XM files version $0104. By Mr.H of Triton in 1994. - Be prepared!

Are you sure you want to know? :-) ============================================================================ ****************************** * The XM file structure: * ****************************** Offset Length Type 0 17 37 38 58 60 +4 +6 +8 +10 +12 +14 +16 +18 +20 17 20 1 20 2 4 2 2 2 2 2 2 2 2 256 (char) (char) (char) (char) (word) (dword) (word) (word) (word) (word) (word) (word) ID text: 'Extended module: ' Module name, padded with zeroes $1a Tracker name Version number, hi-byte major and low-byte minor The current format is version $0103

Header size Song length (in patten order table) Restart position Number of channels (2,4,6,8,10,...,32) Number of patterns (max 256) Number of instruments (max 128) Flags: bit 0: 0 = Amiga frequency table (see below); 1 = Linear frequency table (word) Default tempo (word) Default BPM (byte) Pattern order table Patterns: ---------

? +4 +5 +7 ?

4 1 2 2 ?

(dword) (byte) (word) (word)

Pattern header length Packing type (always 0) Number of rows in pattern (1..256) Packed patterndata size Packed pattern data Instruments: ------------

? +4 +26 +27

4 22 1 2

(dword) (char) (byte) (word)

Instrument size Instrument name Instrument type (always 0) Number of samples in instrument

If the number of samples > 0, then the this will follow: ! ! ! +29 +33 +129 4 96 48 (dword) Sample header size (byte) Sample number for all notes (byte) Points for volume envelope

! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !

+177 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +241

48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2

(byte) (byte) (byte) (byte) (byte) (byte) (byte) (byte) (byte) (byte) (byte) (byte) (byte) (byte) (byte) (word) (word)

Points for panning envelope Number of volume points Number of panning points Volume sustain point Volume loop start point Volume loop end point Panning sustain point Panning loop start point Panning loop end point Volume type: bit 0: On; 1: Sustain; 2: Loop Panning type: bit 0: On; 1: Sustain; 2: Loop Vibrato type Vibrato sweep Vibrato depth Vibrato rate Volume fadeout Reserved Sample headers: ---------------

? +4 +8 +12 +13 +14 +15 +16 +17 +18

4 4 4 1 1 1 1 1 1 22

(dword) (dword) (dword) (byte) (byte) (byte) (byte) (byte) (byte) (char)

Sample length Sample loop start Sample loop length Volume Finetune (signed byte -16..+15) Type: Bit 0-1: 0 = No loop, 1 = Forward loop, 2 = Ping-pong loop; 4: 16-bit sampledata Panning (0-255) Relative note number (signed byte) Reserved Sample name Sample data: ------------

?

?

Sample data (signed): The samples are stored as delta values. To convert to real data: old=0; for i=1 to len new=sample[i]+old; sample[i]=new; old=new;

*********************** * Pattern format: * *********************** The patterns are stored as ordinary MOD patterns, except that each note is stored as 5 bytes: ? +1 +2 1 1 1 (byte) Note (0-71, 0 = C-0) (byte) Instrument (0-128) (byte) Volume column byte (see below)

+3 +4

1 1

(byte) Effect type (byte) Effect parameter

A simle packing scheme is also adopted, so that the patterns not become TOO large: Since the MSB in the note value is never used, if is used for the compression. If the bit is set, then the other bits are interpreted as follows: bit 0 1 2 3 4 set: set: set: set: set: Note follows Instrument follows Volume column byte follows Effect type follows Guess what!

It is very simple, but far from optimal. If you want a better, you can always repack the patterns in your loader.

****************************** * Volumes and envelopes: * ****************************** The volume formula: FinalVol=(FadeOutVol/65536)*(EnvelopeVol/64)*(GlobalVol/64)*(Vol/64)*Scale; The panning formula: FinalPan=Pan+(EnvelopePan-32)*(128-Abs(Pan-128))/32; Envelope: --------The envelopes are processed once per frame, instead of every frame where no new notes are read. This is also true for the instrument vibrato and the fadeout. Since I am so lazy and the tracker is rather self-explaining I am not going to write any more for the moment. ******************************** * Periods and frequencies: * ******************************** PatternNote = 0..95 (0 = C-0, 95 = B-7) FineTune = -128..+127 (-128 = -1 halftone, +127 = +127/128 halftones) RelativeTone = -96..95 (0 => C-4 = C-4) RealNote = PatternNote + RelativeTone; (0..118, 0 = C-0, 118 = A#9) Linear frequence table: ----------------------Period = 10*12*16*4 - Note*16*4 - FineTune/2; Frequency = 8363*2^((6*12*16*4 - Period) / (12*16*4)); Amiga frequence table:

---------------------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); (The period is interpolated for finer finetune values) Frequency = 8363*1712/Period; PeriodTab = Array[0..12*8-1] of Word = ( 907,900,894,887,881,875,868,862,856,850,844,838,832,826,820,814, 808,802,796,791,785,779,774,768,762,757,752,746,741,736,730,725, 720,715,709,704,699,694,689,684,678,675,670,665,660,655,651,646, 640,636,632,628,623,619,614,610,604,601,597,592,588,584,580,575, 570,567,563,559,555,551,547,543,538,535,532,528,524,520,516,513, 508,505,502,498,494,491,487,484,480,477,474,470,467,463,460,457); ************************* * Standard effects: * ************************* 0 1 2 3 4 5 6 7 8 9 A B C D E1 E2 E3 E4 E5 E6 E7 E9 EA EB EC ED EE F G H K L P R T X1 X2 (*) (*) (*) (*) (*) (*) (*) (*) Appregio Porta up Porta down Tone porta Vibrato Tone porta+Volume slide Vibrato+Volume slide Tremolo Set panning Sample offset Volume slide Position jump Set volume Pattern break Fine porta up Fine porta down Set gliss control Set vibrato control Set finetune Set loop begin/loop Set tremolo control Retrig note Fine volume slide up Fine volume slide down Note cut Note delay Pattern delay Set tempo/BPM Set global volume Global volume slide Key off Set envelope position Panning slide Multi retrig note Tremor Extra fine porta up Extra fine porta down

(*) (*)

(*) (*)

(*) (*) (*) (*) (*)

(*) = If the command byte is zero, the last nonzero byte for the command should be used. ********************************* * Effects in volume column: * ********************************* All effects in the volume column should work as the standard effects. The volume column is interpreted before the standard effects, so some standard effects may override volume column effects. Value 0 $10-$50 : : $60-$6f $70-$7f $80-$8f $90-$9f $a0-$af $b0-$bf $c0-$cf $d0-$df $e0-$ef $f0-$ff Meaning Do nothing Set volume Value-$10 : : : : Volume slide down Volume slide up Fine volume slide down Fine volume slide up Set vibrato speed Vibrato Set panning Panning slide left Panning slide right Tone porta

============================================================================ This should be just about everything (I hope?). You will probably need some information about the MOD format and maybe about S3M. Have fun! Fredrik Huss / Mr.H of Triton