Scream Tracker 3 Module

From MultimediaWiki
Revision as of 15:38, 18 October 2010 by GreaseMonkey (talk | contribs) (→‎File Format: added some version IDs, thanks to Saga_Musix)
Jump to navigation Jump to search
  • Extension: s3m

A normally 16-channel module format for MS-DOS on the PC, it can also support OPL2 FM synthesis (9 melodic channels + 5 drums). While the format itself can technically support 32 channels, only the 30 mentioned have any meaning assigned to them, and they are usually not all used at the same time.

Aspects which are easy to get wrong with this format are in bold text.

Unless otherwise specified, this information pertains to Scream Tracker v3.21's play routine.

File Format

The format is little-endian (least significant byte first). A "byte" is 8 bits, a "word" is 16 bits, and a "dword" (double word) is 32 bits. Hex values will be denoted with "0x". A parapointer points to pp*16 in the file due to the DOS nature of the format.

Note that if some parts of the format are inconsistent, it's usually best to let it slip, as ST3 itself will allegedly for instance load instruments which don't have the "SCRS" / "SCRI" mark.

  • 28 bytes: module name, NUL-terminated, NUL-padded.
  • Byte: 0x1A.
  • Byte: 16 (0x10) to indicate this is a Scream Tracker 3 module.
  • 2 reserved bytes, should be set to 0x00.
  • 6 words, denoting the following:
    • Order count
    • Instrument count
    • Pattern count
    • Flags
      • Bit 0 (pre-3.01 ONLY): ST2 vibrato (effect unknown).
      • Bit 1 (pre-3.01 ONLY): ST2 tempo (effect unknown).
      • Bit 3 (pre-3.01 ONLY): Amiga slides (effect unknown).
      • Bit 4: 0-vol optimisations - turn off looping notes which have a zero volume for more than(?) 2 rows.
      • Bit 5: Amiga limits (limit periods to confine to 113 <= x <= 856).
      • Bit 6 (pre-3.01 ONLY): Enable filter / sfx with SB (effect unknown).
      • Bit 7: ST3.00 volume slides (automatically enabled if tracker version is <= 0x1300) - if enabled, all volume slides occur every tick.
      • Bit 8: Special custom data in file (uses "Special" field)
  • Tracker version
    • 0x1xyy == Scream Tracker x.yy
    • 0x2xyy == Imago Orpheus x.yy
    • 0x3xyy == Impulse Tracker x.yy
    • 0x4xyy == Schism Tracker (version numbering scheme is different)
    • 0x5xyy == OpenMPT
  • File format information
    • 1 == signed samples (horribly, horribly old)
    • 2 == unsigned samples
    • Anything else is invalid and ST3 will not load the file(?).
  • 4 byte string: "SCRM"
  • 6 bytes, denoting the following:
    • Global volume (range 0 <= x <= 64) which is used in calculating individual channel volumes and is nasty.
    • Initial speed (ticks per row / TPR) - if 0 or 255, it is ignored and 6 is used instead. The value of 255 is very unusual as AFF (set speed to 0xFF == 255) still works.
    • Initial tempo - if less than 33, it is ignored and 125 is used instead.
    • Mixing volume (range 16 <= x <= 127) which is only used for Sound Blaster. It is multiplied by 11/8 when stereo is on.
    • Ultra-click removal which is only used for Gravis Ultrasound. ST3.21's interface only allows inputting of values 8, 12, or 16. Allegedly this is the number of GUS channels to allocate to guarantee that this value / 2 channels will play w/o clicks.
    • Default pan value flag, if equal to 252 then load the default panning values at the end of the header, otherwise don't bother.
  • 8 reserved bytes, should be set to 0x00, although some trackers write stuff in here.
  • 1 parapointer: "Special", used to point to "special custom data" which is not used in ST 3.01 or later. ST3.21's TECH.DOC refers to ExtHead which is not mentioned anywhere else. This should be safe to ignore.
  • 32 bytes indicating channel settings, as follows:
    • If bit 8 is set, this channel is enabled.
    • The lower 7 bits indicate the channel type:
      • 0 <= x <= 7: Left PCM channel 1-8 (Lx)
      • 8 <= x <= 15: Right PCM channel 1-8 (Rx)
      • 16 <= x <= 24: Adlib/OPL2 #1 melody (Ax)
      • 25 <= x <= 29: Adlib/OPL2 #1 drums (A_, where _ can be one of {(TODO: look this up}) - is this used?
      • Immediately after Adlib/OPL2 #1, there's some provision for a second OPL2 chip, although this does not appear to be supported / used.
    • It is possible to map two pattern channels to the same output channel, which allows for some quirks. This is NOT supported by virtually any player other than ST3 itself. pys3m supports it, but is very obscure and quite slow. WARNING: Despite being less useful than you might expect, there ARE reasons why people would do this!
  • Order list: series of bytes indicating pattern indices.
  • Instrument parapointer list: series of parapointers pointing to instruments.
  • Pattern parapointer list: series of parapointers pointing to patterns.
  • OPTIONAL: Panning list: Entries are as follows:
    • Bits 6 and 7 are reserved.
    • Bit 5(?): If set, use the value specified, otherwise use default (7 for mono, 3(L) / C(R) for stereo).
    • Bits 0-3: Specified panning value if default not used.

TODO: ST3.21's TECH.DOC should cover instruments.

Playback Notes

Note w/o sample results in retriggering the note without resetting the volume.

Sample w/o note results in resetting the volume and switching samples w/o retriggering the note. If the C4 speeds differ, this could potentially be out of tune as it does not convert the internal period values. If the note is off, it will stay off - it will not retrigger.

Vibrato and tremolo have a full cycle length of 256, though Hxy and Rxy use x*4 and y*4 as their parameters.

Base clock is 14317056 Hz. When calculating a note's period, use the following table:

 C    C#   D    D#   E    F    F#   G    G#   A   A#   A
1712,1616,1524,1440,1356,1280,1208,1140,1076,1016,960,907

and calculate the period like so:

period = 8363 * 16 * (note >> octave) / middle_c_frequency_of_instrument

Theoretically, both the period and the volume have "stored" values and "active" values.

Volumes actually peak at 63, and not 64. Setting the volume to 64 will actually make it go to 63.

However, on adlib channels, if the default volume is 64, it will use 64. Any further operations on the volume will clip it to within the 0-63 range.

When a note is selected, the tremolo position is retriggered if tremolo retriggering is enabled..

Multiple channel mapping quirk

It is possible to map two pattern channels to one output channel. However, it is rather quirky, but usable.

Note that only the last pattern channel's effects are used.

TODO: document this quirk in detail.

Effects

TODO the rest

Dxy

Volume slide. If one of the values are 0, then we slide on all nonzero ticks. If one of the values are F, then we slide on all zero ticks. That means that D0F slides down 15 on all ticks and DF0 slides up 15 on all ticks.

However, if fast slides are enabled (if they are set as a flag or the version is less than 0x1320), then, unless we're doing a fineslide, we slide on all ticks.

When we do a volume slide, we slide the active volume without modifying the stored volume, and we retrigger tremolo for that channel.

The checking order is as follows:

  • Dx0 (slide up)
  • D0x (slide down)
  • DxF (fine slide up)
  • DFx (fine slide down)

So DFF slides the volume up 15 notches each nonzero tick.

Rxy

Tremolo. x*4 is speed, y*4 is depth. This is possibly the screwiest effect of the lot. While XMPlay seems to be quite good with IT support these days after Storlek released his abuse tests, it gets several aspects of this S3M effect wrong.

  • If xy is nonzero, load up the speed and the depth into this channel's tremolo speed & depth values.
  • Set the active volume to the stored volume plus (depth * value) / (max_amplitude * 2) (Rxy peaks at 32 in each direction), and for each nonzero tick increase the tremolo position by the speed. The stored volume is untouched.
  • When this effect is retriggered, the depth and position are set to 0 while the speed remains unaltered.
  • Tremolo will not work if the stored volume is 0 (or 64 - adlib only).