home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 September / Chip_2000-09_cd1.bin / sharewar / Slunec / app / 16 / MOD.SWG / 0030_XM.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-04  |  9KB  |  255 lines

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