Advertisement
Guest User

Untitled

a guest
Jul 24th, 2020
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.47 KB | None | 0 0
  1.  
  2.  
  3. The XM module format description for XM files version $0104.
  4.  
  5. By Mr.H of Triton in 1994.
  6.  
  7. ============================================================================
  8. Some additions and a few corrections were made by ByteRaver & Wodan from
  9. TNT / NO-ID. Reach me at erlandvo@hotmail.com for further questions.
  10. ============================================================================
  11.  
  12. When you have to implement the XM file format in your loader, keep in
  13. mind that Triton's philosophy goes a bit like this: "If it's zero or
  14. empty, don't store it"
  15.  
  16. General layout of the XM file:
  17.  
  18. - General header (ID text, Module Name, $1a, Tracker name, see below)
  19. - header of 1st pattern
  20. - data (packed, see below) of 1st pattern
  21. - header of 2nd pattern
  22. - data (packed, see below) of 2nd pattern
  23. .....
  24. - header of last pattern
  25. - data (packed, see below) of last pattern
  26.  
  27. - 1st part of 1st instrumentheader
  28. - if nr_of_samples>0 then this data follows:
  29. - 2nd part of 1st instrumentheader
  30. - 1st sampleheader
  31. - 2nd sampleheader follows (if any)
  32. .....
  33. - last sampleheader (if any)
  34. - if the sample_size>0 (1st sample header) then sampledata of
  35. 1st sample follows
  36. - if the sample_size>0 (2nd sample header) then sampledata of
  37. 2nd sample follows
  38. .....
  39. - if the sample_size>0 (last sample header) then sampledata of
  40. last sample follows
  41.  
  42. - 1st part of 2nd instrumentheader
  43. ... same layout as 1st instrument.
  44.  
  45. - 1st part of last instrumentheader.
  46. ... same layout as 1st instrument.
  47.  
  48.  
  49.  
  50. ******************************
  51. * The XM file structure: *
  52. ******************************
  53.  
  54. The string at offset 38 should read "FastTracker II" but some trackers
  55. (e.g.
  56. DigiTracker) use this field for other purposes (DigiTracker stores the
  57. Composer's name here). This field being trashed doesn't necessarily mean
  58. that the XM file is corrupt.
  59.  
  60. Offset Length Type
  61.  
  62. 0 17 (char) ID text: 'Extended module: '
  63. 17 20 (char) Module name, padded with spaces
  64. 37 1 (char) $1a
  65. 38 20 (char) Tracker name
  66. 58 2 (word) Version number, hi-byte major and low-byte minor
  67. The current format is version $0103
  68. 60 4 (dword) Header size
  69. +4 2 (word) Song length (in patten order table)
  70. +6 2 (word) Restart position
  71. +8 2 (word) Number of channels (2,4,6,8,10,...,32)
  72. +10 2 (word) Number of patterns (max 256)
  73. +12 2 (word) Number of instruments (max 128)
  74. +14 2 (word) Flags: bit 0: 0 = Amiga frequency table (see
  75. below);
  76. 1 = Linear frequency table
  77. +16 2 (word) Default tempo
  78. +18 2 (word) Default BPM
  79. +20 256 (byte) Pattern order table
  80.  
  81. Patterns:
  82. ---------
  83.  
  84. ? 4 (dword) Pattern header length
  85. +4 1 (byte) Packing type (always 0)
  86. +5 2 (word) Number of rows in pattern (1..256)
  87. +7 2 (word) Packed patterndata size
  88.  
  89. ? ? Packed pattern data
  90.  
  91. Note that if the Module uses a totally empty pattern, this pattern
  92. is *NOT* stored in the XM; in other words, you need to create an empty
  93. pattern if the module needs one.
  94. In fact, to be save, you'll always have to create a "standard" empty
  95. pattern: allocate 64*(nr of channels) bytes and set them to value $80
  96. (128 dec). Initialise the header of this pattern with the standard
  97. values:
  98. pattern header length = 9
  99. Packing type = 0
  100. Number of rows in pattern = 64
  101. Packed patterndata size = 64*(nr of channels)
  102.  
  103. If the field "Packed patterndata size" is set to 0, the pattern is NOT
  104. stored in the file but it MAY be used by the song.
  105. Also note that whenever a pattern nr in the pattern sequence table is
  106. higher than the nr of patterns (common for converted S3M's), you should
  107. play the standard empty pattern.
  108.  
  109. Instruments:
  110. ------------
  111.  
  112. ? 4 (dword) Instrument size
  113. +4 22 (char) Instrument name
  114. +26 1 (byte) Instrument type (always 0)
  115. +27 2 (word) Number of samples in instrument
  116.  
  117. If the number of samples > 0, then the this will follow:
  118.  
  119. +29 4 (dword) Sample header size
  120. +33 96 (byte) Sample number for all notes
  121. +129 48 (word) Points for volume envelope
  122. +177 48 (word) Points for panning envelope
  123.  
  124. Envelope points: x,y...x,y.... in couples (2 words/point => a maximum of 12 points).
  125.  
  126. +225 1 (byte) Number of volume points
  127. +226 1 (byte) Number of panning points
  128. +227 1 (byte) Volume sustain point
  129. +228 1 (byte) Volume loop start point
  130. +229 1 (byte) Volume loop end point
  131. +230 1 (byte) Panning sustain point
  132. +231 1 (byte) Panning loop start point
  133. +232 1 (byte) Panning loop end point
  134. +233 1 (byte) Volume type: bit 0: On; 1: Sustain; 2: Loop
  135. +234 1 (byte) Panning type: bit 0: On; 1: Sustain; 2: Loop
  136. +235 1 (byte) Vibrato type
  137. +236 1 (byte) Vibrato sweep
  138. +237 1 (byte) Vibrato depth
  139. +238 1 (byte) Vibrato rate
  140. +239 2 (word) Volume fadeout
  141. +241 11 (word) Reserved
  142.  
  143. You should use the "sample header size" (first field of second part of
  144. instrumentheader) to compute the total size of the 2 headers as stored
  145. in the file.
  146.  
  147. Sample headers:
  148. ---------------
  149.  
  150. ? 4 (dword) Sample length
  151. +4 4 (dword) Sample loop start
  152. +8 4 (dword) Sample loop length
  153.  
  154. Note: If the sample Loop length (precedent field) is 0, the sample is *NOT*
  155. a looping one, even if the "Forward loop" bit is set in the "TYPE" field.
  156.  
  157. +12 1 (byte) Volume
  158. +13 1 (byte) Finetune (signed byte -128..+127)
  159. +14 1 (byte) Type: Bit 0-1: 0 = No loop,
  160. 1 = Forward loop,
  161. 2 = Ping-pong loop;
  162. 4: 16-bit sampledata
  163. +15 1 (byte) Panning (0-255)
  164. +16 1 (byte) Relative note number (signed byte)
  165. +17 1 (byte) Reserved
  166. +18 22 (char) Sample name
  167.  
  168. Sample data:
  169. ------------
  170.  
  171. ? ? Sample data (signed): The samples are stored
  172. as delta values. To convert to real data:
  173.  
  174. old=0;
  175. for i=1 to len
  176. new=sample[i]+old;
  177. sample[i]=new;
  178. old=new;
  179.  
  180. Even 16-bit data is stored as delta values. (It only makes really
  181. sens to store every other byte as delta value, but this is as easy.
  182. Oh, well.)
  183.  
  184.  
  185. ***********************
  186. * Pattern format: *
  187. ***********************
  188.  
  189. The patterns are stored as ordinary MOD patterns, except that each
  190. note is stored as 5 bytes:
  191.  
  192. ? 1 (byte) Note (1-96, 1 = C-0)
  193. +1 1 (byte) Instrument (1-128)
  194. +2 1 (byte) Volume column byte (see below)
  195. +3 1 (byte) Effect type
  196. +4 1 (byte) Effect parameter
  197.  
  198. (When Note = 97, a "key off" command occurs).
  199.  
  200. A simple packing scheme is also adopted, so that the patterns not become
  201. TOO large: Since the MSB in the note value is never used, if is used for
  202. the compression. If the bit is set, then the other bits are interpreted
  203. as follows:
  204.  
  205. bit 0 set: Note follows
  206. 1 set: Instrument follows
  207. 2 set: Volume column byte follows
  208. 3 set: Effect type follows
  209. 4 set: Guess what!
  210.  
  211. It is very simple, but far from optimal. If you want a better,
  212. you can always repack the patterns in your loader.
  213.  
  214. XM patterns are stored as following:
  215.  
  216. - A pattern is a sequence of lines.
  217. - A line is a sequence of notes.
  218. - a note is stored as described above.
  219.  
  220. ******************************
  221. * Volumes and envelopes: *
  222. ******************************
  223.  
  224. The volume formula:
  225.  
  226.  
  227. FinalVol=(FadeOutVol/65536)*(EnvelopeVol/64)*(GlobalVol/64)*(Vol/64)*Scale;
  228.  
  229. The panning formula:
  230.  
  231. FinalPan=Pan+(EnvelopePan-32)*(128-Abs(Pan-128))/32;
  232.  
  233. If no envelope is active, use the value 32 instead of "EnvelopePan"
  234.  
  235. Envelope:
  236. ---------
  237.  
  238. The envelopes are processed once per frame, instead of every frame where
  239. no new notes are read. This is also true for the instrument vibrato and
  240. the fadeout. Since I am so lazy and the tracker is rather self-explaining
  241. I am not going to write any more for the moment.
  242.  
  243. - max x value: 0x144 = 324d (for enveloppe points)
  244. - max y value: 0x40 = 64d (for enveloppe points)
  245.  
  246.  
  247. ********************************
  248. * Periods and frequencies: *
  249. ********************************
  250.  
  251. PatternNote = 1..96 (1 = C-0, 96 = B-7)
  252. FineTune = -128..+127 (-128 = -1 halftone, +127 = +127/128 halftones)
  253.  
  254. RelativeTone = -96..95 (0 => C-4 = C-4)
  255.  
  256. RealNote = PatternNote + RelativeTone; (0..118, 0 = C-0, 118 = A#9)
  257.  
  258. Linear frequence table:
  259. -----------------------
  260.  
  261. Period = 10*12*16*4 - Note*16*4 - FineTune/2;
  262. Frequency = 8363*2^((6*12*16*4 - Period) / (12*16*4));
  263.  
  264. The above formulas DO work as long as you don't replace "*2^" by "shl"
  265. (the result of 2^(...) is a floating point number).
  266.  
  267. When using linear Freq Tables, the distance between two octaves is
  268. 255 portamento units. e.g. the effect "1FF" at speed 1 will slide the
  269. pitch one octave up.
  270.  
  271. Amiga frequence table:
  272. ----------------------
  273.  
  274. Period = (PeriodTab[(Note MOD 12)*8 + FineTune/16]*(1-Frac(FineTune/16)) +
  275. PeriodTab[(Note MOD 12)*8 + FineTune/16+1]*(Frac(FineTune/16)))
  276. *16/2^(Note DIV 12);
  277.  
  278. (The period is interpolated for finer finetune values)
  279.  
  280. Frequency = 8363*1712/Period;
  281.  
  282.  
  283.  
  284.  
  285. PeriodTab = Array[0..12*8-1] of Word = (
  286. 907,900,894,887,881,875,868,862,856,850,844,838,832,826,820,814,
  287. 808,802,796,791,785,779,774,768,762,757,752,746,741,736,730,725,
  288. 720,715,709,704,699,694,689,684,678,675,670,665,660,655,651,646,
  289. 640,636,632,628,623,619,614,610,604,601,597,592,588,584,580,575,
  290. 570,567,563,559,555,551,547,543,538,535,532,528,524,520,516,513,
  291. 508,505,502,498,494,491,487,484,480,477,474,470,467,463,460,457);
  292.  
  293.  
  294.  
  295. *************************
  296. * Standard effects: *
  297. *************************
  298.  
  299. 0 Appregio
  300. 1 (*) Porta up
  301. 2 (*) Porta down
  302. 3 (*) Tone porta
  303. 4 (*) Vibrato
  304. 5 (*) Tone porta+Volume slide
  305. 6 (*) Vibrato+Volume slide
  306. 7 (*) Tremolo
  307. 8 Set panning
  308. 9 Sample offset
  309. A (*) Volume slide
  310. B Position jump
  311. C Set volume
  312. D Pattern break
  313. E1 (*) Fine porta up
  314. E2 (*) Fine porta down
  315. E3 Set gliss control
  316. E4 Set vibrato control
  317. E5 Set finetune
  318. E6 Set loop begin/loop
  319. E7 Set tremolo control
  320. E9 Retrig note
  321. EA (*) Fine volume slide up
  322. EB (*) Fine volume slide down
  323. EC Note cut
  324. ED Note delay
  325. EE Pattern delay
  326. F Set tempo/BPM
  327. G (010h) Set global volume
  328. H (*) (011h) Global volume slide
  329. I (012h) Unused
  330. J (013h) Unused
  331. K (014h) Unused
  332. L (015h) Set envelope position
  333. M (016h) Unused
  334. N (017h) Unused
  335. O (018h) Unused
  336. P (*) (019h) Panning slide
  337. Q (01ah) Unused
  338. R (*) (01bh) Multi retrig note
  339. S (01ch) Unused
  340. T (01dh) Tremor
  341. U (01eh) Unused
  342. V (01fh) Unused
  343. W (020h) Unused
  344. X1 (*) (021h) Extra fine porta up
  345. X2 (*) (021h) Extra fine porta down
  346.  
  347. (*) = If the command byte is zero, the last nonzero byte for the command should be used.
  348.  
  349. *********************************
  350. * Effects in volume column: *
  351. *********************************
  352.  
  353. All effects in the volume column should work as the standard effects.
  354. The volume column is interpreted before the standard effects, so
  355. some standard effects may override volume column effects.
  356.  
  357. Value Meaning
  358.  
  359. 0 Do nothing
  360. $10-$50 Set volume Value-$10
  361. : : :
  362. : : :
  363. $60-$6f Volume slide down
  364. $70-$7f Volume slide up
  365. $80-$8f Fine volume slide down
  366. $90-$9f Fine volume slide up
  367. $a0-$af Set vibrato speed
  368. $b0-$bf Vibrato
  369. $c0-$cf Set panning
  370. $d0-$df Panning slide left
  371. $e0-$ef Panning slide right
  372. $f0-$ff Tone porta
  373.  
  374.  
  375.  
  376. ============================================================================
  377.  
  378. This should be just about everything (I hope?). You will probably need
  379. some information about the MOD format and maybe about S3M.
  380.  
  381. A very good reference is MODFILxx.TXT (xx = version nr.): this file
  382. contains only very few errors, and it IS written in good English (easy
  383. to understand). I (Byteraver) will soon release a Fixed version of this file.
  384.  
  385.  
  386. Have fun!
  387.  
  388. Fredrik Huss / Mr.H of Triton
  389.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement