Advertisement
Guest User

Untitled

a guest
Jul 24th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.53 KB | None | 0 0
  1.  
  2.  
  3.  
  4. The XM module format description for XM files version $0104.
  5.  
  6. By Mr.H of Triton in 1994.
  7.  
  8. - Be prepared! Are you sure you want to know? :-)
  9.  
  10. << A LOT of comments, corrections and notes added by Guru and
  11. Alfred of Sahara Surfers in 1995. All additions are included in
  12. double angle brackets << like this >> and everything outside
  13. them is left intact. Note the HUGE amount of errors in the
  14. original text. Triton: Perhaps you'd like to include THIS in the
  15. next FT2 release? :-)
  16.  
  17. Not copyrighted, released into public domain (at least the
  18. additions by us). Feel free to do what you wish. Credits please.
  19.  
  20. Remember - the added information is based on REAL XM files. >>
  21.  
  22. ============================================================================
  23.  
  24.  
  25. ******************************
  26. * The XM file structure: *
  27. ******************************
  28.  
  29. Offset Length Type
  30.  
  31. 0 17 (char) ID text: 'Extended module: '
  32. << Nope: 'Extended Module: ' >>
  33. 17 20 (char) Module name, padded with zeroes
  34. 37 1 (char) $1a
  35. 38 20 (char) Tracker name
  36. 58 2 (word) Version number, hi-byte major and low-byte minor
  37. The current format is version $0103
  38. << Nope, it's $0104. Format versions
  39. below $0104 have a LOT of differences.
  40. Check this field! >>
  41.  
  42. 60 4 (dword) Header size
  43. << Calculated FROM THIS OFFSET, not from
  44. the beginning of the file! >>
  45. +4 2 (word) Song length (in patten order table)
  46. +6 2 (word) Restart position
  47. +8 2 (word) Number of channels (2,4,6,8,10,...,32)
  48. +10 2 (word) Number of patterns (max 256)
  49. +12 2 (word) Number of instruments (max 128)
  50. +14 2 (word) Flags: bit 0: 0 = Amiga frequency table (see below);
  51. 1 = Linear frequency table
  52. +16 2 (word) Default tempo
  53. +18 2 (word) Default BPM
  54. +20 256 (byte) Pattern order table
  55.  
  56. Patterns:
  57. ---------
  58.  
  59. ? 4 (dword) Pattern header length
  60. +4 1 (byte) Packing type (always 0)
  61. +5 2 (word) Number of rows in pattern (1..256)
  62. +7 2 (word) Packed patterndata size
  63. << Note! This is zero if the pattern is
  64. completely empty and no pattern data
  65. follows! >>
  66.  
  67. ? ? Packed pattern data
  68.  
  69. Instruments:
  70. ------------
  71.  
  72. ? 4 (dword) Instrument size << header that is >>
  73. +4 22 (char) Instrument name
  74. +26 1 (byte) Instrument type (always 0)
  75. << This seems pretty random, don't
  76. assume it's zero >>
  77. +27 2 (word) Number of samples in instrument
  78.  
  79. If the number of samples > 0, then the this will follow:
  80.  
  81. ! +29 4 (dword) Sample header size
  82. ! +33 96 (byte) Sample number for all notes
  83. ! +129 48 (byte) Points for volume envelope
  84. ! +177 48 (byte) Points for panning envelope
  85. ! +225 1 (byte) Number of volume points
  86. ! +226 1 (byte) Number of panning points
  87. ! +227 1 (byte) Volume sustain point
  88. ! +228 1 (byte) Volume loop start point
  89. ! +229 1 (byte) Volume loop end point
  90. ! +230 1 (byte) Panning sustain point
  91. ! +231 1 (byte) Panning loop start point
  92. ! +232 1 (byte) Panning loop end point
  93. ! +233 1 (byte) Volume type: bit 0: On; 1: Sustain; 2: Loop
  94. ! +234 1 (byte) Panning type: bit 0: On; 1: Sustain; 2: Loop
  95. ! +235 1 (byte) Vibrato type
  96. ! +236 1 (byte) Vibrato sweep
  97. ! +237 1 (byte) Vibrato depth
  98. ! +238 1 (byte) Vibrato rate
  99. ! +239 2 (word) Volume fadeout
  100. ! +241 2 (word) Reserved
  101. << "Instrument Size" field tends to be more than the
  102. actual size of the structure documented here (it
  103. includes also the extended instrument sample header
  104. above). So remember to check it and skip the additional
  105. bytes before the first sample header >>
  106. !
  107. ! Sample headers:
  108. ! ---------------
  109. !
  110. ! ? 4 (dword) Sample length
  111. ! +4 4 (dword) Sample loop start
  112. ! +8 4 (dword) Sample loop length
  113. ! +12 1 (byte) Volume
  114. ! +13 1 (byte) Finetune (signed byte -16..+15)
  115. ! +14 1 (byte) Type: Bit 0-1: 0 = No loop, 1 = Forward loop,
  116. ! 2 = Ping-pong loop;
  117. ! 4: 16-bit sampledata
  118. ! +15 1 (byte) Panning (0-255)
  119. ! +16 1 (byte) Relative note number (signed byte)
  120. ! +17 1 (byte) Reserved
  121. ! +18 22 (char) Sample name
  122.  
  123. << Note! After the instrument header the file contains
  124. ALL sample headers for the instrument followed by the
  125. sample data for all samples >>
  126. !
  127. ! Sample data:
  128. ! ------------
  129. !
  130. ! ? ? Sample data (signed): The samples are stored
  131. ! as delta values. To convert to real data:
  132. !
  133. ! old=0;
  134. ! for i=1 to len
  135. ! new=sample[i]+old;
  136. ! sample[i]=new;
  137. ! old=new;
  138.  
  139.  
  140.  
  141. ***********************
  142. * Pattern format: *
  143. ***********************
  144.  
  145. The patterns are stored as ordinary MOD patterns, except that each
  146. note is stored as 5 bytes:
  147.  
  148. ? 1 (byte) Note (0-71, 0 = C-0)
  149. << Hah. Actually note numbers are 1-96,
  150. 97 being the key-off note (try to find
  151. that in the documentation!) >>
  152. +1 1 (byte) Instrument (0-128)
  153. << More like 1-128 >>
  154. +2 1 (byte) Volume column byte (see below)
  155. +3 1 (byte) Effect type
  156. +4 1 (byte) Effect parameter
  157.  
  158. A simle packing scheme is also adopted, so that the patterns not become
  159. TOO large: Since the MSB in the note value is never used, if is used for
  160. the compression. If the bit is set, then the other bits are interpreted
  161. as follows:
  162.  
  163. bit 0 set: Note follows
  164. 1 set: Instrument follows
  165. 2 set: Volume column byte follows
  166. 3 set: Effect follows
  167. 4 set: Guess what!
  168.  
  169. It is very simple, but far from optimal. If you want a better,
  170. you can always repack the patterns in your loader.
  171.  
  172.  
  173. ******************************
  174. * Volumes and envelopes: *
  175. ******************************
  176.  
  177. The volume formula:
  178.  
  179. FinalVol=(FadeOutVol/65536)*(EnvelopeVol/64)*(GlobalVol/64)*(Vol/64)*Scale;
  180.  
  181. << The FadeOutVol is originally 65535 and is decremented by
  182. instrument.fadeout each tick after note is released >>
  183.  
  184. The panning formula:
  185.  
  186. FinalPan=Pan+(EnvelopePan-32)*(128-Abs(Pan-128))/32;
  187.  
  188. << Note that the panning envelope values range from 0-64, not
  189. -128 - +127 >>
  190.  
  191. Envelope:
  192. ---------
  193.  
  194. The envelopes are processed once per frame, instead of every frame where
  195. no new notes are read. This is also true for the instrument vibrato and
  196. the fadeout. Since I am so lazy and the tracker is rather self-explaining
  197. I am not going to write any more for the moment.
  198.  
  199. << Anyone have ANY idea how instrument autovibrato works? >>
  200.  
  201.  
  202. ********************************
  203. * Periods and frequencies: *
  204. ********************************
  205.  
  206. PatternNote = 0..95 (0 = C-0, 95 = B-7)
  207. << Blah: Note = 1..96, 1 = C-0, 97 = key off >>
  208.  
  209. FineTune = -128..+127 (-128 = -1 halftone, +127 = +127/128 halftones)
  210. RelativeTone = -96..95 (0 => C-4 = C-4)
  211.  
  212. RealNote = PatternNote + RelativeTone; (0..118, 0 = C-0, 118 = A#9)
  213.  
  214. Linear frequence table:
  215. -----------------------
  216.  
  217. Period = 10*12*16*4 - Note*16*4 - FineTune/2;
  218. Frequency = 8363*2^((6*12*16*4 - Period) / (12*16*4));
  219.  
  220. Amiga frequence table:
  221. ----------------------
  222.  
  223. Period = (PeriodTab[(Note MOD 12)*8 + FineTune/16]*(1-Frac(FineTune/16)) +
  224. PeriodTab[(Note MOD 12)*8 + FineTune/16]*(Frac(FineTune/16)))
  225. *16/2^(Note DIV 12);
  226. (The period is interpolated for finer finetune values)
  227. Frequency = 8363*1712/Period;
  228.  
  229. << The interpolation code above doesn't work because of
  230. several reasons:
  231. 1. It does not interpolate (try adding 1 to the
  232. PeriodTab index in the second line)
  233. 2. It may go past the table beginning for negative
  234. finetune values
  235. Write your own interpolation routine instead - it's not that
  236. hard. >>
  237.  
  238. PeriodTab = Array[0..12*8-1] of Word = (
  239. 907,900,894,887,881,875,868,862,856,850,844,838,832,826,820,814,
  240. 808,802,796,791,785,779,774,768,762,757,752,746,741,736,730,725,
  241. 720,715,709,704,699,694,689,684,678,675,670,665,660,655,651,646,
  242. 640,636,632,628,623,619,614,610,604,601,597,592,588,584,580,575,
  243. 570,567,563,559,555,551,547,543,538,535,532,528,524,520,516,513,
  244. 508,505,502,498,494,491,487,484,480,477,474,470,467,463,460,457);
  245.  
  246. << Note! The period table is made for 1-based note numbers, so in
  247. practise it contains the period values for B-3 to G#4. Fun. >>
  248.  
  249.  
  250. *************************
  251. * Standard effects: *
  252. *************************
  253.  
  254. 0 Appregio << ;) >>
  255. 1 (*) Porta up
  256. 2 (*) Porta down
  257. 3 (*) Tone porta
  258. 4 (*) Vibrato
  259. 5 (*) Tone porta+Volume slide
  260. 6 (*) Vibrato+Volume slide
  261. 7 (*) Tremolo
  262. 8 Set panning
  263. 9 Sample offset
  264. A (*) Volume slide
  265. B Position jump
  266. C Set volume
  267. D Pattern break
  268. E1 (*) Fine porta up
  269. E2 (*) Fine porta down
  270. E3 Set gliss control
  271. E4 Set vibrato control
  272. E5 Set finetune
  273. E6 Set loop begin/loop
  274. E7 Set tremolo control
  275. E9 Retrig note
  276. EA (*) Fine volume slide up
  277. EB (*) Fine volume slide down
  278. EC Note cut
  279. ED Note delay
  280. EE Pattern delay
  281. F Set tempo/BPM
  282. G Set global volume
  283. H (*) Global volume slide
  284. K Key off << also note number 97 >>
  285. L Set envelope position
  286. P (*) Panning slide
  287. R (*) Multi retrig note
  288. T Tremor
  289. X1 (*) Extra fine porta up
  290. X2 (*) Extra fine porta down
  291.  
  292. (*) = If the command byte is zero, the last nonzero byte for the
  293. command should be used.
  294.  
  295. << The commands are reasonably Protracker compatible although
  296. not all PT "features" (some might call them replay routine bugs)
  297. are implemented. >>
  298.  
  299. *********************************
  300. * Effects in volume column: *
  301. *********************************
  302.  
  303. All effects in the volume column should work as the standard effects.
  304. The volume column is interpreted before the standard effects, so
  305. some standard effects may override volume column effects.
  306.  
  307. Value Meaning
  308.  
  309. 0 Do nothing
  310. $10-$50 Set volume Value-$10
  311. : : :
  312. : : :
  313. $60-$6f Volume slide down
  314. $70-$7f Volume slide up
  315. $80-$8f Fine volume slide down
  316. $90-$9f Fine volume slide up
  317. $a0-$af Set vibrato speed
  318. $b0-$bf Vibrato
  319. $c0-$cf Set panning
  320. $d0-$df Panning slide left
  321. $e0-$ef Panning slide right
  322. $f0-$ff Tone porta
  323.  
  324.  
  325. << And here goes one more section that this document really
  326. should have had:
  327.  
  328. ********************
  329. * General layout *
  330. ********************
  331.  
  332. The layout of a typical XM is like this:
  333.  
  334. XM header (up to and excluding header size field, now 60 bytes)
  335. Rest of the header (length including header size field)
  336. Pattern 0 header (length in header)
  337. Pattern 0 data (length in header)
  338. Pattern 1 header (length in header)
  339. Pattern 1 data (length in header)
  340. ... (* number of patterns)
  341. Instrument 0 header (length in size field is this and next one together)
  342. if (numSample > 0)
  343. Extra header
  344. Sample 0 header (size in instrument extra header)
  345. Sample 1 header (size in instrument extra header)
  346. ... (* number of samples in instrument)
  347. Sample 0 data (length in sample header)
  348. Sample 1 data (length in sample header)
  349. ... (* number of samples in instrument)
  350. Instrument 1 header (length in size field is this and next one together)
  351. ... (* number of instruments)
  352. >>
  353.  
  354.  
  355.  
  356. ============================================================================
  357.  
  358. This should be just about everything (I hope?). You will probably need
  359. some information about the MOD format and maybe about S3M.
  360.  
  361. Have fun!
  362. << And we sure had! >>
  363.  
  364. Fredrik Huss / Mr.H of Triton
  365.  
  366. << Jarno Paananen & Petteri Kangaslampi - Guru & Alfred / S2
  367.  
  368. If you have questions that you think we might be able to
  369. answer, have found out more mistakes in this document, or
  370. know how instrument autovibrato works, e-mail us at:
  371. Jarno: jpaana@kauhajoki.fi
  372. _or_
  373. Petteri: pekangas@sci.fi
  374. >>
  375.  
  376.  
  377.  
  378.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement