home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / scrmt321.zip / TECH.DOC < prev    next >
Text File  |  1994-12-06  |  19KB  |  403 lines

  1.           Scream Tracker 3.20 File Formats And Mixing Info
  2.           ================================================
  3.  
  4. This document finally containts the OFFICIAL information on s3m format
  5. and much more. There might be some errors here, so if something seems
  6. weird, don't just blindly believe it. Think first if it could be just
  7. a typo or something.
  8.  
  9. -----------------------------------------------------------------------------
  10. What is the S3M file format?
  11. What is the samplefile format?
  12. What is the adlib instrument format?
  13.  
  14.  
  15.         The first table describes the S3M header. All other blocks are
  16.         pointer to by pointers, so in theory they could be anywhere in
  17.         the file. However, the practical standard order is:
  18.         - header
  19.         - instruments in order
  20.         - patterns in order
  21.         - samples in order
  22.  
  23.         Next the instrument header is described. It is stored to S3M
  24.         for each instrument and also saved to the start of all samples
  25.         saved from ST3. Same header is also used by Advance Digiplayer.
  26.  
  27.         The third part is the description of the packed pattern format.
  28.  
  29.  
  30.                                 S3M Module header
  31.           0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
  32.         ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
  33.   0000: │ Song name, max 28 chars (end with NUL (0))                    │
  34.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  35.   0010: │                                               │1Ah│Typ│ x │ x │
  36.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  37.   0020: │OrdNum │InsNum │PatNum │ Flags │ Cwt/v │ Ffi   │'S'│'C'│'R'│'M'│
  38.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  39.   0030: │g.v│i.s│i.t│m.v│u.c│d.p│ x │ x │ x │ x │ x │ x │ x │ x │Special│
  40.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  41.   0040: │Channel settings for 32 channels, 255=unused,+128=disabled     │
  42.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  43.   0050: │                                                               │
  44.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  45.   0060: │Orders; length=OrdNum (should be even)                         │
  46.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  47.   xxx1: │Parapointers to instruments; length=InsNum*2                   │
  48.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  49.   xxx2: │Parapointers to patterns; length=PatNum*2                      │
  50.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  51.   xxx3: │Channel default pan positions                                  │
  52.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  53.         xxx1=70h+orders
  54.         xxx2=70h+orders+instruments*2
  55.         xxx3=70h+orders+instruments*2+patterns*2
  56.  
  57.         Parapointers to file offset Y is (Y-Offset of file header)/16.
  58.         You could think of parapointers as segments relative to the
  59.         start of the S3M file.
  60.  
  61.         Type    = File type: 16=ST3 module
  62.         Ordnum  = Number of orders in file (should be even!)
  63.     Insnum    = Number of instruments in file
  64.     Patnum    = Number of patterns in file
  65.         Cwt/v   = Created with tracker / version: &0xfff=version, >>12=tracker
  66.                         ST3.00:0x1300 (NOTE: volumeslides on EVERY frame)
  67.                         ST3.01:0x1301
  68.                         ST3.03:0x1303
  69.                         ST3.20:0x1320
  70.         Ffi     = File format information
  71.                         1=[VERY OLD] signed samples
  72.                         2=unsigned samples
  73.         Flags   =  [ These are old flags for Ffv1. Not supported in ST3.01
  74.                    |  +1:st2vibrato
  75.                    |  +2:st2tempo
  76.                    |  +4:amigaslides
  77.                    | +32:enable filter/sfx with sb
  78.                    ]
  79.                     +8: 0vol optimizations
  80.                           Automatically turn off looping notes whose volume
  81.                           is zero for >2 note rows.
  82.                    +16: amiga limits
  83.                           Disallow any notes that go beond the amiga hardware
  84.                           limits (like amiga does). This means that sliding
  85.                           up stops at B#5 etc. Also affects some minor amiga
  86.                           compatibility issues.
  87.                    +64: st3.00 volumeslides
  88.                           Normally volumeslide is NOT performed on first
  89.                           frame of each row (this is according to amiga
  90.                           playing). If this is set, volumeslide is performed
  91.                           ALSO on the first row. This is set by default
  92.                           if the Cwt/v files is 0x1300
  93.                   +128: special custom data in file (see below)
  94.         Special = pointer to special custom data (not used by ST3.01)
  95.         ExtHead = pointer to extended header data area (generally after)
  96.                   the main header)
  97.     g.v    = global volume (see next section)
  98.     m.v    = master volume (see next section) 7 lower bits
  99.                   bit 8: stereo(1) / mono(0)
  100.     i.s    = initial speed (command A)
  101.     i.t        = initial tempo (command T)
  102.         u.c     = ultra click removal. ST3 uses u.c gus channels to
  103.                   guarantee, that u.c/2 channels run without any clicks.
  104.                   If more channels are used, some clicks might appear.
  105.                   The number displayed in ST3 order page is u.c/2
  106.         d.p     = 252 when default channel pan positions are present
  107.                   in the end of the header (xxx3). If !=252 ST3 doesn't
  108.                   try to load channel pan settings.
  109.  
  110.         Channel settings (byte per channel):
  111.           bit 8: channel enabled
  112.         bit 0-7: channel type
  113.                  0..7   : Left Sample Channel 1-8
  114.                  8..15  : Right Sample Channel 1-8
  115.                  16..31 : Adlib channels (9 melody + 5 drums)
  116.  
  117.         Channel pan settings (byte per channel):
  118.         bit 6-7: reserved
  119.           bit 5: 1=default pan position specified, 0=use defaults:
  120.                  for mono 7, for stereo 3 or C.
  121.         bit 0-3: default pan position
  122.  
  123.  
  124.         Global volume directly divides the volume numbers used. So
  125.         if the module has a note with volume 48 and master volume
  126.         is 32, the note will be played with volume 24. This affects
  127.         both Gravis & SoundBlasters.
  128.  
  129.         Master volume only affects the SoundBlaster. It controls
  130.         the amount of sample multiplication (see mixing section
  131.         of this doc). The bigger the value the bigger the output
  132.         volume (and thus quality) will be. However if the value
  133.         is too big, the mixer may have to clip the output to
  134.         fit the 8 bit output stream. The default value works
  135.         pretty well. Note that in stereo, the mastermul is
  136.         internally multiplied by 11/8 inside the player since
  137.         there is generally more room in the output stream.
  138.  
  139.         Order list lists the order in which to play the patterns. 255=--
  140.         is the end of tune mark and 254=++ is just a marker that is
  141.         skipped.
  142.  
  143.  
  144.  
  145.                         Digiplayer/ST3 samplefileformat
  146.           0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
  147.         ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
  148.   0000: │[T]│ Dos filename (12345678.ABC)                   │    MemSeg │
  149.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  150.   0010: │Length │HI:leng│LoopBeg│HI:LBeg│LoopEnd│HI:Lend│Vol│ x │[P]│[F]│
  151.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  152.   0020: │C2Spd  │HI:C2sp│ x │ x │ x │ x │Int:Gp │Int:512│Int:lastused   │
  153.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  154.   0030: │ Sample name, 28 characters max... (incl. NUL)                 │
  155.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  156.   0040: │ ...sample name...                             │'S'│'C'│'R'│'S'│
  157.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  158.   xxxx:    sampledata
  159.  
  160.         Length / LoopBegin / LoopEnd are all 32 bit parameters although
  161.         ST3 only support file sizes up to 64,000 bytes. Files bigger
  162.         than that are clipped to 64,000 bytes when loaded to ST3. NOTE
  163.         that LoopEnd points to one byte AFTER the end of the sample,
  164.         so LoopEnd=100 means that byte 99.9999 (fixed) is the last one
  165.         played.
  166.         C2Spd  = Herz for middle C. ST3 only uses lower 16 bits.
  167.         Vol    = Default volume 0..64
  168.         Memseg = Pointer to sampledata
  169.                  Inside a sample or S3M, MemSeg tells the parapointer to
  170.                  the actual sampledata. In files all 24 bits are used.
  171.                  In memory the value points to the actual sample segment
  172.                  or Fxxx if sample is in EMS under handle xxx. In memory
  173.                  the first memseg byte is overwritten with 0 to create
  174.                  the dos filename terminator nul.
  175.         Int:Gp = Internal: Address of sample in gravis memory /32
  176.                  (only used while module in memory)
  177.         Int:512= Internal: flags for soundblaster loop expansion
  178.                  (only used while module in memory)
  179.         Int:las= Internal: last used position (only works with sb)
  180.                  (only used while module in memory)
  181.         [T]ype   1=Sample, 2=adlib melody, 3+=adlib drum (see below for
  182.                  adlib structure)
  183.     [F]lags, +1=loop on
  184.          +2=stereo (after Length bytes for LEFT channel,
  185.                another Length bytes for RIGHT channel)
  186.                  +4=16-bit sample (intel LO-HI byteorder)
  187.                  (+2/+4 not supported by ST3.01)
  188.         [P]ack   0=unpacked, 1=DP30ADPCM packing (not used by ST3.01)
  189.  
  190.  
  191.  
  192.                               adlib instrument format
  193.           0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
  194.         ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
  195.   0000: │[T]│ Dos filename (12345678.123)                   │00h│00h│00h│
  196.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  197.   0010: │D00│D01│D02│D03│D04│D05│D06│D07│D08│D09│D0A│D0B│Vol│Dsk│ x │ x │
  198.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  199.   0020: │C2Spd  │HI:C2sp│ x │ x │ x │ x │ x │ x │ x │ x │ x │ x │ x │ x │
  200.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  201.   0030: │ Sample name, 28 characters max... (incl. NUL)                 │
  202.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  203.   0040: │ ...sample name...                             │'S'│'C'│'R'│'I'│
  204.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  205.  
  206.         [T]ype  = 2:amel 3:abd 4:asnare 5:atom 6:acym 7:ahihat
  207.         C2Spd   = 'Herz' for middle C. ST3 only uses lower 16 bits.
  208.                   Actually this is a modifier since there is no
  209.                   clear frequency for adlib instruments. It scales
  210.                   the note freq sent to adlib.
  211.         D00..D0B contains the adlib instrument specs packed like this:
  212.         modulator:                                              carrier:
  213.         D00=[freq.muliplier]+[?scale env.]*16+[?sustain]*32+    =D01
  214.                 [?pitch vib]*64+[?vol.vib]*128
  215.     D02=[63-volume]+[levelscale&1]*128+[l.s.&2]*64        =D03
  216.     D04=[attack]*16+[decay]                    =D05
  217.     D06=[15-sustain]*16+[release]                =D07
  218.     D08=[wave select]                    =D09
  219.     D0A=[modulation feedback]*2+[?additive synthesis]
  220.     D0B=unused
  221.  
  222.  
  223.  
  224.                           packed pattern format
  225.           0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
  226.         ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
  227.   0000: │Length │ packed data, see below...
  228.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  229.  
  230.         Length = length of packed pattern
  231.  
  232.         Unpacked pattern is always 32 channels by 64 rows. Below
  233.         is the unpacked format st uses for reference:
  234.           Unpacked Internal memoryformat for patterns (not used in files):
  235.           NOTE: each channel takes 320 bytes, rows for each channel are
  236.                 sequential, so one unpacked pattern takes 10K.
  237.           byte 0 - Note; hi=oct, lo=note, 255=empty note,
  238.                    254=key off (used with adlib, with samples stops smp)
  239.           byte 1 - Instrument      ;0=..
  240.           byte 2 - Volume          ;255=..
  241.           byte 3 - Special command ;255=..
  242.           byte 4 - Command info    ;
  243.  
  244.         Packed data consits of following entries:
  245.         BYTE:what  0=end of row
  246.                    &31=channel
  247.                    &32=follows;  BYTE:note, BYTE:instrument
  248.                    &64=follows;  BYTE:volume
  249.                    &128=follows; BYTE:command, BYTE:info
  250.  
  251.         So to unpack, first read one byte. If it's zero, this row is
  252.         done (64 rows in entire pattern). If nonzero, the channel
  253.         this entry belongs to is in BYTE AND 31. Then if bit 32
  254.         is set, read NOTE and INSTRUMENT (2 bytes). Then if bit
  255.         64 is set read VOLUME (1 byte). Then if bit 128 is set
  256.         read COMMAND and INFO (2 bytes).
  257.  
  258.         For information on commands / how st3 plays them, see the
  259.         manual.
  260.     
  261.  
  262. -----------------------------------------------------------------------------
  263. What is the Stmik300old format?
  264. What is the STIMPORT file format?
  265. What is the SIMPLEXFILE format?
  266.  
  267.         The old stmik 300 (never published because it has no
  268.         usable interface) want's that the samples in the module
  269.         are pre-extended for soundblaster. This means that
  270.         samples have an extra 512 bytes of loop after their
  271.         loopend (or silence if no loop). The save option for
  272.         old stmik does this extension. Otherwise the fileformat
  273.         is the same as for a normal S3M.
  274.  
  275.         STIMPORT file format is supposed to be an easy way of
  276.         imputting weird data to st3. That is, it should be
  277.         easy to convert something to STIMPORT format. The format
  278.         goes like this:
  279.  
  280.           0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
  281.         ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
  282.   0000: │'S'│'T'│'I'│'M'│'P'│'O'│'R'│'T'│i.s│ x │ x │ x │ x │ x │ x │ x │
  283.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  284.   0010: │Notedata...
  285.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  286.   xxxx: │Instruments...
  287.         ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
  288.  
  289.         There are no patterns or orders, just a continuos note stream
  290.         of following structures:
  291.           0    1    2    3    4    5
  292.         ┌────┬────┬────┬────┬────┬────┐
  293.         │Chan│Note│Inst│Volu│Cmnd│Info│
  294.         └────┴────┴────┴────┴────┴────┘
  295.         Chan is the channel number for the note +128. Value 0 stands
  296.         for next row. Value 255 stands for end of note stream.
  297.         Note/Inst/Cmnd/Info are like in the unpacked memory pattern
  298.         (see previous section)
  299.  
  300.         After the notedata there can be instruments (optional)
  301.         Every instrument consits of the following block:
  302.           0    1    2    3    4
  303.         ┌────┬────┬────┬────┬────┬────┬────┬────┬───────────...─┬──────...
  304.         │Inst│Flag│LoopBeg  │LoopEnd  │Length   │ Sampledata... │ Name (opt)
  305.         └────┴────┴────┴────┴────┴────┴────┴────┴───────────...─┴──────...
  306.         Inst = number of instrument to load (0=end of instruments)
  307.         Flag = +1=loop enabled +128=name after sampledata (null terminated)
  308.         LoopBeg/LoopEnd/Length = guess
  309.         Sampledata = raw sampledata for Length bytes.
  310.  
  311.  
  312.         SIMPLEXFORMAT is designed for easy export of notedata.
  313.         The contents of a S3Y file is:
  314.  
  315.         32 first instruments, 128 bytes each.
  316.           The 80 first bytes correspond to the ST3 Samplefile header
  317.           (described in this file). The rest correspond to nothing.
  318.         Raw notedata for the entire song - 9 channels stored.
  319.           Every row consists of 9 notes, each consisting of 5 bytes:
  320.           ┌───┬───┬───┬───┬───┬
  321.           │not│ins│vol│cmd│inf│
  322.           ├───┼───┼───┼───┼───┼
  323.           byte 0 - Note; hi=oct, lo=note, 255=empty note,
  324.                    254=key off (used with adlib, with samples stops smp)
  325.           byte 1 - Instrument      ;0=..
  326.           byte 2 - Volume          ;255=..
  327.           byte 3 - Special command ;255=..
  328.           byte 4 - Command info    ;
  329.  
  330.  
  331. -----------------------------------------------------------------------------
  332. What is C2SPD?
  333. How to calculate the note frequencies like ST3?
  334. How does ST3 mix depending on master volume?
  335.  
  336.  
  337.         Finetuning (C2SPD) is actually the frequency in herz for
  338.         the note C4. Why is it C2SPD? Well, originally in ST2
  339.         the middle note was C2 and the name stuck. Later in ST3
  340.         the middle note was raised to C4 for more octaves... So
  341.         actually C2SPD should be called C4SPD...
  342.  
  343.  
  344.         Table for note frequencies used by ST3:
  345.  
  346.       note:  C    C#   D    D#   E    F    F#   G    G#   A    A#   B
  347.     period: 1712,1616,1524,1440,1356,1280,1208,1140,1076,1016,0960,0907
  348.     
  349.     middle octave is 4.
  350.     
  351.              8363 * 16 * ( period(NOTE) >> octave(NOTE) )
  352.     note_st3period = --------------------------------------------
  353.               middle_c_finetunevalue(INSTRUMENT)
  354.              
  355.     note_amigaperiod = note_st3period / 4
  356.              
  357.     note_herz=14317056 / note_st3period
  358.  
  359.         Note that ST3 uses period values that are 4 times larger than the
  360.         amiga to allow for extra fine slides (which are 4 times finer
  361.         than normal fine slides).
  362.  
  363.  
  364.         How ST3 mixes:
  365.  
  366.         1) volumetable is created in the following way:
  367.  
  368.         > volumetable[volume][sampledata]=volume*(sampledata-128)/64;
  369.  
  370.         NOTE: sampledata in memory is unsigned in ST3, so the -128 in the
  371.               formula converts it so that the volumetable output is signed.
  372.  
  373.         2) postprocessing table is created with this pseudocode:
  374.  
  375.         > z=mastervol&127;
  376.         > if(z<0x10) z=0x10;
  377.         > c=2048*16/z;
  378.         > a=(2048-c)/2;
  379.         > b=a+c;
  380.         >                     { 0                , if x < a
  381.         > posttable[x+1024] = { (x-a)*256/(b-a)  , if a <= x < b
  382.         >                     { 255              , if x > b
  383.  
  384.         3) mixing the samples
  385.  
  386.         output=1024
  387.         for i=0 to number of channels
  388.                 output+=volumetable[volume*globalvolume/64][sampledata];
  389.         next
  390.         realoutput=posttable[output]
  391.  
  392.  
  393.         This is how the mixing is done in theory. In practice it's a bit
  394.         different for speed reasons, but the result is the same.
  395.  
  396.  
  397. -----------------------------------------------------------------------------
  398. That's it. If there are any more questions, that's too bad :-) If you have
  399. problems with the S3M format, try to contact somone who already supports
  400. it (there is quite a lot of support for the S3M already, so that shouldn't
  401. be too hard...) Good luck for reading / writing Scream Tracker files.
  402.  
  403.