home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / ft206.zip / XM.TXT < prev   
Text File  |  1995-07-23  |  10KB  |  271 lines

  1.  
  2.        The XM module format description for XM files version $0104.
  3.  
  4.        By Mr.H of Triton in 1994.
  5.  
  6.        - Be prepared! Are you sure you want to know? :-)
  7.  
  8.  ============================================================================
  9.  
  10.  
  11.    ******************************
  12.    *   The XM file structure:   *
  13.    ******************************
  14.  
  15.    Offset Length Type
  16.  
  17.       0     17   (char) ID text: 'Extended module: '
  18.      17     20   (char) Module name, padded with zeroes
  19.      37      1   (char) $1a
  20.      38     20   (char) Tracker name
  21.      58      2   (word) Version number, hi-byte major and low-byte minor
  22.                         The current format is version $0103
  23.  
  24.      60      4  (dword) Header size
  25.      +4      2   (word) Song length (in patten order table)
  26.      +6      2   (word) Restart position
  27.      +8      2   (word) Number of channels (2,4,6,8,10,...,32)
  28.     +10      2   (word) Number of patterns (max 256)
  29.     +12      2   (word) Number of instruments (max 128)
  30.     +14      2   (word) Flags: bit 0: 0 = Amiga frequency table (see below);
  31.                                       1 = Linear frequency table
  32.     +16      2   (word) Default tempo
  33.     +18      2   (word) Default BPM
  34.     +20    256   (byte) Pattern order table
  35.  
  36.                         Patterns:
  37.                         ---------
  38.  
  39.       ?      4  (dword) Pattern header length
  40.      +4      1   (byte) Packing type (always 0)
  41.      +5      2   (word) Number of rows in pattern (1..256)
  42.      +7      2   (word) Packed patterndata size
  43.  
  44.       ?      ?          Packed pattern data
  45.  
  46.                         Instruments:
  47.                         ------------
  48.  
  49.       ?      4  (dword) Instrument size
  50.      +4     22   (char) Instrument name
  51.     +26      1   (byte) Instrument type (always 0)
  52.     +27      2   (word) Number of samples in instrument
  53.  
  54.    If the number of samples > 0, then the this will follow:
  55.  
  56.    !     +29      4  (dword) Sample header size
  57.    !     +33     96   (byte) Sample number for all notes
  58.    !    +129     48   (byte) Points for volume envelope
  59.    !    +177     48   (byte) Points for panning envelope
  60.    !    +225      1   (byte) Number of volume points
  61.    !    +226      1   (byte) Number of panning points
  62.    !    +227      1   (byte) Volume sustain point
  63.    !    +228      1   (byte) Volume loop start point
  64.    !    +229      1   (byte) Volume loop end point
  65.    !    +230      1   (byte) Panning sustain point
  66.    !    +231      1   (byte) Panning loop start point
  67.    !    +232      1   (byte) Panning loop end point
  68.    !    +233      1   (byte) Volume type: bit 0: On; 1: Sustain; 2: Loop
  69.    !    +234      1   (byte) Panning type: bit 0: On; 1: Sustain; 2: Loop
  70.    !    +235      1   (byte) Vibrato type
  71.    !    +236      1   (byte) Vibrato sweep
  72.    !    +237      1   (byte) Vibrato depth
  73.    !    +238      1   (byte) Vibrato rate
  74.    !    +239      2   (word) Volume fadeout
  75.    !    +241      2   (word) Reserved
  76.    !
  77.    !                         Sample headers:
  78.    !                         ---------------
  79.    !
  80.    !       ?      4  (dword) Sample length
  81.    !      +4      4  (dword) Sample loop start
  82.    !      +8      4  (dword) Sample loop length
  83.    !     +12      1   (byte) Volume
  84.    !     +13      1   (byte) Finetune (signed byte -16..+15)
  85.    !     +14      1   (byte) Type: Bit 0-1: 0 = No loop, 1 = Forward loop,
  86.    !                                        2 = Ping-pong loop;
  87.    !                                     4: 16-bit sampledata
  88.    !     +15      1   (byte) Panning (0-255)
  89.    !     +16      1   (byte) Relative note number (signed byte)
  90.    !     +17      1   (byte) Reserved
  91.    !     +18     22   (char) Sample name
  92.    !
  93.    !                         Sample data:
  94.    !                         ------------
  95.    !
  96.    !       ?      ?          Sample data (signed): The samples are stored
  97.    !                         as delta values. To convert to real data:
  98.    !
  99.    !                         old=0;
  100.    !                         for i=1 to len
  101.    !                            new=sample[i]+old;
  102.    !                            sample[i]=new;
  103.    !                            old=new;
  104.  
  105.  
  106.  
  107.    ***********************
  108.    *   Pattern format:   *
  109.    ***********************
  110.  
  111.    The patterns are stored as ordinary MOD patterns, except that each
  112.    note is stored as 5 bytes:
  113.  
  114.       ?      1   (byte) Note (0-71, 0 = C-0)
  115.      +1      1   (byte) Instrument (0-128)
  116.      +2      1   (byte) Volume column byte (see below)
  117.      +3      1   (byte) Effect type
  118.      +4      1   (byte) Effect parameter
  119.  
  120.    A simle packing scheme is also adopted, so that the patterns not become
  121.    TOO large: Since the MSB in the note value is never used, if is used for
  122.    the compression. If the bit is set, then the other bits are interpreted
  123.    as follows:
  124.  
  125.       bit 0 set: Note follows
  126.           1 set: Instrument follows
  127.           2 set: Volume column byte follows
  128.           3 set: Effect type follows
  129.           4 set: Guess what!
  130.  
  131.    It is very simple, but far from optimal. If you want a better,
  132.    you can always repack the patterns in your loader.
  133.  
  134.  
  135.  
  136.    ******************************
  137.    *   Volumes and envelopes:   *
  138.    ******************************
  139.  
  140.    The volume formula:
  141.  
  142.    FinalVol=(FadeOutVol/65536)*(EnvelopeVol/64)*(GlobalVol/64)*(Vol/64)*Scale;
  143.  
  144.    The panning formula:
  145.  
  146.    FinalPan=Pan+(EnvelopePan-32)*(128-Abs(Pan-128))/32;
  147.  
  148.       Envelope:
  149.       ---------
  150.  
  151.    The envelopes are processed once per frame, instead of every frame where
  152.    no new notes are read. This is also true for the instrument vibrato and
  153.    the fadeout. Since I am so lazy and the tracker is rather self-explaining
  154.    I am not going to write any more for the moment.
  155.  
  156.  
  157.    ********************************
  158.    *   Periods and frequencies:   *
  159.    ********************************
  160.  
  161.    PatternNote = 0..95 (0 = C-0, 95 = B-7)
  162.  
  163.    FineTune = -128..+127 (-128 = -1 halftone, +127 = +127/128 halftones)
  164.    RelativeTone = -96..95 (0 => C-4 = C-4)
  165.  
  166.    RealNote = PatternNote + RelativeTone; (0..118, 0 = C-0, 118 = A#9)
  167.  
  168.       Linear frequence table:
  169.       -----------------------
  170.  
  171.    Period = 10*12*16*4 - Note*16*4 - FineTune/2;
  172.    Frequency = 8363*2^((6*12*16*4 - Period) / (12*16*4));
  173.  
  174.       Amiga frequence table:
  175.       ----------------------
  176.  
  177.    Period = (PeriodTab[(Note MOD 12)*8 + FineTune/16]*(1-Frac(FineTune/16)) +
  178.              PeriodTab[(Note MOD 12)*8 + FineTune/16]*(Frac(FineTune/16)))
  179.             *16/2^(Note DIV 12);
  180.       (The period is interpolated for finer finetune values)
  181.    Frequency = 8363*1712/Period;
  182.  
  183.    PeriodTab = Array[0..12*8-1] of Word = (
  184.       907,900,894,887,881,875,868,862,856,850,844,838,832,826,820,814,
  185.       808,802,796,791,785,779,774,768,762,757,752,746,741,736,730,725,
  186.       720,715,709,704,699,694,689,684,678,675,670,665,660,655,651,646,
  187.       640,636,632,628,623,619,614,610,604,601,597,592,588,584,580,575,
  188.       570,567,563,559,555,551,547,543,538,535,532,528,524,520,516,513,
  189.       508,505,502,498,494,491,487,484,480,477,474,470,467,463,460,457);
  190.  
  191.  
  192.    *************************
  193.    *   Standard effects:   *
  194.    *************************
  195.  
  196.       0      Appregio
  197.       1  (*) Porta up
  198.       2  (*) Porta down
  199.       3  (*) Tone porta
  200.       4  (*) Vibrato
  201.       5  (*) Tone porta+Volume slide
  202.       6  (*) Vibrato+Volume slide
  203.       7  (*) Tremolo
  204.       8      Set panning
  205.       9      Sample offset
  206.       A  (*) Volume slide
  207.       B      Position jump
  208.       C      Set volume
  209.       D      Pattern break
  210.       E1 (*) Fine porta up
  211.       E2 (*) Fine porta down
  212.       E3     Set gliss control
  213.       E4     Set vibrato control
  214.       E5     Set finetune
  215.       E6     Set loop begin/loop
  216.       E7     Set tremolo control
  217.       E9     Retrig note
  218.       EA (*) Fine volume slide up
  219.       EB (*) Fine volume slide down
  220.       EC     Note cut
  221.       ED     Note delay
  222.       EE     Pattern delay
  223.       F      Set tempo/BPM
  224.       G      Set global volume
  225.       H  (*) Global volume slide
  226.       K      Key off
  227.       L      Set envelope position
  228.       P  (*) Panning slide
  229.       R  (*) Multi retrig note
  230.       T      Tremor
  231.       X1 (*) Extra fine porta up
  232.       X2 (*) Extra fine porta down
  233.  
  234.       (*) = If the command byte is zero, the last nonzero byte for the
  235.             command should be used.
  236.  
  237.    *********************************
  238.    *   Effects in volume column:   *
  239.    *********************************
  240.  
  241.    All effects in the volume column should work as the standard effects.
  242.    The volume column is interpreted before the standard effects, so
  243.    some standard effects may override volume column effects.
  244.  
  245.    Value      Meaning
  246.  
  247.       0       Do nothing
  248.     $10-$50   Set volume Value-$10
  249.       :          :        :
  250.       :          :        :
  251.     $60-$6f   Volume slide down
  252.     $70-$7f   Volume slide up
  253.     $80-$8f   Fine volume slide down
  254.     $90-$9f   Fine volume slide up
  255.     $a0-$af   Set vibrato speed
  256.     $b0-$bf   Vibrato
  257.     $c0-$cf   Set panning
  258.     $d0-$df   Panning slide left
  259.     $e0-$ef   Panning slide right
  260.     $f0-$ff   Tone porta
  261.  
  262.  
  263.  ============================================================================
  264.  
  265.    This should be just about everything (I hope?). You will probably need
  266.    some information about the MOD format and maybe about S3M.
  267.  
  268.    Have fun!
  269.  
  270.              Fredrik Huss / Mr.H of Triton
  271.