<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://moddingwiki.shikadi.net/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Saga</id>
	<title>ModdingWiki - User contributions [en-gb]</title>
	<link rel="self" type="application/atom+xml" href="https://moddingwiki.shikadi.net/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Saga"/>
	<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/wiki/Special:Contributions/Saga"/>
	<updated>2026-05-14T06:33:17Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.11</generator>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=DSIK_Module_Format&amp;diff=11930</id>
		<title>DSIK Module Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=DSIK_Module_Format&amp;diff=11930"/>
		<updated>2024-07-10T14:32:15Z</updated>

		<summary type="html">&lt;p&gt;Saga: Effects &amp;gt; 0F in OpenMPT were confused with effects from another .DSM format; and 7-bit panning comes from DSMI.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 16&lt;br /&gt;
 | NumTracks = 1&lt;br /&gt;
 | NumPatterns = 65,535 (only 255 playable)&lt;br /&gt;
 | NumOrders = 128&lt;br /&gt;
 | Tags = Title, instrument names, instrument filenames&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Trugg}}&lt;br /&gt;
   {{Game|Flying Tiger}}&lt;br /&gt;
   {{Game|Rollin}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;DSIK Module Format&#039;&#039;&#039; is the music format used by the &#039;&#039;Digital Sound Interface Kit&#039;&#039; by Carlos Hasan.  This was a C and Pascal library for game authors to simplify sound card programming.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file is a &#039;&#039;&#039;non-standard&#039;&#039;&#039; [[Resource Interchange File Format (RIFF)]] structure.  It is exactly the same as a standard RIFF file, except that the padding bytes between chunks have been omitted.  So if the length of a chunk is an odd number, the padding byte should not be included and the following chunk will not start on a word boundary.&lt;br /&gt;
&lt;br /&gt;
The files are composed of the following chunks:&lt;br /&gt;
&lt;br /&gt;
* RIFF (type: DSMF)&lt;br /&gt;
** SONG&lt;br /&gt;
** INST&lt;br /&gt;
** PATT&lt;br /&gt;
&lt;br /&gt;
The data in each chunk is explained below.&lt;br /&gt;
&lt;br /&gt;
=== SONG chunk ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Song title, null-terminated&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || version || File version&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || flags ||&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || pad ||&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || numOrders || Number of valid entries in &amp;lt;tt&amp;gt;orders&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || numSamples ||&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || numPatterns ||&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || numChannels ||&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volGlobal || Global volume&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volMaster || Master volume&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || initialSpeed ||&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || initialBPM ||&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[16] || channelMap ||&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[128] || orders || Order list.  First value is index of first pattern to play, etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== INST chunk ===&lt;br /&gt;
&lt;br /&gt;
This chunk stores all the instruments in the song.  There are multiple &#039;&#039;&#039;INST&#039;&#039;&#039; chunks in the file, one per instrument.  The data in each chunk is as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| char[13] || filename || Instrument filename, null-terminated&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || flags || Zero or more of: 1=loop active, 2=signed PCM, 4=packed PCM, 64=delta PCM&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Default volume of the sample if not volume is given when a note is played.  The range is from 0 (silent) to 64 (loudest), note this is 65 different values.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Length of the sample data, in bytes.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Position of the loop start point, in bytes, relative to the start of the sample data.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopEnd || Position of the loop end point, in bytes, relative to the start of the sample data.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || address_ptr || Used internally for holding in-memory address of sample data, ignore when reading and write as zero.&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || midCRate || Default is 8363&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || period || Default for middle-C is 428&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Sample name, null-terminated&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[length] || data || Sample data, 8-bit mono PCM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Sample data must be 8-bit mono PCM, signed or unsigned based on &amp;lt;tt&amp;gt;flags&amp;lt;/tt&amp;gt; {{TODO|Confirm that signed PCM actually works}}.  Other formats are rejected by the DSIK library.  Some samples appear to be truncated .wav files and still have the &#039;data&#039; fourcc visible, however this is not part of the format and these bytes will be played as audio data, causing an audible click at the start of playback.&lt;br /&gt;
&lt;br /&gt;
The period is calculated from a sample rate (in Hertz) as &amp;lt;code&amp;gt;period = 8363 * 428 / Hertz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PATT chunk ===&lt;br /&gt;
&lt;br /&gt;
This chunk stores all the patterns in the song.  There are multiple &#039;&#039;&#039;PATT&#039;&#039;&#039; chunks in the file, one per pattern.  The data in each chunk is as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || length || Length of pattern data, in bytes, including this length field also&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[length - 2] || data || Pattern data, see below&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pattern data is comprised of a flag byte, followed by a variable number of data bytes depending on the value of the flag.  This is very similar to [[S3M Format]] but the bit fields are different.  The flag byte is broken down as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!width=100| 7 !!width=100| 6 !!width=100| 5 !!width=100| 4 !!width=100| 3 !!width=100| 2 !!width=100| 1 !!width=100| 0&lt;br /&gt;
|-&lt;br /&gt;
| Note present&lt;br /&gt;
| Instrument present&lt;br /&gt;
| Volume present&lt;br /&gt;
| Command present&lt;br /&gt;
|colspan=4 align=center| Channel number&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* If the entire value is zero, the row number is incremented and the next flag is read.  Otherwise:&lt;br /&gt;
* If the flag indicates a note is present, the next byte is the note.   Note numbers are semitones, with note 49 being middle C, note 50 being C#4, note 51 being D4, etc.  Adding 11 to the note number will turn them into standard MIDI note numbers.&lt;br /&gt;
* If an instrument is present, the next byte is the zero-based index of the instrument to use.&lt;br /&gt;
* If a volume is present, the next byte is the volume for this note/channel.  The range is from 0 (silent) to 64 (loudest), note this is 65 different values.&lt;br /&gt;
* If a command is present, the next two bytes are the command and value respectively.  Standard .mod commands appear to be used {{TODO|Confirm}}&lt;br /&gt;
&lt;br /&gt;
After these bytes have been read, the next flag byte is read.  Once 64 rows have been read, the end of the pattern data should have been reached.&lt;br /&gt;
&lt;br /&gt;
If the instrument is read but it is zero, then the previous instrument on that channel should be used instead (same as S3M).&lt;br /&gt;
&lt;br /&gt;
Effects are the same as in MOD files (i.e. 0x00 through 0x0F are valid effect commands).&lt;br /&gt;
&lt;br /&gt;
Effect 0x08 is 7-bit panning (0x00 = left, 0x80 = right) with parameter 0xA4 enabling surround, as introduced by Dual Module Player and the DSMI library.&lt;br /&gt;
&lt;br /&gt;
=== Timing ===&lt;br /&gt;
&lt;br /&gt;
See [[S3M Format#Timing]] for a discussion on timing using the &amp;lt;tt&amp;gt;initialBPM&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;initialSpeed&amp;lt;/tt&amp;gt; values.&lt;br /&gt;
&lt;br /&gt;
=== Design issues ===&lt;br /&gt;
&lt;br /&gt;
The file format suffers from a number of design inconsistencies:&lt;br /&gt;
&lt;br /&gt;
* The &#039;&#039;&#039;DSMF&#039;&#039;&#039; format should have been registered with Microsoft as it is in uppercase, however this does not appear to have been done&lt;br /&gt;
* The &#039;&#039;&#039;INST&#039;&#039;&#039; and &#039;&#039;&#039;PATT&#039;&#039;&#039; chunks should have been placed inside &#039;&#039;&#039;LIST&#039;&#039;&#039; chunks, in the spirit of the RIFF format&lt;br /&gt;
* The instrument chunk includes a length field for the sample data, however this is redundant as the chunk itself already has a length.  The two length fields do make it possible to store additional data between the end of the sample data and the end of the chunk, which would normally be ignored, however it seems simpler to just define a new chunk type if new data needs to be stored without breaking backwards compatibility.&lt;br /&gt;
* The instrument chunk stores an address field even though this is only used during playback and does not need to be stored in the file.&lt;br /&gt;
* The pattern chunk also has an extra field to store the length of the pattern data.  However the value in this field includes the length of the field itself, making the value identical to the RIFF chunk&#039;s length field.  The result is that the identical value is written twice, once as a 32-bit value for the RIFF PATT chunk and then immediately again as a 16-bit value.&lt;br /&gt;
* The number of instruments and patterns is stored in the &#039;&#039;&#039;SONG&#039;&#039;&#039; chunk, however this is redundant as the values can be calculated from the number of &#039;&#039;&#039;INST&#039;&#039;&#039; and &#039;&#039;&#039;PATT&#039;&#039;&#039; chunks respectively.&lt;br /&gt;
* There is a 16-bit value for the number of orders, allowing up to 65,535 orders in the song, yet there is a fixed-length array allowing only 128 orders.&lt;br /&gt;
* The pattern count is 16-bit allowing up to 65,536 patterns in the song, but the order list is made up of 8-bit values, meaning only the first 256 patterns can be played.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[Camoto]]&lt;br /&gt;
| Platform = Linux/Windows&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canExport = Many&lt;br /&gt;
| canImport = Many&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = Yes&lt;br /&gt;
| notes = Minimal support for effects&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = Chronos Module Converter&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = [[MOD Format|.mod]] .stm [[S3M Format|.s3m]] .mtm .dsm .psm&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = Most accurate for converting .dsm to .s3m&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = DSIK&#039;s &amp;lt;tt&amp;gt;conv.exe&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = [[MOD Format|.mod]] .stm [[S3M Format|.s3m]] .669 .mtm&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = Yes&lt;br /&gt;
| notes = Official tool&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = ModPlug&lt;br /&gt;
| Platform = Windows&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = Plays at wrong tempo (no support for effect 0x0F)&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = OpenMPT&lt;br /&gt;
| Platform = Any&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Many&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
&lt;br /&gt;
* The original Digital Sound Interface Kit library is available as &amp;lt;tt&amp;gt;dsik_c.zip&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;dsik_pas.zip&amp;lt;/tt&amp;gt; for the C and Pascal versions respectively, from various FTP sites such as [http://ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/wgt/ lanet.lv]&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
This file format was documented by [[User:Malvineous|Malvineous]] by reading the DSIK sample code, with the pattern data documented from reading the OpenMPT source code.  If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;br /&gt;
&lt;br /&gt;
[[Category:DSIK]]&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=10926</id>
		<title>ProTracker Studio Module</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=10926"/>
		<updated>2023-03-28T21:16:26Z</updated>

		<summary type="html">&lt;p&gt;Saga: /* Order sub-segment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 1-256 (PSM) / 1-32 (PSM16)&lt;br /&gt;
 | NumTracks = unlimited (PSM) / 1 (PSM16)&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Epic Pinball}}&lt;br /&gt;
   {{Game|Extreme Pinball}}&lt;br /&gt;
   {{Game|Jazz Jackrabbit}}&lt;br /&gt;
   {{Game|One Must Fall}}&lt;br /&gt;
   {{Game|Silverball}}&lt;br /&gt;
   {{Game|Sinaria}}&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;ProTracker Studio Module&#039;&#039;&#039; (PSM) file format is used for the music in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]].  The file format is named after ProTracker, an Amiga program, though this program was probably actually not used to write PSM files. One Must Fall&#039;s music was written in Multitracker, and the music for Jazz Jackrabbit, Epic Pinball and Extreme Pinball probably in Scream Tracker.&lt;br /&gt;
&lt;br /&gt;
There are two file types that use the extension .PSM; they are both used by Epic Megagames&#039; MASI sound system, but are used by different versions of the system. The two formats are:&lt;br /&gt;
&lt;br /&gt;
* PSM New Format: Used by Jazz Jackrabbit, Epic Pinball, Extreme Pinball, One Must Fall, Sinaria (in this game with slight differences, see below), newest PSM format&lt;br /&gt;
* PSM 16:         Used by Silverball, an older version of the format which is closer to ScreamTracker-style modules.&lt;br /&gt;
&lt;br /&gt;
The most common of the two PSM formats is the new format, and most programs that try to interpret PSM files will be expecting this. For example, ModPlug Player cannot open Silverball files as these are in the PSM 16 format.&lt;br /&gt;
&lt;br /&gt;
There are actually two slightly different variants of the new formats: A common one used in several games, and one used in the game Sinaria. It is not entirely clear if the format used in Sinaria is newer or older - in some ways, like the effect interpretation, it resembles PSM16 more than the new format, so it could be an earlier version of the new PSM format. But Sinaria was released later than or around the same time as most other games using the new PSM format, so maybe it just took really long to develop. The format not used in Sinaria will be called &amp;quot;regular&amp;quot; in this document.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM New Format =&lt;br /&gt;
&lt;br /&gt;
This format is used by [[:Category:Epic Megagames|Epic]] games in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]]. It is notable for consisting of a number of segments (chunks) and sub segments. It bears the 4-byte signature &#039;PSM &#039; at the file start.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Song segment&lt;br /&gt;
 Samples&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 12 bytes long:&lt;br /&gt;
&lt;br /&gt;
 File header:&lt;br /&gt;
 0   4  ID     &#039;PSM &#039;; indicates file is PSM format&lt;br /&gt;
 4   4  Size   Filesize - 12&lt;br /&gt;
 8   4  ID2    &#039;FILE&#039;; indicates start of file info&lt;br /&gt;
&lt;br /&gt;
After the header, some chunks follow in IFF-style. You should not expect chunks to come up in the same order as they are described here. A good way to handle chunks is to read the 4-Byte ID and the 4-Byte size field first, then evaluate the ID and decide what to do next based on this ID. Note that the size field does not include the ID and itself; it only holds the size of the chunk &#039;&#039;content&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Title segment ==&lt;br /&gt;
&lt;br /&gt;
This segment is optional, and one of the few segments that can be absent when playing PSM files in most programs. (Most programs expect all other segments to exist, even if they are not vital.)&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;TITL&#039;; indicates a title follows&lt;br /&gt;
 4   4  Size   Size of title as dword after this dword&lt;br /&gt;
 8   ?  Title  Song title&lt;br /&gt;
&lt;br /&gt;
== Song info segment ==&lt;br /&gt;
&lt;br /&gt;
This segment seems to indicate the beginning of the song data and is not really relevant when parsing.&lt;br /&gt;
&lt;br /&gt;
 12  4  ID     &#039;SDFT&#039;; indicates start of format info&lt;br /&gt;
 16  4  Size   Size of next header as dword, (8)&lt;br /&gt;
 20  8  Song   &#039;MAINSONG&#039;; indicates song type. No other song types are known.&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
Each pattern is stored in its own PBOD chunk. Note that there are two possible formats for this chunk; one is used in the &amp;quot;regular&amp;quot; format (as used in Epic Pinball, Extreme Pinball, Jazz Jackrabbit, One Must Fall) and the other in the &amp;quot;Sinaria&amp;quot; format (as used in Sinaria)&lt;br /&gt;
&lt;br /&gt;
 Pattern segment:&lt;br /&gt;
 0   4  ID     &#039;PBOD&#039;; indicates a pattern follows (Pattern BODy)&lt;br /&gt;
 4   4  Size   Length of pattern data as dword, after this dword&lt;br /&gt;
 4   4  Size   Same value again.&lt;br /&gt;
&lt;br /&gt;
 Pattern:&lt;br /&gt;
 0 4/8  Number Pattern ID. See note below.&lt;br /&gt;
 4   2  Row n  Number of rows in ALL channels in pattern (64 usually, but can differ.) as word.&lt;br /&gt;
 6   ?  Data   Contains pattern data as a number of rows of interlaced channels (12341234...)&lt;br /&gt;
               &#039;&#039;Usual&#039;&#039; settings is 64 rows of 4 channels. Epic Pinball has shorter patterns for example, but they also include a &amp;quot;break to row&amp;quot; command at the end of the pattern.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; There are two variants of the format. In the &amp;quot;regular&amp;quot; variant, the pattern ID is 4 bytes long and starts with a &#039;P&#039;, followed by an integer number which is the pattern number, padded to 4 bytes with spaces. Caution: This number might or might not be zero-padded; In some files, the ID of the first pattern could be &#039;P0  &#039;, but there are also files where it is &#039;P00 &#039;!. In C/C++, you could use atoi() to parse this value.&lt;br /&gt;
In the format used in the game Sinaria, This field is 8 bytes long instead of 4 bytes, and the first 4 bytes read &amp;quot;PATT&amp;quot;, so the first pattern could be for example &#039;PATT0   &#039;. You may want to deal with this by first reading for bytes, and if they are equal to &amp;quot;PATT&amp;quot;, read four more bytes for the pattern ID.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Pattern row channel entry:&lt;br /&gt;
 ?   1  Flags  Contains four flags that indicate which pattern data follows&lt;br /&gt;
 +1  1  Chan   The channel this data belongs to.&lt;br /&gt;
 +2  1  Note   Present if bit 7 in Flags is set. Pitch, $01 is C-1, etc... The octaves&lt;br /&gt;
               are aligned by 16, i.e. B-1 is $0C but the next note, C-2, is $10.&lt;br /&gt;
 +3  1  Ins    Present if bit 6 in Flags is set. Instrument used, 0-31&lt;br /&gt;
 +4  1  Vol    Present if bit 5 in Flags is set. Volume change to, 0-63 = 0-127; optional&lt;br /&gt;
 +5  1  Effect Present if bit 4 in Flags is set. Effect to use, volume slide, Portamanto...&lt;br /&gt;
 +6  x  Eff Am Present if bit 4 in Flags is set. Parameter of effect, e.g amount of slide&lt;br /&gt;
&lt;br /&gt;
Each row consists of a word giving the size of the row (Including the word) followed by the channel data. A channel is only included if it has data in it, but a totally empty row is still included. So an &#039;empty&#039; row (Where none of the channels have data.) thus consists of just a word of value 2.&lt;br /&gt;
&lt;br /&gt;
Each channel entry consists of between 3-7 bytes. The first byte is a flag that shows what data follows. (The highest four bits indicate whether there are bytes for the following four variables; Note ($80), Instrument ($40), Volume ($20), Effect AND Effect parameter ($10). Thus 5 bytes are represented by a combination of 4 possibilities.) The next byte identifies the channel (Since each channel may or may not be present.) starting at 0 for channel 1. The remaining 5 bytes may or may not be present depending on their flag and contain data for Note, Instrument(Sample) used, Volume change for channel, Effect and Effect parameter.&lt;br /&gt;
&lt;br /&gt;
There are several things to note about this; Effect and Effect magnitude MUST occur together. Sample numbers, like channels are numbered starting at 0, not 1. Magnitudes (For effect AND volume) are from 0-127, not 0-64 as in other formats.&lt;br /&gt;
&lt;br /&gt;
=== Effect conversion ===&lt;br /&gt;
&lt;br /&gt;
Note that this table is guaranteed to be correct; Most effects seem to be converted correctly, though. Note that these values are not correct for the PSM files that can be found in the game Sinaria. Leave out all divisions and it will be correct again.&lt;br /&gt;
&lt;br /&gt;
 PSM Command   Param length  S3M Command&lt;br /&gt;
 &lt;br /&gt;
  Volume commands&lt;br /&gt;
    1           1 Byte        DxF - fine volside up&lt;br /&gt;
    2           1 Byte        Dx0 - volslide up&lt;br /&gt;
    3           1 Byte        DFx - fine volslide down&lt;br /&gt;
    4           1 Byte        D0x - volslide down&lt;br /&gt;
 &lt;br /&gt;
 Portamento commands&lt;br /&gt;
    B           1 Byte        FFx - fine porta up (divide x by 4)&lt;br /&gt;
    C           1 Byte        Fxx - porta up (if x &amp;lt; 4, use FFx, else divide x by 4)&lt;br /&gt;
    D           1 Byte        EFx - fine porta down (divide x by 4)&lt;br /&gt;
    E           1 Byte        Exx - porta down (if x &amp;lt; 4, use EFx, else divide x by 4)&lt;br /&gt;
    F           1 Byte        Gxx - portamento (divide x by 4)&lt;br /&gt;
   10           1 Byte        S1x - glissando control&lt;br /&gt;
   11           1 Byte        Lx0 - tone porta + volslide up&lt;br /&gt;
   12           1 Byte        L0x - tone porta + volslide down&lt;br /&gt;
    &lt;br /&gt;
 Vibrato&lt;br /&gt;
   15           1 Byte        Hxy - vibrato&lt;br /&gt;
   16           1 Byte        S3x - vibrato waveform&lt;br /&gt;
   17           1 Byte        K0x - vibrato + volslide up&lt;br /&gt;
   18           1 Byte        Kx0 - vibrato + volslide down&lt;br /&gt;
   	&lt;br /&gt;
 Tremolo			&lt;br /&gt;
   1F           1 Byte        Rxy - tremolo&lt;br /&gt;
   20           1 Byte        S4x - tremolo waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample commands&lt;br /&gt;
   29           3 Bytes       Oxx - offset (xx corresponds to the 2nd byte)&lt;br /&gt;
   2A           1 Byte        Q0x - retrigger&lt;br /&gt;
   2B           1 Byte        SCx - note cut&lt;br /&gt;
   2C           1 Byte        SDx - note delay&lt;br /&gt;
 &lt;br /&gt;
 Position change&lt;br /&gt;
   33           2 Bytes       Bxx - position jump - ignored by PLAY.EXE&lt;br /&gt;
   34           1 Byte        Cxx - break to row&lt;br /&gt;
                                    PLAY.EXE entirely ignores the parameter (it always breaks to the first&lt;br /&gt;
                                    row), so it is maybe best to do this in your own player as well.&lt;br /&gt;
                                    If the original file was an S3M, the parameter is double-BCD-encoded,&lt;br /&gt;
                                    i.e. on top of the original format&#039;s BCD encoding, the same encoding&lt;br /&gt;
                                    is applied again. to translate into the correct target row in binary,&lt;br /&gt;
                                    apply this twice: param = (param &amp;amp; 0xF0) * 10 + (param &amp;amp; 0x0F)&lt;br /&gt;
                                    For MOD files, the parameter is a normal binary number.&lt;br /&gt;
   35           1 Byte        SBx - pattern loop&lt;br /&gt;
   36           1 Byte        SEx - pattern delay&lt;br /&gt;
  &lt;br /&gt;
 Speed change&lt;br /&gt;
   3D           1 Byte        Axx - set speed&lt;br /&gt;
   3E           1 Byte        Txx - set tempo&lt;br /&gt;
 &lt;br /&gt;
 Misc. commands&lt;br /&gt;
   47           1 Byte        Jxy - arpeggio&lt;br /&gt;
   48           1 Byte        S2x - set finetune&lt;br /&gt;
   49           1 Byte        S8x - set balance&lt;br /&gt;
&lt;br /&gt;
Effect interpretation is slightly different in Sinaria&#039;s format. Slide command parameters are more like in PSM16.&lt;br /&gt;
&lt;br /&gt;
== Song segment ==&lt;br /&gt;
&lt;br /&gt;
This segment contains most of the important data used to play the song. It contains several sub-segments, each of the same format as a normal segment, but contained in the song segment. Note that there might be more than one song segment and thus, more than one order list, default speed, default tempo, etc... For example, in Extreme Pinball, all the different jingles and mission songs are stored as separate SONG chunks. It is up to the developer to find a clever way of managing / playing several sub songs.&lt;br /&gt;
&lt;br /&gt;
 Segment structure:&lt;br /&gt;
 0   4  ID     &#039;SONG&#039; indicates start of song structure&lt;br /&gt;
 4   4  Size   Size of song structure, including all sub-segments&lt;br /&gt;
 8   9  Type   Type of song this is for; This is &#039;MAINSONG &#039; in almost all PSM files. Extreme Pinball has several SONG items with different types!&lt;br /&gt;
 17  1  Comp   Compression, for PSM = 1 (Uncompressed)&lt;br /&gt;
 18  1  Chan   Number of channels, usually, but not always, 4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Date sub-segment ===&lt;br /&gt;
&lt;br /&gt;
This dates the file and is used by some programs. It is usually the first sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DATE&#039; indicates date data&lt;br /&gt;
 4   4  Size   Size of date segment (6)&lt;br /&gt;
 8   6  Date   Date as text, YYMMDD&lt;br /&gt;
&lt;br /&gt;
This can also be used as a way to heuristically detect if the regular or Sinara version of the format is being used. Sinaria&#039;s song dates are: 800211, 940902, 940903, 940906, 940914, 941213&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Order sub-segment ===&lt;br /&gt;
&lt;br /&gt;
The order list describes how patterns are arranged in the song. This allows the same pattern of instruments to be played more than once in a song (e.g. a chorus). without the pattern data having to be duplicated. There should be only one order. In most module formats, the order list only consists of pattern indices, but in the PSM format it resembles a tiny scripting language that can do more than just list patterns. For example, It typically contains chunks that set the tempo of the song and the channel panning. In theory, these chunks can occur between two pattern chunks, changing the tempo or panning of a pattern without having to duplicate the pattern data, but in practice this feature is not used, so it can be ignored when writing a PSM loader.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;OPLH&#039; indicates start of pattern placement order&lt;br /&gt;
 4   4  Size   Size of order segment&lt;br /&gt;
 8   2  Cnt.   Number of following chunks&lt;br /&gt;
&lt;br /&gt;
Now, the following chunks may follow until the end of the &amp;quot;OPLH&amp;quot; chunk is reached. Every chunk is identified by its first byte:&lt;br /&gt;
* $00 (1 Byte): End (Nothing follows)&lt;br /&gt;
* $01 (5/9 Bytes): Order list item follows (e.g. &amp;quot;P0 &amp;amp;nbsp;&amp;quot;, &amp;quot;P12 &amp;quot; in regular format or &amp;quot;PATT0 &amp;amp;nbsp;&amp;amp;nbsp;&amp;quot; in Sinaria format, see above) - join those to get the complete order list.&lt;br /&gt;
* $02 (7 Bytes): Play Range: The command appears to take three 16-bit values (PLAY.EXE displays &amp;quot;xx from yy to zz&amp;quot;), however parsing of the next opcode continues at the position of the third parameter, and PLAY.EXE crashes with a division error. This command is not used in any known soundtrack, and is not written by CONVERT.EXE.&lt;br /&gt;
* $03 (4 Bytes): Jump Loop: Works the same as $04 Jump Line, but with another byte following after the 16-bit value. The purpose of that byte is unknown. This command is not used in any known soundtrack, and is not written by CONVERT.EXE.&lt;br /&gt;
* $04 (3 Bytes): Jump Line: This 16-bit value indicates the &amp;quot;restart chunk&amp;quot;. If the end of the subsong is reached, it will jump back to this chunk. In many cases, this would be 4th chunk (not 3rd chunk, as the chunk index is starting at 0!), which is a panning index in most PSMs - So you would just go to the nearest order list item that&#039;s following this chunk. However, this can also point to a valid order list chunk.&lt;br /&gt;
* $05: Channel Flip (3 Bytes): Changes the channel type without specifying pan position. The first byte is the channel index, the second byte is the channel type (see command $0D). This command is not used in any known soundtrack, and is not written by CONVERT.EXE.&lt;br /&gt;
* $06: Transpose (2 Bytes): Does not appear to do anything, regardless of parameter. This command is not used in any known soundtrack, and is not written by CONVERT.EXE.&lt;br /&gt;
* $07 (2 Bytes): Next byte sets the speed (ticks/row) for this subtune&lt;br /&gt;
* $08 (2 Bytes): Next byte sets the tempo for this subtune&lt;br /&gt;
* $0C (7 Bytes): Sample map table: This chunk is always $0C $00 $FF $00 $00 $01 $00. This seems to be an unfinished feature of the order list scripting language. It appears that this maps e.g. what is &amp;quot;I0&amp;quot; in the file to sample 1. Only the fourth and fifth byte ($00 $00) actually seem to do something: They translate the sample number in the pattern to different instruments in the file.&lt;br /&gt;
* $0D (4 Bytes): Channel panning index. Next byte is channel number (Start at 0), then initial pan ($00 ... $FF) and a type byte follow. The byte seems to tell what to do with the previous pan position (0 - use it, 2 - ignore it, make this channel surround, 4 - set to center).&lt;br /&gt;
* $0E (3 Bytes): Channel volume index. Next byte is channel number (Start at 0), then volume ($00 ... $FF). $FF in most cases. Some OMF 2097 tracks use a lower volume.&lt;br /&gt;
&lt;br /&gt;
=== Pattern list ===&lt;br /&gt;
&lt;br /&gt;
This is simply a list of all the patterns used in the file. You do not really need to parse this, it seems to be a purely informational chunk.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;PATT&#039; indicates start of pattern list&lt;br /&gt;
 4   4  Size   Size of pattern list after this&lt;br /&gt;
 8   4  Size   Same as above&lt;br /&gt;
 12  4x Pat    An ordered list &#039;P0  &#039;, &#039;P1  &#039;... for all patterns in the file, each entry 4 bytes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sample list sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Similar to the above, this is a list of all the samples used in the file. It is usually the last sub-segment in the song segment and you do not really need to parse this.&lt;br /&gt;
&lt;br /&gt;
  0  4   ID     &#039;DSAM&#039;; indicates start of sample list, used to say what samples are &#039;full&#039;&lt;br /&gt;
                Any samples not on this list will be ignored, even if they have data&lt;br /&gt;
  4  4   Size   Size of list after this&lt;br /&gt;
  8  4   Size   Same value as above&lt;br /&gt;
  12 15x Entry  Sample entries, one for each sample in the file, each entry 15 bytes&lt;br /&gt;
&lt;br /&gt;
 Sample entry:&lt;br /&gt;
 0   8  Format Sample format, padded with spaces (END, RAG2...) This is important to some programs&lt;br /&gt;
 8   4  ID     &#039;I0  &#039;, &#039;I1  &#039;... the sample ID (&#039;I&#039; means &#039;Instrument&#039;). Again, be sure to accept both &#039;I0  &#039; and &#039;I00 &#039;!&lt;br /&gt;
 12  2  Num    The sample number, 0,1,2... for the sample&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
Samples are the raw sound data that makes up the instruments on the song. The actual format depends on the sample format. Samples have information in their headers which allows data to be played at different pitches (Speeds.) and to loop from and to various points in the data. This is by far the largest part of the file, since the raw data takes up so much space.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DSMP&#039; indicates start of sample&lt;br /&gt;
 4   4  Size   Size of following sample as &#039;DSMP&#039; + dword from end of word&lt;br /&gt;
 8   9  Flags  If highest bit is set, then sample is looped&lt;br /&gt;
 9   8  Songn. Filename of the original module (without extension)&lt;br /&gt;
 17  4  INSx   Last digit of sample (Instrument) number, 0-9; with 31 instruments possible&lt;br /&gt;
               Only last digit is shown. E.g 1st, 11th, 21st and 31st sample is &#039;INS0&#039;&lt;br /&gt;
 21  33 Name   Defines the instrument name or file, usually a .st or line of text&lt;br /&gt;
 54  51 Header Sample parameters (Can also 58 bytes long, padded with nuls)&lt;br /&gt;
               Byte 1-6 are unknown (but apparently always $00 $00 $00 $00 $00 $FF)&lt;br /&gt;
               Bytes 7-8 is instrument number&lt;br /&gt;
               Bytes 9-12 are sample length&lt;br /&gt;
               Bytes 13-16 are loop start&lt;br /&gt;
               Bytes 17-20 are loop end (all $FF means at end of sample)&lt;br /&gt;
               Bytes 21-22 are unknown (second byte could be finetune in Sinaria, but seems to be unused)&lt;br /&gt;
               Byte 23 is default volume&lt;br /&gt;
               Bytes 24-27 are unknwon&lt;br /&gt;
               Bytes 28-31 is frequency (Sample rate). MASI ignores the upper 16 bits, even if they are non-zero.&lt;br /&gt;
               19 $00-bytes follow (padding?)&lt;br /&gt;
 105 ?  Data   Music data in 8-bit mono format&lt;br /&gt;
&lt;br /&gt;
The sample header is slightly different in Sinaria&#039;s format: INSx is 8 bytes long (like the PATT IDs), and the last 21 $00-bytes are just 16 bytes (so that the struct is 96 bytes large in both formats).&lt;br /&gt;
&lt;br /&gt;
The PSM new format, along with the PSM 16 format use delta-encoded samples, something to make the file smaller when zipped. &#039;Deltas&#039;, convert a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. It has the effect that if a single byte in the sample is changed, the entire sample will be degraded. This use of deltas varies slightly from that of the PSM 16. The &#039;start value&#039; of the string is assumed to be $80 (128) and the first byte will thus turn this into the first desired value, the second delta converts the first value to the second, and so on.) All deltas are signed, 1-byte values, but loop (Thus 10 - 20 = -10 can also be considered as 10 + 236 = 246). An example of this is as follows:&lt;br /&gt;
&lt;br /&gt;
 RAW:   (128) 64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: -64  0   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Encryption ==&lt;br /&gt;
&lt;br /&gt;
CONVERT.EXE can produce &amp;quot;encrypted&amp;quot; PSM files with the /K command line switch. The encryption scheme is simple: It adds 1 to the first byte, 2 to the second, 3 to the third, and so until, for the entire file. It does not appear like any game made use of this feature, though.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM 16 =&lt;br /&gt;
&lt;br /&gt;
This is the format used in [[Silverball]], early versions of Epic Pinball and possibly other games. The designation &#039;Protracker Studio 16 format&#039; was given to it by the only reliable source of information on this format, and may not be the official designation.&lt;br /&gt;
&lt;br /&gt;
The format bears many similarities to the S3M format; the file is set out roughly the same, patterns and samples are similar, indeed, near identical and the functionality is similar. It also shows many similarities to the ProTracker MOD format and retains vestiges of Amiga compatibility.&lt;br /&gt;
&lt;br /&gt;
This format can be identified by its signature &#039;PSMþ&#039;, though files may lack this and still function.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Order&lt;br /&gt;
 Pan segment&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Sample data&lt;br /&gt;
 Sample headers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
 0    4  Sig      Signature, &#039;PSMþ&#039;&lt;br /&gt;
 4    59 Title    Song title, padded with nulls. Unlike other formats, this must also be terminated&lt;br /&gt;
                  with a null byte. (It sometimes is not terminated, though.)&lt;br /&gt;
 62   1           This must be $1A to end the song name, like in S3M format.&lt;br /&gt;
 64   1  Type     Song type, First bit: 0 - Module (w/samp.), 1 - Song (w/o samples)&lt;br /&gt;
                  Second bit: 0 - 3 octave Protracker, 1 - 5 octave; remaining bits reserved.&lt;br /&gt;
 65   1  PSM v    PSM format version, $10 for this format (Hence the name PSM 16) = &#039;v1.00&#039;.&lt;br /&gt;
                  Sometimes, this is also $01, but there&#039;s no difference in the format itself.&lt;br /&gt;
 66   1  Patt v   Pattern version, 0 or 1. 0 means the pattern is stored in the module are in the 32&lt;br /&gt;
                  channel file format.  A 1 signifies the patterns as being stored as a 255&lt;br /&gt;
                  channel format. (I have not found any PSM16 modules that have this format.)&lt;br /&gt;
 67   1   Speed   Song speed&lt;br /&gt;
 68   1   BPM     Beats per minute, the default Amiga BPM value. (The only reason that the Amiga BPM&lt;br /&gt;
                  format is still followed here is that it allows more control over the final hz value.)&lt;br /&gt;
                  Range: 32 to 255.&lt;br /&gt;
 69   1   Vol     Master volume of song, 0-255&lt;br /&gt;
 70   2   Len     Song length, 0-255. The number of patterns to play in the song, in total.&lt;br /&gt;
 72   2   Ordlen  The number of orders actually stored at the order offset. It was hoped that the&lt;br /&gt;
                  PSM 16 format would allow multiple orders, so this would be the length of the first&lt;br /&gt;
                  order. This doesn&#039;t appea to ahve happened, and is usually the same as the previous value.&lt;br /&gt;
 74   2   Patnum  Number of patterns in the song. 1-255&lt;br /&gt;
 76   2   Sampnum Number of samples and &#039;sample structures&#039; in song, 1-255&lt;br /&gt;
 78   2   NCIS    Number of channels in song to PLAY. 1-32. &lt;br /&gt;
 80   2   NCP     Number of Channels to Process; describes the MAXIMUM number of channels to process.&lt;br /&gt;
                  As an example, when converting 669 files,  NCP = 9 because some track information &lt;br /&gt;
                  is in Channel 8, but the Number of Channels to Play was set to 8, (Channel numbers&lt;br /&gt;
                  to play from 0 to 7.) 1-32&lt;br /&gt;
 82   4   Ordoff  Location of order in header&lt;br /&gt;
 86   4   Panoff  Location of pan positions in header&lt;br /&gt;
 90   4   Patoff  Location of patterns in header&lt;br /&gt;
 94   4   Sampoff Location of sample headers in header&lt;br /&gt;
 98   4   Commoff Location of comments in header&lt;br /&gt;
 102  4   Patsiz  Total pattern size; the total size of all the patterns loaded from the pattern offset.&lt;br /&gt;
 106  40  Fillers 10 fillers, to be used for any possible expansions.&lt;br /&gt;
&lt;br /&gt;
It is important to notice that the offsets point to the first byte &#039;&#039;&#039;after&#039;&#039;&#039; the chunk ID, i.e. &amp;quot;Ordoff&amp;quot; points to the first byte after &amp;quot;PORD&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Order and Pan positions ==&lt;br /&gt;
&lt;br /&gt;
These are two separate segments, pointed to in the header. They may be anywhere, but usually follow the header sometimes after an amount of blank space. They are often padded with blank space. They are basically lists.&lt;br /&gt;
&lt;br /&gt;
Order: This segment is pointed to in the header, and sets the PSM 16 format apart. The PSM 16 format was designed to be much more like the MOD format, allowing game designers to set flags to switch from one set of patterns to another, in effect allowing one file to contain more than one song. (For example a boss flag might make the music switch from a clam patterns 1-4 to a racy and dangerous patterns 5-7.)&lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    Signature, not needed, &#039;PORD&#039;&lt;br /&gt;
 4    ?   Ords   Pattern numbers and order. There will be [Ordlen] bytes of patterns&lt;br /&gt;
 ?    2   Lang   Order language, not implemented, so left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pan Positions: &lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    &#039;PPAN&#039;&lt;br /&gt;
 4    12  Pan    Pan positions; empty positions left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
 0    2   Size   Size of pattern, including these bytes&lt;br /&gt;
 2    1   Len    Length of pattern, in rows. Max length is 64 rows.&lt;br /&gt;
 3    1   Chan   Number of channels in pattern, 1-32&lt;br /&gt;
 4    ?   Data   Pattern data&lt;br /&gt;
&lt;br /&gt;
This is similar to the previous two segments, except actual pattern data is stored here. Patterns are very similar to the S3M format, and consist of y rows of x channels. Each row contains a number of channels and ends with a byte of value 0. Each channel is between 2-6+ bytes long. A totally empty channel is represented by a single byte of value 0.&lt;br /&gt;
&lt;br /&gt;
Each channel starts with a flag byte, abcddddd, where a,b and c indicate whether there is a note and instrument, volume or special effect and effect magnitude in the following data, and dddd is the channel number (0-31, used since a given channel may or may not be present in a row.)&lt;br /&gt;
&lt;br /&gt;
The usual maximum length of a channel entry is 6 bytes (1 flag byte, 2 Note AND instrument bytes, 1 volume byte and two Effect and Effect magnitude bytes.) Thus Note&amp;amp;ins\Eff&amp;amp;Eff mag must always occur together.&lt;br /&gt;
&lt;br /&gt;
Like S3M, volume range is 0-64, as is special magnitude. However, special effects range from 0-255, like PSM New Format.&lt;br /&gt;
&lt;br /&gt;
=== Effects conversion ===&lt;br /&gt;
&lt;br /&gt;
 ###  Co  MOD  Description               Arguments&lt;br /&gt;
 ---  --  ---  -----------               ---------&lt;br /&gt;
 Volume Commands&lt;br /&gt;
   1  A1   EA  Fine Volume Slide Up      B xx xx=speed&lt;br /&gt;
   2  A2   A   Volume Slide Up           B xx xx=speed&lt;br /&gt;
   3  A3   EB  Fine Volume Slide Down    B xx xx=speed&lt;br /&gt;
   4  A4   A   Volume Slide Down         B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Portamento Commands&lt;br /&gt;
  10  B0   E1  Fine Porta Up             B xx xx=speed&lt;br /&gt;
  11  B1   1   Portamento Up             B xx xx=speed&lt;br /&gt;
  12  B2   E2  Fine Porta Down           B xx xx=speed&lt;br /&gt;
  13  B3   2   Portamento Down           B xx xx=speed&lt;br /&gt;
  14  B4   3   Tone Portamento           B xx xx=speed&lt;br /&gt;
  15  B5   E3  Set Glissando Control     B xx xx=0 - Off, 1 - On&lt;br /&gt;
  16  B6   5   Tone Port+Vol Slide Up    B xx xx=speed&lt;br /&gt;
  17  B7   5   Tone Port+Vol Slide Down  B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Vibrato Commands&lt;br /&gt;
  20  C0   4   Vibrato                   B xy x=speed, y=depth&lt;br /&gt;
  21  C1   E4  Set Vibrato Waveform      B x  x=Waveform&lt;br /&gt;
  21  C2   6   Vibrato+Vol Slide Up      B xx xx=speed&lt;br /&gt;
  22  C3   6   Vibrato+Vol Slide Down    B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Tremolo Commands&lt;br /&gt;
  30  D0   7   Tremolo                   B xy x=speed, y=depth&lt;br /&gt;
  31  D1   E7  Set Tremolo Control       B x  x=Waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample Commands&lt;br /&gt;
  40  E0   9   Sample Offset             3B Position for offset change (0-1,048,575)&lt;br /&gt;
  41  E1   E9  Retrig Note               B xx xx=tick to retrigger sample&lt;br /&gt;
  42  E2   EC  Note Cut                  B xx xx=tick to cut note&lt;br /&gt;
  43  E3   ED  Note Delay                B xx xx=ticks to delay note&lt;br /&gt;
 &lt;br /&gt;
 Pos. Change Commands&lt;br /&gt;
  50  F0   B   Position Jump             B xx xx=order position&lt;br /&gt;
  51  F1   D   Pattern Break             B xx Skip to line xx in next pattern&lt;br /&gt;
  52  F2   E6  Jump Loop                 B xx xx=number of loops  0 Set&lt;br /&gt;
  53  F3   EE  Pattern Delay             B xx xx=notes to delay pattern&lt;br /&gt;
 &lt;br /&gt;
 Speed Change Cmds&lt;br /&gt;
  60  G0   F   Set Regular Speed         B xx xx=speed&lt;br /&gt;
  61  G1   F   Set BPM                   B xx xx=BPM (32-255)&lt;br /&gt;
 &lt;br /&gt;
 Misc. Commands&lt;br /&gt;
  70  H0   0   Arpeggio                  B xy x=semitone #1, y=semitone #2&lt;br /&gt;
  71  H1   E5  Set Finetune              B xx xx=finetune&lt;br /&gt;
  72  H2       Set Balance               B xx xx=Balance (0-15)&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
 Sample segment&lt;br /&gt;
 0    4   ID     &#039;PSAM&#039; (Psm SAMple)&lt;br /&gt;
 4    ?  Data    Sample data&lt;br /&gt;
&lt;br /&gt;
 Sample header segment&lt;br /&gt;
 0    4   ID     &#039;PSAH&#039; (Psm SAmple Header)&lt;br /&gt;
 4    ?  Data    Sample headers&lt;br /&gt;
&lt;br /&gt;
 Sample header&lt;br /&gt;
 0    13  Name   Sample filename, terminated with a null.&lt;br /&gt;
 13   24  Desc   Sample description or comments.&lt;br /&gt;
 37   4   Offs   Location of raw sample data in file&lt;br /&gt;
 43   4   Mem    This is the physical offset in RAM/DRAM of the sample. (Often blank.)&lt;br /&gt;
 45   2   Num    Sample number, 1-255&lt;br /&gt;
 47   1   Type   Sample type: (In some games left blank; if this is the case then the&lt;br /&gt;
                 sample format is END, as used in most PSM New Format files)&lt;br /&gt;
                 Bit 0: 0 - Digital, 1 - Synthesized&lt;br /&gt;
                 Bit 2: 0 - 8-bit, 1 - 16-bit&lt;br /&gt;
                 Bit 3: 0 - Signed, 1 - Unsigned&lt;br /&gt;
                 Bit 4: 0 - Deltas, 1 - Raw&lt;br /&gt;
                 Bit 5: 0 - Loop normally, 1 - Bidirectional&lt;br /&gt;
                 Bit 6: 1 - Gravis patch (unsupported)&lt;br /&gt;
                 Bit 7: 0 - No loop, 1 - Loop sample&lt;br /&gt;
 48   4   Len    Sample length, in bytes.&lt;br /&gt;
 52   4   Rep st Sample repeat start; if sample loops, the loop starts here.&lt;br /&gt;
 56   4   Rep fn Sample repeat end, if sample loops, it ends here. If this is less than the sample&lt;br /&gt;
                 repeat start, the sample loops backwards.&lt;br /&gt;
 60   1   Tune   Fine tune; range 0-15, Tune 0-7 = 0-7; tune -1 - -8 = 8-15&lt;br /&gt;
 61   1   Vol    Sample volume, 0-64&lt;br /&gt;
 62   2   Freq   This is the frequency for the sample at a C of Octave 2.&lt;br /&gt;
                 Typical values are 8,000 hz to 8,448 hz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like in S3M, sample headers are stored separately from the raw sample data.&lt;br /&gt;
&lt;br /&gt;
A type of sample storage used often, like in the PSM New Format is &#039;Deltas&#039;, which converts a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte, often making them compress better using general-purpose file compression tools. Thus:&lt;br /&gt;
&lt;br /&gt;
 RAW:        64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: 11  64   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
This is done to make files more compressible, but doesn&#039;t seem to be used much.&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.shikadi.net/files/psm2scrm.zip psm2scrm.zip] - DOS program to convert .PSM songs into ScreamTracker .S3M format, suitable for playing in your favourite tracker/module player. Works only with PSM New Format and is not nearly as accurate as OpenMPT.&lt;br /&gt;
* [https://openmpt.org OpenMPT] 1.18 and newer can load all PSM and PSM16 files.&lt;br /&gt;
* [https://openmpt.org/legacy_software ModPlug Tracker] and OpenMPT 1.17 can play the files and save them as S3M. More complex songs don&#039;t load correctly though. Works only with new format.&lt;br /&gt;
* [http://kode54.foobar2000.org/ foo_dumb] is a plugin for various module formats for the Foobar2k media player. It supports both PSM16 and PSM and is similar to OpenMPT in playback quality.&lt;br /&gt;
* [http://ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/mxinfo/epictest.zip EPICTEST] is a demonstration of the Epic Megagames MASI. It contains CONVERT.EXE which can be used to convert modules to the new PSM format.&lt;br /&gt;
* [http://www.jazz2online.com/J2Ov2/downloads/info.php?levelID=5471#29435] JJ1MOD can convert S3M files to new PSM, though often with errors (Though these are usually only detectable with older programs such as game executables.) It is currently the only utility able to do this, and works only with New Format.&lt;br /&gt;
&lt;br /&gt;
= Notes =&lt;br /&gt;
&lt;br /&gt;
The New PSM format was reverse engineered by Levellord and tidied up by Levellass. It is possible there may be minor errors in the sample format information, especially since this is poorly documented.&lt;br /&gt;
Some format definitions have been updated and corrected by Johannes Schultz of the OpenMPT development team.&lt;br /&gt;
&lt;br /&gt;
The PSM16 format documentation was found on Wotsit and written up by Levellass (this appears to be an official document from the MASI developer). More info is needed.&lt;br /&gt;
&lt;br /&gt;
In all formats the following table shows how note bytes are converted into actual notes: (PSM new format has the widest range, 0-255)&lt;br /&gt;
&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;br /&gt;
           | C-0   0 | C-1  12 | C-2  24 | C-3  36 | C-4  48 |&lt;br /&gt;
           | C#0   1 | C#1  13 | C#2  25 | C#3  37 | C#4  49 |&lt;br /&gt;
           | D-0   2 | D-1  14 | D-2  26 | D-3  38 | D-4  50 |&lt;br /&gt;
           | D#0   3 | D#1  15 | D#2  27 | D#3  39 | D#4  51 |&lt;br /&gt;
           | E-0   4 | E-1  16 | E-2  28 | E-3  40 | E-4  52 |&lt;br /&gt;
           | F-0   5 | F-1  17 | F-2  29 | F-3  41 | F-4  53 |&lt;br /&gt;
           | F#0   6 | F#1  18 | F#2  30 | F#3  42 | F#4  54 |&lt;br /&gt;
           | G-0   7 | G-1  19 | G-2  31 | G-3  43 | G-4  55 |&lt;br /&gt;
           | G#0   8 | G#1  20 | G#2  32 | G#3  44 | G#4  56 |&lt;br /&gt;
           | A-0   9 | A-1  21 | A-2  33 | A-3  45 | A-4  57 |&lt;br /&gt;
           | A#0  10 | A#1  22 | A#2  34 | A#3  46 | A#4  58 |&lt;br /&gt;
           | B-0  11 | B-1  23 | B-2  35 | B-3  47 | B-4  59 |&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=SBI_Format&amp;diff=10925</id>
		<title>SBI Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=SBI_Format&amp;diff=10925"/>
		<updated>2023-03-28T17:28:44Z</updated>

		<summary type="html">&lt;p&gt;Saga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Instrument-only&lt;br /&gt;
 | Instruments = OPL&lt;br /&gt;
 | NumChannels = 1&lt;br /&gt;
 | NumTracks = 0&lt;br /&gt;
 | Tags = Title&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;SBI (Sound Blaster Instrument) Format&#039;&#039;&#039; stores a single instrument suitable for playback on a sound card with an OPL2 or OPL3 chip.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file is structured as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name!! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][4] || signature || &amp;quot;SBI&amp;quot; followed by 0x1A&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][32] || name || Instrument title (must be NULL-terminated)&lt;br /&gt;
|-&lt;br /&gt;
| [[BYTE]][16] || inst || Instrument settings (see below)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Some files generated with JuceOPLVSTi erroneously use byte 0x1D instead of 0x1A in the signature.&lt;br /&gt;
&lt;br /&gt;
=== Instrument settings ===&lt;br /&gt;
&lt;br /&gt;
The instrument is in the following format.  This is identical to the format used for each instrument in [[CMF Format]] songs and [[IBK Format]] instrument banks.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!OPL base register!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModChar||0x20||Modulator characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarChar||0x23||Carrier characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModScale||0x40||Modulator key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarScale||0x43||Carrier key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModAttack||0x60||Modulator attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarAttack||0x63||Carrier attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModSustain||0x80||Modulator sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarSustain||0x83||Carrier sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModWaveSel||0xE0||Modulator wave select&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarWaveSel||0xE3||Carrier wave select&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iFeedback||0xC0||Feedback/connection&lt;br /&gt;
|-&lt;br /&gt;
|[[BYTE]][5]&lt;br /&gt;
|colspan=3|Padding to bring instrument definition up to 16 bytes. Sometimes a byte is missing, resulting a 51-byte file rather than a 52-byte file. It is probably safer to not expect this padding to exist at all.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Percussive instruments ====&lt;br /&gt;
&lt;br /&gt;
In the basic SBI format, there is no indication as to whether a given instrument should be played in melodic or percussive mode.  Playing an instrument destined for one mode in the other usually sounds quite bad.&lt;br /&gt;
&lt;br /&gt;
==== SBI format extension ====&lt;br /&gt;
&lt;br /&gt;
The SBTimbre editor takes advantage of the 5-byte padding area to store additional information.&lt;br /&gt;
If any percussion-related fields have non-zero values, the timbre can be identified as a drum instrument.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iPercVoc||Percussion voice number (BassDrum=6, Snare=7, Tomtom=8, Cymbal=9, HighHat=10)&lt;br /&gt;
|-&lt;br /&gt;
|[[INT8]]||iTranspos||Note offset in semitones&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iPercPitch||Fixed percussion pitch (MIDI note 0-127)&lt;br /&gt;
|-&lt;br /&gt;
|[[BYTE]][2]&lt;br /&gt;
|colspan=2|Reserved&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[SBTimbre]]&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Yes; [[SBI Format|.sbi]]&lt;br /&gt;
| canImport = Yes; many&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = Can import or export instruments in SBI format&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[SBANK]]&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Yes; many&lt;br /&gt;
| canImport = Yes; many&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = Сan convert SBI between [[AdLib Instrument Format|AdLib INS]] format&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[OPL3 Bank Editor]]&lt;br /&gt;
| Platform = Linux, Windows, macOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Yes; many&lt;br /&gt;
| canImport = Yes; many&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = Can import or export instruments in SBI format&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=10924</id>
		<title>ProTracker Studio Module</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=10924"/>
		<updated>2023-03-27T21:12:38Z</updated>

		<summary type="html">&lt;p&gt;Saga: /* Order sub-segment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 1-256 (PSM) / 1-32 (PSM16)&lt;br /&gt;
 | NumTracks = unlimited (PSM) / 1 (PSM16)&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Epic Pinball}}&lt;br /&gt;
   {{Game|Extreme Pinball}}&lt;br /&gt;
   {{Game|Jazz Jackrabbit}}&lt;br /&gt;
   {{Game|One Must Fall}}&lt;br /&gt;
   {{Game|Silverball}}&lt;br /&gt;
   {{Game|Sinaria}}&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;ProTracker Studio Module&#039;&#039;&#039; (PSM) file format is used for the music in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]].  The file format is named after ProTracker, an Amiga program, though this program was probably actually not used to write PSM files. One Must Fall&#039;s music was written in Multitracker, and the music for Jazz Jackrabbit, Epic Pinball and Extreme Pinball probably in Scream Tracker.&lt;br /&gt;
&lt;br /&gt;
There are two file types that use the extension .PSM; they are both used by Epic Megagames&#039; MASI sound system, but are used by different versions of the system. The two formats are:&lt;br /&gt;
&lt;br /&gt;
* PSM New Format: Used by Jazz Jackrabbit, Epic Pinball, Extreme Pinball, One Must Fall, Sinaria (in this game with slight differences, see below), newest PSM format&lt;br /&gt;
* PSM 16:         Used by Silverball, an older version of the format which is closer to ScreamTracker-style modules.&lt;br /&gt;
&lt;br /&gt;
The most common of the two PSM formats is the new format, and most programs that try to interpret PSM files will be expecting this. For example, ModPlug Player cannot open Silverball files as these are in the PSM 16 format.&lt;br /&gt;
&lt;br /&gt;
There are actually two slightly different variants of the new formats: A common one used in several games, and one used in the game Sinaria. It is not entirely clear if the format used in Sinaria is newer or older - in some ways, like the effect interpretation, it resembles PSM16 more than the new format, so it could be an earlier version of the new PSM format. But Sinaria was released later than or around the same time as most other games using the new PSM format, so maybe it just took really long to develop. The format not used in Sinaria will be called &amp;quot;regular&amp;quot; in this document.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM New Format =&lt;br /&gt;
&lt;br /&gt;
This format is used by [[:Category:Epic Megagames|Epic]] games in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]]. It is notable for consisting of a number of segments (chunks) and sub segments. It bears the 4-byte signature &#039;PSM &#039; at the file start.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Song segment&lt;br /&gt;
 Samples&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 12 bytes long:&lt;br /&gt;
&lt;br /&gt;
 File header:&lt;br /&gt;
 0   4  ID     &#039;PSM &#039;; indicates file is PSM format&lt;br /&gt;
 4   4  Size   Filesize - 12&lt;br /&gt;
 8   4  ID2    &#039;FILE&#039;; indicates start of file info&lt;br /&gt;
&lt;br /&gt;
After the header, some chunks follow in IFF-style. You should not expect chunks to come up in the same order as they are described here. A good way to handle chunks is to read the 4-Byte ID and the 4-Byte size field first, then evaluate the ID and decide what to do next based on this ID. Note that the size field does not include the ID and itself; it only holds the size of the chunk &#039;&#039;content&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Title segment ==&lt;br /&gt;
&lt;br /&gt;
This segment is optional, and one of the few segments that can be absent when playing PSM files in most programs. (Most programs expect all other segments to exist, even if they are not vital.)&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;TITL&#039;; indicates a title follows&lt;br /&gt;
 4   4  Size   Size of title as dword after this dword&lt;br /&gt;
 8   ?  Title  Song title&lt;br /&gt;
&lt;br /&gt;
== Song info segment ==&lt;br /&gt;
&lt;br /&gt;
This segment seems to indicate the beginning of the song data and is not really relevant when parsing.&lt;br /&gt;
&lt;br /&gt;
 12  4  ID     &#039;SDFT&#039;; indicates start of format info&lt;br /&gt;
 16  4  Size   Size of next header as dword, (8)&lt;br /&gt;
 20  8  Song   &#039;MAINSONG&#039;; indicates song type. No other song types are known.&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
Each pattern is stored in its own PBOD chunk. Note that there are two possible formats for this chunk; one is used in the &amp;quot;regular&amp;quot; format (as used in Epic Pinball, Extreme Pinball, Jazz Jackrabbit, One Must Fall) and the other in the &amp;quot;Sinaria&amp;quot; format (as used in Sinaria)&lt;br /&gt;
&lt;br /&gt;
 Pattern segment:&lt;br /&gt;
 0   4  ID     &#039;PBOD&#039;; indicates a pattern follows (Pattern BODy)&lt;br /&gt;
 4   4  Size   Length of pattern data as dword, after this dword&lt;br /&gt;
 4   4  Size   Same value again.&lt;br /&gt;
&lt;br /&gt;
 Pattern:&lt;br /&gt;
 0 4/8  Number Pattern ID. See note below.&lt;br /&gt;
 4   2  Row n  Number of rows in ALL channels in pattern (64 usually, but can differ.) as word.&lt;br /&gt;
 6   ?  Data   Contains pattern data as a number of rows of interlaced channels (12341234...)&lt;br /&gt;
               &#039;&#039;Usual&#039;&#039; settings is 64 rows of 4 channels. Epic Pinball has shorter patterns for example, but they also include a &amp;quot;break to row&amp;quot; command at the end of the pattern.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; There are two variants of the format. In the &amp;quot;regular&amp;quot; variant, the pattern ID is 4 bytes long and starts with a &#039;P&#039;, followed by an integer number which is the pattern number, padded to 4 bytes with spaces. Caution: This number might or might not be zero-padded; In some files, the ID of the first pattern could be &#039;P0  &#039;, but there are also files where it is &#039;P00 &#039;!. In C/C++, you could use atoi() to parse this value.&lt;br /&gt;
In the format used in the game Sinaria, This field is 8 bytes long instead of 4 bytes, and the first 4 bytes read &amp;quot;PATT&amp;quot;, so the first pattern could be for example &#039;PATT0   &#039;. You may want to deal with this by first reading for bytes, and if they are equal to &amp;quot;PATT&amp;quot;, read four more bytes for the pattern ID.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Pattern row channel entry:&lt;br /&gt;
 ?   1  Flags  Contains four flags that indicate which pattern data follows&lt;br /&gt;
 +1  1  Chan   The channel this data belongs to.&lt;br /&gt;
 +2  1  Note   Present if bit 7 in Flags is set. Pitch, $01 is C-1, etc... The octaves&lt;br /&gt;
               are aligned by 16, i.e. B-1 is $0C but the next note, C-2, is $10.&lt;br /&gt;
 +3  1  Ins    Present if bit 6 in Flags is set. Instrument used, 0-31&lt;br /&gt;
 +4  1  Vol    Present if bit 5 in Flags is set. Volume change to, 0-63 = 0-127; optional&lt;br /&gt;
 +5  1  Effect Present if bit 4 in Flags is set. Effect to use, volume slide, Portamanto...&lt;br /&gt;
 +6  x  Eff Am Present if bit 4 in Flags is set. Parameter of effect, e.g amount of slide&lt;br /&gt;
&lt;br /&gt;
Each row consists of a word giving the size of the row (Including the word) followed by the channel data. A channel is only included if it has data in it, but a totally empty row is still included. So an &#039;empty&#039; row (Where none of the channels have data.) thus consists of just a word of value 2.&lt;br /&gt;
&lt;br /&gt;
Each channel entry consists of between 3-7 bytes. The first byte is a flag that shows what data follows. (The highest four bits indicate whether there are bytes for the following four variables; Note ($80), Instrument ($40), Volume ($20), Effect AND Effect parameter ($10). Thus 5 bytes are represented by a combination of 4 possibilities.) The next byte identifies the channel (Since each channel may or may not be present.) starting at 0 for channel 1. The remaining 5 bytes may or may not be present depending on their flag and contain data for Note, Instrument(Sample) used, Volume change for channel, Effect and Effect parameter.&lt;br /&gt;
&lt;br /&gt;
There are several things to note about this; Effect and Effect magnitude MUST occur together. Sample numbers, like channels are numbered starting at 0, not 1. Magnitudes (For effect AND volume) are from 0-127, not 0-64 as in other formats.&lt;br /&gt;
&lt;br /&gt;
=== Effect conversion ===&lt;br /&gt;
&lt;br /&gt;
Note that this table is guaranteed to be correct; Most effects seem to be converted correctly, though. Note that these values are not correct for the PSM files that can be found in the game Sinaria. Leave out all divisions and it will be correct again.&lt;br /&gt;
&lt;br /&gt;
 PSM Command   Param length  S3M Command&lt;br /&gt;
 &lt;br /&gt;
  Volume commands&lt;br /&gt;
    1           1 Byte        DxF - fine volside up&lt;br /&gt;
    2           1 Byte        Dx0 - volslide up&lt;br /&gt;
    3           1 Byte        DFx - fine volslide down&lt;br /&gt;
    4           1 Byte        D0x - volslide down&lt;br /&gt;
 &lt;br /&gt;
 Portamento commands&lt;br /&gt;
    B           1 Byte        FFx - fine porta up (divide x by 4)&lt;br /&gt;
    C           1 Byte        Fxx - porta up (if x &amp;lt; 4, use FFx, else divide x by 4)&lt;br /&gt;
    D           1 Byte        EFx - fine porta down (divide x by 4)&lt;br /&gt;
    E           1 Byte        Exx - porta down (if x &amp;lt; 4, use EFx, else divide x by 4)&lt;br /&gt;
    F           1 Byte        Gxx - portamento (divide x by 4)&lt;br /&gt;
   10           1 Byte        S1x - glissando control&lt;br /&gt;
   11           1 Byte        Lx0 - tone porta + volslide up&lt;br /&gt;
   12           1 Byte        L0x - tone porta + volslide down&lt;br /&gt;
    &lt;br /&gt;
 Vibrato&lt;br /&gt;
   15           1 Byte        Hxy - vibrato&lt;br /&gt;
   16           1 Byte        S3x - vibrato waveform&lt;br /&gt;
   17           1 Byte        K0x - vibrato + volslide up&lt;br /&gt;
   18           1 Byte        Kx0 - vibrato + volslide down&lt;br /&gt;
   	&lt;br /&gt;
 Tremolo			&lt;br /&gt;
   1F           1 Byte        Rxy - tremolo&lt;br /&gt;
   20           1 Byte        S4x - tremolo waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample commands&lt;br /&gt;
   29           3 Bytes       Oxx - offset (xx corresponds to the 2nd byte)&lt;br /&gt;
   2A           1 Byte        Q0x - retrigger&lt;br /&gt;
   2B           1 Byte        SCx - note cut&lt;br /&gt;
   2C           1 Byte        SDx - note delay&lt;br /&gt;
 &lt;br /&gt;
 Position change&lt;br /&gt;
   33           2 Bytes       Bxx - position jump - ignored by PLAY.EXE&lt;br /&gt;
   34           1 Byte        Cxx - break to row&lt;br /&gt;
                                    PLAY.EXE entirely ignores the parameter (it always breaks to the first&lt;br /&gt;
                                    row), so it is maybe best to do this in your own player as well.&lt;br /&gt;
                                    If the original file was an S3M, the parameter is double-BCD-encoded,&lt;br /&gt;
                                    i.e. on top of the original format&#039;s BCD encoding, the same encoding&lt;br /&gt;
                                    is applied again. to translate into the correct target row in binary,&lt;br /&gt;
                                    apply this twice: param = (param &amp;amp; 0xF0) * 10 + (param &amp;amp; 0x0F)&lt;br /&gt;
                                    For MOD files, the parameter is a normal binary number.&lt;br /&gt;
   35           1 Byte        SBx - pattern loop&lt;br /&gt;
   36           1 Byte        SEx - pattern delay&lt;br /&gt;
  &lt;br /&gt;
 Speed change&lt;br /&gt;
   3D           1 Byte        Axx - set speed&lt;br /&gt;
   3E           1 Byte        Txx - set tempo&lt;br /&gt;
 &lt;br /&gt;
 Misc. commands&lt;br /&gt;
   47           1 Byte        Jxy - arpeggio&lt;br /&gt;
   48           1 Byte        S2x - set finetune&lt;br /&gt;
   49           1 Byte        S8x - set balance&lt;br /&gt;
&lt;br /&gt;
Effect interpretation is slightly different in Sinaria&#039;s format. Slide command parameters are more like in PSM16.&lt;br /&gt;
&lt;br /&gt;
== Song segment ==&lt;br /&gt;
&lt;br /&gt;
This segment contains most of the important data used to play the song. It contains several sub-segments, each of the same format as a normal segment, but contained in the song segment. Note that there might be more than one song segment and thus, more than one order list, default speed, default tempo, etc... For example, in Extreme Pinball, all the different jingles and mission songs are stored as separate SONG chunks. It is up to the developer to find a clever way of managing / playing several sub songs.&lt;br /&gt;
&lt;br /&gt;
 Segment structure:&lt;br /&gt;
 0   4  ID     &#039;SONG&#039; indicates start of song structure&lt;br /&gt;
 4   4  Size   Size of song structure, including all sub-segments&lt;br /&gt;
 8   9  Type   Type of song this is for; This is &#039;MAINSONG &#039; in almost all PSM files. Extreme Pinball has several SONG items with different types!&lt;br /&gt;
 17  1  Comp   Compression, for PSM = 1 (Uncompressed)&lt;br /&gt;
 18  1  Chan   Number of channels, usually, but not always, 4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Date sub-segment ===&lt;br /&gt;
&lt;br /&gt;
This dates the file and is used by some programs. It is usually the first sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DATE&#039; indicates date data&lt;br /&gt;
 4   4  Size   Size of date segment (6)&lt;br /&gt;
 8   6  Date   Date as text, YYMMDD&lt;br /&gt;
&lt;br /&gt;
This can also be used as a way to heuristically detect if the regular or Sinara version of the format is being used. Sinaria&#039;s song dates are: 800211, 940902, 940903, 940906, 940914, 941213&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Order sub-segment ===&lt;br /&gt;
&lt;br /&gt;
The order list describes how patterns are arranged in the song. This allows the same pattern of instruments to be played more than once in a song (e.g. a chorus). without the pattern data having to be duplicated. There should be only one order. In most module formats, the order list only consists of pattern indices, but in the PSM format it resembles a tiny scripting language that can do more than just list patterns. For example, It typically contains chunks that set the tempo of the song and the channel panning. In theory, these chunks can occur between two pattern chunks, changing the tempo or panning of a pattern without having to duplicate the pattern data, but in practice this feature is not used, so it can be ignored when writing a PSM loader.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;OPLH&#039; indicates start of pattern placement order&lt;br /&gt;
 4   4  Size   Size of order segment&lt;br /&gt;
 8   2  Cnt.   Number of following chunks&lt;br /&gt;
&lt;br /&gt;
Now, the following chunks may follow until the end of the &amp;quot;OPLH&amp;quot; chunk is reached. Every chunk is identified by its first byte:&lt;br /&gt;
* $00 (1 Byte): End (Nothing follows)&lt;br /&gt;
* $01 (5/9 Bytes): Order list item follows (e.g. &amp;quot;P0 &amp;amp;nbsp;&amp;quot;, &amp;quot;P12 &amp;quot; in regular format or &amp;quot;PATT0 &amp;amp;nbsp;&amp;amp;nbsp;&amp;quot; in Sinaria format, see above) - join those to get the complete order list.&lt;br /&gt;
* $02: Play Range: N/A&lt;br /&gt;
* $03: Jump Loop: N/A&lt;br /&gt;
* $04 (3 Bytes): This 16-bit value indicates the &amp;quot;restart chunk&amp;quot;. If the end of the subsong is reached, it will jump back to this chunk. In many cases, this would be 4th chunk (not 3rd chunk, as the chunk index is starting at 0!), which is a panning index in most PSMs - So you would just go to the nearest order list item that&#039;s following this chunk. However, this can also point to a valid order list chunk.&lt;br /&gt;
* $05: Channel Flip (3 Bytes): Changes the channel type without specifying pan position. The first byte is the channel index, the second byte is the channel type (see command $0D). This command is not used in any known soundtrack, and is not written by CONVERT.EXE.&lt;br /&gt;
* $06: Transpose (2 Bytes): Does not appear to do anything, regardless of parameter. This command is not used in any known soundtrack, and is not written by CONVERT.EXE.&lt;br /&gt;
* $07 (2 Bytes): Next byte sets the speed (ticks/row) for this subtune&lt;br /&gt;
* $08 (2 Bytes): Next byte sets the tempo for this subtune&lt;br /&gt;
* $0C (7 Bytes): Sample map table: This chunk is always $0C $00 $FF $00 $00 $01 $00. This seems to be an unfinished feature of the order list scripting language. It appears that this maps e.g. what is &amp;quot;I0&amp;quot; in the file to sample 1. Only the fourth and fifth byte ($00 $00) actually seem to do something: They translate the sample number in the pattern to different instruments in the file.&lt;br /&gt;
* $0D (4 Bytes): Channel panning index. Next byte is channel number (Start at 0), then initial pan ($00 ... $FF) and a type byte follow. The byte seems to tell what to do with the previous pan position (0 - use it, 2 - ignore it, make this channel surround, 4 - set to center).&lt;br /&gt;
* $0E (3 Bytes): Channel volume index. Next byte is channel number (Start at 0), then volume ($00 ... $FF). $FF in most cases. Some OMF 2097 tracks use a lower volume.&lt;br /&gt;
&lt;br /&gt;
N/A: This chunk is not used in any game soundtrack. The length and meaning of its parameters is unknown.&lt;br /&gt;
&lt;br /&gt;
=== Pattern list ===&lt;br /&gt;
&lt;br /&gt;
This is simply a list of all the patterns used in the file. You do not really need to parse this, it seems to be a purely informational chunk.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;PATT&#039; indicates start of pattern list&lt;br /&gt;
 4   4  Size   Size of pattern list after this&lt;br /&gt;
 8   4  Size   Same as above&lt;br /&gt;
 12  4x Pat    An ordered list &#039;P0  &#039;, &#039;P1  &#039;... for all patterns in the file, each entry 4 bytes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sample list sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Similar to the above, this is a list of all the samples used in the file. It is usually the last sub-segment in the song segment and you do not really need to parse this.&lt;br /&gt;
&lt;br /&gt;
  0  4   ID     &#039;DSAM&#039;; indicates start of sample list, used to say what samples are &#039;full&#039;&lt;br /&gt;
                Any samples not on this list will be ignored, even if they have data&lt;br /&gt;
  4  4   Size   Size of list after this&lt;br /&gt;
  8  4   Size   Same value as above&lt;br /&gt;
  12 15x Entry  Sample entries, one for each sample in the file, each entry 15 bytes&lt;br /&gt;
&lt;br /&gt;
 Sample entry:&lt;br /&gt;
 0   8  Format Sample format, padded with spaces (END, RAG2...) This is important to some programs&lt;br /&gt;
 8   4  ID     &#039;I0  &#039;, &#039;I1  &#039;... the sample ID (&#039;I&#039; means &#039;Instrument&#039;). Again, be sure to accept both &#039;I0  &#039; and &#039;I00 &#039;!&lt;br /&gt;
 12  2  Num    The sample number, 0,1,2... for the sample&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
Samples are the raw sound data that makes up the instruments on the song. The actual format depends on the sample format. Samples have information in their headers which allows data to be played at different pitches (Speeds.) and to loop from and to various points in the data. This is by far the largest part of the file, since the raw data takes up so much space.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DSMP&#039; indicates start of sample&lt;br /&gt;
 4   4  Size   Size of following sample as &#039;DSMP&#039; + dword from end of word&lt;br /&gt;
 8   9  Flags  If highest bit is set, then sample is looped&lt;br /&gt;
 9   8  Songn. Filename of the original module (without extension)&lt;br /&gt;
 17  4  INSx   Last digit of sample (Instrument) number, 0-9; with 31 instruments possible&lt;br /&gt;
               Only last digit is shown. E.g 1st, 11th, 21st and 31st sample is &#039;INS0&#039;&lt;br /&gt;
 21  33 Name   Defines the instrument name or file, usually a .st or line of text&lt;br /&gt;
 54  51 Header Sample parameters (Can also 58 bytes long, padded with nuls)&lt;br /&gt;
               Byte 1-6 are unknown (but apparently always $00 $00 $00 $00 $00 $FF)&lt;br /&gt;
               Bytes 7-8 is instrument number&lt;br /&gt;
               Bytes 9-12 are sample length&lt;br /&gt;
               Bytes 13-16 are loop start&lt;br /&gt;
               Bytes 17-20 are loop end (all $FF means at end of sample)&lt;br /&gt;
               Bytes 21-22 are unknown (second byte could be finetune in Sinaria, but seems to be unused)&lt;br /&gt;
               Byte 23 is default volume&lt;br /&gt;
               Bytes 24-27 are unknwon&lt;br /&gt;
               Bytes 28-31 is frequency (Sample rate). MASI ignores the upper 16 bits, even if they are non-zero.&lt;br /&gt;
               19 $00-bytes follow (padding?)&lt;br /&gt;
 105 ?  Data   Music data in 8-bit mono format&lt;br /&gt;
&lt;br /&gt;
The sample header is slightly different in Sinaria&#039;s format: INSx is 8 bytes long (like the PATT IDs), and the last 21 $00-bytes are just 16 bytes (so that the struct is 96 bytes large in both formats).&lt;br /&gt;
&lt;br /&gt;
The PSM new format, along with the PSM 16 format use delta-encoded samples, something to make the file smaller when zipped. &#039;Deltas&#039;, convert a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. It has the effect that if a single byte in the sample is changed, the entire sample will be degraded. This use of deltas varies slightly from that of the PSM 16. The &#039;start value&#039; of the string is assumed to be $80 (128) and the first byte will thus turn this into the first desired value, the second delta converts the first value to the second, and so on.) All deltas are signed, 1-byte values, but loop (Thus 10 - 20 = -10 can also be considered as 10 + 236 = 246). An example of this is as follows:&lt;br /&gt;
&lt;br /&gt;
 RAW:   (128) 64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: -64  0   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Encryption ==&lt;br /&gt;
&lt;br /&gt;
CONVERT.EXE can produce &amp;quot;encrypted&amp;quot; PSM files with the /K command line switch. The encryption scheme is simple: It adds 1 to the first byte, 2 to the second, 3 to the third, and so until, for the entire file. It does not appear like any game made use of this feature, though.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM 16 =&lt;br /&gt;
&lt;br /&gt;
This is the format used in [[Silverball]], early versions of Epic Pinball and possibly other games. The designation &#039;Protracker Studio 16 format&#039; was given to it by the only reliable source of information on this format, and may not be the official designation.&lt;br /&gt;
&lt;br /&gt;
The format bears many similarities to the S3M format; the file is set out roughly the same, patterns and samples are similar, indeed, near identical and the functionality is similar. It also shows many similarities to the ProTracker MOD format and retains vestiges of Amiga compatibility.&lt;br /&gt;
&lt;br /&gt;
This format can be identified by its signature &#039;PSMþ&#039;, though files may lack this and still function.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Order&lt;br /&gt;
 Pan segment&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Sample data&lt;br /&gt;
 Sample headers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
 0    4  Sig      Signature, &#039;PSMþ&#039;&lt;br /&gt;
 4    59 Title    Song title, padded with nulls. Unlike other formats, this must also be terminated&lt;br /&gt;
                  with a null byte. (It sometimes is not terminated, though.)&lt;br /&gt;
 62   1           This must be $1A to end the song name, like in S3M format.&lt;br /&gt;
 64   1  Type     Song type, First bit: 0 - Module (w/samp.), 1 - Song (w/o samples)&lt;br /&gt;
                  Second bit: 0 - 3 octave Protracker, 1 - 5 octave; remaining bits reserved.&lt;br /&gt;
 65   1  PSM v    PSM format version, $10 for this format (Hence the name PSM 16) = &#039;v1.00&#039;.&lt;br /&gt;
                  Sometimes, this is also $01, but there&#039;s no difference in the format itself.&lt;br /&gt;
 66   1  Patt v   Pattern version, 0 or 1. 0 means the pattern is stored in the module are in the 32&lt;br /&gt;
                  channel file format.  A 1 signifies the patterns as being stored as a 255&lt;br /&gt;
                  channel format. (I have not found any PSM16 modules that have this format.)&lt;br /&gt;
 67   1   Speed   Song speed&lt;br /&gt;
 68   1   BPM     Beats per minute, the default Amiga BPM value. (The only reason that the Amiga BPM&lt;br /&gt;
                  format is still followed here is that it allows more control over the final hz value.)&lt;br /&gt;
                  Range: 32 to 255.&lt;br /&gt;
 69   1   Vol     Master volume of song, 0-255&lt;br /&gt;
 70   2   Len     Song length, 0-255. The number of patterns to play in the song, in total.&lt;br /&gt;
 72   2   Ordlen  The number of orders actually stored at the order offset. It was hoped that the&lt;br /&gt;
                  PSM 16 format would allow multiple orders, so this would be the length of the first&lt;br /&gt;
                  order. This doesn&#039;t appea to ahve happened, and is usually the same as the previous value.&lt;br /&gt;
 74   2   Patnum  Number of patterns in the song. 1-255&lt;br /&gt;
 76   2   Sampnum Number of samples and &#039;sample structures&#039; in song, 1-255&lt;br /&gt;
 78   2   NCIS    Number of channels in song to PLAY. 1-32. &lt;br /&gt;
 80   2   NCP     Number of Channels to Process; describes the MAXIMUM number of channels to process.&lt;br /&gt;
                  As an example, when converting 669 files,  NCP = 9 because some track information &lt;br /&gt;
                  is in Channel 8, but the Number of Channels to Play was set to 8, (Channel numbers&lt;br /&gt;
                  to play from 0 to 7.) 1-32&lt;br /&gt;
 82   4   Ordoff  Location of order in header&lt;br /&gt;
 86   4   Panoff  Location of pan positions in header&lt;br /&gt;
 90   4   Patoff  Location of patterns in header&lt;br /&gt;
 94   4   Sampoff Location of sample headers in header&lt;br /&gt;
 98   4   Commoff Location of comments in header&lt;br /&gt;
 102  4   Patsiz  Total pattern size; the total size of all the patterns loaded from the pattern offset.&lt;br /&gt;
 106  40  Fillers 10 fillers, to be used for any possible expansions.&lt;br /&gt;
&lt;br /&gt;
It is important to notice that the offsets point to the first byte &#039;&#039;&#039;after&#039;&#039;&#039; the chunk ID, i.e. &amp;quot;Ordoff&amp;quot; points to the first byte after &amp;quot;PORD&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Order and Pan positions ==&lt;br /&gt;
&lt;br /&gt;
These are two separate segments, pointed to in the header. They may be anywhere, but usually follow the header sometimes after an amount of blank space. They are often padded with blank space. They are basically lists.&lt;br /&gt;
&lt;br /&gt;
Order: This segment is pointed to in the header, and sets the PSM 16 format apart. The PSM 16 format was designed to be much more like the MOD format, allowing game designers to set flags to switch from one set of patterns to another, in effect allowing one file to contain more than one song. (For example a boss flag might make the music switch from a clam patterns 1-4 to a racy and dangerous patterns 5-7.)&lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    Signature, not needed, &#039;PORD&#039;&lt;br /&gt;
 4    ?   Ords   Pattern numbers and order. There will be [Ordlen] bytes of patterns&lt;br /&gt;
 ?    2   Lang   Order language, not implemented, so left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pan Positions: &lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    &#039;PPAN&#039;&lt;br /&gt;
 4    12  Pan    Pan positions; empty positions left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
 0    2   Size   Size of pattern, including these bytes&lt;br /&gt;
 2    1   Len    Length of pattern, in rows. Max length is 64 rows.&lt;br /&gt;
 3    1   Chan   Number of channels in pattern, 1-32&lt;br /&gt;
 4    ?   Data   Pattern data&lt;br /&gt;
&lt;br /&gt;
This is similar to the previous two segments, except actual pattern data is stored here. Patterns are very similar to the S3M format, and consist of y rows of x channels. Each row contains a number of channels and ends with a byte of value 0. Each channel is between 2-6+ bytes long. A totally empty channel is represented by a single byte of value 0.&lt;br /&gt;
&lt;br /&gt;
Each channel starts with a flag byte, abcddddd, where a,b and c indicate whether there is a note and instrument, volume or special effect and effect magnitude in the following data, and dddd is the channel number (0-31, used since a given channel may or may not be present in a row.)&lt;br /&gt;
&lt;br /&gt;
The usual maximum length of a channel entry is 6 bytes (1 flag byte, 2 Note AND instrument bytes, 1 volume byte and two Effect and Effect magnitude bytes.) Thus Note&amp;amp;ins\Eff&amp;amp;Eff mag must always occur together.&lt;br /&gt;
&lt;br /&gt;
Like S3M, volume range is 0-64, as is special magnitude. However, special effects range from 0-255, like PSM New Format.&lt;br /&gt;
&lt;br /&gt;
=== Effects conversion ===&lt;br /&gt;
&lt;br /&gt;
 ###  Co  MOD  Description               Arguments&lt;br /&gt;
 ---  --  ---  -----------               ---------&lt;br /&gt;
 Volume Commands&lt;br /&gt;
   1  A1   EA  Fine Volume Slide Up      B xx xx=speed&lt;br /&gt;
   2  A2   A   Volume Slide Up           B xx xx=speed&lt;br /&gt;
   3  A3   EB  Fine Volume Slide Down    B xx xx=speed&lt;br /&gt;
   4  A4   A   Volume Slide Down         B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Portamento Commands&lt;br /&gt;
  10  B0   E1  Fine Porta Up             B xx xx=speed&lt;br /&gt;
  11  B1   1   Portamento Up             B xx xx=speed&lt;br /&gt;
  12  B2   E2  Fine Porta Down           B xx xx=speed&lt;br /&gt;
  13  B3   2   Portamento Down           B xx xx=speed&lt;br /&gt;
  14  B4   3   Tone Portamento           B xx xx=speed&lt;br /&gt;
  15  B5   E3  Set Glissando Control     B xx xx=0 - Off, 1 - On&lt;br /&gt;
  16  B6   5   Tone Port+Vol Slide Up    B xx xx=speed&lt;br /&gt;
  17  B7   5   Tone Port+Vol Slide Down  B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Vibrato Commands&lt;br /&gt;
  20  C0   4   Vibrato                   B xy x=speed, y=depth&lt;br /&gt;
  21  C1   E4  Set Vibrato Waveform      B x  x=Waveform&lt;br /&gt;
  21  C2   6   Vibrato+Vol Slide Up      B xx xx=speed&lt;br /&gt;
  22  C3   6   Vibrato+Vol Slide Down    B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Tremolo Commands&lt;br /&gt;
  30  D0   7   Tremolo                   B xy x=speed, y=depth&lt;br /&gt;
  31  D1   E7  Set Tremolo Control       B x  x=Waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample Commands&lt;br /&gt;
  40  E0   9   Sample Offset             3B Position for offset change (0-1,048,575)&lt;br /&gt;
  41  E1   E9  Retrig Note               B xx xx=tick to retrigger sample&lt;br /&gt;
  42  E2   EC  Note Cut                  B xx xx=tick to cut note&lt;br /&gt;
  43  E3   ED  Note Delay                B xx xx=ticks to delay note&lt;br /&gt;
 &lt;br /&gt;
 Pos. Change Commands&lt;br /&gt;
  50  F0   B   Position Jump             B xx xx=order position&lt;br /&gt;
  51  F1   D   Pattern Break             B xx Skip to line xx in next pattern&lt;br /&gt;
  52  F2   E6  Jump Loop                 B xx xx=number of loops  0 Set&lt;br /&gt;
  53  F3   EE  Pattern Delay             B xx xx=notes to delay pattern&lt;br /&gt;
 &lt;br /&gt;
 Speed Change Cmds&lt;br /&gt;
  60  G0   F   Set Regular Speed         B xx xx=speed&lt;br /&gt;
  61  G1   F   Set BPM                   B xx xx=BPM (32-255)&lt;br /&gt;
 &lt;br /&gt;
 Misc. Commands&lt;br /&gt;
  70  H0   0   Arpeggio                  B xy x=semitone #1, y=semitone #2&lt;br /&gt;
  71  H1   E5  Set Finetune              B xx xx=finetune&lt;br /&gt;
  72  H2       Set Balance               B xx xx=Balance (0-15)&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
 Sample segment&lt;br /&gt;
 0    4   ID     &#039;PSAM&#039; (Psm SAMple)&lt;br /&gt;
 4    ?  Data    Sample data&lt;br /&gt;
&lt;br /&gt;
 Sample header segment&lt;br /&gt;
 0    4   ID     &#039;PSAH&#039; (Psm SAmple Header)&lt;br /&gt;
 4    ?  Data    Sample headers&lt;br /&gt;
&lt;br /&gt;
 Sample header&lt;br /&gt;
 0    13  Name   Sample filename, terminated with a null.&lt;br /&gt;
 13   24  Desc   Sample description or comments.&lt;br /&gt;
 37   4   Offs   Location of raw sample data in file&lt;br /&gt;
 43   4   Mem    This is the physical offset in RAM/DRAM of the sample. (Often blank.)&lt;br /&gt;
 45   2   Num    Sample number, 1-255&lt;br /&gt;
 47   1   Type   Sample type: (In some games left blank; if this is the case then the&lt;br /&gt;
                 sample format is END, as used in most PSM New Format files)&lt;br /&gt;
                 Bit 0: 0 - Digital, 1 - Synthesized&lt;br /&gt;
                 Bit 2: 0 - 8-bit, 1 - 16-bit&lt;br /&gt;
                 Bit 3: 0 - Signed, 1 - Unsigned&lt;br /&gt;
                 Bit 4: 0 - Deltas, 1 - Raw&lt;br /&gt;
                 Bit 5: 0 - Loop normally, 1 - Bidirectional&lt;br /&gt;
                 Bit 6: 1 - Gravis patch (unsupported)&lt;br /&gt;
                 Bit 7: 0 - No loop, 1 - Loop sample&lt;br /&gt;
 48   4   Len    Sample length, in bytes.&lt;br /&gt;
 52   4   Rep st Sample repeat start; if sample loops, the loop starts here.&lt;br /&gt;
 56   4   Rep fn Sample repeat end, if sample loops, it ends here. If this is less than the sample&lt;br /&gt;
                 repeat start, the sample loops backwards.&lt;br /&gt;
 60   1   Tune   Fine tune; range 0-15, Tune 0-7 = 0-7; tune -1 - -8 = 8-15&lt;br /&gt;
 61   1   Vol    Sample volume, 0-64&lt;br /&gt;
 62   2   Freq   This is the frequency for the sample at a C of Octave 2.&lt;br /&gt;
                 Typical values are 8,000 hz to 8,448 hz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like in S3M, sample headers are stored separately from the raw sample data.&lt;br /&gt;
&lt;br /&gt;
A type of sample storage used often, like in the PSM New Format is &#039;Deltas&#039;, which converts a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte, often making them compress better using general-purpose file compression tools. Thus:&lt;br /&gt;
&lt;br /&gt;
 RAW:        64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: 11  64   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
This is done to make files more compressible, but doesn&#039;t seem to be used much.&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.shikadi.net/files/psm2scrm.zip psm2scrm.zip] - DOS program to convert .PSM songs into ScreamTracker .S3M format, suitable for playing in your favourite tracker/module player. Works only with PSM New Format and is not nearly as accurate as OpenMPT.&lt;br /&gt;
* [https://openmpt.org OpenMPT] 1.18 and newer can load all PSM and PSM16 files.&lt;br /&gt;
* [https://openmpt.org/legacy_software ModPlug Tracker] and OpenMPT 1.17 can play the files and save them as S3M. More complex songs don&#039;t load correctly though. Works only with new format.&lt;br /&gt;
* [http://kode54.foobar2000.org/ foo_dumb] is a plugin for various module formats for the Foobar2k media player. It supports both PSM16 and PSM and is similar to OpenMPT in playback quality.&lt;br /&gt;
* [http://ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/mxinfo/epictest.zip EPICTEST] is a demonstration of the Epic Megagames MASI. It contains CONVERT.EXE which can be used to convert modules to the new PSM format.&lt;br /&gt;
* [http://www.jazz2online.com/J2Ov2/downloads/info.php?levelID=5471#29435] JJ1MOD can convert S3M files to new PSM, though often with errors (Though these are usually only detectable with older programs such as game executables.) It is currently the only utility able to do this, and works only with New Format.&lt;br /&gt;
&lt;br /&gt;
= Notes =&lt;br /&gt;
&lt;br /&gt;
The New PSM format was reverse engineered by Levellord and tidied up by Levellass. It is possible there may be minor errors in the sample format information, especially since this is poorly documented.&lt;br /&gt;
Some format definitions have been updated and corrected by Johannes Schultz of the OpenMPT development team.&lt;br /&gt;
&lt;br /&gt;
The PSM16 format documentation was found on Wotsit and written up by Levellass (this appears to be an official document from the MASI developer). More info is needed.&lt;br /&gt;
&lt;br /&gt;
In all formats the following table shows how note bytes are converted into actual notes: (PSM new format has the widest range, 0-255)&lt;br /&gt;
&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;br /&gt;
           | C-0   0 | C-1  12 | C-2  24 | C-3  36 | C-4  48 |&lt;br /&gt;
           | C#0   1 | C#1  13 | C#2  25 | C#3  37 | C#4  49 |&lt;br /&gt;
           | D-0   2 | D-1  14 | D-2  26 | D-3  38 | D-4  50 |&lt;br /&gt;
           | D#0   3 | D#1  15 | D#2  27 | D#3  39 | D#4  51 |&lt;br /&gt;
           | E-0   4 | E-1  16 | E-2  28 | E-3  40 | E-4  52 |&lt;br /&gt;
           | F-0   5 | F-1  17 | F-2  29 | F-3  41 | F-4  53 |&lt;br /&gt;
           | F#0   6 | F#1  18 | F#2  30 | F#3  42 | F#4  54 |&lt;br /&gt;
           | G-0   7 | G-1  19 | G-2  31 | G-3  43 | G-4  55 |&lt;br /&gt;
           | G#0   8 | G#1  20 | G#2  32 | G#3  44 | G#4  56 |&lt;br /&gt;
           | A-0   9 | A-1  21 | A-2  33 | A-3  45 | A-4  57 |&lt;br /&gt;
           | A#0  10 | A#1  22 | A#2  34 | A#3  46 | A#4  58 |&lt;br /&gt;
           | B-0  11 | B-1  23 | B-2  35 | B-3  47 | B-4  59 |&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=10923</id>
		<title>ProTracker Studio Module</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=10923"/>
		<updated>2023-03-27T21:06:03Z</updated>

		<summary type="html">&lt;p&gt;Saga: /* Order sub-segment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 1-256 (PSM) / 1-32 (PSM16)&lt;br /&gt;
 | NumTracks = unlimited (PSM) / 1 (PSM16)&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Epic Pinball}}&lt;br /&gt;
   {{Game|Extreme Pinball}}&lt;br /&gt;
   {{Game|Jazz Jackrabbit}}&lt;br /&gt;
   {{Game|One Must Fall}}&lt;br /&gt;
   {{Game|Silverball}}&lt;br /&gt;
   {{Game|Sinaria}}&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;ProTracker Studio Module&#039;&#039;&#039; (PSM) file format is used for the music in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]].  The file format is named after ProTracker, an Amiga program, though this program was probably actually not used to write PSM files. One Must Fall&#039;s music was written in Multitracker, and the music for Jazz Jackrabbit, Epic Pinball and Extreme Pinball probably in Scream Tracker.&lt;br /&gt;
&lt;br /&gt;
There are two file types that use the extension .PSM; they are both used by Epic Megagames&#039; MASI sound system, but are used by different versions of the system. The two formats are:&lt;br /&gt;
&lt;br /&gt;
* PSM New Format: Used by Jazz Jackrabbit, Epic Pinball, Extreme Pinball, One Must Fall, Sinaria (in this game with slight differences, see below), newest PSM format&lt;br /&gt;
* PSM 16:         Used by Silverball, an older version of the format which is closer to ScreamTracker-style modules.&lt;br /&gt;
&lt;br /&gt;
The most common of the two PSM formats is the new format, and most programs that try to interpret PSM files will be expecting this. For example, ModPlug Player cannot open Silverball files as these are in the PSM 16 format.&lt;br /&gt;
&lt;br /&gt;
There are actually two slightly different variants of the new formats: A common one used in several games, and one used in the game Sinaria. It is not entirely clear if the format used in Sinaria is newer or older - in some ways, like the effect interpretation, it resembles PSM16 more than the new format, so it could be an earlier version of the new PSM format. But Sinaria was released later than or around the same time as most other games using the new PSM format, so maybe it just took really long to develop. The format not used in Sinaria will be called &amp;quot;regular&amp;quot; in this document.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM New Format =&lt;br /&gt;
&lt;br /&gt;
This format is used by [[:Category:Epic Megagames|Epic]] games in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]]. It is notable for consisting of a number of segments (chunks) and sub segments. It bears the 4-byte signature &#039;PSM &#039; at the file start.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Song segment&lt;br /&gt;
 Samples&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 12 bytes long:&lt;br /&gt;
&lt;br /&gt;
 File header:&lt;br /&gt;
 0   4  ID     &#039;PSM &#039;; indicates file is PSM format&lt;br /&gt;
 4   4  Size   Filesize - 12&lt;br /&gt;
 8   4  ID2    &#039;FILE&#039;; indicates start of file info&lt;br /&gt;
&lt;br /&gt;
After the header, some chunks follow in IFF-style. You should not expect chunks to come up in the same order as they are described here. A good way to handle chunks is to read the 4-Byte ID and the 4-Byte size field first, then evaluate the ID and decide what to do next based on this ID. Note that the size field does not include the ID and itself; it only holds the size of the chunk &#039;&#039;content&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Title segment ==&lt;br /&gt;
&lt;br /&gt;
This segment is optional, and one of the few segments that can be absent when playing PSM files in most programs. (Most programs expect all other segments to exist, even if they are not vital.)&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;TITL&#039;; indicates a title follows&lt;br /&gt;
 4   4  Size   Size of title as dword after this dword&lt;br /&gt;
 8   ?  Title  Song title&lt;br /&gt;
&lt;br /&gt;
== Song info segment ==&lt;br /&gt;
&lt;br /&gt;
This segment seems to indicate the beginning of the song data and is not really relevant when parsing.&lt;br /&gt;
&lt;br /&gt;
 12  4  ID     &#039;SDFT&#039;; indicates start of format info&lt;br /&gt;
 16  4  Size   Size of next header as dword, (8)&lt;br /&gt;
 20  8  Song   &#039;MAINSONG&#039;; indicates song type. No other song types are known.&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
Each pattern is stored in its own PBOD chunk. Note that there are two possible formats for this chunk; one is used in the &amp;quot;regular&amp;quot; format (as used in Epic Pinball, Extreme Pinball, Jazz Jackrabbit, One Must Fall) and the other in the &amp;quot;Sinaria&amp;quot; format (as used in Sinaria)&lt;br /&gt;
&lt;br /&gt;
 Pattern segment:&lt;br /&gt;
 0   4  ID     &#039;PBOD&#039;; indicates a pattern follows (Pattern BODy)&lt;br /&gt;
 4   4  Size   Length of pattern data as dword, after this dword&lt;br /&gt;
 4   4  Size   Same value again.&lt;br /&gt;
&lt;br /&gt;
 Pattern:&lt;br /&gt;
 0 4/8  Number Pattern ID. See note below.&lt;br /&gt;
 4   2  Row n  Number of rows in ALL channels in pattern (64 usually, but can differ.) as word.&lt;br /&gt;
 6   ?  Data   Contains pattern data as a number of rows of interlaced channels (12341234...)&lt;br /&gt;
               &#039;&#039;Usual&#039;&#039; settings is 64 rows of 4 channels. Epic Pinball has shorter patterns for example, but they also include a &amp;quot;break to row&amp;quot; command at the end of the pattern.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; There are two variants of the format. In the &amp;quot;regular&amp;quot; variant, the pattern ID is 4 bytes long and starts with a &#039;P&#039;, followed by an integer number which is the pattern number, padded to 4 bytes with spaces. Caution: This number might or might not be zero-padded; In some files, the ID of the first pattern could be &#039;P0  &#039;, but there are also files where it is &#039;P00 &#039;!. In C/C++, you could use atoi() to parse this value.&lt;br /&gt;
In the format used in the game Sinaria, This field is 8 bytes long instead of 4 bytes, and the first 4 bytes read &amp;quot;PATT&amp;quot;, so the first pattern could be for example &#039;PATT0   &#039;. You may want to deal with this by first reading for bytes, and if they are equal to &amp;quot;PATT&amp;quot;, read four more bytes for the pattern ID.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Pattern row channel entry:&lt;br /&gt;
 ?   1  Flags  Contains four flags that indicate which pattern data follows&lt;br /&gt;
 +1  1  Chan   The channel this data belongs to.&lt;br /&gt;
 +2  1  Note   Present if bit 7 in Flags is set. Pitch, $01 is C-1, etc... The octaves&lt;br /&gt;
               are aligned by 16, i.e. B-1 is $0C but the next note, C-2, is $10.&lt;br /&gt;
 +3  1  Ins    Present if bit 6 in Flags is set. Instrument used, 0-31&lt;br /&gt;
 +4  1  Vol    Present if bit 5 in Flags is set. Volume change to, 0-63 = 0-127; optional&lt;br /&gt;
 +5  1  Effect Present if bit 4 in Flags is set. Effect to use, volume slide, Portamanto...&lt;br /&gt;
 +6  x  Eff Am Present if bit 4 in Flags is set. Parameter of effect, e.g amount of slide&lt;br /&gt;
&lt;br /&gt;
Each row consists of a word giving the size of the row (Including the word) followed by the channel data. A channel is only included if it has data in it, but a totally empty row is still included. So an &#039;empty&#039; row (Where none of the channels have data.) thus consists of just a word of value 2.&lt;br /&gt;
&lt;br /&gt;
Each channel entry consists of between 3-7 bytes. The first byte is a flag that shows what data follows. (The highest four bits indicate whether there are bytes for the following four variables; Note ($80), Instrument ($40), Volume ($20), Effect AND Effect parameter ($10). Thus 5 bytes are represented by a combination of 4 possibilities.) The next byte identifies the channel (Since each channel may or may not be present.) starting at 0 for channel 1. The remaining 5 bytes may or may not be present depending on their flag and contain data for Note, Instrument(Sample) used, Volume change for channel, Effect and Effect parameter.&lt;br /&gt;
&lt;br /&gt;
There are several things to note about this; Effect and Effect magnitude MUST occur together. Sample numbers, like channels are numbered starting at 0, not 1. Magnitudes (For effect AND volume) are from 0-127, not 0-64 as in other formats.&lt;br /&gt;
&lt;br /&gt;
=== Effect conversion ===&lt;br /&gt;
&lt;br /&gt;
Note that this table is guaranteed to be correct; Most effects seem to be converted correctly, though. Note that these values are not correct for the PSM files that can be found in the game Sinaria. Leave out all divisions and it will be correct again.&lt;br /&gt;
&lt;br /&gt;
 PSM Command   Param length  S3M Command&lt;br /&gt;
 &lt;br /&gt;
  Volume commands&lt;br /&gt;
    1           1 Byte        DxF - fine volside up&lt;br /&gt;
    2           1 Byte        Dx0 - volslide up&lt;br /&gt;
    3           1 Byte        DFx - fine volslide down&lt;br /&gt;
    4           1 Byte        D0x - volslide down&lt;br /&gt;
 &lt;br /&gt;
 Portamento commands&lt;br /&gt;
    B           1 Byte        FFx - fine porta up (divide x by 4)&lt;br /&gt;
    C           1 Byte        Fxx - porta up (if x &amp;lt; 4, use FFx, else divide x by 4)&lt;br /&gt;
    D           1 Byte        EFx - fine porta down (divide x by 4)&lt;br /&gt;
    E           1 Byte        Exx - porta down (if x &amp;lt; 4, use EFx, else divide x by 4)&lt;br /&gt;
    F           1 Byte        Gxx - portamento (divide x by 4)&lt;br /&gt;
   10           1 Byte        S1x - glissando control&lt;br /&gt;
   11           1 Byte        Lx0 - tone porta + volslide up&lt;br /&gt;
   12           1 Byte        L0x - tone porta + volslide down&lt;br /&gt;
    &lt;br /&gt;
 Vibrato&lt;br /&gt;
   15           1 Byte        Hxy - vibrato&lt;br /&gt;
   16           1 Byte        S3x - vibrato waveform&lt;br /&gt;
   17           1 Byte        K0x - vibrato + volslide up&lt;br /&gt;
   18           1 Byte        Kx0 - vibrato + volslide down&lt;br /&gt;
   	&lt;br /&gt;
 Tremolo			&lt;br /&gt;
   1F           1 Byte        Rxy - tremolo&lt;br /&gt;
   20           1 Byte        S4x - tremolo waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample commands&lt;br /&gt;
   29           3 Bytes       Oxx - offset (xx corresponds to the 2nd byte)&lt;br /&gt;
   2A           1 Byte        Q0x - retrigger&lt;br /&gt;
   2B           1 Byte        SCx - note cut&lt;br /&gt;
   2C           1 Byte        SDx - note delay&lt;br /&gt;
 &lt;br /&gt;
 Position change&lt;br /&gt;
   33           2 Bytes       Bxx - position jump - ignored by PLAY.EXE&lt;br /&gt;
   34           1 Byte        Cxx - break to row&lt;br /&gt;
                                    PLAY.EXE entirely ignores the parameter (it always breaks to the first&lt;br /&gt;
                                    row), so it is maybe best to do this in your own player as well.&lt;br /&gt;
                                    If the original file was an S3M, the parameter is double-BCD-encoded,&lt;br /&gt;
                                    i.e. on top of the original format&#039;s BCD encoding, the same encoding&lt;br /&gt;
                                    is applied again. to translate into the correct target row in binary,&lt;br /&gt;
                                    apply this twice: param = (param &amp;amp; 0xF0) * 10 + (param &amp;amp; 0x0F)&lt;br /&gt;
                                    For MOD files, the parameter is a normal binary number.&lt;br /&gt;
   35           1 Byte        SBx - pattern loop&lt;br /&gt;
   36           1 Byte        SEx - pattern delay&lt;br /&gt;
  &lt;br /&gt;
 Speed change&lt;br /&gt;
   3D           1 Byte        Axx - set speed&lt;br /&gt;
   3E           1 Byte        Txx - set tempo&lt;br /&gt;
 &lt;br /&gt;
 Misc. commands&lt;br /&gt;
   47           1 Byte        Jxy - arpeggio&lt;br /&gt;
   48           1 Byte        S2x - set finetune&lt;br /&gt;
   49           1 Byte        S8x - set balance&lt;br /&gt;
&lt;br /&gt;
Effect interpretation is slightly different in Sinaria&#039;s format. Slide command parameters are more like in PSM16.&lt;br /&gt;
&lt;br /&gt;
== Song segment ==&lt;br /&gt;
&lt;br /&gt;
This segment contains most of the important data used to play the song. It contains several sub-segments, each of the same format as a normal segment, but contained in the song segment. Note that there might be more than one song segment and thus, more than one order list, default speed, default tempo, etc... For example, in Extreme Pinball, all the different jingles and mission songs are stored as separate SONG chunks. It is up to the developer to find a clever way of managing / playing several sub songs.&lt;br /&gt;
&lt;br /&gt;
 Segment structure:&lt;br /&gt;
 0   4  ID     &#039;SONG&#039; indicates start of song structure&lt;br /&gt;
 4   4  Size   Size of song structure, including all sub-segments&lt;br /&gt;
 8   9  Type   Type of song this is for; This is &#039;MAINSONG &#039; in almost all PSM files. Extreme Pinball has several SONG items with different types!&lt;br /&gt;
 17  1  Comp   Compression, for PSM = 1 (Uncompressed)&lt;br /&gt;
 18  1  Chan   Number of channels, usually, but not always, 4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Date sub-segment ===&lt;br /&gt;
&lt;br /&gt;
This dates the file and is used by some programs. It is usually the first sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DATE&#039; indicates date data&lt;br /&gt;
 4   4  Size   Size of date segment (6)&lt;br /&gt;
 8   6  Date   Date as text, YYMMDD&lt;br /&gt;
&lt;br /&gt;
This can also be used as a way to heuristically detect if the regular or Sinara version of the format is being used. Sinaria&#039;s song dates are: 800211, 940902, 940903, 940906, 940914, 941213&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Order sub-segment ===&lt;br /&gt;
&lt;br /&gt;
The order list describes how patterns are arranged in the song. This allows the same pattern of instruments to be played more than once in a song (e.g. a chorus). without the pattern data having to be duplicated. There should be only one order. In most module formats, the order list only consists of pattern indices, but in the PSM format it resembles a tiny scripting language that can do more than just list patterns. For example, It typically contains chunks that set the tempo of the song and the channel panning. In theory, these chunks can occur between two pattern chunks, changing the tempo or panning of a pattern without having to duplicate the pattern data, but in practice this feature is not used, so it can be ignored when writing a PSM loader.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;OPLH&#039; indicates start of pattern placement order&lt;br /&gt;
 4   4  Size   Size of order segment&lt;br /&gt;
 8   2  Cnt.   Number of following chunks&lt;br /&gt;
&lt;br /&gt;
Now, the following chunks may follow until the end of the &amp;quot;OPLH&amp;quot; chunk is reached. Every chunk is identified by its first byte:&lt;br /&gt;
* $00 (1 Byte): End (Nothing follows)&lt;br /&gt;
* $01 (5/9 Bytes): Order list item follows (e.g. &amp;quot;P0  &amp;quot;, &amp;quot;P12 &amp;quot; in regular format or &amp;quot;PATT0   &amp;quot; in Sinaria format, see above) - join those to get the complete order list.&lt;br /&gt;
* $02: Play Range: N/A&lt;br /&gt;
* $03: Jump Loop: N/A&lt;br /&gt;
* $04 (3 Bytes): This 16-bit value indicates the &amp;quot;restart chunk&amp;quot;. If the end of the subsong is reached, it will jump back to this chunk. In many cases, this would be 4th chunk (not 3rd chunk, as the chunk index is starting at 0!), which is a panning index in most PSMs - So you would just go to the nearest order list item that&#039;s following this chunk. However, this can also point to a valid order list chunk.&lt;br /&gt;
* $05: Channel Flip (3 Bytes): Changes the channel type without specifying pan position. The first byte is the channel index, the second byte is the channel type (see command $0D). This command is not used in any known soundtrack.&lt;br /&gt;
* $06: Transpose (2 Bytes): Does not appear to do anything, regardless of parameter.&lt;br /&gt;
* $07 (2 Bytes): Next byte sets the speed (ticks/row) for this subtune&lt;br /&gt;
* $08 (2 Bytes): Next byte sets the tempo for this subtune&lt;br /&gt;
* $0C (7 Bytes): Sample map table: This chunk is always $0C $00 $FF $00 $00 $01 $00. This seems to be an unfinished feature of the order list scripting language. It appears that this maps e.g. what is &amp;quot;I0&amp;quot; in the file to sample 1. Only the fourth and fifth byte ($00 $00) actually seem to do something: They translate the sample number in the pattern to different instruments in the file.&lt;br /&gt;
* $0D (4 Bytes): Channel panning index. Next byte is channel number (Start at 0), then initial pan ($00 ... $FF) and a type byte follow. The byte seems to tell what to do with the previous pan position (0 - use it, 2 - ignore it, make this channel surround, 4 - set to center).&lt;br /&gt;
* $0E (3 Bytes): Channel volume index. Next byte is channel number (Start at 0), then volume ($00 ... $FF). $FF in most cases. Some OMF 2097 tracks use a lower volume.&lt;br /&gt;
&lt;br /&gt;
N/A: This chunk is not used in any game soundtrack. The length and meaning of its parameters is unknown.&lt;br /&gt;
&lt;br /&gt;
=== Pattern list ===&lt;br /&gt;
&lt;br /&gt;
This is simply a list of all the patterns used in the file. You do not really need to parse this, it seems to be a purely informational chunk.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;PATT&#039; indicates start of pattern list&lt;br /&gt;
 4   4  Size   Size of pattern list after this&lt;br /&gt;
 8   4  Size   Same as above&lt;br /&gt;
 12  4x Pat    An ordered list &#039;P0  &#039;, &#039;P1  &#039;... for all patterns in the file, each entry 4 bytes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sample list sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Similar to the above, this is a list of all the samples used in the file. It is usually the last sub-segment in the song segment and you do not really need to parse this.&lt;br /&gt;
&lt;br /&gt;
  0  4   ID     &#039;DSAM&#039;; indicates start of sample list, used to say what samples are &#039;full&#039;&lt;br /&gt;
                Any samples not on this list will be ignored, even if they have data&lt;br /&gt;
  4  4   Size   Size of list after this&lt;br /&gt;
  8  4   Size   Same value as above&lt;br /&gt;
  12 15x Entry  Sample entries, one for each sample in the file, each entry 15 bytes&lt;br /&gt;
&lt;br /&gt;
 Sample entry:&lt;br /&gt;
 0   8  Format Sample format, padded with spaces (END, RAG2...) This is important to some programs&lt;br /&gt;
 8   4  ID     &#039;I0  &#039;, &#039;I1  &#039;... the sample ID (&#039;I&#039; means &#039;Instrument&#039;). Again, be sure to accept both &#039;I0  &#039; and &#039;I00 &#039;!&lt;br /&gt;
 12  2  Num    The sample number, 0,1,2... for the sample&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
Samples are the raw sound data that makes up the instruments on the song. The actual format depends on the sample format. Samples have information in their headers which allows data to be played at different pitches (Speeds.) and to loop from and to various points in the data. This is by far the largest part of the file, since the raw data takes up so much space.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DSMP&#039; indicates start of sample&lt;br /&gt;
 4   4  Size   Size of following sample as &#039;DSMP&#039; + dword from end of word&lt;br /&gt;
 8   9  Flags  If highest bit is set, then sample is looped&lt;br /&gt;
 9   8  Songn. Filename of the original module (without extension)&lt;br /&gt;
 17  4  INSx   Last digit of sample (Instrument) number, 0-9; with 31 instruments possible&lt;br /&gt;
               Only last digit is shown. E.g 1st, 11th, 21st and 31st sample is &#039;INS0&#039;&lt;br /&gt;
 21  33 Name   Defines the instrument name or file, usually a .st or line of text&lt;br /&gt;
 54  51 Header Sample parameters (Can also 58 bytes long, padded with nuls)&lt;br /&gt;
               Byte 1-6 are unknown (but apparently always $00 $00 $00 $00 $00 $FF)&lt;br /&gt;
               Bytes 7-8 is instrument number&lt;br /&gt;
               Bytes 9-12 are sample length&lt;br /&gt;
               Bytes 13-16 are loop start&lt;br /&gt;
               Bytes 17-20 are loop end (all $FF means at end of sample)&lt;br /&gt;
               Bytes 21-22 are unknown (second byte could be finetune in Sinaria, but seems to be unused)&lt;br /&gt;
               Byte 23 is default volume&lt;br /&gt;
               Bytes 24-27 are unknwon&lt;br /&gt;
               Bytes 28-31 is frequency (Sample rate). MASI ignores the upper 16 bits, even if they are non-zero.&lt;br /&gt;
               19 $00-bytes follow (padding?)&lt;br /&gt;
 105 ?  Data   Music data in 8-bit mono format&lt;br /&gt;
&lt;br /&gt;
The sample header is slightly different in Sinaria&#039;s format: INSx is 8 bytes long (like the PATT IDs), and the last 21 $00-bytes are just 16 bytes (so that the struct is 96 bytes large in both formats).&lt;br /&gt;
&lt;br /&gt;
The PSM new format, along with the PSM 16 format use delta-encoded samples, something to make the file smaller when zipped. &#039;Deltas&#039;, convert a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. It has the effect that if a single byte in the sample is changed, the entire sample will be degraded. This use of deltas varies slightly from that of the PSM 16. The &#039;start value&#039; of the string is assumed to be $80 (128) and the first byte will thus turn this into the first desired value, the second delta converts the first value to the second, and so on.) All deltas are signed, 1-byte values, but loop (Thus 10 - 20 = -10 can also be considered as 10 + 236 = 246). An example of this is as follows:&lt;br /&gt;
&lt;br /&gt;
 RAW:   (128) 64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: -64  0   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Encryption ==&lt;br /&gt;
&lt;br /&gt;
CONVERT.EXE can produce &amp;quot;encrypted&amp;quot; PSM files with the /K command line switch. The encryption scheme is simple: It adds 1 to the first byte, 2 to the second, 3 to the third, and so until, for the entire file. It does not appear like any game made use of this feature, though.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM 16 =&lt;br /&gt;
&lt;br /&gt;
This is the format used in [[Silverball]], early versions of Epic Pinball and possibly other games. The designation &#039;Protracker Studio 16 format&#039; was given to it by the only reliable source of information on this format, and may not be the official designation.&lt;br /&gt;
&lt;br /&gt;
The format bears many similarities to the S3M format; the file is set out roughly the same, patterns and samples are similar, indeed, near identical and the functionality is similar. It also shows many similarities to the ProTracker MOD format and retains vestiges of Amiga compatibility.&lt;br /&gt;
&lt;br /&gt;
This format can be identified by its signature &#039;PSMþ&#039;, though files may lack this and still function.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Order&lt;br /&gt;
 Pan segment&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Sample data&lt;br /&gt;
 Sample headers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
 0    4  Sig      Signature, &#039;PSMþ&#039;&lt;br /&gt;
 4    59 Title    Song title, padded with nulls. Unlike other formats, this must also be terminated&lt;br /&gt;
                  with a null byte. (It sometimes is not terminated, though.)&lt;br /&gt;
 62   1           This must be $1A to end the song name, like in S3M format.&lt;br /&gt;
 64   1  Type     Song type, First bit: 0 - Module (w/samp.), 1 - Song (w/o samples)&lt;br /&gt;
                  Second bit: 0 - 3 octave Protracker, 1 - 5 octave; remaining bits reserved.&lt;br /&gt;
 65   1  PSM v    PSM format version, $10 for this format (Hence the name PSM 16) = &#039;v1.00&#039;.&lt;br /&gt;
                  Sometimes, this is also $01, but there&#039;s no difference in the format itself.&lt;br /&gt;
 66   1  Patt v   Pattern version, 0 or 1. 0 means the pattern is stored in the module are in the 32&lt;br /&gt;
                  channel file format.  A 1 signifies the patterns as being stored as a 255&lt;br /&gt;
                  channel format. (I have not found any PSM16 modules that have this format.)&lt;br /&gt;
 67   1   Speed   Song speed&lt;br /&gt;
 68   1   BPM     Beats per minute, the default Amiga BPM value. (The only reason that the Amiga BPM&lt;br /&gt;
                  format is still followed here is that it allows more control over the final hz value.)&lt;br /&gt;
                  Range: 32 to 255.&lt;br /&gt;
 69   1   Vol     Master volume of song, 0-255&lt;br /&gt;
 70   2   Len     Song length, 0-255. The number of patterns to play in the song, in total.&lt;br /&gt;
 72   2   Ordlen  The number of orders actually stored at the order offset. It was hoped that the&lt;br /&gt;
                  PSM 16 format would allow multiple orders, so this would be the length of the first&lt;br /&gt;
                  order. This doesn&#039;t appea to ahve happened, and is usually the same as the previous value.&lt;br /&gt;
 74   2   Patnum  Number of patterns in the song. 1-255&lt;br /&gt;
 76   2   Sampnum Number of samples and &#039;sample structures&#039; in song, 1-255&lt;br /&gt;
 78   2   NCIS    Number of channels in song to PLAY. 1-32. &lt;br /&gt;
 80   2   NCP     Number of Channels to Process; describes the MAXIMUM number of channels to process.&lt;br /&gt;
                  As an example, when converting 669 files,  NCP = 9 because some track information &lt;br /&gt;
                  is in Channel 8, but the Number of Channels to Play was set to 8, (Channel numbers&lt;br /&gt;
                  to play from 0 to 7.) 1-32&lt;br /&gt;
 82   4   Ordoff  Location of order in header&lt;br /&gt;
 86   4   Panoff  Location of pan positions in header&lt;br /&gt;
 90   4   Patoff  Location of patterns in header&lt;br /&gt;
 94   4   Sampoff Location of sample headers in header&lt;br /&gt;
 98   4   Commoff Location of comments in header&lt;br /&gt;
 102  4   Patsiz  Total pattern size; the total size of all the patterns loaded from the pattern offset.&lt;br /&gt;
 106  40  Fillers 10 fillers, to be used for any possible expansions.&lt;br /&gt;
&lt;br /&gt;
It is important to notice that the offsets point to the first byte &#039;&#039;&#039;after&#039;&#039;&#039; the chunk ID, i.e. &amp;quot;Ordoff&amp;quot; points to the first byte after &amp;quot;PORD&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Order and Pan positions ==&lt;br /&gt;
&lt;br /&gt;
These are two separate segments, pointed to in the header. They may be anywhere, but usually follow the header sometimes after an amount of blank space. They are often padded with blank space. They are basically lists.&lt;br /&gt;
&lt;br /&gt;
Order: This segment is pointed to in the header, and sets the PSM 16 format apart. The PSM 16 format was designed to be much more like the MOD format, allowing game designers to set flags to switch from one set of patterns to another, in effect allowing one file to contain more than one song. (For example a boss flag might make the music switch from a clam patterns 1-4 to a racy and dangerous patterns 5-7.)&lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    Signature, not needed, &#039;PORD&#039;&lt;br /&gt;
 4    ?   Ords   Pattern numbers and order. There will be [Ordlen] bytes of patterns&lt;br /&gt;
 ?    2   Lang   Order language, not implemented, so left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pan Positions: &lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    &#039;PPAN&#039;&lt;br /&gt;
 4    12  Pan    Pan positions; empty positions left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
 0    2   Size   Size of pattern, including these bytes&lt;br /&gt;
 2    1   Len    Length of pattern, in rows. Max length is 64 rows.&lt;br /&gt;
 3    1   Chan   Number of channels in pattern, 1-32&lt;br /&gt;
 4    ?   Data   Pattern data&lt;br /&gt;
&lt;br /&gt;
This is similar to the previous two segments, except actual pattern data is stored here. Patterns are very similar to the S3M format, and consist of y rows of x channels. Each row contains a number of channels and ends with a byte of value 0. Each channel is between 2-6+ bytes long. A totally empty channel is represented by a single byte of value 0.&lt;br /&gt;
&lt;br /&gt;
Each channel starts with a flag byte, abcddddd, where a,b and c indicate whether there is a note and instrument, volume or special effect and effect magnitude in the following data, and dddd is the channel number (0-31, used since a given channel may or may not be present in a row.)&lt;br /&gt;
&lt;br /&gt;
The usual maximum length of a channel entry is 6 bytes (1 flag byte, 2 Note AND instrument bytes, 1 volume byte and two Effect and Effect magnitude bytes.) Thus Note&amp;amp;ins\Eff&amp;amp;Eff mag must always occur together.&lt;br /&gt;
&lt;br /&gt;
Like S3M, volume range is 0-64, as is special magnitude. However, special effects range from 0-255, like PSM New Format.&lt;br /&gt;
&lt;br /&gt;
=== Effects conversion ===&lt;br /&gt;
&lt;br /&gt;
 ###  Co  MOD  Description               Arguments&lt;br /&gt;
 ---  --  ---  -----------               ---------&lt;br /&gt;
 Volume Commands&lt;br /&gt;
   1  A1   EA  Fine Volume Slide Up      B xx xx=speed&lt;br /&gt;
   2  A2   A   Volume Slide Up           B xx xx=speed&lt;br /&gt;
   3  A3   EB  Fine Volume Slide Down    B xx xx=speed&lt;br /&gt;
   4  A4   A   Volume Slide Down         B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Portamento Commands&lt;br /&gt;
  10  B0   E1  Fine Porta Up             B xx xx=speed&lt;br /&gt;
  11  B1   1   Portamento Up             B xx xx=speed&lt;br /&gt;
  12  B2   E2  Fine Porta Down           B xx xx=speed&lt;br /&gt;
  13  B3   2   Portamento Down           B xx xx=speed&lt;br /&gt;
  14  B4   3   Tone Portamento           B xx xx=speed&lt;br /&gt;
  15  B5   E3  Set Glissando Control     B xx xx=0 - Off, 1 - On&lt;br /&gt;
  16  B6   5   Tone Port+Vol Slide Up    B xx xx=speed&lt;br /&gt;
  17  B7   5   Tone Port+Vol Slide Down  B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Vibrato Commands&lt;br /&gt;
  20  C0   4   Vibrato                   B xy x=speed, y=depth&lt;br /&gt;
  21  C1   E4  Set Vibrato Waveform      B x  x=Waveform&lt;br /&gt;
  21  C2   6   Vibrato+Vol Slide Up      B xx xx=speed&lt;br /&gt;
  22  C3   6   Vibrato+Vol Slide Down    B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Tremolo Commands&lt;br /&gt;
  30  D0   7   Tremolo                   B xy x=speed, y=depth&lt;br /&gt;
  31  D1   E7  Set Tremolo Control       B x  x=Waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample Commands&lt;br /&gt;
  40  E0   9   Sample Offset             3B Position for offset change (0-1,048,575)&lt;br /&gt;
  41  E1   E9  Retrig Note               B xx xx=tick to retrigger sample&lt;br /&gt;
  42  E2   EC  Note Cut                  B xx xx=tick to cut note&lt;br /&gt;
  43  E3   ED  Note Delay                B xx xx=ticks to delay note&lt;br /&gt;
 &lt;br /&gt;
 Pos. Change Commands&lt;br /&gt;
  50  F0   B   Position Jump             B xx xx=order position&lt;br /&gt;
  51  F1   D   Pattern Break             B xx Skip to line xx in next pattern&lt;br /&gt;
  52  F2   E6  Jump Loop                 B xx xx=number of loops  0 Set&lt;br /&gt;
  53  F3   EE  Pattern Delay             B xx xx=notes to delay pattern&lt;br /&gt;
 &lt;br /&gt;
 Speed Change Cmds&lt;br /&gt;
  60  G0   F   Set Regular Speed         B xx xx=speed&lt;br /&gt;
  61  G1   F   Set BPM                   B xx xx=BPM (32-255)&lt;br /&gt;
 &lt;br /&gt;
 Misc. Commands&lt;br /&gt;
  70  H0   0   Arpeggio                  B xy x=semitone #1, y=semitone #2&lt;br /&gt;
  71  H1   E5  Set Finetune              B xx xx=finetune&lt;br /&gt;
  72  H2       Set Balance               B xx xx=Balance (0-15)&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
 Sample segment&lt;br /&gt;
 0    4   ID     &#039;PSAM&#039; (Psm SAMple)&lt;br /&gt;
 4    ?  Data    Sample data&lt;br /&gt;
&lt;br /&gt;
 Sample header segment&lt;br /&gt;
 0    4   ID     &#039;PSAH&#039; (Psm SAmple Header)&lt;br /&gt;
 4    ?  Data    Sample headers&lt;br /&gt;
&lt;br /&gt;
 Sample header&lt;br /&gt;
 0    13  Name   Sample filename, terminated with a null.&lt;br /&gt;
 13   24  Desc   Sample description or comments.&lt;br /&gt;
 37   4   Offs   Location of raw sample data in file&lt;br /&gt;
 43   4   Mem    This is the physical offset in RAM/DRAM of the sample. (Often blank.)&lt;br /&gt;
 45   2   Num    Sample number, 1-255&lt;br /&gt;
 47   1   Type   Sample type: (In some games left blank; if this is the case then the&lt;br /&gt;
                 sample format is END, as used in most PSM New Format files)&lt;br /&gt;
                 Bit 0: 0 - Digital, 1 - Synthesized&lt;br /&gt;
                 Bit 2: 0 - 8-bit, 1 - 16-bit&lt;br /&gt;
                 Bit 3: 0 - Signed, 1 - Unsigned&lt;br /&gt;
                 Bit 4: 0 - Deltas, 1 - Raw&lt;br /&gt;
                 Bit 5: 0 - Loop normally, 1 - Bidirectional&lt;br /&gt;
                 Bit 6: 1 - Gravis patch (unsupported)&lt;br /&gt;
                 Bit 7: 0 - No loop, 1 - Loop sample&lt;br /&gt;
 48   4   Len    Sample length, in bytes.&lt;br /&gt;
 52   4   Rep st Sample repeat start; if sample loops, the loop starts here.&lt;br /&gt;
 56   4   Rep fn Sample repeat end, if sample loops, it ends here. If this is less than the sample&lt;br /&gt;
                 repeat start, the sample loops backwards.&lt;br /&gt;
 60   1   Tune   Fine tune; range 0-15, Tune 0-7 = 0-7; tune -1 - -8 = 8-15&lt;br /&gt;
 61   1   Vol    Sample volume, 0-64&lt;br /&gt;
 62   2   Freq   This is the frequency for the sample at a C of Octave 2.&lt;br /&gt;
                 Typical values are 8,000 hz to 8,448 hz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like in S3M, sample headers are stored separately from the raw sample data.&lt;br /&gt;
&lt;br /&gt;
A type of sample storage used often, like in the PSM New Format is &#039;Deltas&#039;, which converts a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte, often making them compress better using general-purpose file compression tools. Thus:&lt;br /&gt;
&lt;br /&gt;
 RAW:        64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: 11  64   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
This is done to make files more compressible, but doesn&#039;t seem to be used much.&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.shikadi.net/files/psm2scrm.zip psm2scrm.zip] - DOS program to convert .PSM songs into ScreamTracker .S3M format, suitable for playing in your favourite tracker/module player. Works only with PSM New Format and is not nearly as accurate as OpenMPT.&lt;br /&gt;
* [https://openmpt.org OpenMPT] 1.18 and newer can load all PSM and PSM16 files.&lt;br /&gt;
* [https://openmpt.org/legacy_software ModPlug Tracker] and OpenMPT 1.17 can play the files and save them as S3M. More complex songs don&#039;t load correctly though. Works only with new format.&lt;br /&gt;
* [http://kode54.foobar2000.org/ foo_dumb] is a plugin for various module formats for the Foobar2k media player. It supports both PSM16 and PSM and is similar to OpenMPT in playback quality.&lt;br /&gt;
* [http://ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/mxinfo/epictest.zip EPICTEST] is a demonstration of the Epic Megagames MASI. It contains CONVERT.EXE which can be used to convert modules to the new PSM format.&lt;br /&gt;
* [http://www.jazz2online.com/J2Ov2/downloads/info.php?levelID=5471#29435] JJ1MOD can convert S3M files to new PSM, though often with errors (Though these are usually only detectable with older programs such as game executables.) It is currently the only utility able to do this, and works only with New Format.&lt;br /&gt;
&lt;br /&gt;
= Notes =&lt;br /&gt;
&lt;br /&gt;
The New PSM format was reverse engineered by Levellord and tidied up by Levellass. It is possible there may be minor errors in the sample format information, especially since this is poorly documented.&lt;br /&gt;
Some format definitions have been updated and corrected by Johannes Schultz of the OpenMPT development team.&lt;br /&gt;
&lt;br /&gt;
The PSM16 format documentation was found on Wotsit and written up by Levellass (this appears to be an official document from the MASI developer). More info is needed.&lt;br /&gt;
&lt;br /&gt;
In all formats the following table shows how note bytes are converted into actual notes: (PSM new format has the widest range, 0-255)&lt;br /&gt;
&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;br /&gt;
           | C-0   0 | C-1  12 | C-2  24 | C-3  36 | C-4  48 |&lt;br /&gt;
           | C#0   1 | C#1  13 | C#2  25 | C#3  37 | C#4  49 |&lt;br /&gt;
           | D-0   2 | D-1  14 | D-2  26 | D-3  38 | D-4  50 |&lt;br /&gt;
           | D#0   3 | D#1  15 | D#2  27 | D#3  39 | D#4  51 |&lt;br /&gt;
           | E-0   4 | E-1  16 | E-2  28 | E-3  40 | E-4  52 |&lt;br /&gt;
           | F-0   5 | F-1  17 | F-2  29 | F-3  41 | F-4  53 |&lt;br /&gt;
           | F#0   6 | F#1  18 | F#2  30 | F#3  42 | F#4  54 |&lt;br /&gt;
           | G-0   7 | G-1  19 | G-2  31 | G-3  43 | G-4  55 |&lt;br /&gt;
           | G#0   8 | G#1  20 | G#2  32 | G#3  44 | G#4  56 |&lt;br /&gt;
           | A-0   9 | A-1  21 | A-2  33 | A-3  45 | A-4  57 |&lt;br /&gt;
           | A#0  10 | A#1  22 | A#2  34 | A#3  46 | A#4  58 |&lt;br /&gt;
           | B-0  11 | B-1  23 | B-2  35 | B-3  47 | B-4  59 |&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=10922</id>
		<title>ProTracker Studio Module</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=10922"/>
		<updated>2023-03-27T20:57:22Z</updated>

		<summary type="html">&lt;p&gt;Saga: /* Order sub-segment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 1-256 (PSM) / 1-32 (PSM16)&lt;br /&gt;
 | NumTracks = unlimited (PSM) / 1 (PSM16)&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Epic Pinball}}&lt;br /&gt;
   {{Game|Extreme Pinball}}&lt;br /&gt;
   {{Game|Jazz Jackrabbit}}&lt;br /&gt;
   {{Game|One Must Fall}}&lt;br /&gt;
   {{Game|Silverball}}&lt;br /&gt;
   {{Game|Sinaria}}&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;ProTracker Studio Module&#039;&#039;&#039; (PSM) file format is used for the music in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]].  The file format is named after ProTracker, an Amiga program, though this program was probably actually not used to write PSM files. One Must Fall&#039;s music was written in Multitracker, and the music for Jazz Jackrabbit, Epic Pinball and Extreme Pinball probably in Scream Tracker.&lt;br /&gt;
&lt;br /&gt;
There are two file types that use the extension .PSM; they are both used by Epic Megagames&#039; MASI sound system, but are used by different versions of the system. The two formats are:&lt;br /&gt;
&lt;br /&gt;
* PSM New Format: Used by Jazz Jackrabbit, Epic Pinball, Extreme Pinball, One Must Fall, Sinaria (in this game with slight differences, see below), newest PSM format&lt;br /&gt;
* PSM 16:         Used by Silverball, an older version of the format which is closer to ScreamTracker-style modules.&lt;br /&gt;
&lt;br /&gt;
The most common of the two PSM formats is the new format, and most programs that try to interpret PSM files will be expecting this. For example, ModPlug Player cannot open Silverball files as these are in the PSM 16 format.&lt;br /&gt;
&lt;br /&gt;
There are actually two slightly different variants of the new formats: A common one used in several games, and one used in the game Sinaria. It is not entirely clear if the format used in Sinaria is newer or older - in some ways, like the effect interpretation, it resembles PSM16 more than the new format, so it could be an earlier version of the new PSM format. But Sinaria was released later than or around the same time as most other games using the new PSM format, so maybe it just took really long to develop. The format not used in Sinaria will be called &amp;quot;regular&amp;quot; in this document.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM New Format =&lt;br /&gt;
&lt;br /&gt;
This format is used by [[:Category:Epic Megagames|Epic]] games in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]]. It is notable for consisting of a number of segments (chunks) and sub segments. It bears the 4-byte signature &#039;PSM &#039; at the file start.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Song segment&lt;br /&gt;
 Samples&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 12 bytes long:&lt;br /&gt;
&lt;br /&gt;
 File header:&lt;br /&gt;
 0   4  ID     &#039;PSM &#039;; indicates file is PSM format&lt;br /&gt;
 4   4  Size   Filesize - 12&lt;br /&gt;
 8   4  ID2    &#039;FILE&#039;; indicates start of file info&lt;br /&gt;
&lt;br /&gt;
After the header, some chunks follow in IFF-style. You should not expect chunks to come up in the same order as they are described here. A good way to handle chunks is to read the 4-Byte ID and the 4-Byte size field first, then evaluate the ID and decide what to do next based on this ID. Note that the size field does not include the ID and itself; it only holds the size of the chunk &#039;&#039;content&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Title segment ==&lt;br /&gt;
&lt;br /&gt;
This segment is optional, and one of the few segments that can be absent when playing PSM files in most programs. (Most programs expect all other segments to exist, even if they are not vital.)&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;TITL&#039;; indicates a title follows&lt;br /&gt;
 4   4  Size   Size of title as dword after this dword&lt;br /&gt;
 8   ?  Title  Song title&lt;br /&gt;
&lt;br /&gt;
== Song info segment ==&lt;br /&gt;
&lt;br /&gt;
This segment seems to indicate the beginning of the song data and is not really relevant when parsing.&lt;br /&gt;
&lt;br /&gt;
 12  4  ID     &#039;SDFT&#039;; indicates start of format info&lt;br /&gt;
 16  4  Size   Size of next header as dword, (8)&lt;br /&gt;
 20  8  Song   &#039;MAINSONG&#039;; indicates song type. No other song types are known.&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
Each pattern is stored in its own PBOD chunk. Note that there are two possible formats for this chunk; one is used in the &amp;quot;regular&amp;quot; format (as used in Epic Pinball, Extreme Pinball, Jazz Jackrabbit, One Must Fall) and the other in the &amp;quot;Sinaria&amp;quot; format (as used in Sinaria)&lt;br /&gt;
&lt;br /&gt;
 Pattern segment:&lt;br /&gt;
 0   4  ID     &#039;PBOD&#039;; indicates a pattern follows (Pattern BODy)&lt;br /&gt;
 4   4  Size   Length of pattern data as dword, after this dword&lt;br /&gt;
 4   4  Size   Same value again.&lt;br /&gt;
&lt;br /&gt;
 Pattern:&lt;br /&gt;
 0 4/8  Number Pattern ID. See note below.&lt;br /&gt;
 4   2  Row n  Number of rows in ALL channels in pattern (64 usually, but can differ.) as word.&lt;br /&gt;
 6   ?  Data   Contains pattern data as a number of rows of interlaced channels (12341234...)&lt;br /&gt;
               &#039;&#039;Usual&#039;&#039; settings is 64 rows of 4 channels. Epic Pinball has shorter patterns for example, but they also include a &amp;quot;break to row&amp;quot; command at the end of the pattern.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; There are two variants of the format. In the &amp;quot;regular&amp;quot; variant, the pattern ID is 4 bytes long and starts with a &#039;P&#039;, followed by an integer number which is the pattern number, padded to 4 bytes with spaces. Caution: This number might or might not be zero-padded; In some files, the ID of the first pattern could be &#039;P0  &#039;, but there are also files where it is &#039;P00 &#039;!. In C/C++, you could use atoi() to parse this value.&lt;br /&gt;
In the format used in the game Sinaria, This field is 8 bytes long instead of 4 bytes, and the first 4 bytes read &amp;quot;PATT&amp;quot;, so the first pattern could be for example &#039;PATT0   &#039;. You may want to deal with this by first reading for bytes, and if they are equal to &amp;quot;PATT&amp;quot;, read four more bytes for the pattern ID.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Pattern row channel entry:&lt;br /&gt;
 ?   1  Flags  Contains four flags that indicate which pattern data follows&lt;br /&gt;
 +1  1  Chan   The channel this data belongs to.&lt;br /&gt;
 +2  1  Note   Present if bit 7 in Flags is set. Pitch, $01 is C-1, etc... The octaves&lt;br /&gt;
               are aligned by 16, i.e. B-1 is $0C but the next note, C-2, is $10.&lt;br /&gt;
 +3  1  Ins    Present if bit 6 in Flags is set. Instrument used, 0-31&lt;br /&gt;
 +4  1  Vol    Present if bit 5 in Flags is set. Volume change to, 0-63 = 0-127; optional&lt;br /&gt;
 +5  1  Effect Present if bit 4 in Flags is set. Effect to use, volume slide, Portamanto...&lt;br /&gt;
 +6  x  Eff Am Present if bit 4 in Flags is set. Parameter of effect, e.g amount of slide&lt;br /&gt;
&lt;br /&gt;
Each row consists of a word giving the size of the row (Including the word) followed by the channel data. A channel is only included if it has data in it, but a totally empty row is still included. So an &#039;empty&#039; row (Where none of the channels have data.) thus consists of just a word of value 2.&lt;br /&gt;
&lt;br /&gt;
Each channel entry consists of between 3-7 bytes. The first byte is a flag that shows what data follows. (The highest four bits indicate whether there are bytes for the following four variables; Note ($80), Instrument ($40), Volume ($20), Effect AND Effect parameter ($10). Thus 5 bytes are represented by a combination of 4 possibilities.) The next byte identifies the channel (Since each channel may or may not be present.) starting at 0 for channel 1. The remaining 5 bytes may or may not be present depending on their flag and contain data for Note, Instrument(Sample) used, Volume change for channel, Effect and Effect parameter.&lt;br /&gt;
&lt;br /&gt;
There are several things to note about this; Effect and Effect magnitude MUST occur together. Sample numbers, like channels are numbered starting at 0, not 1. Magnitudes (For effect AND volume) are from 0-127, not 0-64 as in other formats.&lt;br /&gt;
&lt;br /&gt;
=== Effect conversion ===&lt;br /&gt;
&lt;br /&gt;
Note that this table is guaranteed to be correct; Most effects seem to be converted correctly, though. Note that these values are not correct for the PSM files that can be found in the game Sinaria. Leave out all divisions and it will be correct again.&lt;br /&gt;
&lt;br /&gt;
 PSM Command   Param length  S3M Command&lt;br /&gt;
 &lt;br /&gt;
  Volume commands&lt;br /&gt;
    1           1 Byte        DxF - fine volside up&lt;br /&gt;
    2           1 Byte        Dx0 - volslide up&lt;br /&gt;
    3           1 Byte        DFx - fine volslide down&lt;br /&gt;
    4           1 Byte        D0x - volslide down&lt;br /&gt;
 &lt;br /&gt;
 Portamento commands&lt;br /&gt;
    B           1 Byte        FFx - fine porta up (divide x by 4)&lt;br /&gt;
    C           1 Byte        Fxx - porta up (if x &amp;lt; 4, use FFx, else divide x by 4)&lt;br /&gt;
    D           1 Byte        EFx - fine porta down (divide x by 4)&lt;br /&gt;
    E           1 Byte        Exx - porta down (if x &amp;lt; 4, use EFx, else divide x by 4)&lt;br /&gt;
    F           1 Byte        Gxx - portamento (divide x by 4)&lt;br /&gt;
   10           1 Byte        S1x - glissando control&lt;br /&gt;
   11           1 Byte        Lx0 - tone porta + volslide up&lt;br /&gt;
   12           1 Byte        L0x - tone porta + volslide down&lt;br /&gt;
    &lt;br /&gt;
 Vibrato&lt;br /&gt;
   15           1 Byte        Hxy - vibrato&lt;br /&gt;
   16           1 Byte        S3x - vibrato waveform&lt;br /&gt;
   17           1 Byte        K0x - vibrato + volslide up&lt;br /&gt;
   18           1 Byte        Kx0 - vibrato + volslide down&lt;br /&gt;
   	&lt;br /&gt;
 Tremolo			&lt;br /&gt;
   1F           1 Byte        Rxy - tremolo&lt;br /&gt;
   20           1 Byte        S4x - tremolo waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample commands&lt;br /&gt;
   29           3 Bytes       Oxx - offset (xx corresponds to the 2nd byte)&lt;br /&gt;
   2A           1 Byte        Q0x - retrigger&lt;br /&gt;
   2B           1 Byte        SCx - note cut&lt;br /&gt;
   2C           1 Byte        SDx - note delay&lt;br /&gt;
 &lt;br /&gt;
 Position change&lt;br /&gt;
   33           2 Bytes       Bxx - position jump - ignored by PLAY.EXE&lt;br /&gt;
   34           1 Byte        Cxx - break to row&lt;br /&gt;
                                    PLAY.EXE entirely ignores the parameter (it always breaks to the first&lt;br /&gt;
                                    row), so it is maybe best to do this in your own player as well.&lt;br /&gt;
                                    If the original file was an S3M, the parameter is double-BCD-encoded,&lt;br /&gt;
                                    i.e. on top of the original format&#039;s BCD encoding, the same encoding&lt;br /&gt;
                                    is applied again. to translate into the correct target row in binary,&lt;br /&gt;
                                    apply this twice: param = (param &amp;amp; 0xF0) * 10 + (param &amp;amp; 0x0F)&lt;br /&gt;
                                    For MOD files, the parameter is a normal binary number.&lt;br /&gt;
   35           1 Byte        SBx - pattern loop&lt;br /&gt;
   36           1 Byte        SEx - pattern delay&lt;br /&gt;
  &lt;br /&gt;
 Speed change&lt;br /&gt;
   3D           1 Byte        Axx - set speed&lt;br /&gt;
   3E           1 Byte        Txx - set tempo&lt;br /&gt;
 &lt;br /&gt;
 Misc. commands&lt;br /&gt;
   47           1 Byte        Jxy - arpeggio&lt;br /&gt;
   48           1 Byte        S2x - set finetune&lt;br /&gt;
   49           1 Byte        S8x - set balance&lt;br /&gt;
&lt;br /&gt;
Effect interpretation is slightly different in Sinaria&#039;s format. Slide command parameters are more like in PSM16.&lt;br /&gt;
&lt;br /&gt;
== Song segment ==&lt;br /&gt;
&lt;br /&gt;
This segment contains most of the important data used to play the song. It contains several sub-segments, each of the same format as a normal segment, but contained in the song segment. Note that there might be more than one song segment and thus, more than one order list, default speed, default tempo, etc... For example, in Extreme Pinball, all the different jingles and mission songs are stored as separate SONG chunks. It is up to the developer to find a clever way of managing / playing several sub songs.&lt;br /&gt;
&lt;br /&gt;
 Segment structure:&lt;br /&gt;
 0   4  ID     &#039;SONG&#039; indicates start of song structure&lt;br /&gt;
 4   4  Size   Size of song structure, including all sub-segments&lt;br /&gt;
 8   9  Type   Type of song this is for; This is &#039;MAINSONG &#039; in almost all PSM files. Extreme Pinball has several SONG items with different types!&lt;br /&gt;
 17  1  Comp   Compression, for PSM = 1 (Uncompressed)&lt;br /&gt;
 18  1  Chan   Number of channels, usually, but not always, 4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Date sub-segment ===&lt;br /&gt;
&lt;br /&gt;
This dates the file and is used by some programs. It is usually the first sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DATE&#039; indicates date data&lt;br /&gt;
 4   4  Size   Size of date segment (6)&lt;br /&gt;
 8   6  Date   Date as text, YYMMDD&lt;br /&gt;
&lt;br /&gt;
This can also be used as a way to heuristically detect if the regular or Sinara version of the format is being used. Sinaria&#039;s song dates are: 800211, 940902, 940903, 940906, 940914, 941213&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Order sub-segment ===&lt;br /&gt;
&lt;br /&gt;
The order list describes how patterns are arranged in the song. This allows the same pattern of instruments to be played more than once in a song (e.g. a chorus). without the pattern data having to be duplicated. There should be only one order. In most module formats, the order list only consists of pattern indices, but in the PSM format it resembles a tiny scripting language that can do more than just list patterns. For example, It typically contains chunks that set the tempo of the song and the channel panning. In theory, these chunks can occur between two pattern chunks, changing the tempo or panning of a pattern without having to duplicate the pattern data, but in practice this feature is not used, so it can be ignored when writing a PSM loader.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;OPLH&#039; indicates start of pattern placement order&lt;br /&gt;
 4   4  Size   Size of order segment&lt;br /&gt;
 8   2  Cnt.   Number of following chunks&lt;br /&gt;
&lt;br /&gt;
Now, the following chunks may follow until the end of the &amp;quot;OPLH&amp;quot; chunk is reached. Every chunk is identified by its first byte:&lt;br /&gt;
* $00 (1 Byte): End (Nothing follows)&lt;br /&gt;
* $01 (5/9 Bytes): Order list item follows (e.g. &amp;quot;P0  &amp;quot;, &amp;quot;P12 &amp;quot; in regular format or &amp;quot;PATT0   &amp;quot; in Sinaria format, see above) - join those to get the complete order list.&lt;br /&gt;
* $02: Play Range: N/A&lt;br /&gt;
* $03: Jump Loop: N/A&lt;br /&gt;
* $04 (3 Bytes): This 16-bit value indicates the &amp;quot;restart chunk&amp;quot;. If the end of the subsong is reached, it will jump back to this chunk. In many cases, this would be 4th chunk (not 3rd chunk, as the chunk index is starting at 0!), which is a panning index in most PSMs - So you would just go to the nearest order list item that&#039;s following this chunk. However, this can also point to a valid order list chunk.&lt;br /&gt;
* $05: Channel Flip (3 Bytes): Changes the channel type without specifying pan position. The first byte is the channel index, the second byte is the channel type (see command $0D). This command is not used in any known soundtrack.&lt;br /&gt;
* $06: Transpose: N/A&lt;br /&gt;
* $07 (2 Bytes): Next byte sets the speed (ticks/row) for this subtune&lt;br /&gt;
* $08 (2 Bytes): Next byte sets the tempo for this subtune&lt;br /&gt;
* $0C (7 Bytes): Sample map table: This chunk is always $0C $00 $FF $00 $00 $01 $00. This seems to be an unfinished feature of the order list scripting language. It appears that this maps e.g. what is &amp;quot;I0&amp;quot; in the file to sample 1. Only the fourth and fifth byte ($00 $00) actually seem to do something: They translate the sample number in the pattern to different instruments in the file.&lt;br /&gt;
* $0D (4 Bytes): Channel panning index. Next byte is channel number (Start at 0), then initial pan ($00 ... $FF) and a type byte follow. The byte seems to tell what to do with the previous pan position (0 - use it, 2 - ignore it, make this channel surround, 4 - set to center).&lt;br /&gt;
* $0E (3 Bytes): Channel volume index. Next byte is channel number (Start at 0), then volume ($00 ... $FF). $FF in most cases. Some OMF 2097 tracks use a lower volume.&lt;br /&gt;
&lt;br /&gt;
N/A: This chunk is not used in any game soundtrack. The length and meaning of its parameters is unknown.&lt;br /&gt;
&lt;br /&gt;
=== Pattern list ===&lt;br /&gt;
&lt;br /&gt;
This is simply a list of all the patterns used in the file. You do not really need to parse this, it seems to be a purely informational chunk.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;PATT&#039; indicates start of pattern list&lt;br /&gt;
 4   4  Size   Size of pattern list after this&lt;br /&gt;
 8   4  Size   Same as above&lt;br /&gt;
 12  4x Pat    An ordered list &#039;P0  &#039;, &#039;P1  &#039;... for all patterns in the file, each entry 4 bytes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sample list sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Similar to the above, this is a list of all the samples used in the file. It is usually the last sub-segment in the song segment and you do not really need to parse this.&lt;br /&gt;
&lt;br /&gt;
  0  4   ID     &#039;DSAM&#039;; indicates start of sample list, used to say what samples are &#039;full&#039;&lt;br /&gt;
                Any samples not on this list will be ignored, even if they have data&lt;br /&gt;
  4  4   Size   Size of list after this&lt;br /&gt;
  8  4   Size   Same value as above&lt;br /&gt;
  12 15x Entry  Sample entries, one for each sample in the file, each entry 15 bytes&lt;br /&gt;
&lt;br /&gt;
 Sample entry:&lt;br /&gt;
 0   8  Format Sample format, padded with spaces (END, RAG2...) This is important to some programs&lt;br /&gt;
 8   4  ID     &#039;I0  &#039;, &#039;I1  &#039;... the sample ID (&#039;I&#039; means &#039;Instrument&#039;). Again, be sure to accept both &#039;I0  &#039; and &#039;I00 &#039;!&lt;br /&gt;
 12  2  Num    The sample number, 0,1,2... for the sample&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
Samples are the raw sound data that makes up the instruments on the song. The actual format depends on the sample format. Samples have information in their headers which allows data to be played at different pitches (Speeds.) and to loop from and to various points in the data. This is by far the largest part of the file, since the raw data takes up so much space.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DSMP&#039; indicates start of sample&lt;br /&gt;
 4   4  Size   Size of following sample as &#039;DSMP&#039; + dword from end of word&lt;br /&gt;
 8   9  Flags  If highest bit is set, then sample is looped&lt;br /&gt;
 9   8  Songn. Filename of the original module (without extension)&lt;br /&gt;
 17  4  INSx   Last digit of sample (Instrument) number, 0-9; with 31 instruments possible&lt;br /&gt;
               Only last digit is shown. E.g 1st, 11th, 21st and 31st sample is &#039;INS0&#039;&lt;br /&gt;
 21  33 Name   Defines the instrument name or file, usually a .st or line of text&lt;br /&gt;
 54  51 Header Sample parameters (Can also 58 bytes long, padded with nuls)&lt;br /&gt;
               Byte 1-6 are unknown (but apparently always $00 $00 $00 $00 $00 $FF)&lt;br /&gt;
               Bytes 7-8 is instrument number&lt;br /&gt;
               Bytes 9-12 are sample length&lt;br /&gt;
               Bytes 13-16 are loop start&lt;br /&gt;
               Bytes 17-20 are loop end (all $FF means at end of sample)&lt;br /&gt;
               Bytes 21-22 are unknown (second byte could be finetune in Sinaria, but seems to be unused)&lt;br /&gt;
               Byte 23 is default volume&lt;br /&gt;
               Bytes 24-27 are unknwon&lt;br /&gt;
               Bytes 28-31 is frequency (Sample rate). MASI ignores the upper 16 bits, even if they are non-zero.&lt;br /&gt;
               19 $00-bytes follow (padding?)&lt;br /&gt;
 105 ?  Data   Music data in 8-bit mono format&lt;br /&gt;
&lt;br /&gt;
The sample header is slightly different in Sinaria&#039;s format: INSx is 8 bytes long (like the PATT IDs), and the last 21 $00-bytes are just 16 bytes (so that the struct is 96 bytes large in both formats).&lt;br /&gt;
&lt;br /&gt;
The PSM new format, along with the PSM 16 format use delta-encoded samples, something to make the file smaller when zipped. &#039;Deltas&#039;, convert a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. It has the effect that if a single byte in the sample is changed, the entire sample will be degraded. This use of deltas varies slightly from that of the PSM 16. The &#039;start value&#039; of the string is assumed to be $80 (128) and the first byte will thus turn this into the first desired value, the second delta converts the first value to the second, and so on.) All deltas are signed, 1-byte values, but loop (Thus 10 - 20 = -10 can also be considered as 10 + 236 = 246). An example of this is as follows:&lt;br /&gt;
&lt;br /&gt;
 RAW:   (128) 64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: -64  0   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Encryption ==&lt;br /&gt;
&lt;br /&gt;
CONVERT.EXE can produce &amp;quot;encrypted&amp;quot; PSM files with the /K command line switch. The encryption scheme is simple: It adds 1 to the first byte, 2 to the second, 3 to the third, and so until, for the entire file. It does not appear like any game made use of this feature, though.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM 16 =&lt;br /&gt;
&lt;br /&gt;
This is the format used in [[Silverball]], early versions of Epic Pinball and possibly other games. The designation &#039;Protracker Studio 16 format&#039; was given to it by the only reliable source of information on this format, and may not be the official designation.&lt;br /&gt;
&lt;br /&gt;
The format bears many similarities to the S3M format; the file is set out roughly the same, patterns and samples are similar, indeed, near identical and the functionality is similar. It also shows many similarities to the ProTracker MOD format and retains vestiges of Amiga compatibility.&lt;br /&gt;
&lt;br /&gt;
This format can be identified by its signature &#039;PSMþ&#039;, though files may lack this and still function.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Order&lt;br /&gt;
 Pan segment&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Sample data&lt;br /&gt;
 Sample headers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
 0    4  Sig      Signature, &#039;PSMþ&#039;&lt;br /&gt;
 4    59 Title    Song title, padded with nulls. Unlike other formats, this must also be terminated&lt;br /&gt;
                  with a null byte. (It sometimes is not terminated, though.)&lt;br /&gt;
 62   1           This must be $1A to end the song name, like in S3M format.&lt;br /&gt;
 64   1  Type     Song type, First bit: 0 - Module (w/samp.), 1 - Song (w/o samples)&lt;br /&gt;
                  Second bit: 0 - 3 octave Protracker, 1 - 5 octave; remaining bits reserved.&lt;br /&gt;
 65   1  PSM v    PSM format version, $10 for this format (Hence the name PSM 16) = &#039;v1.00&#039;.&lt;br /&gt;
                  Sometimes, this is also $01, but there&#039;s no difference in the format itself.&lt;br /&gt;
 66   1  Patt v   Pattern version, 0 or 1. 0 means the pattern is stored in the module are in the 32&lt;br /&gt;
                  channel file format.  A 1 signifies the patterns as being stored as a 255&lt;br /&gt;
                  channel format. (I have not found any PSM16 modules that have this format.)&lt;br /&gt;
 67   1   Speed   Song speed&lt;br /&gt;
 68   1   BPM     Beats per minute, the default Amiga BPM value. (The only reason that the Amiga BPM&lt;br /&gt;
                  format is still followed here is that it allows more control over the final hz value.)&lt;br /&gt;
                  Range: 32 to 255.&lt;br /&gt;
 69   1   Vol     Master volume of song, 0-255&lt;br /&gt;
 70   2   Len     Song length, 0-255. The number of patterns to play in the song, in total.&lt;br /&gt;
 72   2   Ordlen  The number of orders actually stored at the order offset. It was hoped that the&lt;br /&gt;
                  PSM 16 format would allow multiple orders, so this would be the length of the first&lt;br /&gt;
                  order. This doesn&#039;t appea to ahve happened, and is usually the same as the previous value.&lt;br /&gt;
 74   2   Patnum  Number of patterns in the song. 1-255&lt;br /&gt;
 76   2   Sampnum Number of samples and &#039;sample structures&#039; in song, 1-255&lt;br /&gt;
 78   2   NCIS    Number of channels in song to PLAY. 1-32. &lt;br /&gt;
 80   2   NCP     Number of Channels to Process; describes the MAXIMUM number of channels to process.&lt;br /&gt;
                  As an example, when converting 669 files,  NCP = 9 because some track information &lt;br /&gt;
                  is in Channel 8, but the Number of Channels to Play was set to 8, (Channel numbers&lt;br /&gt;
                  to play from 0 to 7.) 1-32&lt;br /&gt;
 82   4   Ordoff  Location of order in header&lt;br /&gt;
 86   4   Panoff  Location of pan positions in header&lt;br /&gt;
 90   4   Patoff  Location of patterns in header&lt;br /&gt;
 94   4   Sampoff Location of sample headers in header&lt;br /&gt;
 98   4   Commoff Location of comments in header&lt;br /&gt;
 102  4   Patsiz  Total pattern size; the total size of all the patterns loaded from the pattern offset.&lt;br /&gt;
 106  40  Fillers 10 fillers, to be used for any possible expansions.&lt;br /&gt;
&lt;br /&gt;
It is important to notice that the offsets point to the first byte &#039;&#039;&#039;after&#039;&#039;&#039; the chunk ID, i.e. &amp;quot;Ordoff&amp;quot; points to the first byte after &amp;quot;PORD&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Order and Pan positions ==&lt;br /&gt;
&lt;br /&gt;
These are two separate segments, pointed to in the header. They may be anywhere, but usually follow the header sometimes after an amount of blank space. They are often padded with blank space. They are basically lists.&lt;br /&gt;
&lt;br /&gt;
Order: This segment is pointed to in the header, and sets the PSM 16 format apart. The PSM 16 format was designed to be much more like the MOD format, allowing game designers to set flags to switch from one set of patterns to another, in effect allowing one file to contain more than one song. (For example a boss flag might make the music switch from a clam patterns 1-4 to a racy and dangerous patterns 5-7.)&lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    Signature, not needed, &#039;PORD&#039;&lt;br /&gt;
 4    ?   Ords   Pattern numbers and order. There will be [Ordlen] bytes of patterns&lt;br /&gt;
 ?    2   Lang   Order language, not implemented, so left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pan Positions: &lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    &#039;PPAN&#039;&lt;br /&gt;
 4    12  Pan    Pan positions; empty positions left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
 0    2   Size   Size of pattern, including these bytes&lt;br /&gt;
 2    1   Len    Length of pattern, in rows. Max length is 64 rows.&lt;br /&gt;
 3    1   Chan   Number of channels in pattern, 1-32&lt;br /&gt;
 4    ?   Data   Pattern data&lt;br /&gt;
&lt;br /&gt;
This is similar to the previous two segments, except actual pattern data is stored here. Patterns are very similar to the S3M format, and consist of y rows of x channels. Each row contains a number of channels and ends with a byte of value 0. Each channel is between 2-6+ bytes long. A totally empty channel is represented by a single byte of value 0.&lt;br /&gt;
&lt;br /&gt;
Each channel starts with a flag byte, abcddddd, where a,b and c indicate whether there is a note and instrument, volume or special effect and effect magnitude in the following data, and dddd is the channel number (0-31, used since a given channel may or may not be present in a row.)&lt;br /&gt;
&lt;br /&gt;
The usual maximum length of a channel entry is 6 bytes (1 flag byte, 2 Note AND instrument bytes, 1 volume byte and two Effect and Effect magnitude bytes.) Thus Note&amp;amp;ins\Eff&amp;amp;Eff mag must always occur together.&lt;br /&gt;
&lt;br /&gt;
Like S3M, volume range is 0-64, as is special magnitude. However, special effects range from 0-255, like PSM New Format.&lt;br /&gt;
&lt;br /&gt;
=== Effects conversion ===&lt;br /&gt;
&lt;br /&gt;
 ###  Co  MOD  Description               Arguments&lt;br /&gt;
 ---  --  ---  -----------               ---------&lt;br /&gt;
 Volume Commands&lt;br /&gt;
   1  A1   EA  Fine Volume Slide Up      B xx xx=speed&lt;br /&gt;
   2  A2   A   Volume Slide Up           B xx xx=speed&lt;br /&gt;
   3  A3   EB  Fine Volume Slide Down    B xx xx=speed&lt;br /&gt;
   4  A4   A   Volume Slide Down         B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Portamento Commands&lt;br /&gt;
  10  B0   E1  Fine Porta Up             B xx xx=speed&lt;br /&gt;
  11  B1   1   Portamento Up             B xx xx=speed&lt;br /&gt;
  12  B2   E2  Fine Porta Down           B xx xx=speed&lt;br /&gt;
  13  B3   2   Portamento Down           B xx xx=speed&lt;br /&gt;
  14  B4   3   Tone Portamento           B xx xx=speed&lt;br /&gt;
  15  B5   E3  Set Glissando Control     B xx xx=0 - Off, 1 - On&lt;br /&gt;
  16  B6   5   Tone Port+Vol Slide Up    B xx xx=speed&lt;br /&gt;
  17  B7   5   Tone Port+Vol Slide Down  B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Vibrato Commands&lt;br /&gt;
  20  C0   4   Vibrato                   B xy x=speed, y=depth&lt;br /&gt;
  21  C1   E4  Set Vibrato Waveform      B x  x=Waveform&lt;br /&gt;
  21  C2   6   Vibrato+Vol Slide Up      B xx xx=speed&lt;br /&gt;
  22  C3   6   Vibrato+Vol Slide Down    B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Tremolo Commands&lt;br /&gt;
  30  D0   7   Tremolo                   B xy x=speed, y=depth&lt;br /&gt;
  31  D1   E7  Set Tremolo Control       B x  x=Waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample Commands&lt;br /&gt;
  40  E0   9   Sample Offset             3B Position for offset change (0-1,048,575)&lt;br /&gt;
  41  E1   E9  Retrig Note               B xx xx=tick to retrigger sample&lt;br /&gt;
  42  E2   EC  Note Cut                  B xx xx=tick to cut note&lt;br /&gt;
  43  E3   ED  Note Delay                B xx xx=ticks to delay note&lt;br /&gt;
 &lt;br /&gt;
 Pos. Change Commands&lt;br /&gt;
  50  F0   B   Position Jump             B xx xx=order position&lt;br /&gt;
  51  F1   D   Pattern Break             B xx Skip to line xx in next pattern&lt;br /&gt;
  52  F2   E6  Jump Loop                 B xx xx=number of loops  0 Set&lt;br /&gt;
  53  F3   EE  Pattern Delay             B xx xx=notes to delay pattern&lt;br /&gt;
 &lt;br /&gt;
 Speed Change Cmds&lt;br /&gt;
  60  G0   F   Set Regular Speed         B xx xx=speed&lt;br /&gt;
  61  G1   F   Set BPM                   B xx xx=BPM (32-255)&lt;br /&gt;
 &lt;br /&gt;
 Misc. Commands&lt;br /&gt;
  70  H0   0   Arpeggio                  B xy x=semitone #1, y=semitone #2&lt;br /&gt;
  71  H1   E5  Set Finetune              B xx xx=finetune&lt;br /&gt;
  72  H2       Set Balance               B xx xx=Balance (0-15)&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
 Sample segment&lt;br /&gt;
 0    4   ID     &#039;PSAM&#039; (Psm SAMple)&lt;br /&gt;
 4    ?  Data    Sample data&lt;br /&gt;
&lt;br /&gt;
 Sample header segment&lt;br /&gt;
 0    4   ID     &#039;PSAH&#039; (Psm SAmple Header)&lt;br /&gt;
 4    ?  Data    Sample headers&lt;br /&gt;
&lt;br /&gt;
 Sample header&lt;br /&gt;
 0    13  Name   Sample filename, terminated with a null.&lt;br /&gt;
 13   24  Desc   Sample description or comments.&lt;br /&gt;
 37   4   Offs   Location of raw sample data in file&lt;br /&gt;
 43   4   Mem    This is the physical offset in RAM/DRAM of the sample. (Often blank.)&lt;br /&gt;
 45   2   Num    Sample number, 1-255&lt;br /&gt;
 47   1   Type   Sample type: (In some games left blank; if this is the case then the&lt;br /&gt;
                 sample format is END, as used in most PSM New Format files)&lt;br /&gt;
                 Bit 0: 0 - Digital, 1 - Synthesized&lt;br /&gt;
                 Bit 2: 0 - 8-bit, 1 - 16-bit&lt;br /&gt;
                 Bit 3: 0 - Signed, 1 - Unsigned&lt;br /&gt;
                 Bit 4: 0 - Deltas, 1 - Raw&lt;br /&gt;
                 Bit 5: 0 - Loop normally, 1 - Bidirectional&lt;br /&gt;
                 Bit 6: 1 - Gravis patch (unsupported)&lt;br /&gt;
                 Bit 7: 0 - No loop, 1 - Loop sample&lt;br /&gt;
 48   4   Len    Sample length, in bytes.&lt;br /&gt;
 52   4   Rep st Sample repeat start; if sample loops, the loop starts here.&lt;br /&gt;
 56   4   Rep fn Sample repeat end, if sample loops, it ends here. If this is less than the sample&lt;br /&gt;
                 repeat start, the sample loops backwards.&lt;br /&gt;
 60   1   Tune   Fine tune; range 0-15, Tune 0-7 = 0-7; tune -1 - -8 = 8-15&lt;br /&gt;
 61   1   Vol    Sample volume, 0-64&lt;br /&gt;
 62   2   Freq   This is the frequency for the sample at a C of Octave 2.&lt;br /&gt;
                 Typical values are 8,000 hz to 8,448 hz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like in S3M, sample headers are stored separately from the raw sample data.&lt;br /&gt;
&lt;br /&gt;
A type of sample storage used often, like in the PSM New Format is &#039;Deltas&#039;, which converts a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte, often making them compress better using general-purpose file compression tools. Thus:&lt;br /&gt;
&lt;br /&gt;
 RAW:        64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: 11  64   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
This is done to make files more compressible, but doesn&#039;t seem to be used much.&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.shikadi.net/files/psm2scrm.zip psm2scrm.zip] - DOS program to convert .PSM songs into ScreamTracker .S3M format, suitable for playing in your favourite tracker/module player. Works only with PSM New Format and is not nearly as accurate as OpenMPT.&lt;br /&gt;
* [https://openmpt.org OpenMPT] 1.18 and newer can load all PSM and PSM16 files.&lt;br /&gt;
* [https://openmpt.org/legacy_software ModPlug Tracker] and OpenMPT 1.17 can play the files and save them as S3M. More complex songs don&#039;t load correctly though. Works only with new format.&lt;br /&gt;
* [http://kode54.foobar2000.org/ foo_dumb] is a plugin for various module formats for the Foobar2k media player. It supports both PSM16 and PSM and is similar to OpenMPT in playback quality.&lt;br /&gt;
* [http://ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/mxinfo/epictest.zip EPICTEST] is a demonstration of the Epic Megagames MASI. It contains CONVERT.EXE which can be used to convert modules to the new PSM format.&lt;br /&gt;
* [http://www.jazz2online.com/J2Ov2/downloads/info.php?levelID=5471#29435] JJ1MOD can convert S3M files to new PSM, though often with errors (Though these are usually only detectable with older programs such as game executables.) It is currently the only utility able to do this, and works only with New Format.&lt;br /&gt;
&lt;br /&gt;
= Notes =&lt;br /&gt;
&lt;br /&gt;
The New PSM format was reverse engineered by Levellord and tidied up by Levellass. It is possible there may be minor errors in the sample format information, especially since this is poorly documented.&lt;br /&gt;
Some format definitions have been updated and corrected by Johannes Schultz of the OpenMPT development team.&lt;br /&gt;
&lt;br /&gt;
The PSM16 format documentation was found on Wotsit and written up by Levellass (this appears to be an official document from the MASI developer). More info is needed.&lt;br /&gt;
&lt;br /&gt;
In all formats the following table shows how note bytes are converted into actual notes: (PSM new format has the widest range, 0-255)&lt;br /&gt;
&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;br /&gt;
           | C-0   0 | C-1  12 | C-2  24 | C-3  36 | C-4  48 |&lt;br /&gt;
           | C#0   1 | C#1  13 | C#2  25 | C#3  37 | C#4  49 |&lt;br /&gt;
           | D-0   2 | D-1  14 | D-2  26 | D-3  38 | D-4  50 |&lt;br /&gt;
           | D#0   3 | D#1  15 | D#2  27 | D#3  39 | D#4  51 |&lt;br /&gt;
           | E-0   4 | E-1  16 | E-2  28 | E-3  40 | E-4  52 |&lt;br /&gt;
           | F-0   5 | F-1  17 | F-2  29 | F-3  41 | F-4  53 |&lt;br /&gt;
           | F#0   6 | F#1  18 | F#2  30 | F#3  42 | F#4  54 |&lt;br /&gt;
           | G-0   7 | G-1  19 | G-2  31 | G-3  43 | G-4  55 |&lt;br /&gt;
           | G#0   8 | G#1  20 | G#2  32 | G#3  44 | G#4  56 |&lt;br /&gt;
           | A-0   9 | A-1  21 | A-2  33 | A-3  45 | A-4  57 |&lt;br /&gt;
           | A#0  10 | A#1  22 | A#2  34 | A#3  46 | A#4  58 |&lt;br /&gt;
           | B-0  11 | B-1  23 | B-2  35 | B-3  47 | B-4  59 |&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=AMF_Format&amp;diff=10910</id>
		<title>AMF Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=AMF_Format&amp;diff=10910"/>
		<updated>2023-03-22T19:00:05Z</updated>

		<summary type="html">&lt;p&gt;Saga: Created page with &amp;quot;{{Music Infobox  | Type = Tracked  | Instruments = PCM  | NumChannels = 32  | NumTracks = n/a  | NumPatterns = 256  | NumOrders = 256  | Tags = Title, instrument names  | Game...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 32&lt;br /&gt;
 | NumTracks = n/a&lt;br /&gt;
 | NumPatterns = 256&lt;br /&gt;
 | NumOrders = 256&lt;br /&gt;
 | Tags = Title, instrument names&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Disney&#039;s Aladdin}}&lt;br /&gt;
   {{Game|The Lion King}}&lt;br /&gt;
   {{Game|PowBall}}&lt;br /&gt;
   {{Game|H2O}}&lt;br /&gt;
   {{Game|Tronic}}&lt;br /&gt;
   {{Game|Pinball World}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
There are two different AMF module formats: Ayslum Music Format (used in [[Crusader: No Remorse]] and [[Crusader: No Regret]]) and the music format introduced by the Digital Sound and Music Interface (DSMI) by Otto Chrons. This article describes the latter format. DSMI and its module format was used in a number of games. Some later games, in particular those published by Webfoot, use a slightly different variant of the format identified by its &amp;quot;DMF&amp;quot; magic bytes (instead of &amp;quot;AMF&amp;quot;). This variant uses delta-encoded samples and omits song and sample names, leading to slightly improved compressability with general-purpose compression algorithms (such as DEFLATE). The AMF format is well-supported by a variety of module players, such as libxmp and libopenmpt.&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Karl_Morton_Music_Format&amp;diff=10214</id>
		<title>Karl Morton Music Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Karl_Morton_Music_Format&amp;diff=10214"/>
		<updated>2021-12-23T15:29:56Z</updated>

		<summary type="html">&lt;p&gt;Saga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 32 (only 4 usable in-game)&lt;br /&gt;
 | NumTracks = no limit&lt;br /&gt;
 | NumPatterns = n/a&lt;br /&gt;
 | NumOrders = n/a&lt;br /&gt;
 | Tags = Title, instrument names&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Psycho Pinball}}&lt;br /&gt;
   {{Game|Micro Machines 2}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The [[Karl Morton Music Format]] is the music format used by Karl Morton&#039;s sound engine used in the games [[Psycho Pinball]], [[Micro Machines 2]] and [[Back To Baghdad]], although the latter only uses its sound effect file format, not the music format. This is not the official name of the format, but as no official tooling or documentation seems to be available for this format, a simple name was chosen based on the sound engine author&#039;s name.&lt;br /&gt;
&lt;br /&gt;
In general, this format follows the semantics of the ProTracker MOD format. Knowledge of the MOD format and its features is assumed.&lt;br /&gt;
&lt;br /&gt;
A somewhat unique feature of this format is that subsongs can re-use samples with different metadata. For example, one song in a file might use a specific sample with a default volume of 64, while another song might reference the same sample data but with a default volume of 48. This allows for greater flexibility when reusing those samples between songs.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The format follows an IFF-like structure, but with no explicit file header (the file directly starts with the first chunk).&lt;br /&gt;
&lt;br /&gt;
=== Chunk Header ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][4] || ID || chunk ID (&amp;quot;SONG&amp;quot; or &amp;quot;SMPL&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || length || chunk length, including this header (so must be at least 8)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first chunk in the file must be a SONG chunk, apart from this the chunk order doesn&#039;t matter.&lt;br /&gt;
&lt;br /&gt;
Typically, SONG and SMPL chunks are interleaved, each SONG being followed by the SMPLs it adds to the sample pool shared between SONGs.&lt;br /&gt;
But this order should not be relied on.&lt;br /&gt;
&lt;br /&gt;
=== SONG chunk ===&lt;br /&gt;
&lt;br /&gt;
Each subsong is represented by its own SONG chunk.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][32] || song name || null-terminated song name&lt;br /&gt;
|-&lt;br /&gt;
| SAMPLE_REFERENCE[31] || sample map || maps song samples to those samples in the global sample pool&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][2] || unknown || always 0 (maybe just padding)&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] ||  number of channels || between 1 and 4 - file will be rejected if this is &amp;gt; 32. If it&#039;s more than 4 but less than 33 the extra channels will simply not be played.&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || restart position || byte offset into music data&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || size of music data || should be chunk size - 1108&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][] || music data || format is explained below&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;SAMPLE_REFERENCE&amp;lt;/tt&amp;gt; maps samples from the SMPL chunk pool to instrument numbers in the pattern editor (the first &amp;lt;tt&amp;gt;SAMPLE_REFERENCE&amp;lt;/tt&amp;gt; is instrument 1, and so on). It is defined as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][32] || sample name || must reference one of the SMPL chunks&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT8]] || MOD finetune || 0...15&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT8]] || default volume || 0...64&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Music data is basically one gigantic pattern and stored in row-major order (like most module formats).&lt;br /&gt;
The pattern is played in a strictly linear order, there are no jump commands or pattern loops.&lt;br /&gt;
There is per-channel state that stores the last used note, instrument, command and parameter as well as a repeat counter.&lt;br /&gt;
&lt;br /&gt;
To decode one pattern cell:&lt;br /&gt;
&lt;br /&gt;
* If repeat counter &amp;gt; 0: Decrement repeat counter by 1 and reuse note, instrument, command and parameter from previous row. Continue with next channel.&lt;br /&gt;
* Read [[UINT8]], let&#039;s name it NOTE.&lt;br /&gt;
* If (NOTE AND 0x80): Reuse note, instrument, command and parameter from previous row and set repeat counter to (NOTE AND 0x7F). Continue with next channel.&lt;br /&gt;
* If NOTE is between 1 and 36 (inclusively), it&#039;s a regular note (C-1 to B-3 in ProTracker), otherwise no note is present&lt;br /&gt;
* Read [[UINT8]], let&#039;s name it INSTRUMENT.&lt;br /&gt;
* Set instrument number in this cell to INSTRUMENT AND 0x1F&lt;br /&gt;
* If (INSTRUMENT AND 0x80): Repeat previous command and parameter for this channel&lt;br /&gt;
* Otherwise, read the two [[UINT8]]s, the command and parameter bytes.&lt;br /&gt;
* Continue with next channel.&lt;br /&gt;
&lt;br /&gt;
Command bytes and their translation to ProTracker MOD commands:&lt;br /&gt;
* &amp;lt;tt&amp;gt;00&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;Cxx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;01&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;EAx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;02&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;EBx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;03&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;E1x&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;04&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;E2x&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;05&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;E5x&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;06&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;9xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;07&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;3xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;08&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;5xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;09&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;4xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0A&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;6xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0B&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;0xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0C&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;1xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0D&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;2xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0E&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;Axx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0F&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;E9x&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;10&amp;lt;/tt&amp;gt;: Instant portamento (like 3FF but is always fully executed on first tick)&lt;br /&gt;
* &amp;lt;tt&amp;gt;11&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;ECx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;12&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;Fxx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;13&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;7xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;14&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;000&amp;lt;/tt&amp;gt; (empty command)&lt;br /&gt;
&lt;br /&gt;
Missing MOD effects are: 8, B, D, E3, E4, E5, E6, E7, E8, ED, EE, EF.&lt;br /&gt;
&lt;br /&gt;
Most commands that translate to extended Exy commands can take values &amp;gt; 0x0F as parameters (finetune command ignores high nibble).&lt;br /&gt;
&lt;br /&gt;
The player will jump to the restart position once the repeat counter of each channel has reached 0 and no bytes are left to be read.&lt;br /&gt;
&lt;br /&gt;
If no tempo is specified on the first row of the pattern, the MOD defaults of tempo 125 and 6 ticks per row are assumed.&lt;br /&gt;
&lt;br /&gt;
=== SMPL chunk ===&lt;br /&gt;
&lt;br /&gt;
Every sample is described by its own SMPL chunk.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][32] || sample name || null-terminated, referenced by SONG chunks&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || loop start || in bytes&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || size of sample data || should be chunk size - 48&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][] || sample data || in 8-bit signed mono PCM format&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that a SMPL can be shared between songs and use different finetune and volume values between songs.&lt;br /&gt;
&lt;br /&gt;
== A note on the string format ==&lt;br /&gt;
&lt;br /&gt;
The last character of sample names must be a null-terminator (the engine uses a string comparison not limited to 32 characters when matching samples).&amp;lt;br&amp;gt;&lt;br /&gt;
While it is not required by the engine, the following restrictions are proposed for newly created files to keep the life of developers easy that have to support dozens of files and may thus want to employ heuristics whether files are of a specific type:&lt;br /&gt;
It is suggested that all strings (i.e. instances of [[char]][32]) do not use byte values 1 to 31 (so only printable ASCII/ANSI), and after the first null terminator, the rest of the string has to be padded with nulls as well.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [https://openmpt.org/ OpenMPT]&lt;br /&gt;
| Platform = Windows&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Many&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = OpenMPT 1.30 or higher is required.&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [https://github.com/sagamusix/mod2mus mod2mus]&lt;br /&gt;
| Platform = Any&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = MOD&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = Converts 1-4 channel ProTracker MOD files to MUS&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
This file format was reverse-engineered by [[User:Saga|Saga]]. If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=DRO_Format&amp;diff=10202</id>
		<title>DRO Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=DRO_Format&amp;diff=10202"/>
		<updated>2021-11-14T01:08:40Z</updated>

		<summary type="html">&lt;p&gt;Saga: /* Tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = OPL&lt;br /&gt;
 | Instruments = OPL&lt;br /&gt;
 | NumChannels = 9 or 11 (OPL2), 18 or 22 (Dual OPL2 and OPL3)&lt;br /&gt;
 | NumTracks = 1&lt;br /&gt;
}}&lt;br /&gt;
The &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;D&amp;lt;/u&amp;gt;OSBox &amp;lt;u&amp;gt;R&amp;lt;/u&amp;gt;aw &amp;lt;u&amp;gt;O&amp;lt;/u&amp;gt;PL (DRO)&amp;lt;/b&amp;gt; format is used for storing captured OPL data from a game running in the cross-platform DOS emulator [http://dosbox.sourceforge.net DOSBox].&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file begins with a header:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|BYTE[8]||cSignature||&amp;quot;DBRAWOPL&amp;quot; (not NULL-terminated)&lt;br /&gt;
|-&lt;br /&gt;
|UINT16LE||iVersionMajor||Version number (high)&lt;br /&gt;
|-&lt;br /&gt;
|UINT16LE||iVersionMinor||Version number (low)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The rest of the header depends on the version.  If iVersionMajor is 5 and iVersionMinor is 6, then the version would be called &amp;quot;5.6&amp;quot; here.&lt;br /&gt;
&lt;br /&gt;
=== Version 0.1 ===&lt;br /&gt;
&lt;br /&gt;
The first version of the DRO Format was used up to and including DOSBox version 0.72.  Note that the major and minor field names were swapped beginning with DOSBox 0.73, so this version used to be 1.0, but after DOSBox 0.73 it became 0.1 instead.&lt;br /&gt;
&lt;br /&gt;
==== Header ====&lt;br /&gt;
&lt;br /&gt;
The version 0.1 header follows on directly from the main file header.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|UINT32LE||iLengthMS||Length of the song in milliseconds&lt;br /&gt;
|-&lt;br /&gt;
|UINT32LE||iLengthBytes||Length of the song data in bytes&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iHardwareType||Flag listing the hardware used in the song&lt;br /&gt;
|-&lt;br /&gt;
|UINT8[3]||iHardwareExtra||Rest of hardware type or song data (see below)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;iHardwareType&#039;&#039; is one of the following values:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!&#039;&#039;iHardwareType&#039;&#039;!!Description&lt;br /&gt;
|-&lt;br /&gt;
|0||OPL2&lt;br /&gt;
|-&lt;br /&gt;
|1||OPL3&lt;br /&gt;
|-&lt;br /&gt;
|2||Dual OPL2&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In early files, the field was a UINT8, however in most common (recent) files it is a UINT32LE with only the first byte used.  Unfortunately the version number was not changed between these revisions, so the only way to correctly identify the formats is to check the three &amp;lt;tt&amp;gt;iHardwareExtra&amp;lt;/tt&amp;gt; bytes.  If these are all zero then they can safely be ignored (iHardwareType was a UINT32.)  If any of the three bytes in &amp;lt;tt&amp;gt;iHardwareExtra&amp;lt;/tt&amp;gt; are non-zero, then this is an early revision of the format and those three bytes are actually song data&amp;lt;ref&amp;gt;In the [http://adplug.sourceforge.net AdPlug distribution], tests/samurai.dro is the early one-byte format, and doofus.dro is the later four-byte variant.&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Song data ====&lt;br /&gt;
&lt;br /&gt;
Directly following the header is &#039;&#039;iLengthBytes&#039;&#039; bytes of OPL data.  The first byte in the song data will be the OPL register, followed by the byte to send to that register.  The &amp;quot;register&amp;quot; can also be one of these control values:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Register value!!Data size!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|0x00||1||Delay.  The single data byte following should be incremented by one, and is then the delay in milliseconds.&lt;br /&gt;
|-&lt;br /&gt;
|0x01||2||Delay.  Same as above only there are two bytes following, in the form of a UINT16LE integer.&lt;br /&gt;
|-&lt;br /&gt;
|0x02||0||Switch to &amp;quot;low&amp;quot; OPL chip (#0)&lt;br /&gt;
|-&lt;br /&gt;
|0x03||0||Switch to &amp;quot;high&amp;quot; OPL chip (#1)&lt;br /&gt;
|-&lt;br /&gt;
|0x04||2||Escape - the next two bytes are normal register/value pairs even though the register might be 0x00-0x04&lt;br /&gt;
|-&lt;br /&gt;
|Other||1||Anything else should be treated as an OPL register, with the byte following being the data to send to that register.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The delays all need to be incremented by one, as having a delay of zero milliseconds would be a waste of space.  Codes 0x02 and 0x03 switch between two OPL chips in dual OPL2 mode, or between register banks in OPL3 mode.  These should only be used if the hardware flag in the header indicates the file is in dual-OPL2 or OPL3 format.&lt;br /&gt;
&lt;br /&gt;
All delays are in milliseconds (which can be treated as 1000Hz if converting between other formats.)&lt;br /&gt;
&lt;br /&gt;
=== Version 2.0 ===&lt;br /&gt;
&lt;br /&gt;
Version 2.0 of the DRO Format was introduced with DOSBox 0.73.&lt;br /&gt;
&lt;br /&gt;
==== Header ====&lt;br /&gt;
&lt;br /&gt;
The version 2.0 header also follows on directly from the main file header.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|UINT32LE||iLengthPairs||Length of the song in register/value pairs (TODO: confirm - 1 == one register + one value, or two bytes)&lt;br /&gt;
|-&lt;br /&gt;
|UINT32LE||iLengthMS||Length of the song data (&amp;quot;chunk&amp;quot; -?) in milliseconds&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iHardwareType||Flag listing the hardware used in the song&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iFormat||Data arrangement&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iCompression||Compression type, zero means no compression (currently only zero is used)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iShortDelayCode||Command code for short delay (1-256ms)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iLongDelayCode||Command code for short delay (&amp;gt; 256ms)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iCodemapLength||Number of entries in codemap table&lt;br /&gt;
|-&lt;br /&gt;
|UINT8[iCodemapLength]||iCodemap||Codemap table (see below)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;iHardwareType&#039;&#039; is one of the following values: (which are different in v1.0 and v2.0)&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!&#039;&#039;iHardwareType&#039;&#039;!!Description&lt;br /&gt;
|-&lt;br /&gt;
|0||OPL2&lt;br /&gt;
|-&lt;br /&gt;
|1||Dual OPL2&lt;br /&gt;
|-&lt;br /&gt;
|2||OPL3&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;iFormat&#039;&#039; is one of the following values:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!&#039;&#039;iFormat&#039;&#039;!!Description&lt;br /&gt;
|-&lt;br /&gt;
|0||Commands and data are interleaved (default/as per v1.0)&lt;br /&gt;
|-&lt;br /&gt;
|1||Maybe all commands, followed by all data (unused? - TODO: Confirm)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* &#039;&#039;iLengthMS&#039;&#039; is at a different offset in v1.0 and v2.0&lt;br /&gt;
* The &#039;&#039;iShortDelayCode&#039;&#039; value must have one added to it, as per v1.0 (so a short delay of 2 == a 3ms delay)&lt;br /&gt;
* The &#039;&#039;iLongDelayCode&#039;&#039; value must have one added to it, then be multiplied by 256 (or &amp;quot;&amp;lt;&amp;lt; 8&amp;quot;), so a long delay of 2 == a 768ms delay&lt;br /&gt;
* Because the high bit in each codeword is used to refer to the second OPL2 chip (or the second set of registers in an OPL3), there are only 128 possible codewords (0-127).  Therefore &#039;&#039;iCodemapLength&#039;&#039; must always be 128 or less.&lt;br /&gt;
* DOSBox dumps a snapshot of the current register state at the beginning of a capture.  (Any other registers are assumed initialised to zero.)  This means that even an OPL2 only song will appear to have some data sent to the second OPL chip, because of this initial snapshot.  To really know whether the second OPL chip is in use, you can find out if it is actually making any sound, like so:&lt;br /&gt;
** Examine bit 5 (0x20) on registers 0xB0 to 0xB8.  If this bit is set, a note is playing and the chip is being used.&lt;br /&gt;
** Check whether bitmask 0x1F on register 0xBD is greater than 0x10 (i.e. &amp;lt;code&amp;gt;if (reg[0xBD] &amp;amp; 0x1F &amp;gt; 0x10) ...&amp;lt;/code&amp;gt;).  If so, the chip is in percussive mode and a rhythm instrument is being played, so the chip is being used.&lt;br /&gt;
&lt;br /&gt;
===== Codemap table =====&lt;br /&gt;
The codemap table maps index numbers to OPL registers.  As there are 256 possible OPL registers but only a subset of these actually used, the mapping table allows up to 128 OPL registers to be used in a song.  The other 128 (with the high bit set) are used for the second OPL2 chip in a dual-OPL2 capture.&lt;br /&gt;
&lt;br /&gt;
The table is a list of &#039;&#039;iCodemapLength&#039;&#039; bytes, with the index used later in the file.  For example this code table:&lt;br /&gt;
&lt;br /&gt;
 01 04 05 08 BD&lt;br /&gt;
&lt;br /&gt;
Means that when the song references register #0 the data should be sent to OPL register 0x01, when the song references register #4 the data should go to OPL register 0xBD.  If the song references register #128 (i.e. register 128+0), data should be sent to OPL register 0x01 on the &#039;&#039;&#039;second&#039;&#039;&#039; chip (in dual OPL2 mode) or the second set of registers (OPL3 mode).  Likewise register #132 (128+4) is OPL register 0xBD on the &#039;&#039;&#039;second&#039;&#039;&#039; chip.&lt;br /&gt;
&lt;br /&gt;
==== Song data ====&lt;br /&gt;
&lt;br /&gt;
Directly following the header is the song data in register index and value pairs.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iRegisterIndex||Register to write to.  This is an index into the codemap table.&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iValue||Value to write to the OPL register&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This structure is repeated &#039;&#039;iLengthPairs&#039;&#039; times.  Note that while &#039;&#039;iRegisterIndex&#039;&#039; is normally an index into the codemap table, it can also match &#039;&#039;iShortDelayCode&#039;&#039; or &#039;&#039;iLongDelayCode&#039;&#039; if &#039;&#039;iValue&#039;&#039; is to be treated as a delay length (see above.)  If the high bit is set (&amp;lt;code&amp;gt;iRegisterIndex &amp;amp; 0x80&amp;lt;/code&amp;gt;) then it is a register on the second OPL chip in a dual-OPL2 song (so the high bit should be removed and the value looked up as normal, but then sent to the second OPL chip instead.)&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[AdPlug]]&lt;br /&gt;
| Platform = Windows/Linux/DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = v1/v2&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[Camoto]]&lt;br /&gt;
| Platform = Linux/Win&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Yes; many&lt;br /&gt;
| canImport = Yes; many&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = v1/v2&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://www.dosbox.com/ DOSBox]&lt;br /&gt;
| Platform = Windows/Mac/Linux&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = v2-only since 0.73.  Produces .dro files as a result of capturing Adlib data from DOS games and applications&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://www.jestarjokin.net/apps/drotrimmer DRO Trimmer]&lt;br /&gt;
| Platform = Any (Python)&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = Edits .dro files to remove unwanted notes from the start and end&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://www.shikadi.net/utils/dro2imf DRO2IMF]&lt;br /&gt;
| Platform = Windows/Mac/Linux&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Yes; [[IMF Format|.imf]]&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = Converts v1/v2 .dro to .imf&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[DRO2MIDI]]&lt;br /&gt;
| Platform = Windows/Mac/Linux&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Yes; [[MID Format|.mid]]&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = Converts v1/v2 .dro and .imf to .mid&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[OpenMPT]]&lt;br /&gt;
| Platform = Windows&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = Yes; many&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = OpenMPT 1.30 and newer can export a DRO v1 register dump for songs that use OPL instruments.&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== Similar formats ==&lt;br /&gt;
* [[RAW Format (Adlib)|Rdos&#039; RAW format]] serves the same purpose, only these files were originally created through the RAC (Rdos Adlib Capture) TSR running under native DOS.&lt;br /&gt;
* The [[IMF Format|id Software Music Format (IMF)]] stores Adlib data in a similar manner in order to provide background music in many Apogee games.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=DRO_Format&amp;diff=10201</id>
		<title>DRO Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=DRO_Format&amp;diff=10201"/>
		<updated>2021-11-14T01:08:20Z</updated>

		<summary type="html">&lt;p&gt;Saga: /* Tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = OPL&lt;br /&gt;
 | Instruments = OPL&lt;br /&gt;
 | NumChannels = 9 or 11 (OPL2), 18 or 22 (Dual OPL2 and OPL3)&lt;br /&gt;
 | NumTracks = 1&lt;br /&gt;
}}&lt;br /&gt;
The &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;D&amp;lt;/u&amp;gt;OSBox &amp;lt;u&amp;gt;R&amp;lt;/u&amp;gt;aw &amp;lt;u&amp;gt;O&amp;lt;/u&amp;gt;PL (DRO)&amp;lt;/b&amp;gt; format is used for storing captured OPL data from a game running in the cross-platform DOS emulator [http://dosbox.sourceforge.net DOSBox].&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file begins with a header:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|BYTE[8]||cSignature||&amp;quot;DBRAWOPL&amp;quot; (not NULL-terminated)&lt;br /&gt;
|-&lt;br /&gt;
|UINT16LE||iVersionMajor||Version number (high)&lt;br /&gt;
|-&lt;br /&gt;
|UINT16LE||iVersionMinor||Version number (low)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The rest of the header depends on the version.  If iVersionMajor is 5 and iVersionMinor is 6, then the version would be called &amp;quot;5.6&amp;quot; here.&lt;br /&gt;
&lt;br /&gt;
=== Version 0.1 ===&lt;br /&gt;
&lt;br /&gt;
The first version of the DRO Format was used up to and including DOSBox version 0.72.  Note that the major and minor field names were swapped beginning with DOSBox 0.73, so this version used to be 1.0, but after DOSBox 0.73 it became 0.1 instead.&lt;br /&gt;
&lt;br /&gt;
==== Header ====&lt;br /&gt;
&lt;br /&gt;
The version 0.1 header follows on directly from the main file header.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|UINT32LE||iLengthMS||Length of the song in milliseconds&lt;br /&gt;
|-&lt;br /&gt;
|UINT32LE||iLengthBytes||Length of the song data in bytes&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iHardwareType||Flag listing the hardware used in the song&lt;br /&gt;
|-&lt;br /&gt;
|UINT8[3]||iHardwareExtra||Rest of hardware type or song data (see below)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;iHardwareType&#039;&#039; is one of the following values:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!&#039;&#039;iHardwareType&#039;&#039;!!Description&lt;br /&gt;
|-&lt;br /&gt;
|0||OPL2&lt;br /&gt;
|-&lt;br /&gt;
|1||OPL3&lt;br /&gt;
|-&lt;br /&gt;
|2||Dual OPL2&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In early files, the field was a UINT8, however in most common (recent) files it is a UINT32LE with only the first byte used.  Unfortunately the version number was not changed between these revisions, so the only way to correctly identify the formats is to check the three &amp;lt;tt&amp;gt;iHardwareExtra&amp;lt;/tt&amp;gt; bytes.  If these are all zero then they can safely be ignored (iHardwareType was a UINT32.)  If any of the three bytes in &amp;lt;tt&amp;gt;iHardwareExtra&amp;lt;/tt&amp;gt; are non-zero, then this is an early revision of the format and those three bytes are actually song data&amp;lt;ref&amp;gt;In the [http://adplug.sourceforge.net AdPlug distribution], tests/samurai.dro is the early one-byte format, and doofus.dro is the later four-byte variant.&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Song data ====&lt;br /&gt;
&lt;br /&gt;
Directly following the header is &#039;&#039;iLengthBytes&#039;&#039; bytes of OPL data.  The first byte in the song data will be the OPL register, followed by the byte to send to that register.  The &amp;quot;register&amp;quot; can also be one of these control values:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Register value!!Data size!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|0x00||1||Delay.  The single data byte following should be incremented by one, and is then the delay in milliseconds.&lt;br /&gt;
|-&lt;br /&gt;
|0x01||2||Delay.  Same as above only there are two bytes following, in the form of a UINT16LE integer.&lt;br /&gt;
|-&lt;br /&gt;
|0x02||0||Switch to &amp;quot;low&amp;quot; OPL chip (#0)&lt;br /&gt;
|-&lt;br /&gt;
|0x03||0||Switch to &amp;quot;high&amp;quot; OPL chip (#1)&lt;br /&gt;
|-&lt;br /&gt;
|0x04||2||Escape - the next two bytes are normal register/value pairs even though the register might be 0x00-0x04&lt;br /&gt;
|-&lt;br /&gt;
|Other||1||Anything else should be treated as an OPL register, with the byte following being the data to send to that register.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The delays all need to be incremented by one, as having a delay of zero milliseconds would be a waste of space.  Codes 0x02 and 0x03 switch between two OPL chips in dual OPL2 mode, or between register banks in OPL3 mode.  These should only be used if the hardware flag in the header indicates the file is in dual-OPL2 or OPL3 format.&lt;br /&gt;
&lt;br /&gt;
All delays are in milliseconds (which can be treated as 1000Hz if converting between other formats.)&lt;br /&gt;
&lt;br /&gt;
=== Version 2.0 ===&lt;br /&gt;
&lt;br /&gt;
Version 2.0 of the DRO Format was introduced with DOSBox 0.73.&lt;br /&gt;
&lt;br /&gt;
==== Header ====&lt;br /&gt;
&lt;br /&gt;
The version 2.0 header also follows on directly from the main file header.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|UINT32LE||iLengthPairs||Length of the song in register/value pairs (TODO: confirm - 1 == one register + one value, or two bytes)&lt;br /&gt;
|-&lt;br /&gt;
|UINT32LE||iLengthMS||Length of the song data (&amp;quot;chunk&amp;quot; -?) in milliseconds&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iHardwareType||Flag listing the hardware used in the song&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iFormat||Data arrangement&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iCompression||Compression type, zero means no compression (currently only zero is used)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iShortDelayCode||Command code for short delay (1-256ms)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iLongDelayCode||Command code for short delay (&amp;gt; 256ms)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iCodemapLength||Number of entries in codemap table&lt;br /&gt;
|-&lt;br /&gt;
|UINT8[iCodemapLength]||iCodemap||Codemap table (see below)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;iHardwareType&#039;&#039; is one of the following values: (which are different in v1.0 and v2.0)&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!&#039;&#039;iHardwareType&#039;&#039;!!Description&lt;br /&gt;
|-&lt;br /&gt;
|0||OPL2&lt;br /&gt;
|-&lt;br /&gt;
|1||Dual OPL2&lt;br /&gt;
|-&lt;br /&gt;
|2||OPL3&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;iFormat&#039;&#039; is one of the following values:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!&#039;&#039;iFormat&#039;&#039;!!Description&lt;br /&gt;
|-&lt;br /&gt;
|0||Commands and data are interleaved (default/as per v1.0)&lt;br /&gt;
|-&lt;br /&gt;
|1||Maybe all commands, followed by all data (unused? - TODO: Confirm)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* &#039;&#039;iLengthMS&#039;&#039; is at a different offset in v1.0 and v2.0&lt;br /&gt;
* The &#039;&#039;iShortDelayCode&#039;&#039; value must have one added to it, as per v1.0 (so a short delay of 2 == a 3ms delay)&lt;br /&gt;
* The &#039;&#039;iLongDelayCode&#039;&#039; value must have one added to it, then be multiplied by 256 (or &amp;quot;&amp;lt;&amp;lt; 8&amp;quot;), so a long delay of 2 == a 768ms delay&lt;br /&gt;
* Because the high bit in each codeword is used to refer to the second OPL2 chip (or the second set of registers in an OPL3), there are only 128 possible codewords (0-127).  Therefore &#039;&#039;iCodemapLength&#039;&#039; must always be 128 or less.&lt;br /&gt;
* DOSBox dumps a snapshot of the current register state at the beginning of a capture.  (Any other registers are assumed initialised to zero.)  This means that even an OPL2 only song will appear to have some data sent to the second OPL chip, because of this initial snapshot.  To really know whether the second OPL chip is in use, you can find out if it is actually making any sound, like so:&lt;br /&gt;
** Examine bit 5 (0x20) on registers 0xB0 to 0xB8.  If this bit is set, a note is playing and the chip is being used.&lt;br /&gt;
** Check whether bitmask 0x1F on register 0xBD is greater than 0x10 (i.e. &amp;lt;code&amp;gt;if (reg[0xBD] &amp;amp; 0x1F &amp;gt; 0x10) ...&amp;lt;/code&amp;gt;).  If so, the chip is in percussive mode and a rhythm instrument is being played, so the chip is being used.&lt;br /&gt;
&lt;br /&gt;
===== Codemap table =====&lt;br /&gt;
The codemap table maps index numbers to OPL registers.  As there are 256 possible OPL registers but only a subset of these actually used, the mapping table allows up to 128 OPL registers to be used in a song.  The other 128 (with the high bit set) are used for the second OPL2 chip in a dual-OPL2 capture.&lt;br /&gt;
&lt;br /&gt;
The table is a list of &#039;&#039;iCodemapLength&#039;&#039; bytes, with the index used later in the file.  For example this code table:&lt;br /&gt;
&lt;br /&gt;
 01 04 05 08 BD&lt;br /&gt;
&lt;br /&gt;
Means that when the song references register #0 the data should be sent to OPL register 0x01, when the song references register #4 the data should go to OPL register 0xBD.  If the song references register #128 (i.e. register 128+0), data should be sent to OPL register 0x01 on the &#039;&#039;&#039;second&#039;&#039;&#039; chip (in dual OPL2 mode) or the second set of registers (OPL3 mode).  Likewise register #132 (128+4) is OPL register 0xBD on the &#039;&#039;&#039;second&#039;&#039;&#039; chip.&lt;br /&gt;
&lt;br /&gt;
==== Song data ====&lt;br /&gt;
&lt;br /&gt;
Directly following the header is the song data in register index and value pairs.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iRegisterIndex||Register to write to.  This is an index into the codemap table.&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iValue||Value to write to the OPL register&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This structure is repeated &#039;&#039;iLengthPairs&#039;&#039; times.  Note that while &#039;&#039;iRegisterIndex&#039;&#039; is normally an index into the codemap table, it can also match &#039;&#039;iShortDelayCode&#039;&#039; or &#039;&#039;iLongDelayCode&#039;&#039; if &#039;&#039;iValue&#039;&#039; is to be treated as a delay length (see above.)  If the high bit is set (&amp;lt;code&amp;gt;iRegisterIndex &amp;amp; 0x80&amp;lt;/code&amp;gt;) then it is a register on the second OPL chip in a dual-OPL2 song (so the high bit should be removed and the value looked up as normal, but then sent to the second OPL chip instead.)&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[AdPlug]]&lt;br /&gt;
| Platform = Windows/Linux/DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = v1/v2&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[Camoto]]&lt;br /&gt;
| Platform = Linux/Win&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Yes; many&lt;br /&gt;
| canImport = Yes; many&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = v1/v2&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://www.dosbox.com/ DOSBox]&lt;br /&gt;
| Platform = Windows/Mac/Linux&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = v2-only since 0.73.  Produces .dro files as a result of capturing Adlib data from DOS games and applications&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://www.jestarjokin.net/apps/drotrimmer DRO Trimmer]&lt;br /&gt;
| Platform = Any (Python)&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = Edits .dro files to remove unwanted notes from the start and end&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://www.shikadi.net/utils/dro2imf DRO2IMF]&lt;br /&gt;
| Platform = Windows/Mac/Linux&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Yes; [[IMF Format|.imf]]&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = Converts v1/v2 .dro to .imf&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[DRO2MIDI]]&lt;br /&gt;
| Platform = Windows/Mac/Linux&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Yes; [[MID Format|.mid]]&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = Converts v1/v2 .dro and .imf to .mid&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[OpenMPT]]&lt;br /&gt;
| Platform = Windows&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = OpenMPT 1.30 and newer can export a DRO v1 register dump for songs that use OPL instruments.&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== Similar formats ==&lt;br /&gt;
* [[RAW Format (Adlib)|Rdos&#039; RAW format]] serves the same purpose, only these files were originally created through the RAC (Rdos Adlib Capture) TSR running under native DOS.&lt;br /&gt;
* The [[IMF Format|id Software Music Format (IMF)]] stores Adlib data in a similar manner in order to provide background music in many Apogee games.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=DRO_Format&amp;diff=10200</id>
		<title>DRO Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=DRO_Format&amp;diff=10200"/>
		<updated>2021-11-14T01:07:57Z</updated>

		<summary type="html">&lt;p&gt;Saga: /* Tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = OPL&lt;br /&gt;
 | Instruments = OPL&lt;br /&gt;
 | NumChannels = 9 or 11 (OPL2), 18 or 22 (Dual OPL2 and OPL3)&lt;br /&gt;
 | NumTracks = 1&lt;br /&gt;
}}&lt;br /&gt;
The &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;D&amp;lt;/u&amp;gt;OSBox &amp;lt;u&amp;gt;R&amp;lt;/u&amp;gt;aw &amp;lt;u&amp;gt;O&amp;lt;/u&amp;gt;PL (DRO)&amp;lt;/b&amp;gt; format is used for storing captured OPL data from a game running in the cross-platform DOS emulator [http://dosbox.sourceforge.net DOSBox].&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file begins with a header:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|BYTE[8]||cSignature||&amp;quot;DBRAWOPL&amp;quot; (not NULL-terminated)&lt;br /&gt;
|-&lt;br /&gt;
|UINT16LE||iVersionMajor||Version number (high)&lt;br /&gt;
|-&lt;br /&gt;
|UINT16LE||iVersionMinor||Version number (low)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The rest of the header depends on the version.  If iVersionMajor is 5 and iVersionMinor is 6, then the version would be called &amp;quot;5.6&amp;quot; here.&lt;br /&gt;
&lt;br /&gt;
=== Version 0.1 ===&lt;br /&gt;
&lt;br /&gt;
The first version of the DRO Format was used up to and including DOSBox version 0.72.  Note that the major and minor field names were swapped beginning with DOSBox 0.73, so this version used to be 1.0, but after DOSBox 0.73 it became 0.1 instead.&lt;br /&gt;
&lt;br /&gt;
==== Header ====&lt;br /&gt;
&lt;br /&gt;
The version 0.1 header follows on directly from the main file header.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|UINT32LE||iLengthMS||Length of the song in milliseconds&lt;br /&gt;
|-&lt;br /&gt;
|UINT32LE||iLengthBytes||Length of the song data in bytes&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iHardwareType||Flag listing the hardware used in the song&lt;br /&gt;
|-&lt;br /&gt;
|UINT8[3]||iHardwareExtra||Rest of hardware type or song data (see below)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;iHardwareType&#039;&#039; is one of the following values:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!&#039;&#039;iHardwareType&#039;&#039;!!Description&lt;br /&gt;
|-&lt;br /&gt;
|0||OPL2&lt;br /&gt;
|-&lt;br /&gt;
|1||OPL3&lt;br /&gt;
|-&lt;br /&gt;
|2||Dual OPL2&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In early files, the field was a UINT8, however in most common (recent) files it is a UINT32LE with only the first byte used.  Unfortunately the version number was not changed between these revisions, so the only way to correctly identify the formats is to check the three &amp;lt;tt&amp;gt;iHardwareExtra&amp;lt;/tt&amp;gt; bytes.  If these are all zero then they can safely be ignored (iHardwareType was a UINT32.)  If any of the three bytes in &amp;lt;tt&amp;gt;iHardwareExtra&amp;lt;/tt&amp;gt; are non-zero, then this is an early revision of the format and those three bytes are actually song data&amp;lt;ref&amp;gt;In the [http://adplug.sourceforge.net AdPlug distribution], tests/samurai.dro is the early one-byte format, and doofus.dro is the later four-byte variant.&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Song data ====&lt;br /&gt;
&lt;br /&gt;
Directly following the header is &#039;&#039;iLengthBytes&#039;&#039; bytes of OPL data.  The first byte in the song data will be the OPL register, followed by the byte to send to that register.  The &amp;quot;register&amp;quot; can also be one of these control values:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Register value!!Data size!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|0x00||1||Delay.  The single data byte following should be incremented by one, and is then the delay in milliseconds.&lt;br /&gt;
|-&lt;br /&gt;
|0x01||2||Delay.  Same as above only there are two bytes following, in the form of a UINT16LE integer.&lt;br /&gt;
|-&lt;br /&gt;
|0x02||0||Switch to &amp;quot;low&amp;quot; OPL chip (#0)&lt;br /&gt;
|-&lt;br /&gt;
|0x03||0||Switch to &amp;quot;high&amp;quot; OPL chip (#1)&lt;br /&gt;
|-&lt;br /&gt;
|0x04||2||Escape - the next two bytes are normal register/value pairs even though the register might be 0x00-0x04&lt;br /&gt;
|-&lt;br /&gt;
|Other||1||Anything else should be treated as an OPL register, with the byte following being the data to send to that register.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The delays all need to be incremented by one, as having a delay of zero milliseconds would be a waste of space.  Codes 0x02 and 0x03 switch between two OPL chips in dual OPL2 mode, or between register banks in OPL3 mode.  These should only be used if the hardware flag in the header indicates the file is in dual-OPL2 or OPL3 format.&lt;br /&gt;
&lt;br /&gt;
All delays are in milliseconds (which can be treated as 1000Hz if converting between other formats.)&lt;br /&gt;
&lt;br /&gt;
=== Version 2.0 ===&lt;br /&gt;
&lt;br /&gt;
Version 2.0 of the DRO Format was introduced with DOSBox 0.73.&lt;br /&gt;
&lt;br /&gt;
==== Header ====&lt;br /&gt;
&lt;br /&gt;
The version 2.0 header also follows on directly from the main file header.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|UINT32LE||iLengthPairs||Length of the song in register/value pairs (TODO: confirm - 1 == one register + one value, or two bytes)&lt;br /&gt;
|-&lt;br /&gt;
|UINT32LE||iLengthMS||Length of the song data (&amp;quot;chunk&amp;quot; -?) in milliseconds&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iHardwareType||Flag listing the hardware used in the song&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iFormat||Data arrangement&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iCompression||Compression type, zero means no compression (currently only zero is used)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iShortDelayCode||Command code for short delay (1-256ms)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iLongDelayCode||Command code for short delay (&amp;gt; 256ms)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iCodemapLength||Number of entries in codemap table&lt;br /&gt;
|-&lt;br /&gt;
|UINT8[iCodemapLength]||iCodemap||Codemap table (see below)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;iHardwareType&#039;&#039; is one of the following values: (which are different in v1.0 and v2.0)&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!&#039;&#039;iHardwareType&#039;&#039;!!Description&lt;br /&gt;
|-&lt;br /&gt;
|0||OPL2&lt;br /&gt;
|-&lt;br /&gt;
|1||Dual OPL2&lt;br /&gt;
|-&lt;br /&gt;
|2||OPL3&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;iFormat&#039;&#039; is one of the following values:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!&#039;&#039;iFormat&#039;&#039;!!Description&lt;br /&gt;
|-&lt;br /&gt;
|0||Commands and data are interleaved (default/as per v1.0)&lt;br /&gt;
|-&lt;br /&gt;
|1||Maybe all commands, followed by all data (unused? - TODO: Confirm)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* &#039;&#039;iLengthMS&#039;&#039; is at a different offset in v1.0 and v2.0&lt;br /&gt;
* The &#039;&#039;iShortDelayCode&#039;&#039; value must have one added to it, as per v1.0 (so a short delay of 2 == a 3ms delay)&lt;br /&gt;
* The &#039;&#039;iLongDelayCode&#039;&#039; value must have one added to it, then be multiplied by 256 (or &amp;quot;&amp;lt;&amp;lt; 8&amp;quot;), so a long delay of 2 == a 768ms delay&lt;br /&gt;
* Because the high bit in each codeword is used to refer to the second OPL2 chip (or the second set of registers in an OPL3), there are only 128 possible codewords (0-127).  Therefore &#039;&#039;iCodemapLength&#039;&#039; must always be 128 or less.&lt;br /&gt;
* DOSBox dumps a snapshot of the current register state at the beginning of a capture.  (Any other registers are assumed initialised to zero.)  This means that even an OPL2 only song will appear to have some data sent to the second OPL chip, because of this initial snapshot.  To really know whether the second OPL chip is in use, you can find out if it is actually making any sound, like so:&lt;br /&gt;
** Examine bit 5 (0x20) on registers 0xB0 to 0xB8.  If this bit is set, a note is playing and the chip is being used.&lt;br /&gt;
** Check whether bitmask 0x1F on register 0xBD is greater than 0x10 (i.e. &amp;lt;code&amp;gt;if (reg[0xBD] &amp;amp; 0x1F &amp;gt; 0x10) ...&amp;lt;/code&amp;gt;).  If so, the chip is in percussive mode and a rhythm instrument is being played, so the chip is being used.&lt;br /&gt;
&lt;br /&gt;
===== Codemap table =====&lt;br /&gt;
The codemap table maps index numbers to OPL registers.  As there are 256 possible OPL registers but only a subset of these actually used, the mapping table allows up to 128 OPL registers to be used in a song.  The other 128 (with the high bit set) are used for the second OPL2 chip in a dual-OPL2 capture.&lt;br /&gt;
&lt;br /&gt;
The table is a list of &#039;&#039;iCodemapLength&#039;&#039; bytes, with the index used later in the file.  For example this code table:&lt;br /&gt;
&lt;br /&gt;
 01 04 05 08 BD&lt;br /&gt;
&lt;br /&gt;
Means that when the song references register #0 the data should be sent to OPL register 0x01, when the song references register #4 the data should go to OPL register 0xBD.  If the song references register #128 (i.e. register 128+0), data should be sent to OPL register 0x01 on the &#039;&#039;&#039;second&#039;&#039;&#039; chip (in dual OPL2 mode) or the second set of registers (OPL3 mode).  Likewise register #132 (128+4) is OPL register 0xBD on the &#039;&#039;&#039;second&#039;&#039;&#039; chip.&lt;br /&gt;
&lt;br /&gt;
==== Song data ====&lt;br /&gt;
&lt;br /&gt;
Directly following the header is the song data in register index and value pairs.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iRegisterIndex||Register to write to.  This is an index into the codemap table.&lt;br /&gt;
|-&lt;br /&gt;
|UINT8||iValue||Value to write to the OPL register&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This structure is repeated &#039;&#039;iLengthPairs&#039;&#039; times.  Note that while &#039;&#039;iRegisterIndex&#039;&#039; is normally an index into the codemap table, it can also match &#039;&#039;iShortDelayCode&#039;&#039; or &#039;&#039;iLongDelayCode&#039;&#039; if &#039;&#039;iValue&#039;&#039; is to be treated as a delay length (see above.)  If the high bit is set (&amp;lt;code&amp;gt;iRegisterIndex &amp;amp; 0x80&amp;lt;/code&amp;gt;) then it is a register on the second OPL chip in a dual-OPL2 song (so the high bit should be removed and the value looked up as normal, but then sent to the second OPL chip instead.)&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[AdPlug]]&lt;br /&gt;
| Platform = Windows/Linux/DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = v1/v2&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[Camoto]]&lt;br /&gt;
| Platform = Linux/Win&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Yes; many&lt;br /&gt;
| canImport = Yes; many&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = v1/v2&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://www.dosbox.com/ DOSBox]&lt;br /&gt;
| Platform = Windows/Mac/Linux&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = v2-only since 0.73.  Produces .dro files as a result of capturing Adlib data from DOS games and applications&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://www.jestarjokin.net/apps/drotrimmer DRO Trimmer]&lt;br /&gt;
| Platform = Any (Python)&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = Edits .dro files to remove unwanted notes from the start and end&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://www.shikadi.net/utils/dro2imf DRO2IMF]&lt;br /&gt;
| Platform = Windows/Mac/Linux&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Yes; [[IMF Format|.imf]]&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = Converts v1/v2 .dro to .imf&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[DRO2MIDI]]&lt;br /&gt;
| Platform = Windows/Mac/Linux&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Yes; [[MID Format|.mid]]&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = Converts v1/v2 .dro and .imf to .mid&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[OpenMPT]]&lt;br /&gt;
| Platform = Windows&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
| notes = OpenMPT 1.30 and newer can export a DRO register dump for songs that use OPL instruments.&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== Similar formats ==&lt;br /&gt;
* [[RAW Format (Adlib)|Rdos&#039; RAW format]] serves the same purpose, only these files were originally created through the RAC (Rdos Adlib Capture) TSR running under native DOS.&lt;br /&gt;
* The [[IMF Format|id Software Music Format (IMF)]] stores Adlib data in a similar manner in order to provide background music in many Apogee games.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=User:Saga&amp;diff=9760</id>
		<title>User:Saga</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=User:Saga&amp;diff=9760"/>
		<updated>2021-05-17T17:43:06Z</updated>

		<summary type="html">&lt;p&gt;Saga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, I&#039;m [https://sagamusix.de/ Saga Musix] and I&#039;m an OpenMPT developer. I have fixed OpenMPT&#039;s PSM loader and corrected the [[ProTracker Studio Module|PSM specs]] while doing so. I also reverse-engineered the [[Karl Morton Music Format|music format]] used in [[Psycho Pinball]] and [[Micro Machines 2]] on PC.&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Jazz_2_Music_Format&amp;diff=9186</id>
		<title>Jazz 2 Music Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Jazz_2_Music_Format&amp;diff=9186"/>
		<updated>2020-10-16T19:24:14Z</updated>

		<summary type="html">&lt;p&gt;Saga: /* Data body */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 255 (practically limited to 64 by source formats)&lt;br /&gt;
 | NumTracks = 1&lt;br /&gt;
 | NumPatterns = 256&lt;br /&gt;
 | NumOrders = 256&lt;br /&gt;
 | Tags = Title, instrument names, sample names&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Jazz Jackrabbit 2}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The J2B format is just a container for the custom format of the Galaxy Sound System, RIFF AMFF or RIFF AM.&lt;br /&gt;
&lt;br /&gt;
== Container Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 24 bytes long:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][4] || format identifier || &amp;quot;MUSE&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || format subtype || 0xDEADBEAF (RIFF AM) or 0xDEADBABE (RIFF AMFF); indicates the file content, but is pretty useless (you should not rely on this at all!)&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || size || Size of the complete file&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || checksum  || Checksum of the data block (&#039;&#039;before&#039;&#039; decompression)&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || compressed size ||  Length of the data block &#039;&#039;before&#039;&#039; decompression (should be file size - 24 bytes)&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || uncompressed size ||  Length of the data block &#039;&#039;after&#039;&#039; decompression&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][] || music data || This is the actual music file in either RIFF AMFF or RIFF AM format; It&#039;s compressed using standard [[Zlib Compression|zlib compression]]. Simply use zlib&#039;s &amp;quot;uncompress&amp;quot; macro to read this.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Data body ==&lt;br /&gt;
&lt;br /&gt;
The uncompressed data body contains a module in either RIFF AMFF or RIFF AM format. Both formats are rather similar, but RIFF AM follows the RIFF conventions more strictly. RIFF AMFF was only used in early versions of Jazz Jackrabbit 2, which explains why RIFF AM is generally the more advanced format of the two. RIFF AMFF is internally very close to the XM format, with a few additions to support some S3M / IT commands.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [https://openmpt.org/ OpenMPT]&lt;br /&gt;
| Platform = Windows&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Many&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes =&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [https://j2c.jazz2online.com/programs.htm mod2j2b]&lt;br /&gt;
| Platform = Windows&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = MOD, XM, S3M, IT, MTM, 669&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = Some formats are converted rather poorly (e.g. MTM, 669). There are two different mod2j2b executables for AM and AMFF files.&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Jazz_2_Music_Format&amp;diff=9185</id>
		<title>Jazz 2 Music Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Jazz_2_Music_Format&amp;diff=9185"/>
		<updated>2020-10-16T19:21:49Z</updated>

		<summary type="html">&lt;p&gt;Saga: /* Data body */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 255 (practically limited to 64 by source formats)&lt;br /&gt;
 | NumTracks = 1&lt;br /&gt;
 | NumPatterns = 256&lt;br /&gt;
 | NumOrders = 256&lt;br /&gt;
 | Tags = Title, instrument names, sample names&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Jazz Jackrabbit 2}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The J2B format is just a container for the custom format of the Galaxy Sound System, RIFF AMFF or RIFF AM.&lt;br /&gt;
&lt;br /&gt;
== Container Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 24 bytes long:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][4] || format identifier || &amp;quot;MUSE&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || format subtype || 0xDEADBEAF (RIFF AM) or 0xDEADBABE (RIFF AMFF); indicates the file content, but is pretty useless (you should not rely on this at all!)&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || size || Size of the complete file&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || checksum  || Checksum of the data block (&#039;&#039;before&#039;&#039; decompression)&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || compressed size ||  Length of the data block &#039;&#039;before&#039;&#039; decompression (should be file size - 24 bytes)&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || uncompressed size ||  Length of the data block &#039;&#039;after&#039;&#039; decompression&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][] || music data || This is the actual music file in either RIFF AMFF or RIFF AM format; It&#039;s compressed using standard [[Zlib Compression|zlib compression]]. Simply use zlib&#039;s &amp;quot;uncompress&amp;quot; macro to read this.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Data body ==&lt;br /&gt;
&lt;br /&gt;
The uncompressed data body contains a module in either RIFF AMFF or RIFF AM format. Both formats are rather similar, but RIFF AM follows the RIFF conventions more strictly. RIFF AMFF was only used in early versions of Jazz Jackrabbit 2, which explains why RIFF AM is generally the more advanced format of the two. RIFF AMFF is internally very close to the XM format, with a few additions to support some S3M / IT commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [https://openmpt.org/ OpenMPT]&lt;br /&gt;
| Platform = Windows&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Many&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes =&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [https://j2c.jazz2online.com/programs.htm mod2j2b]&lt;br /&gt;
| Platform = Windows&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = MOD, XM, S3M, IT, MTM, 669&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = Some formats are converted rather poorly (e.g. MTM, 669)&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Jazz_2_Music_Format&amp;diff=9184</id>
		<title>Jazz 2 Music Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Jazz_2_Music_Format&amp;diff=9184"/>
		<updated>2020-10-16T19:20:36Z</updated>

		<summary type="html">&lt;p&gt;Saga: Add format template and tools&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 255 (practically limited to 64 by source formats)&lt;br /&gt;
 | NumTracks = 1&lt;br /&gt;
 | NumPatterns = 256&lt;br /&gt;
 | NumOrders = 256&lt;br /&gt;
 | Tags = Title, instrument names, sample names&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Jazz Jackrabbit 2}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The J2B format is just a container for the custom format of the Galaxy Sound System, RIFF AMFF or RIFF AM.&lt;br /&gt;
&lt;br /&gt;
== Container Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 24 bytes long:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][4] || format identifier || &amp;quot;MUSE&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || format subtype || 0xDEADBEAF (RIFF AM) or 0xDEADBABE (RIFF AMFF); indicates the file content, but is pretty useless (you should not rely on this at all!)&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || size || Size of the complete file&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || checksum  || Checksum of the data block (&#039;&#039;before&#039;&#039; decompression)&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || compressed size ||  Length of the data block &#039;&#039;before&#039;&#039; decompression (should be file size - 24 bytes)&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || uncompressed size ||  Length of the data block &#039;&#039;after&#039;&#039; decompression&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][] || music data || This is the actual music file in either RIFF AMFF or RIFF AM format; It&#039;s compressed using standard [[Zlib Compression|zlib compression]]. Simply use zlib&#039;s &amp;quot;uncompress&amp;quot; macro to read this.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Data body ==&lt;br /&gt;
&lt;br /&gt;
The uncompressed data body contains a module in either RIFF AMFF or RIFF AM format. Both formats are rather similar, but RIFF AM follows the RIFF conventions more strictly. RIFF AMFF was only used in early versions of Jazz Jackrabbit 2, which explains why RIFF AM is generally the more advanced format of the two. RIFF AMFF is internally very close to the XM format, with a few additions to support some S3M / IT commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [https://openmpt.org/ OpenMPT]&lt;br /&gt;
| Platform = Windows&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Many&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes =&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [https://j2c.jazz2online.com/programs.htm mod2j2b]&lt;br /&gt;
| Platform = Any&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = MOD, XM, S3M, IT, MTM, 669&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = Some formats are converted rather poorly (e.g. MTM, 669)&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=MID_Format&amp;diff=9183</id>
		<title>MID Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=MID_Format&amp;diff=9183"/>
		<updated>2020-10-15T16:46:14Z</updated>

		<summary type="html">&lt;p&gt;Saga: A note on the signedness of delay values&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = MIDI&lt;br /&gt;
 | Instruments = MIDI&lt;br /&gt;
 | NumChannels = 16&lt;br /&gt;
 | NumTracks = 65535&lt;br /&gt;
 | NumPatterns = 1&lt;br /&gt;
 | NumOrders = 0&lt;br /&gt;
 | Tags = Text events&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Blood}}&lt;br /&gt;
   {{Game|Boppin&#039;}}&lt;br /&gt;
   {{Game|Duke Nukem 3D}}&lt;br /&gt;
   {{Game|Hi Octane}}&lt;br /&gt;
   {{Game|Hocus Pocus}}&lt;br /&gt;
   {{Game|Magic Pockets}}&lt;br /&gt;
   {{Game|Prince of Persia}}&lt;br /&gt;
   {{Game|Rise of the Triad}}&lt;br /&gt;
   {{Game|Sango Fighter}}&lt;br /&gt;
   {{Game|Shadow Warrior}}&lt;br /&gt;
   {{Game|SimCity 2000}}&lt;br /&gt;
   {{Game|Wacky Wheels}}&lt;br /&gt;
   {{Game|Where In the World Is Carmen Sandiego?}}&lt;br /&gt;
}}&lt;br /&gt;
The &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;M&amp;lt;/u&amp;gt;usical &amp;lt;u&amp;gt;I&amp;lt;/u&amp;gt;nstrument &amp;lt;u&amp;gt;D&amp;lt;/u&amp;gt;igital &amp;lt;u&amp;gt;I&amp;lt;/u&amp;gt;nterface (MIDI) file format&amp;lt;/b&amp;gt; is used for storing the notes required to accurately reproduce a song.  Commercial instruments are available that &amp;quot;speak&amp;quot; the MIDI protocol, and a MIDI file (.mid) simply stores the data sent over the wire, with a few headers on the front.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
A MIDI file starts with an overall &#039;&#039;MThd&#039;&#039; header, followed by one or more &#039;&#039;MTrk&#039;&#039; headers for each &amp;quot;track&amp;quot; (a track is normally created for each instrument, for simplicity when the song is being composed.)&lt;br /&gt;
&lt;br /&gt;
=== MThd Header ===&lt;br /&gt;
The file begins with a header:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|BYTE[4]||cSignature||&amp;quot;MThd&amp;quot; (not NULL-terminated)&lt;br /&gt;
|-&lt;br /&gt;
|UINT32BE||iLength||Length of MThd block (usually 6)&lt;br /&gt;
|-&lt;br /&gt;
|UINT16BE||iType||0, 1 or 2 (for format-0, 1 or 2)&lt;br /&gt;
|-&lt;br /&gt;
|UINT16BE||iNumTracks||Number of tracks (will be 1 for format-0)&lt;br /&gt;
|-&lt;br /&gt;
|UINT16BE||iTicksPerQuarterNote||Number of MIDI delay ticks in a quarter-note&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If the high bit in &amp;lt;tt&amp;gt;iTicksPerQuarterNote&amp;lt;/tt&amp;gt; is set (0x8000) then the file uses SMPTE timing instead, which is rare and not covered here.&lt;br /&gt;
&lt;br /&gt;
=== MTrk block ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;MTrk&#039;&#039; block is repeated once for each track in the song (the &#039;&#039;&#039;iNumTracks&#039;&#039;&#039; field in the MThd header.)&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|BYTE[4]||cSignature||&amp;quot;MTrk&amp;quot; (not NULL-terminated)&lt;br /&gt;
|-&lt;br /&gt;
|UINT32BE||iLength||Length of block&lt;br /&gt;
|-&lt;br /&gt;
|BYTE[iLength]||cData||MIDI data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== MIDI data ===&lt;br /&gt;
&lt;br /&gt;
The MIDI data consists of a delay value (in MIDI variable-length integer notation), followed by a MIDI event byte (see [[#MIDI events]] below.)  The event data follows, and will be different depending on the event.  It then starts again with the delay value for the next event.&lt;br /&gt;
&lt;br /&gt;
==== MIDI lengths ====&lt;br /&gt;
&lt;br /&gt;
MIDI lengths are stored as variable length integers, between one and four bytes long.  Each byte only uses the lower 7-bits, with the MSB set if there is another length byte following.  The bytes are in big endian order.  Some examples of these length bytes are:&lt;br /&gt;
&lt;br /&gt;
  50      // Hex value 0x50&lt;br /&gt;
  81 50   // Hex value 0xD0 ((0x81 &amp;amp; 0x7F) &amp;lt;&amp;lt; 7) | (0x50 &amp;amp; 0x7F)&lt;br /&gt;
&lt;br /&gt;
Here is some C code to read these values:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
const char *midi_data = &amp;quot;\x81\x50&amp;quot;;&lt;br /&gt;
unsigned long val = 0;&lt;br /&gt;
&lt;br /&gt;
for (int i = 0; i &amp;lt; 4; i++) {&lt;br /&gt;
&lt;br /&gt;
	// Include the lower 7-bits of this byte into the value&lt;br /&gt;
	val |= midi_data[i] &amp;amp; 0x7F;&lt;br /&gt;
&lt;br /&gt;
	// If the high bit is set, shift the value up&lt;br /&gt;
	// seven bits to make room for the next value&lt;br /&gt;
	if (midi_data[i] &amp;amp; 0x80) val &amp;lt;&amp;lt;= 7;&lt;br /&gt;
	else break; // High bit unset means end of value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
printf(&amp;quot;Value is %lu\n&amp;quot;, val);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Generally variable-length integers are defined to be unsigned numbers.  However, some MIDI files in the wild assume that delays are measured as signed 32-bit integers, which is used to shift some MIDI events at the start of the file into the negative range.  For this reason, if the first delay value on a channel is 2,147,483,648 or greater, it should be treated as a signed number instead.&lt;br /&gt;
&lt;br /&gt;
Generally speaking, MIDI data that can be sent over the wire uses these values (e.g. delays), whereas data only used to write .mid files on disk (e.g. MTrk lengths in bytes) use normal big-endian fixed-length values.&lt;br /&gt;
&lt;br /&gt;
==== MIDI events ====&lt;br /&gt;
&lt;br /&gt;
This table lists the different MIDI events that can occur in a song.  The events are listed as channel zero (e.g. 0x80, which would become 0x85 for channel five.)  Removing the high bit (&amp;lt;code&amp;gt;(byte &amp;amp; 0x7F) &amp;gt;&amp;gt; 4&amp;lt;/code&amp;gt;) will give the &#039;event number&#039;.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Register value!!Event number!!Data size!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|0x80||0||2||Note off&lt;br /&gt;
|-&lt;br /&gt;
|0x90||1||2||Note on&lt;br /&gt;
|-&lt;br /&gt;
|0xA0||2||2||Polyphonic key pressure&lt;br /&gt;
|-&lt;br /&gt;
|0xB0||3||2||Controller&lt;br /&gt;
|-&lt;br /&gt;
|0xC0||4||1||Instrument change&lt;br /&gt;
|-&lt;br /&gt;
|0xD0||5||1||Channel pressure&lt;br /&gt;
|-&lt;br /&gt;
|0xE0||6||2||Pitch bend&lt;br /&gt;
|-&lt;br /&gt;
|0xF0||7||Any||Sysex&lt;br /&gt;
|-&lt;br /&gt;
|0xFF||N/A||Any||Meta-event&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The data bytes for each event are described in the sections below.&lt;br /&gt;
&lt;br /&gt;
Each event is preceded by a delay (as a MIDILEN variable-length integer, see [[#MIDI lengths]] above) which specifies the number of MIDI ticks until the event should be actioned.&lt;br /&gt;
&lt;br /&gt;
To convert the number of MIDI ticks into a usable time value, the &amp;lt;tt&amp;gt;iTicksPerQuarterNote&amp;lt;/tt&amp;gt; field from the header will allow the tick count to be converted into a fractional number of quarter notes, then the song&#039;s tempo (in microseconds per quarter note) will allow this fractional number of quarter notes to be converted into microseconds.&lt;br /&gt;
&lt;br /&gt;
The default tempo of 500,000 microseconds per quarter note applies until overridden by a [[#0x51: Set tempo|set-tempo]] event.&lt;br /&gt;
&lt;br /&gt;
===== Running-status =====&lt;br /&gt;
&lt;br /&gt;
Any event values without the high-bit set (i.e. less than 0x80) are so-called &amp;quot;running status&amp;quot; values.  If one of these bytes is encountered as a MIDI event, it is actually the first data byte of the event instead.  The actual event is the same as the previous one.  For example, these two lines are equivalent: (delay bytes omitted for clarity)&lt;br /&gt;
&lt;br /&gt;
 90 40 7F   91 44 7F   91 47 7F   81 44 7F  (full syntax)&lt;br /&gt;
 90 40 7F   91 44 7F      47 7F      44 00  (with running status)&lt;br /&gt;
&lt;br /&gt;
This means:&lt;br /&gt;
* 90 40 7F: Turn note 0x40 on channel 0 at maximum velocity&lt;br /&gt;
* 91 44 7F: Then turn note 0x44 on channel 1 at maximum velocity&lt;br /&gt;
* 47 7F: Turn note 0x47 on the same channel (running status means use event 0x91 from before)&lt;br /&gt;
* 44 00: Turn note 0x44 off on the same channel (running status uses event 0x91 again, and takes advantage of note-on at zero velocity being the same as note-off)&lt;br /&gt;
&lt;br /&gt;
Meta-events do not affect running status, so any event from 0xF0 to 0xFF can appear in the middle of data without affecting the running status.  For example the following line is equivalent to the two lines above:&lt;br /&gt;
&lt;br /&gt;
 90 40 7F   91 44 7F   FF 01 02 AA BB   47 7F   F0 02 AA F7   44 00&lt;br /&gt;
&lt;br /&gt;
===== 0x80: Note off =====&lt;br /&gt;
Stops the specified note from sounding on this channel.  Does not affect any other notes currently being played on the same channel.  A note-on event with a velocity of zero is the same as a note-off event.&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iNote||MIDI note number to key-off (0-127)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iVelocity||How hard to release the note (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== 0x90: Note on =====&lt;br /&gt;
Plays the specified note on the given channel.  Multiple notes can be sounding at the same time on the same channel.  A velocity of zero is the same as a note-off event (this is often used with running status to minimise the amount of data used.)&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iNote||MIDI note number to key-on (0-127)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iVelocity||How hard to press the note (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== 0xA0: Polyphonic key pressure =====&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iPressure||Pressure value (0-127)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iNote||MIDI note number to affect (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Like [[#0xD0: Channel pressure|channel pressure]], but applies to individual notes on the channel.&lt;br /&gt;
&lt;br /&gt;
===== 0xB0: Controller =====&lt;br /&gt;
Set a MIDI controller to the specified value.  TODO: List of standard controllers&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iController||Controller index (0-127)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iValue||Value to set (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== 0xC0: Instrument change =====&lt;br /&gt;
Set the channel to the specified instrument.&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iInstrument||Instrument number (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== 0xD0: Channel pressure =====&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iPressure||Pressure value (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Also known as &amp;quot;channel aftertouch&amp;quot;, it is designed for instruments that can have their volume/intensity changed after the initial velocity set in the note-on event, such as woodwind instruments where a note can start softly and then become louder.  The exact meaning is implementation-defined.  For example, this event may set the volume of the notes currently playing on the channel in a similar way as velocity in a note-on event, but other possibilites include applying a filter change or vibrato to the notes.&lt;br /&gt;
&lt;br /&gt;
===== 0xE0: Pitch bend =====&lt;br /&gt;
Bend all notes on the channel up or down by the specified amount.  The value is between 0 and 16384.  The value 8192 is in the middle and means no bend, thus 8192 can be subtracted from this the value to create a signed integer between -8192 and +8191, with zero meaning &amp;quot;no bend.&amp;quot;  The actual pitch resulting from the bend depends on the range, which is set (usually at the start of the song) by a MIDI controller message.&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iLSB||Least significant byte (0-127)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iMSB||Most significant byte (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The value is calculated by combining the lower seven bits from each of the two bytes into a single 14-bit value: &amp;lt;code&amp;gt;value = (iMSB &amp;lt;&amp;lt; 7) | iLSB&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== 0xF0: System exclusive =====&lt;br /&gt;
These messages are used to send proprietary commands to various MIDI devices.  They are essentially a list of raw bytes to send.  The channel is not used, so 0xF0 through 0xFF are different &amp;quot;sysex&amp;quot; messages.  Since 0xFF is used as a reset it would have no use in a .mid file on disk, so this event is used for meta-events described below.&lt;br /&gt;
&lt;br /&gt;
The event type (0xF0 to 0xFE) is followed by this structure:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|MIDILEN iLength||Length of data&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 cData[iLength]||Block of data, iLength bytes long&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Event 0xFF has a different structure and is covered below.  The event types are defined as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Event type!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|0xF0||Start system exclusive event&lt;br /&gt;
|-&lt;br /&gt;
|0xF1||MIDI time code&lt;br /&gt;
|-&lt;br /&gt;
|0xF2||Song position pointer&lt;br /&gt;
|-&lt;br /&gt;
|0xF3||Song select&lt;br /&gt;
|-&lt;br /&gt;
|0xF4||(Unused)&lt;br /&gt;
|-&lt;br /&gt;
|0xF5||(Unused)&lt;br /&gt;
|-&lt;br /&gt;
|0xF6||Tune request&lt;br /&gt;
|-&lt;br /&gt;
|0xF7||End system exclusive event (EOX)&lt;br /&gt;
|-&lt;br /&gt;
|0xF8||Timing clock&lt;br /&gt;
|-&lt;br /&gt;
|0xF9||(Unused)&lt;br /&gt;
|-&lt;br /&gt;
|0xFA||Start playback&lt;br /&gt;
|-&lt;br /&gt;
|0xFB||Continue playback&lt;br /&gt;
|-&lt;br /&gt;
|0xFC||Stop playback&lt;br /&gt;
|-&lt;br /&gt;
|0xFD||(Unused)&lt;br /&gt;
|-&lt;br /&gt;
|0xFE||Active sensing&lt;br /&gt;
|-&lt;br /&gt;
|0xFF||System reset (used for meta-event in a MIDI file)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Meta events ====&lt;br /&gt;
&lt;br /&gt;
Meta events are events specific to MIDI files themselves.  They are not transmitted to MIDI devices.  A meta event is signalled by the 0xFF system exclusive event.  The following table lists the format of the bytes following the 0xFF.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iType||Meta-event type&lt;br /&gt;
|-&lt;br /&gt;
|MIDILEN iLength||Length of event data&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 cData[iLength]||Event data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following section lists the meaning of various values of &amp;lt;tt&amp;gt;iType&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== 0x01 - 0x0F: Text =====&lt;br /&gt;
These events set various types of text.  The event data is the text to set.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Event type!!Text use&lt;br /&gt;
|-&lt;br /&gt;
|0x01||Generic text event.  Often the first text event in a song is used as its title.&lt;br /&gt;
|-&lt;br /&gt;
|0x02||Copyright notice&lt;br /&gt;
|-&lt;br /&gt;
|0x03||Track name.  Often the first event (format-0) or the first track (format-1) is the song title.&lt;br /&gt;
|-&lt;br /&gt;
|0x04||Instrument name&lt;br /&gt;
|-&lt;br /&gt;
|0x05||Lyric&lt;br /&gt;
|-&lt;br /&gt;
|0x06||Marker&lt;br /&gt;
|-&lt;br /&gt;
|0x07||Cue point (e.g. stage instructions)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== 0x2F: End of track =====&lt;br /&gt;
Mandatory event at the end of each MTrk track.  The length field is always zero, so there are no bytes of event data.&lt;br /&gt;
&lt;br /&gt;
===== 0x51: Set tempo =====&lt;br /&gt;
This event should always have a length of three.  The event data is a big-endian integer (&#039;&#039;&#039;not&#039;&#039;&#039; in MIDI variable-length notation) indicating the number of microseconds in a quarter note.  Together with the &amp;lt;tt&amp;gt;iTicksPerQuarterNote&amp;lt;/tt&amp;gt; value from the header, this allows MIDI ticks to be converted into microseconds for correct playback speed of the MIDI file.&lt;br /&gt;
&lt;br /&gt;
Unless overridden by this event, the number of microseconds in a quarter note defaults to 500,000.&lt;br /&gt;
&lt;br /&gt;
===== 0x7F: Manufacturer-specific =====&lt;br /&gt;
The first data byte of this event is a manufacturer ID.  If it is 0x00, then the following [[UINT16BE]] is the actual manufacturer ID.  This means either one or three bytes total will be read to obtain the manufacturer ID.&lt;br /&gt;
&lt;br /&gt;
If the manufacturer ID is 0x3F then it is an Ad Lib, Inc. event, and the file format is technically &amp;lt;tt&amp;gt;.mdi&amp;lt;/tt&amp;gt; (an Ad Lib MIDI file with embedded OPL instruments), see [[MDI Format]] for details.&lt;br /&gt;
&lt;br /&gt;
===== Additional meta-events =====&lt;br /&gt;
&lt;br /&gt;
Other meta-events (not so important for playing back game music) are listed on various web sites:&lt;br /&gt;
&lt;br /&gt;
* http://www.omega-art.com/midi/mfiles.html#meta&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
* [[DRO2MIDI]] - converts .dro files into [[MID Format|.mid files]]&lt;br /&gt;
&lt;br /&gt;
== Similar formats ==&lt;br /&gt;
* [[MDI Format|MDI files]] have the same container format, but with different event specification.&lt;br /&gt;
* [[CMF Format|CMF files]] store their song data in MIDI format.&lt;br /&gt;
* [[MUS Format|MUS files]] are single-track MIDI files made by id Software.&lt;br /&gt;
* [[XMI Format|XMI files]] are Extended MIDI files.&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* https://web.archive.org/web/20070104033706/http://www.cybermuff.cz/music/MIDIspec.htm - great reference for the MIDI spec&lt;br /&gt;
&lt;br /&gt;
[[Category:Build engine]]&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=MID_Format&amp;diff=9182</id>
		<title>MID Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=MID_Format&amp;diff=9182"/>
		<updated>2020-10-15T16:42:08Z</updated>

		<summary type="html">&lt;p&gt;Saga: /* 0xA0: Polyphonic key pressure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = MIDI&lt;br /&gt;
 | Instruments = MIDI&lt;br /&gt;
 | NumChannels = 16&lt;br /&gt;
 | NumTracks = 65535&lt;br /&gt;
 | NumPatterns = 1&lt;br /&gt;
 | NumOrders = 0&lt;br /&gt;
 | Tags = Text events&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Blood}}&lt;br /&gt;
   {{Game|Boppin&#039;}}&lt;br /&gt;
   {{Game|Duke Nukem 3D}}&lt;br /&gt;
   {{Game|Hi Octane}}&lt;br /&gt;
   {{Game|Hocus Pocus}}&lt;br /&gt;
   {{Game|Magic Pockets}}&lt;br /&gt;
   {{Game|Prince of Persia}}&lt;br /&gt;
   {{Game|Rise of the Triad}}&lt;br /&gt;
   {{Game|Sango Fighter}}&lt;br /&gt;
   {{Game|Shadow Warrior}}&lt;br /&gt;
   {{Game|SimCity 2000}}&lt;br /&gt;
   {{Game|Wacky Wheels}}&lt;br /&gt;
   {{Game|Where In the World Is Carmen Sandiego?}}&lt;br /&gt;
}}&lt;br /&gt;
The &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;M&amp;lt;/u&amp;gt;usical &amp;lt;u&amp;gt;I&amp;lt;/u&amp;gt;nstrument &amp;lt;u&amp;gt;D&amp;lt;/u&amp;gt;igital &amp;lt;u&amp;gt;I&amp;lt;/u&amp;gt;nterface (MIDI) file format&amp;lt;/b&amp;gt; is used for storing the notes required to accurately reproduce a song.  Commercial instruments are available that &amp;quot;speak&amp;quot; the MIDI protocol, and a MIDI file (.mid) simply stores the data sent over the wire, with a few headers on the front.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
A MIDI file starts with an overall &#039;&#039;MThd&#039;&#039; header, followed by one or more &#039;&#039;MTrk&#039;&#039; headers for each &amp;quot;track&amp;quot; (a track is normally created for each instrument, for simplicity when the song is being composed.)&lt;br /&gt;
&lt;br /&gt;
=== MThd Header ===&lt;br /&gt;
The file begins with a header:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|BYTE[4]||cSignature||&amp;quot;MThd&amp;quot; (not NULL-terminated)&lt;br /&gt;
|-&lt;br /&gt;
|UINT32BE||iLength||Length of MThd block (usually 6)&lt;br /&gt;
|-&lt;br /&gt;
|UINT16BE||iType||0, 1 or 2 (for format-0, 1 or 2)&lt;br /&gt;
|-&lt;br /&gt;
|UINT16BE||iNumTracks||Number of tracks (will be 1 for format-0)&lt;br /&gt;
|-&lt;br /&gt;
|UINT16BE||iTicksPerQuarterNote||Number of MIDI delay ticks in a quarter-note&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If the high bit in &amp;lt;tt&amp;gt;iTicksPerQuarterNote&amp;lt;/tt&amp;gt; is set (0x8000) then the file uses SMPTE timing instead, which is rare and not covered here.&lt;br /&gt;
&lt;br /&gt;
=== MTrk block ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;MTrk&#039;&#039; block is repeated once for each track in the song (the &#039;&#039;&#039;iNumTracks&#039;&#039;&#039; field in the MThd header.)&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|BYTE[4]||cSignature||&amp;quot;MTrk&amp;quot; (not NULL-terminated)&lt;br /&gt;
|-&lt;br /&gt;
|UINT32BE||iLength||Length of block&lt;br /&gt;
|-&lt;br /&gt;
|BYTE[iLength]||cData||MIDI data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== MIDI data ===&lt;br /&gt;
&lt;br /&gt;
The MIDI data consists of a delay value (in MIDI variable-length integer notation), followed by a MIDI event byte (see [[#MIDI events]] below.)  The event data follows, and will be different depending on the event.  It then starts again with the delay value for the next event.&lt;br /&gt;
&lt;br /&gt;
==== MIDI lengths ====&lt;br /&gt;
&lt;br /&gt;
MIDI lengths are stored as variable length integers, between one and four bytes long.  Each byte only uses the lower 7-bits, with the MSB set if there is another length byte following.  The bytes are in big endian order.  Some examples of these length bytes are:&lt;br /&gt;
&lt;br /&gt;
  50      // Hex value 0x50&lt;br /&gt;
  81 50   // Hex value 0xD0 ((0x81 &amp;amp; 0x7F) &amp;lt;&amp;lt; 7) | (0x50 &amp;amp; 0x7F)&lt;br /&gt;
&lt;br /&gt;
Here is some C code to read these values:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
const char *midi_data = &amp;quot;\x81\x50&amp;quot;;&lt;br /&gt;
unsigned long val = 0;&lt;br /&gt;
&lt;br /&gt;
for (int i = 0; i &amp;lt; 4; i++) {&lt;br /&gt;
&lt;br /&gt;
	// Include the lower 7-bits of this byte into the value&lt;br /&gt;
	val |= midi_data[i] &amp;amp; 0x7F;&lt;br /&gt;
&lt;br /&gt;
	// If the high bit is set, shift the value up&lt;br /&gt;
	// seven bits to make room for the next value&lt;br /&gt;
	if (midi_data[i] &amp;amp; 0x80) val &amp;lt;&amp;lt;= 7;&lt;br /&gt;
	else break; // High bit unset means end of value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
printf(&amp;quot;Value is %lu\n&amp;quot;, val);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Generally speaking, MIDI data that can be sent over the wire uses these values (e.g. delays), whereas data only used to write .mid files on disk (e.g. MTrk lengths in bytes) use normal big-endian fixed-length values.&lt;br /&gt;
&lt;br /&gt;
==== MIDI events ====&lt;br /&gt;
&lt;br /&gt;
This table lists the different MIDI events that can occur in a song.  The events are listed as channel zero (e.g. 0x80, which would become 0x85 for channel five.)  Removing the high bit (&amp;lt;code&amp;gt;(byte &amp;amp; 0x7F) &amp;gt;&amp;gt; 4&amp;lt;/code&amp;gt;) will give the &#039;event number&#039;.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Register value!!Event number!!Data size!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|0x80||0||2||Note off&lt;br /&gt;
|-&lt;br /&gt;
|0x90||1||2||Note on&lt;br /&gt;
|-&lt;br /&gt;
|0xA0||2||2||Polyphonic key pressure&lt;br /&gt;
|-&lt;br /&gt;
|0xB0||3||2||Controller&lt;br /&gt;
|-&lt;br /&gt;
|0xC0||4||1||Instrument change&lt;br /&gt;
|-&lt;br /&gt;
|0xD0||5||1||Channel pressure&lt;br /&gt;
|-&lt;br /&gt;
|0xE0||6||2||Pitch bend&lt;br /&gt;
|-&lt;br /&gt;
|0xF0||7||Any||Sysex&lt;br /&gt;
|-&lt;br /&gt;
|0xFF||N/A||Any||Meta-event&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The data bytes for each event are described in the sections below.&lt;br /&gt;
&lt;br /&gt;
Each event is preceded by a delay (as a MIDILEN variable-length integer, see [[#MIDI lengths]] above) which specifies the number of MIDI ticks until the event should be actioned.&lt;br /&gt;
&lt;br /&gt;
To convert the number of MIDI ticks into a usable time value, the &amp;lt;tt&amp;gt;iTicksPerQuarterNote&amp;lt;/tt&amp;gt; field from the header will allow the tick count to be converted into a fractional number of quarter notes, then the song&#039;s tempo (in microseconds per quarter note) will allow this fractional number of quarter notes to be converted into microseconds.&lt;br /&gt;
&lt;br /&gt;
The default tempo of 500,000 microseconds per quarter note applies until overridden by a [[#0x51: Set tempo|set-tempo]] event.&lt;br /&gt;
&lt;br /&gt;
===== Running-status =====&lt;br /&gt;
&lt;br /&gt;
Any event values without the high-bit set (i.e. less than 0x80) are so-called &amp;quot;running status&amp;quot; values.  If one of these bytes is encountered as a MIDI event, it is actually the first data byte of the event instead.  The actual event is the same as the previous one.  For example, these two lines are equivalent: (delay bytes omitted for clarity)&lt;br /&gt;
&lt;br /&gt;
 90 40 7F   91 44 7F   91 47 7F   81 44 7F  (full syntax)&lt;br /&gt;
 90 40 7F   91 44 7F      47 7F      44 00  (with running status)&lt;br /&gt;
&lt;br /&gt;
This means:&lt;br /&gt;
* 90 40 7F: Turn note 0x40 on channel 0 at maximum velocity&lt;br /&gt;
* 91 44 7F: Then turn note 0x44 on channel 1 at maximum velocity&lt;br /&gt;
* 47 7F: Turn note 0x47 on the same channel (running status means use event 0x91 from before)&lt;br /&gt;
* 44 00: Turn note 0x44 off on the same channel (running status uses event 0x91 again, and takes advantage of note-on at zero velocity being the same as note-off)&lt;br /&gt;
&lt;br /&gt;
Meta-events do not affect running status, so any event from 0xF0 to 0xFF can appear in the middle of data without affecting the running status.  For example the following line is equivalent to the two lines above:&lt;br /&gt;
&lt;br /&gt;
 90 40 7F   91 44 7F   FF 01 02 AA BB   47 7F   F0 02 AA F7   44 00&lt;br /&gt;
&lt;br /&gt;
===== 0x80: Note off =====&lt;br /&gt;
Stops the specified note from sounding on this channel.  Does not affect any other notes currently being played on the same channel.  A note-on event with a velocity of zero is the same as a note-off event.&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iNote||MIDI note number to key-off (0-127)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iVelocity||How hard to release the note (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== 0x90: Note on =====&lt;br /&gt;
Plays the specified note on the given channel.  Multiple notes can be sounding at the same time on the same channel.  A velocity of zero is the same as a note-off event (this is often used with running status to minimise the amount of data used.)&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iNote||MIDI note number to key-on (0-127)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iVelocity||How hard to press the note (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== 0xA0: Polyphonic key pressure =====&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iPressure||Pressure value (0-127)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iNote||MIDI note number to affect (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Like [[#0xD0: Channel pressure|channel pressure]], but applies to individual notes on the channel.&lt;br /&gt;
&lt;br /&gt;
===== 0xB0: Controller =====&lt;br /&gt;
Set a MIDI controller to the specified value.  TODO: List of standard controllers&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iController||Controller index (0-127)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iValue||Value to set (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== 0xC0: Instrument change =====&lt;br /&gt;
Set the channel to the specified instrument.&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iInstrument||Instrument number (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== 0xD0: Channel pressure =====&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iPressure||Pressure value (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Also known as &amp;quot;channel aftertouch&amp;quot;, it is designed for instruments that can have their volume/intensity changed after the initial velocity set in the note-on event, such as woodwind instruments where a note can start softly and then become louder.  The exact meaning is implementation-defined.  For example, this event may set the volume of the notes currently playing on the channel in a similar way as velocity in a note-on event, but other possibilites include applying a filter change or vibrato to the notes.&lt;br /&gt;
&lt;br /&gt;
===== 0xE0: Pitch bend =====&lt;br /&gt;
Bend all notes on the channel up or down by the specified amount.  The value is between 0 and 16384.  The value 8192 is in the middle and means no bend, thus 8192 can be subtracted from this the value to create a signed integer between -8192 and +8191, with zero meaning &amp;quot;no bend.&amp;quot;  The actual pitch resulting from the bend depends on the range, which is set (usually at the start of the song) by a MIDI controller message.&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iLSB||Least significant byte (0-127)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iMSB||Most significant byte (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The value is calculated by combining the lower seven bits from each of the two bytes into a single 14-bit value: &amp;lt;code&amp;gt;value = (iMSB &amp;lt;&amp;lt; 7) | iLSB&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== 0xF0: System exclusive =====&lt;br /&gt;
These messages are used to send proprietary commands to various MIDI devices.  They are essentially a list of raw bytes to send.  The channel is not used, so 0xF0 through 0xFF are different &amp;quot;sysex&amp;quot; messages.  Since 0xFF is used as a reset it would have no use in a .mid file on disk, so this event is used for meta-events described below.&lt;br /&gt;
&lt;br /&gt;
The event type (0xF0 to 0xFE) is followed by this structure:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|MIDILEN iLength||Length of data&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 cData[iLength]||Block of data, iLength bytes long&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Event 0xFF has a different structure and is covered below.  The event types are defined as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Event type!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|0xF0||Start system exclusive event&lt;br /&gt;
|-&lt;br /&gt;
|0xF1||MIDI time code&lt;br /&gt;
|-&lt;br /&gt;
|0xF2||Song position pointer&lt;br /&gt;
|-&lt;br /&gt;
|0xF3||Song select&lt;br /&gt;
|-&lt;br /&gt;
|0xF4||(Unused)&lt;br /&gt;
|-&lt;br /&gt;
|0xF5||(Unused)&lt;br /&gt;
|-&lt;br /&gt;
|0xF6||Tune request&lt;br /&gt;
|-&lt;br /&gt;
|0xF7||End system exclusive event (EOX)&lt;br /&gt;
|-&lt;br /&gt;
|0xF8||Timing clock&lt;br /&gt;
|-&lt;br /&gt;
|0xF9||(Unused)&lt;br /&gt;
|-&lt;br /&gt;
|0xFA||Start playback&lt;br /&gt;
|-&lt;br /&gt;
|0xFB||Continue playback&lt;br /&gt;
|-&lt;br /&gt;
|0xFC||Stop playback&lt;br /&gt;
|-&lt;br /&gt;
|0xFD||(Unused)&lt;br /&gt;
|-&lt;br /&gt;
|0xFE||Active sensing&lt;br /&gt;
|-&lt;br /&gt;
|0xFF||System reset (used for meta-event in a MIDI file)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Meta events ====&lt;br /&gt;
&lt;br /&gt;
Meta events are events specific to MIDI files themselves.  They are not transmitted to MIDI devices.  A meta event is signalled by the 0xFF system exclusive event.  The following table lists the format of the bytes following the 0xFF.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iType||Meta-event type&lt;br /&gt;
|-&lt;br /&gt;
|MIDILEN iLength||Length of event data&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 cData[iLength]||Event data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following section lists the meaning of various values of &amp;lt;tt&amp;gt;iType&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== 0x01 - 0x0F: Text =====&lt;br /&gt;
These events set various types of text.  The event data is the text to set.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Event type!!Text use&lt;br /&gt;
|-&lt;br /&gt;
|0x01||Generic text event.  Often the first text event in a song is used as its title.&lt;br /&gt;
|-&lt;br /&gt;
|0x02||Copyright notice&lt;br /&gt;
|-&lt;br /&gt;
|0x03||Track name.  Often the first event (format-0) or the first track (format-1) is the song title.&lt;br /&gt;
|-&lt;br /&gt;
|0x04||Instrument name&lt;br /&gt;
|-&lt;br /&gt;
|0x05||Lyric&lt;br /&gt;
|-&lt;br /&gt;
|0x06||Marker&lt;br /&gt;
|-&lt;br /&gt;
|0x07||Cue point (e.g. stage instructions)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== 0x2F: End of track =====&lt;br /&gt;
Mandatory event at the end of each MTrk track.  The length field is always zero, so there are no bytes of event data.&lt;br /&gt;
&lt;br /&gt;
===== 0x51: Set tempo =====&lt;br /&gt;
This event should always have a length of three.  The event data is a big-endian integer (&#039;&#039;&#039;not&#039;&#039;&#039; in MIDI variable-length notation) indicating the number of microseconds in a quarter note.  Together with the &amp;lt;tt&amp;gt;iTicksPerQuarterNote&amp;lt;/tt&amp;gt; value from the header, this allows MIDI ticks to be converted into microseconds for correct playback speed of the MIDI file.&lt;br /&gt;
&lt;br /&gt;
Unless overridden by this event, the number of microseconds in a quarter note defaults to 500,000.&lt;br /&gt;
&lt;br /&gt;
===== 0x7F: Manufacturer-specific =====&lt;br /&gt;
The first data byte of this event is a manufacturer ID.  If it is 0x00, then the following [[UINT16BE]] is the actual manufacturer ID.  This means either one or three bytes total will be read to obtain the manufacturer ID.&lt;br /&gt;
&lt;br /&gt;
If the manufacturer ID is 0x3F then it is an Ad Lib, Inc. event, and the file format is technically &amp;lt;tt&amp;gt;.mdi&amp;lt;/tt&amp;gt; (an Ad Lib MIDI file with embedded OPL instruments), see [[MDI Format]] for details.&lt;br /&gt;
&lt;br /&gt;
===== Additional meta-events =====&lt;br /&gt;
&lt;br /&gt;
Other meta-events (not so important for playing back game music) are listed on various web sites:&lt;br /&gt;
&lt;br /&gt;
* http://www.omega-art.com/midi/mfiles.html#meta&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
* [[DRO2MIDI]] - converts .dro files into [[MID Format|.mid files]]&lt;br /&gt;
&lt;br /&gt;
== Similar formats ==&lt;br /&gt;
* [[MDI Format|MDI files]] have the same container format, but with different event specification.&lt;br /&gt;
* [[CMF Format|CMF files]] store their song data in MIDI format.&lt;br /&gt;
* [[MUS Format|MUS files]] are single-track MIDI files made by id Software.&lt;br /&gt;
* [[XMI Format|XMI files]] are Extended MIDI files.&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* https://web.archive.org/web/20070104033706/http://www.cybermuff.cz/music/MIDIspec.htm - great reference for the MIDI spec&lt;br /&gt;
&lt;br /&gt;
[[Category:Build engine]]&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=MID_Format&amp;diff=9181</id>
		<title>MID Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=MID_Format&amp;diff=9181"/>
		<updated>2020-10-15T16:41:06Z</updated>

		<summary type="html">&lt;p&gt;Saga: Clarify that channel pressure behaviour is not standardized&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = MIDI&lt;br /&gt;
 | Instruments = MIDI&lt;br /&gt;
 | NumChannels = 16&lt;br /&gt;
 | NumTracks = 65535&lt;br /&gt;
 | NumPatterns = 1&lt;br /&gt;
 | NumOrders = 0&lt;br /&gt;
 | Tags = Text events&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Blood}}&lt;br /&gt;
   {{Game|Boppin&#039;}}&lt;br /&gt;
   {{Game|Duke Nukem 3D}}&lt;br /&gt;
   {{Game|Hi Octane}}&lt;br /&gt;
   {{Game|Hocus Pocus}}&lt;br /&gt;
   {{Game|Magic Pockets}}&lt;br /&gt;
   {{Game|Prince of Persia}}&lt;br /&gt;
   {{Game|Rise of the Triad}}&lt;br /&gt;
   {{Game|Sango Fighter}}&lt;br /&gt;
   {{Game|Shadow Warrior}}&lt;br /&gt;
   {{Game|SimCity 2000}}&lt;br /&gt;
   {{Game|Wacky Wheels}}&lt;br /&gt;
   {{Game|Where In the World Is Carmen Sandiego?}}&lt;br /&gt;
}}&lt;br /&gt;
The &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;M&amp;lt;/u&amp;gt;usical &amp;lt;u&amp;gt;I&amp;lt;/u&amp;gt;nstrument &amp;lt;u&amp;gt;D&amp;lt;/u&amp;gt;igital &amp;lt;u&amp;gt;I&amp;lt;/u&amp;gt;nterface (MIDI) file format&amp;lt;/b&amp;gt; is used for storing the notes required to accurately reproduce a song.  Commercial instruments are available that &amp;quot;speak&amp;quot; the MIDI protocol, and a MIDI file (.mid) simply stores the data sent over the wire, with a few headers on the front.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
A MIDI file starts with an overall &#039;&#039;MThd&#039;&#039; header, followed by one or more &#039;&#039;MTrk&#039;&#039; headers for each &amp;quot;track&amp;quot; (a track is normally created for each instrument, for simplicity when the song is being composed.)&lt;br /&gt;
&lt;br /&gt;
=== MThd Header ===&lt;br /&gt;
The file begins with a header:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|BYTE[4]||cSignature||&amp;quot;MThd&amp;quot; (not NULL-terminated)&lt;br /&gt;
|-&lt;br /&gt;
|UINT32BE||iLength||Length of MThd block (usually 6)&lt;br /&gt;
|-&lt;br /&gt;
|UINT16BE||iType||0, 1 or 2 (for format-0, 1 or 2)&lt;br /&gt;
|-&lt;br /&gt;
|UINT16BE||iNumTracks||Number of tracks (will be 1 for format-0)&lt;br /&gt;
|-&lt;br /&gt;
|UINT16BE||iTicksPerQuarterNote||Number of MIDI delay ticks in a quarter-note&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If the high bit in &amp;lt;tt&amp;gt;iTicksPerQuarterNote&amp;lt;/tt&amp;gt; is set (0x8000) then the file uses SMPTE timing instead, which is rare and not covered here.&lt;br /&gt;
&lt;br /&gt;
=== MTrk block ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;MTrk&#039;&#039; block is repeated once for each track in the song (the &#039;&#039;&#039;iNumTracks&#039;&#039;&#039; field in the MThd header.)&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|BYTE[4]||cSignature||&amp;quot;MTrk&amp;quot; (not NULL-terminated)&lt;br /&gt;
|-&lt;br /&gt;
|UINT32BE||iLength||Length of block&lt;br /&gt;
|-&lt;br /&gt;
|BYTE[iLength]||cData||MIDI data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== MIDI data ===&lt;br /&gt;
&lt;br /&gt;
The MIDI data consists of a delay value (in MIDI variable-length integer notation), followed by a MIDI event byte (see [[#MIDI events]] below.)  The event data follows, and will be different depending on the event.  It then starts again with the delay value for the next event.&lt;br /&gt;
&lt;br /&gt;
==== MIDI lengths ====&lt;br /&gt;
&lt;br /&gt;
MIDI lengths are stored as variable length integers, between one and four bytes long.  Each byte only uses the lower 7-bits, with the MSB set if there is another length byte following.  The bytes are in big endian order.  Some examples of these length bytes are:&lt;br /&gt;
&lt;br /&gt;
  50      // Hex value 0x50&lt;br /&gt;
  81 50   // Hex value 0xD0 ((0x81 &amp;amp; 0x7F) &amp;lt;&amp;lt; 7) | (0x50 &amp;amp; 0x7F)&lt;br /&gt;
&lt;br /&gt;
Here is some C code to read these values:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
const char *midi_data = &amp;quot;\x81\x50&amp;quot;;&lt;br /&gt;
unsigned long val = 0;&lt;br /&gt;
&lt;br /&gt;
for (int i = 0; i &amp;lt; 4; i++) {&lt;br /&gt;
&lt;br /&gt;
	// Include the lower 7-bits of this byte into the value&lt;br /&gt;
	val |= midi_data[i] &amp;amp; 0x7F;&lt;br /&gt;
&lt;br /&gt;
	// If the high bit is set, shift the value up&lt;br /&gt;
	// seven bits to make room for the next value&lt;br /&gt;
	if (midi_data[i] &amp;amp; 0x80) val &amp;lt;&amp;lt;= 7;&lt;br /&gt;
	else break; // High bit unset means end of value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
printf(&amp;quot;Value is %lu\n&amp;quot;, val);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Generally speaking, MIDI data that can be sent over the wire uses these values (e.g. delays), whereas data only used to write .mid files on disk (e.g. MTrk lengths in bytes) use normal big-endian fixed-length values.&lt;br /&gt;
&lt;br /&gt;
==== MIDI events ====&lt;br /&gt;
&lt;br /&gt;
This table lists the different MIDI events that can occur in a song.  The events are listed as channel zero (e.g. 0x80, which would become 0x85 for channel five.)  Removing the high bit (&amp;lt;code&amp;gt;(byte &amp;amp; 0x7F) &amp;gt;&amp;gt; 4&amp;lt;/code&amp;gt;) will give the &#039;event number&#039;.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Register value!!Event number!!Data size!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|0x80||0||2||Note off&lt;br /&gt;
|-&lt;br /&gt;
|0x90||1||2||Note on&lt;br /&gt;
|-&lt;br /&gt;
|0xA0||2||2||Polyphonic key pressure&lt;br /&gt;
|-&lt;br /&gt;
|0xB0||3||2||Controller&lt;br /&gt;
|-&lt;br /&gt;
|0xC0||4||1||Instrument change&lt;br /&gt;
|-&lt;br /&gt;
|0xD0||5||1||Channel pressure&lt;br /&gt;
|-&lt;br /&gt;
|0xE0||6||2||Pitch bend&lt;br /&gt;
|-&lt;br /&gt;
|0xF0||7||Any||Sysex&lt;br /&gt;
|-&lt;br /&gt;
|0xFF||N/A||Any||Meta-event&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The data bytes for each event are described in the sections below.&lt;br /&gt;
&lt;br /&gt;
Each event is preceded by a delay (as a MIDILEN variable-length integer, see [[#MIDI lengths]] above) which specifies the number of MIDI ticks until the event should be actioned.&lt;br /&gt;
&lt;br /&gt;
To convert the number of MIDI ticks into a usable time value, the &amp;lt;tt&amp;gt;iTicksPerQuarterNote&amp;lt;/tt&amp;gt; field from the header will allow the tick count to be converted into a fractional number of quarter notes, then the song&#039;s tempo (in microseconds per quarter note) will allow this fractional number of quarter notes to be converted into microseconds.&lt;br /&gt;
&lt;br /&gt;
The default tempo of 500,000 microseconds per quarter note applies until overridden by a [[#0x51: Set tempo|set-tempo]] event.&lt;br /&gt;
&lt;br /&gt;
===== Running-status =====&lt;br /&gt;
&lt;br /&gt;
Any event values without the high-bit set (i.e. less than 0x80) are so-called &amp;quot;running status&amp;quot; values.  If one of these bytes is encountered as a MIDI event, it is actually the first data byte of the event instead.  The actual event is the same as the previous one.  For example, these two lines are equivalent: (delay bytes omitted for clarity)&lt;br /&gt;
&lt;br /&gt;
 90 40 7F   91 44 7F   91 47 7F   81 44 7F  (full syntax)&lt;br /&gt;
 90 40 7F   91 44 7F      47 7F      44 00  (with running status)&lt;br /&gt;
&lt;br /&gt;
This means:&lt;br /&gt;
* 90 40 7F: Turn note 0x40 on channel 0 at maximum velocity&lt;br /&gt;
* 91 44 7F: Then turn note 0x44 on channel 1 at maximum velocity&lt;br /&gt;
* 47 7F: Turn note 0x47 on the same channel (running status means use event 0x91 from before)&lt;br /&gt;
* 44 00: Turn note 0x44 off on the same channel (running status uses event 0x91 again, and takes advantage of note-on at zero velocity being the same as note-off)&lt;br /&gt;
&lt;br /&gt;
Meta-events do not affect running status, so any event from 0xF0 to 0xFF can appear in the middle of data without affecting the running status.  For example the following line is equivalent to the two lines above:&lt;br /&gt;
&lt;br /&gt;
 90 40 7F   91 44 7F   FF 01 02 AA BB   47 7F   F0 02 AA F7   44 00&lt;br /&gt;
&lt;br /&gt;
===== 0x80: Note off =====&lt;br /&gt;
Stops the specified note from sounding on this channel.  Does not affect any other notes currently being played on the same channel.  A note-on event with a velocity of zero is the same as a note-off event.&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iNote||MIDI note number to key-off (0-127)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iVelocity||How hard to release the note (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== 0x90: Note on =====&lt;br /&gt;
Plays the specified note on the given channel.  Multiple notes can be sounding at the same time on the same channel.  A velocity of zero is the same as a note-off event (this is often used with running status to minimise the amount of data used.)&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iNote||MIDI note number to key-on (0-127)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iVelocity||How hard to press the note (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== 0xA0: Polyphonic key pressure =====&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iPressure||Pressure value (0-127)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iNote||MIDI note number to affect (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== 0xB0: Controller =====&lt;br /&gt;
Set a MIDI controller to the specified value.  TODO: List of standard controllers&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iController||Controller index (0-127)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iValue||Value to set (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== 0xC0: Instrument change =====&lt;br /&gt;
Set the channel to the specified instrument.&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iInstrument||Instrument number (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== 0xD0: Channel pressure =====&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iPressure||Pressure value (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Also known as &amp;quot;channel aftertouch&amp;quot;, it is designed for instruments that can have their volume/intensity changed after the initial velocity set in the note-on event, such as woodwind instruments where a note can start softly and then become louder.  The exact meaning is implementation-defined.  For example, this event may set the volume of the notes currently playing on the channel in a similar way as velocity in a note-on event, but other possibilites include applying a filter change or vibrato to the notes.&lt;br /&gt;
&lt;br /&gt;
===== 0xE0: Pitch bend =====&lt;br /&gt;
Bend all notes on the channel up or down by the specified amount.  The value is between 0 and 16384.  The value 8192 is in the middle and means no bend, thus 8192 can be subtracted from this the value to create a signed integer between -8192 and +8191, with zero meaning &amp;quot;no bend.&amp;quot;  The actual pitch resulting from the bend depends on the range, which is set (usually at the start of the song) by a MIDI controller message.&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iLSB||Least significant byte (0-127)&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iMSB||Most significant byte (0-127)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The value is calculated by combining the lower seven bits from each of the two bytes into a single 14-bit value: &amp;lt;code&amp;gt;value = (iMSB &amp;lt;&amp;lt; 7) | iLSB&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== 0xF0: System exclusive =====&lt;br /&gt;
These messages are used to send proprietary commands to various MIDI devices.  They are essentially a list of raw bytes to send.  The channel is not used, so 0xF0 through 0xFF are different &amp;quot;sysex&amp;quot; messages.  Since 0xFF is used as a reset it would have no use in a .mid file on disk, so this event is used for meta-events described below.&lt;br /&gt;
&lt;br /&gt;
The event type (0xF0 to 0xFE) is followed by this structure:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|MIDILEN iLength||Length of data&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 cData[iLength]||Block of data, iLength bytes long&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Event 0xFF has a different structure and is covered below.  The event types are defined as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Event type!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|0xF0||Start system exclusive event&lt;br /&gt;
|-&lt;br /&gt;
|0xF1||MIDI time code&lt;br /&gt;
|-&lt;br /&gt;
|0xF2||Song position pointer&lt;br /&gt;
|-&lt;br /&gt;
|0xF3||Song select&lt;br /&gt;
|-&lt;br /&gt;
|0xF4||(Unused)&lt;br /&gt;
|-&lt;br /&gt;
|0xF5||(Unused)&lt;br /&gt;
|-&lt;br /&gt;
|0xF6||Tune request&lt;br /&gt;
|-&lt;br /&gt;
|0xF7||End system exclusive event (EOX)&lt;br /&gt;
|-&lt;br /&gt;
|0xF8||Timing clock&lt;br /&gt;
|-&lt;br /&gt;
|0xF9||(Unused)&lt;br /&gt;
|-&lt;br /&gt;
|0xFA||Start playback&lt;br /&gt;
|-&lt;br /&gt;
|0xFB||Continue playback&lt;br /&gt;
|-&lt;br /&gt;
|0xFC||Stop playback&lt;br /&gt;
|-&lt;br /&gt;
|0xFD||(Unused)&lt;br /&gt;
|-&lt;br /&gt;
|0xFE||Active sensing&lt;br /&gt;
|-&lt;br /&gt;
|0xFF||System reset (used for meta-event in a MIDI file)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Meta events ====&lt;br /&gt;
&lt;br /&gt;
Meta events are events specific to MIDI files themselves.  They are not transmitted to MIDI devices.  A meta event is signalled by the 0xFF system exclusive event.  The following table lists the format of the bytes following the 0xFF.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data bytes!!Purpose&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 iType||Meta-event type&lt;br /&gt;
|-&lt;br /&gt;
|MIDILEN iLength||Length of event data&lt;br /&gt;
|-&lt;br /&gt;
|UINT8 cData[iLength]||Event data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following section lists the meaning of various values of &amp;lt;tt&amp;gt;iType&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===== 0x01 - 0x0F: Text =====&lt;br /&gt;
These events set various types of text.  The event data is the text to set.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Event type!!Text use&lt;br /&gt;
|-&lt;br /&gt;
|0x01||Generic text event.  Often the first text event in a song is used as its title.&lt;br /&gt;
|-&lt;br /&gt;
|0x02||Copyright notice&lt;br /&gt;
|-&lt;br /&gt;
|0x03||Track name.  Often the first event (format-0) or the first track (format-1) is the song title.&lt;br /&gt;
|-&lt;br /&gt;
|0x04||Instrument name&lt;br /&gt;
|-&lt;br /&gt;
|0x05||Lyric&lt;br /&gt;
|-&lt;br /&gt;
|0x06||Marker&lt;br /&gt;
|-&lt;br /&gt;
|0x07||Cue point (e.g. stage instructions)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===== 0x2F: End of track =====&lt;br /&gt;
Mandatory event at the end of each MTrk track.  The length field is always zero, so there are no bytes of event data.&lt;br /&gt;
&lt;br /&gt;
===== 0x51: Set tempo =====&lt;br /&gt;
This event should always have a length of three.  The event data is a big-endian integer (&#039;&#039;&#039;not&#039;&#039;&#039; in MIDI variable-length notation) indicating the number of microseconds in a quarter note.  Together with the &amp;lt;tt&amp;gt;iTicksPerQuarterNote&amp;lt;/tt&amp;gt; value from the header, this allows MIDI ticks to be converted into microseconds for correct playback speed of the MIDI file.&lt;br /&gt;
&lt;br /&gt;
Unless overridden by this event, the number of microseconds in a quarter note defaults to 500,000.&lt;br /&gt;
&lt;br /&gt;
===== 0x7F: Manufacturer-specific =====&lt;br /&gt;
The first data byte of this event is a manufacturer ID.  If it is 0x00, then the following [[UINT16BE]] is the actual manufacturer ID.  This means either one or three bytes total will be read to obtain the manufacturer ID.&lt;br /&gt;
&lt;br /&gt;
If the manufacturer ID is 0x3F then it is an Ad Lib, Inc. event, and the file format is technically &amp;lt;tt&amp;gt;.mdi&amp;lt;/tt&amp;gt; (an Ad Lib MIDI file with embedded OPL instruments), see [[MDI Format]] for details.&lt;br /&gt;
&lt;br /&gt;
===== Additional meta-events =====&lt;br /&gt;
&lt;br /&gt;
Other meta-events (not so important for playing back game music) are listed on various web sites:&lt;br /&gt;
&lt;br /&gt;
* http://www.omega-art.com/midi/mfiles.html#meta&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
* [[DRO2MIDI]] - converts .dro files into [[MID Format|.mid files]]&lt;br /&gt;
&lt;br /&gt;
== Similar formats ==&lt;br /&gt;
* [[MDI Format|MDI files]] have the same container format, but with different event specification.&lt;br /&gt;
* [[CMF Format|CMF files]] store their song data in MIDI format.&lt;br /&gt;
* [[MUS Format|MUS files]] are single-track MIDI files made by id Software.&lt;br /&gt;
* [[XMI Format|XMI files]] are Extended MIDI files.&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* https://web.archive.org/web/20070104033706/http://www.cybermuff.cz/music/MIDIspec.htm - great reference for the MIDI spec&lt;br /&gt;
&lt;br /&gt;
[[Category:Build engine]]&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Karl_Morton_Music_Format&amp;diff=9178</id>
		<title>Karl Morton Music Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Karl_Morton_Music_Format&amp;diff=9178"/>
		<updated>2020-10-14T21:30:46Z</updated>

		<summary type="html">&lt;p&gt;Saga: Add mod2mus&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 32 (only 4 usable in-game)&lt;br /&gt;
 | NumTracks = no limit&lt;br /&gt;
 | NumPatterns = n/a&lt;br /&gt;
 | NumOrders = n/a&lt;br /&gt;
 | Tags = Title, instrument names&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Psycho Pinball}}&lt;br /&gt;
   {{Game|Micro Machines 2}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The [[Karl Morton Music Format]] is the music format used by Karl Morton&#039;s sound engine used in the games [[Psycho Pinball]], [[Micro Machines 2]] and [[Back To Baghdad]], although the latter only uses its sound effect file format, not the music format. This is not the official name of the format, but as no official tooling or documentation seems to be available for this format, a simple name was chosen based on the sound engine author&#039;s name.&lt;br /&gt;
&lt;br /&gt;
In general, this format follows the semantics of the ProTracker MOD format. Knowledge of the MOD format and its features is assumed.&lt;br /&gt;
&lt;br /&gt;
A somewhat unique feature of this format is that subsongs can re-use samples with different metadata. For example, one song in a file might use a specific sample with a default volume of 64, while another song might reference the same sample data but with a default volume of 48. This allows for greater flexibility when reusing those samples between songs.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The format follows an IFF-like structure, but with no explicit file header (the file directly starts with the first chunk).&lt;br /&gt;
&lt;br /&gt;
=== Chunk Header ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][4] || ID || chunk ID (&amp;quot;SONG&amp;quot; or &amp;quot;SMPL&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || length || chunk length, including this header (so must be at least 8)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first chunk in the file must be a SONG chunk, apart from this the chunk order doesn&#039;t matter.&lt;br /&gt;
&lt;br /&gt;
Typically, SONG and SMPL chunks are interleaved, each SONG being followed by the SMPLs it adds to the sample pool shared between SONGs.&lt;br /&gt;
But this order should not be relied on.&lt;br /&gt;
&lt;br /&gt;
=== SONG chunk ===&lt;br /&gt;
&lt;br /&gt;
Each subsong is represented by its own SONG chunk.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][32] || song name || null-terminated song name&lt;br /&gt;
|-&lt;br /&gt;
| SAMPLE_REFERENCE[31] || sample map || maps song samples to those samples in the global sample pool&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][2] || unknown || always 0 (maybe just padding)&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] ||  number of channels || between 1 and 4 - file will be rejected if this is &amp;gt; 32. If it&#039;s more than 4 but less than 33 the extra channels will simply not be played.&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || restart position || byte offset into music data&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || size of music data || should be chunk size - 1108&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][] || music data || format is explained below&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;SAMPLE_REFERENCE&amp;lt;/tt&amp;gt; maps samples from the SMPL chunk pool to instrument numbers in the pattern editor (the first &amp;lt;tt&amp;gt;SAMPLE_REFERENCE&amp;lt;/tt&amp;gt; is instrument 1, and so on). It is defined as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][32] || sample name || must reference one of the SMPL chunks&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT8]] || MOD finetune || 0...15&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT8]] || default volume || 0...64&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Music data is basically one gigantic pattern and stored in row-major order (like most module formats).&lt;br /&gt;
The pattern is played in a strictly linear order, there are no jump commands or pattern loops.&lt;br /&gt;
There is per-channel state that stores the last used note, instrument, command and parameter as well as a repeat counter.&lt;br /&gt;
&lt;br /&gt;
To decode one pattern cell:&lt;br /&gt;
&lt;br /&gt;
* If repeat counter &amp;gt; 0: Decrement repeat counter by 1 and reuse note, instrument, command and parameter from previous row. Continue with next channel.&lt;br /&gt;
* Read [[UINT8]], let&#039;s name it NOTE.&lt;br /&gt;
* If (NOTE AND 0x80): Reuse note, instrument, command and parameter from previous row and set repeat counter to (NOTE AND 0x7F). Continue with next channel.&lt;br /&gt;
* If NOTE is between 1 and 36 (inclusively), it&#039;s a regular note (C-1 to B-3 in ProTracker), otherwise no note is present&lt;br /&gt;
* Read [[UINT8]], let&#039;s name it INSTRUMENT.&lt;br /&gt;
* Set instrument number in this cell to INSTRUMENT AND 0x1F&lt;br /&gt;
* If (INSTRUMENT AND 0x80): Repeat previous command and parameter for this channel&lt;br /&gt;
* Otherwise, read the two [[UINT8]]s, the command and parameter bytes.&lt;br /&gt;
* Continue with next channel.&lt;br /&gt;
&lt;br /&gt;
Command bytes and their translation to ProTracker MOD commands:&lt;br /&gt;
* &amp;lt;tt&amp;gt;00&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;Cxx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;01&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;EAx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;02&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;EBx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;03&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;E1x&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;04&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;E2x&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;05&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;E5x&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;06&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;9xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;07&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;3xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;08&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;5xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;09&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;4xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0A&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;6xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0B&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;0xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0C&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;1xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0D&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;2xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0E&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;Axx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0F&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;E9x&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;10&amp;lt;/tt&amp;gt;: Instant portamento (like 3FF but is always fully executed on first tick)&lt;br /&gt;
* &amp;lt;tt&amp;gt;11&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;ECx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;12&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;Fxx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;13&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;7xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;14&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;000&amp;lt;/tt&amp;gt; (empty command)&lt;br /&gt;
&lt;br /&gt;
Missing MOD effects are: 8, B, D, E3, E4, E5, E6, E7, E8, ED, EE, EF.&lt;br /&gt;
&lt;br /&gt;
Most commands that translate to extended Exy commands can take values &amp;gt; 0x0F as parameters (finetune command ignores high nibble).&lt;br /&gt;
&lt;br /&gt;
The player will jump to the restart position once the repeat counter of each channel has reached 0 and no bytes are left to be read.&lt;br /&gt;
&lt;br /&gt;
If no tempo is specified on the first row of the pattern, the MOD defaults of tempo 125 and 6 ticks per row are assumed.&lt;br /&gt;
&lt;br /&gt;
=== SMPL chunk ===&lt;br /&gt;
&lt;br /&gt;
Every sample is described by its own SMPL chunk.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][32] || sample name || null-terminated, referenced by SONG chunks&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || loop start || in bytes&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || size of sample data || should be chunk size - 48&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][] || sample data || in 8-bit signed mono PCM format&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that a SMPL can be shared between songs and use different finetune and volume values between songs.&lt;br /&gt;
&lt;br /&gt;
== A note on the string format ==&lt;br /&gt;
&lt;br /&gt;
The last character of sample names must be a null-terminator (the engine uses a string comparison not limited to 32 characters when matching samples).&amp;lt;br&amp;gt;&lt;br /&gt;
While it is not required by the engine, the following restrictions are proposed for newly created files to keep the life of developers easy that have to support dozens of files and may thus want to employ heuristics whether files are of a specific type:&lt;br /&gt;
It is suggested that all strings (i.e. instances of [[char]][32]) do not use byte values 1 to 31 (so only printable ASCII/ANSI), and after the first null terminator, the rest of the string has to be padded with nulls as well.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [https://openmpt.org/ OpenMPT]&lt;br /&gt;
| Platform = Windows&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Many&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = At the time of writing, OpenMPT 1.30 (which adds support for this format) is not released yet.&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [https://github.com/sagamusix/mod2mus mod2mus]&lt;br /&gt;
| Platform = Any&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = MOD&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = Converts 1-4 channel ProTracker MOD files to MUS&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
This file format was reverse-engineered by [[User:Saga|Saga]]. If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Karl_Morton_Music_Format&amp;diff=9177</id>
		<title>Karl Morton Music Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Karl_Morton_Music_Format&amp;diff=9177"/>
		<updated>2020-10-14T16:16:58Z</updated>

		<summary type="html">&lt;p&gt;Saga: Link data types&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 32 (only 4 usable in-game)&lt;br /&gt;
 | NumTracks = no limit&lt;br /&gt;
 | NumPatterns = n/a&lt;br /&gt;
 | NumOrders = n/a&lt;br /&gt;
 | Tags = Title, instrument names&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Psycho Pinball}}&lt;br /&gt;
   {{Game|Micro Machines 2}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The [[Karl Morton Music Format]] is the music format used by Karl Morton&#039;s sound engine used in the games [[Psycho Pinball]], [[Micro Machines 2]] and [[Back To Baghdad]], although the latter only uses its sound effect file format, not the music format. This is not the official name of the format, but as no official tooling or documentation seems to be available for this format, a simple name was chosen based on the sound engine author&#039;s name.&lt;br /&gt;
&lt;br /&gt;
In general, this format follows the semantics of the ProTracker MOD format. Knowledge of the MOD format and its features is assumed.&lt;br /&gt;
&lt;br /&gt;
A somewhat unique feature of this format is that subsongs can re-use samples with different metadata. For example, one song in a file might use a specific sample with a default volume of 64, while another song might reference the same sample data but with a default volume of 48. This allows for greater flexibility when reusing those samples between songs.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The format follows an IFF-like structure, but with no explicit file header (the file directly starts with the first chunk).&lt;br /&gt;
&lt;br /&gt;
=== Chunk Header ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][4] || ID || chunk ID (&amp;quot;SONG&amp;quot; or &amp;quot;SMPL&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || length || chunk length, including this header (so must be at least 8)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first chunk in the file must be a SONG chunk, apart from this the chunk order doesn&#039;t matter.&lt;br /&gt;
&lt;br /&gt;
Typically, SONG and SMPL chunks are interleaved, each SONG being followed by the SMPLs it adds to the sample pool shared between SONGs.&lt;br /&gt;
But this order should not be relied on.&lt;br /&gt;
&lt;br /&gt;
=== SONG chunk ===&lt;br /&gt;
&lt;br /&gt;
Each subsong is represented by its own SONG chunk.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][32] || song name || null-terminated song name&lt;br /&gt;
|-&lt;br /&gt;
| SAMPLE_REFERENCE[31] || sample map || maps song samples to those samples in the global sample pool&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][2] || unknown || always 0 (maybe just padding)&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] ||  number of channels || between 1 and 4 - file will be rejected if this is &amp;gt; 32. If it&#039;s more than 4 but less than 33 the extra channels will simply not be played.&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || restart position || byte offset into music data&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || size of music data || should be chunk size - 1108&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][] || music data || format is explained below&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;SAMPLE_REFERENCE&amp;lt;/tt&amp;gt; maps samples from the SMPL chunk pool to instrument numbers in the pattern editor (the first &amp;lt;tt&amp;gt;SAMPLE_REFERENCE&amp;lt;/tt&amp;gt; is instrument 1, and so on). It is defined as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][32] || sample name || must reference one of the SMPL chunks&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT8]] || MOD finetune || 0...15&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT8]] || default volume || 0...64&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Music data is basically one gigantic pattern and stored in row-major order (like most module formats).&lt;br /&gt;
The pattern is played in a strictly linear order, there are no jump commands or pattern loops.&lt;br /&gt;
There is per-channel state that stores the last used note, instrument, command and parameter as well as a repeat counter.&lt;br /&gt;
&lt;br /&gt;
To decode one pattern cell:&lt;br /&gt;
&lt;br /&gt;
* If repeat counter &amp;gt; 0: Decrement repeat counter by 1 and reuse note, instrument, command and parameter from previous row. Continue with next channel.&lt;br /&gt;
* Read [[UINT8]], let&#039;s name it NOTE.&lt;br /&gt;
* If (NOTE AND 0x80): Reuse note, instrument, command and parameter from previous row and set repeat counter to (NOTE AND 0x7F). Continue with next channel.&lt;br /&gt;
* If NOTE is between 1 and 36 (inclusively), it&#039;s a regular note (C-1 to B-3 in ProTracker), otherwise no note is present&lt;br /&gt;
* Read [[UINT8]], let&#039;s name it INSTRUMENT.&lt;br /&gt;
* Set instrument number in this cell to INSTRUMENT AND 0x1F&lt;br /&gt;
* If (INSTRUMENT AND 0x80): Repeat previous command and parameter for this channel&lt;br /&gt;
* Otherwise, read the two [[UINT8]]s, the command and parameter bytes.&lt;br /&gt;
* Continue with next channel.&lt;br /&gt;
&lt;br /&gt;
Command bytes and their translation to ProTracker MOD commands:&lt;br /&gt;
* &amp;lt;tt&amp;gt;00&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;Cxx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;01&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;EAx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;02&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;EBx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;03&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;E1x&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;04&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;E2x&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;05&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;E5x&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;06&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;9xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;07&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;3xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;08&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;5xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;09&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;4xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0A&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;6xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0B&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;0xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0C&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;1xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0D&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;2xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0E&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;Axx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0F&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;E9x&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;10&amp;lt;/tt&amp;gt;: Instant portamento (like 3FF but is always fully executed on first tick)&lt;br /&gt;
* &amp;lt;tt&amp;gt;11&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;ECx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;12&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;Fxx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;13&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;7xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;14&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;000&amp;lt;/tt&amp;gt; (empty command)&lt;br /&gt;
&lt;br /&gt;
Missing MOD effects are: 8, B, D, E3, E4, E5, E6, E7, E8, ED, EE, EF.&lt;br /&gt;
&lt;br /&gt;
Most commands that translate to extended Exy commands can take values &amp;gt; 0x0F as parameters (finetune command ignores high nibble).&lt;br /&gt;
&lt;br /&gt;
The player will jump to the restart position once the repeat counter of each channel has reached 0 and no bytes are left to be read.&lt;br /&gt;
&lt;br /&gt;
If no tempo is specified on the first row of the pattern, the MOD defaults of tempo 125 and 6 ticks per row are assumed.&lt;br /&gt;
&lt;br /&gt;
=== SMPL chunk ===&lt;br /&gt;
&lt;br /&gt;
Every sample is described by its own SMPL chunk.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][32] || sample name || null-terminated, referenced by SONG chunks&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || loop start || in bytes&lt;br /&gt;
|-&lt;br /&gt;
| [[UINT32LE]] || size of sample data || should be chunk size - 48&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][] || sample data || in 8-bit signed mono PCM format&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that a SMPL can be shared between songs and use different finetune and volume values between songs.&lt;br /&gt;
&lt;br /&gt;
== A note on the string format ==&lt;br /&gt;
&lt;br /&gt;
The last character of sample names must be a null-terminator (the engine uses a string comparison not limited to 32 characters when matching samples).&amp;lt;br&amp;gt;&lt;br /&gt;
While it is not required by the engine, the following restrictions are proposed for newly created files to keep the life of developers easy that have to support dozens of files and may thus want to employ heuristics whether files are of a specific type:&lt;br /&gt;
It is suggested that all strings (i.e. instances of [[char]][32]) do not use byte values 1 to 31 (so only printable ASCII/ANSI), and after the first null terminator, the rest of the string has to be padded with nulls as well.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[OpenMPT]]&lt;br /&gt;
| Platform = Windows&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Many&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = At the time of writing, OpenMPT 1.30 (which adds support for this format) is not released yet.&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
This file format was reverse-engineered by [[User:Saga|Saga]]. If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Karl_Morton_Music_Format&amp;diff=9176</id>
		<title>Karl Morton Music Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Karl_Morton_Music_Format&amp;diff=9176"/>
		<updated>2020-10-13T21:42:08Z</updated>

		<summary type="html">&lt;p&gt;Saga: Created page with &amp;quot;{{Music Infobox  | Type = Tracked  | Instruments = PCM  | NumChannels = 1-32 (only 4 usable in-game)  | NumTracks = no limit  | NumPatterns = n/a  | NumOrders = n/a  | Tags =...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 1-32 (only 4 usable in-game)&lt;br /&gt;
 | NumTracks = no limit&lt;br /&gt;
 | NumPatterns = n/a&lt;br /&gt;
 | NumOrders = n/a&lt;br /&gt;
 | Tags = Title, instrument names&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Psycho Pinball}}&lt;br /&gt;
   {{Game|Micro Machines 2}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The [[Karl Morton Music Format]] is the music format used by Karl Morton&#039;s sound engine used in the games [[Psycho Pinball]], [[Micro Machines 2]] and [[Back To Baghdad]], although the latter only uses its sound effect file format, not the music format. This is not the official name of the format, but as no official tooling or documentation seems to be available for this format, a simple name was chosen based on the sound engine author&#039;s name.&lt;br /&gt;
&lt;br /&gt;
In general, this format follows the semantics of the ProTracker MOD format. Knowledge of the MOD format and its features is assumed.&lt;br /&gt;
&lt;br /&gt;
A somewhat unique feature of this format is that subsongs can re-use samples with different metadata. For example, one song in a file might use a specific sample with a default volume of 64, while another song might reference the same sample data but with a default volume of 48. This allows for greater flexibility when reusing those samples between songs.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The format follows an IFF-like structure, but with no explicit file header (the file directly starts with the first chunk).&lt;br /&gt;
&lt;br /&gt;
=== Chunk Header ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || ID || chunk ID (&amp;quot;SONG&amp;quot; or &amp;quot;SMPL&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || chunk length, including this header (so must be at least 8)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first chunk in the file must be a SONG chunk, apart from this the chunk order doesn&#039;t matter.&lt;br /&gt;
&lt;br /&gt;
Typically, SONG and SMPL chunks are interleaved, each SONG being followed by the SMPLs it adds to the sample pool shared between SONGs.&lt;br /&gt;
But this order should not be relied on.&lt;br /&gt;
&lt;br /&gt;
=== SONG chunk ===&lt;br /&gt;
&lt;br /&gt;
Each subsong is represented by its own SONG chunk.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| char[32] || song name || Null-terminated song name&lt;br /&gt;
|-&lt;br /&gt;
| SAMPLE_REFERENCE[31] || sample map || maps song samples to those samples in the global sample pool&lt;br /&gt;
|-&lt;br /&gt;
| char[2] || unknown || always 0 (maybe just padding)&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE ||  number of channels || between 1 and 4 - file will be rejected if this is &amp;gt; 32. If it&#039;s more than 4 but less than 33 the extra channels will simply not be played.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || restart position || byte offset into music data&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || size of music data || should be chunk size - 1108&lt;br /&gt;
|-&lt;br /&gt;
| char[] || music data || format is explained below&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;SAMPLE_REFERENCE&amp;lt;/tt&amp;gt; maps samples from the SMPL chunk pool to instrument numbers in the pattern editor (the first &amp;lt;tt&amp;gt;SAMPLE_REFERENCE&amp;lt;/tt&amp;gt; is instrument 1, and so on). It is defined as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| char[32] || sample name || must reference one of the SMPL chunks&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || MOD finetune || 0...15&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || default volume || 0...64&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Music data is basically one gigantic pattern and stored in row-major order (like most module formats).&lt;br /&gt;
The pattern is played in a strictly linear order, there are no jump commands or pattern loops.&lt;br /&gt;
There is per-channel state that stores the last used note, instrument, command and parameter as well as a repeat counter.&lt;br /&gt;
&lt;br /&gt;
To decode one pattern cell:&lt;br /&gt;
&lt;br /&gt;
* If repeat counter &amp;gt; 0: Decrement repeat counter by 1 and reuse note, instrument, command and parameter from previous row. Continue with next channel.&lt;br /&gt;
* Read uint8, let&#039;s name it NOTE.&lt;br /&gt;
* If (NOTE AND 0x80): Reuse note, instrument, command and parameter from previous row and set repeat counter to (NOTE AND 0x7F). Continue with next channel.&lt;br /&gt;
* If NOTE is between 1 and 36 (inclusively), it&#039;s a regular note (C-1 to B-3 in ProTracker), otherwise no note is present&lt;br /&gt;
* Read uint8, let&#039;s name it INSTRUMENT.&lt;br /&gt;
* Set instrument number in this cell to INSTRUMENT AND 0x1F&lt;br /&gt;
* If (INSTRUMENT AND 0x80): Repeat previous command and parameter for this channel&lt;br /&gt;
* Otherwise, read the two uint8s, the command and parameter bytes.&lt;br /&gt;
* Continue with next channel.&lt;br /&gt;
&lt;br /&gt;
Command bytes and their translation to ProTracker MOD commands:&lt;br /&gt;
* &amp;lt;tt&amp;gt;00&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;Cxx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;01&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;EAx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;02&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;EBx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;03&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;E1x&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;04&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;E2x&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;05&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;E5x&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;06&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;9xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;07&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;3xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;08&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;5xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;09&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;4xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0A&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;6xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0B&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;0xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0C&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;1xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0D&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;2xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0E&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;Axx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;0F&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;E9x&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;10&amp;lt;/tt&amp;gt;: Instant portamento (like 3FF but is always fully executed on first tick)&lt;br /&gt;
* &amp;lt;tt&amp;gt;11&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;ECx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;12&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;Fxx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;13&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;7xx&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;14&amp;lt;/tt&amp;gt;: &amp;lt;tt&amp;gt;000&amp;lt;/tt&amp;gt; (empty command)&lt;br /&gt;
&lt;br /&gt;
Missing MOD effects are: 8, B, D, E3, E4, E5, E6, E7, E8, ED, EE, EF.&lt;br /&gt;
&lt;br /&gt;
Most commands that translate to extended Exy commands can take values &amp;gt; 0x0F as parameters (finetune command ignores high nibble).&lt;br /&gt;
&lt;br /&gt;
The player will jump to the restart position once the repeat counter of each channel has reached 0 and no bytes are left to be read.&lt;br /&gt;
&lt;br /&gt;
If no tempo is specified on the first row of the pattern, the MOD defaults of tempo 125 and 6 ticks per row are assumed.&lt;br /&gt;
&lt;br /&gt;
=== SMPL chunk ===&lt;br /&gt;
&lt;br /&gt;
Every sample is described by its own SMPL chunk.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| char[32] || sample name || Null-terminated, referenced by SONG chunks&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loop start || in bytes&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || size of sample data || should be chunk size - 48&lt;br /&gt;
|-&lt;br /&gt;
| char[] || sample data || in 8-bit signed mono PCM format&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that a SMPL can be shared between songs and use different finetune and volume values between songs.&lt;br /&gt;
&lt;br /&gt;
== A note on the string format ==&lt;br /&gt;
&lt;br /&gt;
The last character of sample names must be a null-terminator (the engine uses a string comparison not limited to 32 characters when matching samples).&amp;lt;br&amp;gt;&lt;br /&gt;
While it is not required by the engine, the following restrictions are proposed for newly created files to keep the life of developers easy that have to support dozens of files and may thus want to employ heuristics whether files are of a specific type:&lt;br /&gt;
It is suggested that all strings (i.e. instances of char[32]) do not use byte values 1 to 31 (so only printable ASCII/ANSI), and after the first null terminator, the rest of the string has to be padded with nulls as well.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[OpenMPT]]&lt;br /&gt;
| Platform = Windows&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Many&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = At the time of writing, OpenMPT 1.30 (which adds support for this format) is not released yet.&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
This file format was reverse-engineered by [[User:Saga|Saga]]. If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=CDFM_Format&amp;diff=9107</id>
		<title>CDFM Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=CDFM_Format&amp;diff=9107"/>
		<updated>2020-07-13T14:35:12Z</updated>

		<summary type="html">&lt;p&gt;Saga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{NeedMoreInfo}}&lt;br /&gt;
{{Music Infobox&lt;br /&gt;
 | Type = Custom&lt;br /&gt;
 | Instruments = OPL&lt;br /&gt;
 | Instruments2 = PCM&lt;br /&gt;
 | NumChannels = 13&lt;br /&gt;
 | NumTracks = 1&lt;br /&gt;
 | NumPatterns = 128&lt;br /&gt;
 | NumOrders = 256&lt;br /&gt;
 | Tags = None&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Zone 66}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[CDFM Format]] (alternatively: 670 Format) was developed by the demogroup Renaissance for their Amnesia demo, and was later used in their game [[Zone 66]].  It consists of either nine Adlib channels (for Adlib hardware), nine OPL and four PCM channels (for Sound Blaster hardware) or patches to be played as MIDI instruments (for GUS hardware.)&lt;br /&gt;
&lt;br /&gt;
In Zone 66, most songs have hardware-specific versions, even where the SB song could drop the PCM channels and be played on Adlib.  In these cases the PCM drum channels have been replaced with OPL instruments.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file begins with a header.  Those fields marked &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;GUS only] are missing entirely in SoundBlaster/AdLib songs, and those fields marked &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;AdLib/SB only] are missing entirely in the GUS variant of the song format.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || sampleOffset || &#039;&#039;&#039;[GUS only]&#039;&#039;&#039; Offset of instrument samples from start of file&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || tempo || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Playback speed, larger is slower&amp;lt;br/&amp;gt;&#039;&#039;&#039;[GUS only]&#039;&#039;&#039; Unknown, always 0x66, changing has no effect&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || patternListSize || Size of pattern list&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numPatterns || Number of patterns in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numDigInst || Number of PCM or GUS instruments in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numOPLInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Number of OPL instruments in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || loopDest || Index into &amp;lt;tt&amp;gt;patternOrder&amp;lt;/tt&amp;gt; for next pattern to play after the final one when looping the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || sampleOffset || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Offset of instrument samples from start of file&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[patternListSize] || patternOrder || Order of patterns in the song, &amp;lt;tt&amp;gt;patternListSize&amp;lt;/tt&amp;gt; bytes in length&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE[numPatterns] || patternOffset || Offset of each pattern&#039;s data, relative to the start of the pattern data&lt;br /&gt;
|-&lt;br /&gt;
| PCM_INST[numDigInst] || pcmInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; 16 bytes of info for each digital (PCM) instrument&lt;br /&gt;
|-&lt;br /&gt;
| OPL_INST[numOPLInst] || oplInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; 11-byte instrument patch for each FM (OPL) instrument&lt;br /&gt;
|-&lt;br /&gt;
| GUS_INST[numDigInst] || gusInst || &#039;&#039;&#039;[GUS only]&#039;&#039;&#039; 11 bytes of info for each GUS patch&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pattern data immediately follows.  The &amp;lt;tt&amp;gt;patternOffset&amp;lt;/tt&amp;gt; values are relative to this position, so a value of 0x00000000 corresponds to the first byte here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;PCM_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || address_ptr || Used to place address of sample start in memory - ignore when reading, write as 0x00000000&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Length of sample, in bytes&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Offset of loop return, in bytes, relative to start of sample&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopEnd || Offset of loop trigger, in bytes, relative to start of sample.  Use 0x00FFFFFF for no loop.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The PCM instruments begin at &amp;lt;tt&amp;gt;sampleOffset&amp;lt;/tt&amp;gt; and are raw (no header) 8-bit &#039;&#039;&#039;unsigned&#039;&#039;&#039; PCM data.  If the sample loops, as soon as playback reaches &amp;lt;tt&amp;gt;loopEnd&amp;lt;/tt&amp;gt; (which could be before the end of the sample), playback will immediately jump to &amp;lt;tt&amp;gt;loopStart&amp;lt;/tt&amp;gt;.  The middle-C frequency for all PCM instruments is fixed at 8287 Hz (ProTracker standard).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;OPL_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!OPL base register!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iFeedback||0xC0||Feedback/connection&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModChar||0x20||Modulator characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModScale||0x40||Modulator key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModAttack||0x60||Modulator attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModSustain||0x80||Modulator sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModWaveSel||0xE0||Modulator wave select&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarChar||0x23||Carrier characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarScale||0x43||Carrier key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarAttack||0x63||Carrier attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarSustain||0x83||Carrier sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarWaveSel||0xE3||Carrier wave select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The OPL base registers in this list are for the two operators controlling the first OPL channel.  Adjust them accordingly for the relevant OPL channel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;GUS_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || flags || Bitfield: 1={{TODO|Makes pitch higher}}, 2=loop, 16={{TODO|unknown - mutes instrument}}&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || rate || Playback sampling rate for pitch to be middle-C&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Sample offset, in bytes, of loop start&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Length of sample, in bytes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All sample data is 8-bit &#039;&#039;&#039;signed&#039;&#039;&#039;.  If the loop bit is set (i.e. &amp;lt;tt&amp;gt;flags &amp;amp; 2&amp;lt;/tt&amp;gt;) then when the end of the sample is reached playback jumps immediately to the byte offset indicated by &amp;lt;tt&amp;gt;loopStart&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Tempo ==&lt;br /&gt;
&lt;br /&gt;
All songs use the standard module speed/tempo system.  The tempo is fixed at 144, and the speed can be changed per song.  For SB/AdLib songs, the speed is set once with the value obtained from the file header, while GUS songs include a &#039;set speed&#039; command at the start of each pattern.&lt;br /&gt;
&lt;br /&gt;
== Pattern data (SB/AdLib) ==&lt;br /&gt;
&lt;br /&gt;
The musical score data for SoundBlaster/AdLib files consists of a sequence of variable-length commands, in the following format:&lt;br /&gt;
&lt;br /&gt;
=== 0x00-0x0C: Play note ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2 !! Byte 3&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || &amp;lt;tt&amp;gt;jfffnnnn&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;iiiivvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Play a note on the given channel.&lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x00 through 0x0C.  The value controls the channel used for the note:&lt;br /&gt;
** 0x00: digital 1&lt;br /&gt;
** 0x03: digital 4&lt;br /&gt;
** 0x04: FM 1&lt;br /&gt;
** 0x0C: FM 9&lt;br /&gt;
** 0x0D-0x0F: Invalid&lt;br /&gt;
* &amp;lt;tt&amp;gt;j&amp;lt;/tt&amp;gt;: High (fifth) bit of instrument number.&lt;br /&gt;
* &amp;lt;tt&amp;gt;fff&amp;lt;/tt&amp;gt;: The octave of the note to play.  Middle-C is within octave 2 for digital channels (they have 4 octaves). FM channels have 7 octaves, and the middle-C is in octave 4.&lt;br /&gt;
* &amp;lt;tt&amp;gt;nnnn&amp;lt;/tt&amp;gt;: The number of the note to play within the octave (0-11).&lt;br /&gt;
* &amp;lt;tt&amp;gt;iiii&amp;lt;/tt&amp;gt;: The lower four bits of the instrument to use.  A value of zero uses the first instrument.  This is the first PCM instrument on a digital channel, and the first OPL instrument on an FM channel.&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is almost silent, 0xF is full volume. Notes can be played with zero velocity and then faded in with subsequent volume change commands. Volume is linear for both digital and FM channels, which needs to be translated for FM channels (the OPL chip has a logarithmic volume curve).&lt;br /&gt;
&lt;br /&gt;
Note that for FM channels, the channel number modulo 4 is added to the resulting [[OPL_chip#A0-A8:_Frequency_Number|FNUM]] OPL parameter. This causes the note to be slightly detuned, which is used in the Zone 66 soundtrack to fatten some sounds by playing them on two neighbouring FM channels.&lt;br /&gt;
&lt;br /&gt;
=== 0x20-0x2C: Set volume ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x20 || &amp;lt;tt&amp;gt;0000vvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Set the volume of the playing note on the given channel.  &lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x20 through 0x2C, with the lower four bits representing the channel number as with playing a note.&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is silent, 0xF is full volume.&lt;br /&gt;
&lt;br /&gt;
=== 0x40: Delay ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x40 || &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Delay for the given number of ticks before continuing with the next event.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;: Number of ticks to wait&lt;br /&gt;
&lt;br /&gt;
=== 0x60: End of pattern ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
|-&lt;br /&gt;
| 0x60&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This must be the last command in each pattern.  Playback will jump to the next pattern in the sequence specified in the song header.&lt;br /&gt;
&lt;br /&gt;
=== 0x80: Unknown ===&lt;br /&gt;
&lt;br /&gt;
This command is not used in any known files and crashes Zone 66.  Its purpose, or perhaps incomplete intended purpose, is unknown.&lt;br /&gt;
&lt;br /&gt;
== Pattern data (GUS) ==&lt;br /&gt;
&lt;br /&gt;
The musical score data for GUS files also consists of a sequence of variable-length commands, however the commands are different from the ones used in SB/AdLib files.  The commands are in the following format:&lt;br /&gt;
&lt;br /&gt;
=== 0x00: Delay ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x01 || &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Delay for the given number of ticks before continuing with the next event.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;: Number of ticks to wait&lt;br /&gt;
&lt;br /&gt;
=== 0x01: Set speed ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x01 || &amp;lt;tt&amp;gt;ssssssss&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Adjust the song playback speed.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;ssssssss&amp;lt;/tt&amp;gt;: New speed.  This is the same as the &#039;speed&#039; in standard .mod files (i.e. the number of frames per row), with the module tempo fixed at 144.&lt;br /&gt;
&lt;br /&gt;
=== 0x02: End of pattern ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
|-&lt;br /&gt;
| 0x02&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This must be the last command in each pattern.  Playback will jump to the next pattern in the sequence specified in the song header.&lt;br /&gt;
&lt;br /&gt;
=== 0x40-0x4F: Play note ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2 !! Byte 3 !! Byte 4&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || &amp;lt;tt&amp;gt;ffffffff&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;ppppvvvv&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;iiiiiiii&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Play a note on the given channel.&lt;br /&gt;
&lt;br /&gt;
* The command byte is always 0x40 through 0x4F.  The value controls the channel used for the note:&lt;br /&gt;
** 0x00: GUS channel 1&lt;br /&gt;
** 0x01: GUS channel 2&lt;br /&gt;
** 0x0F: GUS channel 16 {{TODO|Assumed, please confirm}}&lt;br /&gt;
* &amp;lt;tt&amp;gt;ffffffff&amp;lt;/tt&amp;gt;: Note.  Add 25 to this value (i.e. transpose up by two octaves and one note) to obtain standard MIDI note numbers.&lt;br /&gt;
* &amp;lt;tt&amp;gt;pppp&amp;lt;/tt&amp;gt;: Panning, 0=centre, 1=full right, 15=full left&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Velocity, logarithmic, 0=silent, 1=1%, 2=4%, 3=7% ... 12=49.8%, 13=60%, 14=74.9%, 15=100%&lt;br /&gt;
* &amp;lt;tt&amp;gt;iiiiiiii&amp;lt;/tt&amp;gt;: Instrument, 0=first, 1=second, etc.&lt;br /&gt;
&lt;br /&gt;
=== 0x80-0x8F: Set volume ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x80 || &amp;lt;tt&amp;gt;ppppvvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Set the volume of the playing note on the given channel.  &lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x80 through 0x8F, with the lower four bits representing the channel number as with playing a note.&lt;br /&gt;
* &amp;lt;tt&amp;gt;pppp&amp;lt;/tt&amp;gt;: {{TODO|Assumed pan value, same as for note-on}}&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is silent, 0xF is full volume.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
&lt;br /&gt;
Note: CDFM Tracker cannot not directly edit 670 files. However, it comes with a tool to convert them back into editable C67 files.&lt;br /&gt;
&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[Camoto]]&lt;br /&gt;
| Platform = Linux/Win&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes; except GUS&lt;br /&gt;
| canModify = Yes; except GUS&lt;br /&gt;
| canExport = Yes&lt;br /&gt;
| canImport = Yes; except GUS&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://sbfmdrv.blogspot.com.au/2015/12/renaissance-cdfm-music.html CDFM Tracker]&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
This file format was reverse engineered by [[User:Malvineous|Malvineous]].  If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=CDFM_Format&amp;diff=9106</id>
		<title>CDFM Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=CDFM_Format&amp;diff=9106"/>
		<updated>2020-07-13T14:30:26Z</updated>

		<summary type="html">&lt;p&gt;Saga: /* 0x00-0x0C: Play note */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{NeedMoreInfo}}&lt;br /&gt;
{{Music Infobox&lt;br /&gt;
 | Type = Custom&lt;br /&gt;
 | Instruments = OPL&lt;br /&gt;
 | Instruments2 = PCM&lt;br /&gt;
 | NumChannels = 13&lt;br /&gt;
 | NumTracks = 1&lt;br /&gt;
 | NumPatterns = 128&lt;br /&gt;
 | NumOrders = 256&lt;br /&gt;
 | Tags = None&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Zone 66}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[CDFM Format]] was developed by the demogroup Renaissance for their Amnesia demo, and was later used in their game [[Zone 66]].  It consists of either nine Adlib channels (for Adlib hardware), nine OPL and four PCM channels (for Sound Blaster hardware) or patches to be played as MIDI instruments (for GUS hardware.)&lt;br /&gt;
&lt;br /&gt;
In Zone 66, most songs have hardware-specific versions, even where the SB song could drop the PCM channels and be played on Adlib.  In these cases the PCM drum channels have been replaced with OPL instruments.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file begins with a header.  Those fields marked &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;GUS only] are missing entirely in SoundBlaster/AdLib songs, and those fields marked &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;AdLib/SB only] are missing entirely in the GUS variant of the song format.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || sampleOffset || &#039;&#039;&#039;[GUS only]&#039;&#039;&#039; Offset of instrument samples from start of file&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || tempo || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Playback speed, larger is slower&amp;lt;br/&amp;gt;&#039;&#039;&#039;[GUS only]&#039;&#039;&#039; Unknown, always 0x66, changing has no effect&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || patternListSize || Size of pattern list&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numPatterns || Number of patterns in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numDigInst || Number of PCM or GUS instruments in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numOPLInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Number of OPL instruments in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || loopDest || Index into &amp;lt;tt&amp;gt;patternOrder&amp;lt;/tt&amp;gt; for next pattern to play after the final one when looping the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || sampleOffset || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Offset of instrument samples from start of file&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[patternListSize] || patternOrder || Order of patterns in the song, &amp;lt;tt&amp;gt;patternListSize&amp;lt;/tt&amp;gt; bytes in length&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE[numPatterns] || patternOffset || Offset of each pattern&#039;s data, relative to the start of the pattern data&lt;br /&gt;
|-&lt;br /&gt;
| PCM_INST[numDigInst] || pcmInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; 16 bytes of info for each digital (PCM) instrument&lt;br /&gt;
|-&lt;br /&gt;
| OPL_INST[numOPLInst] || oplInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; 11-byte instrument patch for each FM (OPL) instrument&lt;br /&gt;
|-&lt;br /&gt;
| GUS_INST[numDigInst] || gusInst || &#039;&#039;&#039;[GUS only]&#039;&#039;&#039; 11 bytes of info for each GUS patch&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pattern data immediately follows.  The &amp;lt;tt&amp;gt;patternOffset&amp;lt;/tt&amp;gt; values are relative to this position, so a value of 0x00000000 corresponds to the first byte here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;PCM_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || address_ptr || Used to place address of sample start in memory - ignore when reading, write as 0x00000000&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Length of sample, in bytes&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Offset of loop return, in bytes, relative to start of sample&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopEnd || Offset of loop trigger, in bytes, relative to start of sample.  Use 0x00FFFFFF for no loop.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The PCM instruments begin at &amp;lt;tt&amp;gt;sampleOffset&amp;lt;/tt&amp;gt; and are raw (no header) 8-bit &#039;&#039;&#039;unsigned&#039;&#039;&#039; PCM data.  If the sample loops, as soon as playback reaches &amp;lt;tt&amp;gt;loopEnd&amp;lt;/tt&amp;gt; (which could be before the end of the sample), playback will immediately jump to &amp;lt;tt&amp;gt;loopStart&amp;lt;/tt&amp;gt;.  The middle-C frequency for all PCM instruments is fixed at 8287 Hz (ProTracker standard).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;OPL_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!OPL base register!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iFeedback||0xC0||Feedback/connection&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModChar||0x20||Modulator characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModScale||0x40||Modulator key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModAttack||0x60||Modulator attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModSustain||0x80||Modulator sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModWaveSel||0xE0||Modulator wave select&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarChar||0x23||Carrier characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarScale||0x43||Carrier key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarAttack||0x63||Carrier attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarSustain||0x83||Carrier sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarWaveSel||0xE3||Carrier wave select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The OPL base registers in this list are for the two operators controlling the first OPL channel.  Adjust them accordingly for the relevant OPL channel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;GUS_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || flags || Bitfield: 1={{TODO|Makes pitch higher}}, 2=loop, 16={{TODO|unknown - mutes instrument}}&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || rate || Playback sampling rate for pitch to be middle-C&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Sample offset, in bytes, of loop start&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Length of sample, in bytes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All sample data is 8-bit &#039;&#039;&#039;signed&#039;&#039;&#039;.  If the loop bit is set (i.e. &amp;lt;tt&amp;gt;flags &amp;amp; 2&amp;lt;/tt&amp;gt;) then when the end of the sample is reached playback jumps immediately to the byte offset indicated by &amp;lt;tt&amp;gt;loopStart&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Tempo ==&lt;br /&gt;
&lt;br /&gt;
All songs use the standard module speed/tempo system.  The tempo is fixed at 144, and the speed can be changed per song.  For SB/AdLib songs, the speed is set once with the value obtained from the file header, while GUS songs include a &#039;set speed&#039; command at the start of each pattern.&lt;br /&gt;
&lt;br /&gt;
== Pattern data (SB/AdLib) ==&lt;br /&gt;
&lt;br /&gt;
The musical score data for SoundBlaster/AdLib files consists of a sequence of variable-length commands, in the following format:&lt;br /&gt;
&lt;br /&gt;
=== 0x00-0x0C: Play note ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2 !! Byte 3&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || &amp;lt;tt&amp;gt;jfffnnnn&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;iiiivvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Play a note on the given channel.&lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x00 through 0x0C.  The value controls the channel used for the note:&lt;br /&gt;
** 0x00: digital 1&lt;br /&gt;
** 0x03: digital 4&lt;br /&gt;
** 0x04: FM 1&lt;br /&gt;
** 0x0C: FM 9&lt;br /&gt;
** 0x0D-0x0F: Invalid&lt;br /&gt;
* &amp;lt;tt&amp;gt;j&amp;lt;/tt&amp;gt;: High (fifth) bit of instrument number.&lt;br /&gt;
* &amp;lt;tt&amp;gt;fff&amp;lt;/tt&amp;gt;: The octave of the note to play.  Middle-C is within octave 2 for digital channels (they have 4 octaves). FM channels have 7 octaves, and the middle-C is in octave 4.&lt;br /&gt;
* &amp;lt;tt&amp;gt;nnnn&amp;lt;/tt&amp;gt;: The number of the note to play within the octave (0-11).&lt;br /&gt;
* &amp;lt;tt&amp;gt;iiii&amp;lt;/tt&amp;gt;: The lower four bits of the instrument to use.  A value of zero uses the first instrument.  This is the first PCM instrument on a digital channel, and the first OPL instrument on an FM channel.&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is almost silent, 0xF is full volume. Notes can be played with zero velocity and then faded in with subsequent volume change commands. Volume is linear for both digital and FM channels, which needs to be translated for FM channels (the OPL chip has a logarithmic volume curve).&lt;br /&gt;
&lt;br /&gt;
Note that for FM channels, the channel number modulo 4 is added to the resulting [[OPL_chip#A0-A8:_Frequency_Number|FNUM]] OPL parameter. This causes the note to be slightly detuned, which is used in the Zone 66 soundtrack to fatten some sounds by playing them on two neighbouring FM channels.&lt;br /&gt;
&lt;br /&gt;
=== 0x20-0x2C: Set volume ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x20 || &amp;lt;tt&amp;gt;0000vvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Set the volume of the playing note on the given channel.  &lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x20 through 0x2C, with the lower four bits representing the channel number as with playing a note.&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is silent, 0xF is full volume.&lt;br /&gt;
&lt;br /&gt;
=== 0x40: Delay ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x40 || &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Delay for the given number of ticks before continuing with the next event.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;: Number of ticks to wait&lt;br /&gt;
&lt;br /&gt;
=== 0x60: End of pattern ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
|-&lt;br /&gt;
| 0x60&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This must be the last command in each pattern.  Playback will jump to the next pattern in the sequence specified in the song header.&lt;br /&gt;
&lt;br /&gt;
=== 0x80: Unknown ===&lt;br /&gt;
&lt;br /&gt;
This command is not used in any known files and crashes Zone 66.  Its purpose, or perhaps incomplete intended purpose, is unknown.&lt;br /&gt;
&lt;br /&gt;
== Pattern data (GUS) ==&lt;br /&gt;
&lt;br /&gt;
The musical score data for GUS files also consists of a sequence of variable-length commands, however the commands are different from the ones used in SB/AdLib files.  The commands are in the following format:&lt;br /&gt;
&lt;br /&gt;
=== 0x00: Delay ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x01 || &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Delay for the given number of ticks before continuing with the next event.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;: Number of ticks to wait&lt;br /&gt;
&lt;br /&gt;
=== 0x01: Set speed ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x01 || &amp;lt;tt&amp;gt;ssssssss&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Adjust the song playback speed.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;ssssssss&amp;lt;/tt&amp;gt;: New speed.  This is the same as the &#039;speed&#039; in standard .mod files (i.e. the number of frames per row), with the module tempo fixed at 144.&lt;br /&gt;
&lt;br /&gt;
=== 0x02: End of pattern ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
|-&lt;br /&gt;
| 0x02&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This must be the last command in each pattern.  Playback will jump to the next pattern in the sequence specified in the song header.&lt;br /&gt;
&lt;br /&gt;
=== 0x40-0x4F: Play note ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2 !! Byte 3 !! Byte 4&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || &amp;lt;tt&amp;gt;ffffffff&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;ppppvvvv&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;iiiiiiii&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Play a note on the given channel.&lt;br /&gt;
&lt;br /&gt;
* The command byte is always 0x40 through 0x4F.  The value controls the channel used for the note:&lt;br /&gt;
** 0x00: GUS channel 1&lt;br /&gt;
** 0x01: GUS channel 2&lt;br /&gt;
** 0x0F: GUS channel 16 {{TODO|Assumed, please confirm}}&lt;br /&gt;
* &amp;lt;tt&amp;gt;ffffffff&amp;lt;/tt&amp;gt;: Note.  Add 25 to this value (i.e. transpose up by two octaves and one note) to obtain standard MIDI note numbers.&lt;br /&gt;
* &amp;lt;tt&amp;gt;pppp&amp;lt;/tt&amp;gt;: Panning, 0=centre, 1=full right, 15=full left&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Velocity, logarithmic, 0=silent, 1=1%, 2=4%, 3=7% ... 12=49.8%, 13=60%, 14=74.9%, 15=100%&lt;br /&gt;
* &amp;lt;tt&amp;gt;iiiiiiii&amp;lt;/tt&amp;gt;: Instrument, 0=first, 1=second, etc.&lt;br /&gt;
&lt;br /&gt;
=== 0x80-0x8F: Set volume ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x80 || &amp;lt;tt&amp;gt;ppppvvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Set the volume of the playing note on the given channel.  &lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x80 through 0x8F, with the lower four bits representing the channel number as with playing a note.&lt;br /&gt;
* &amp;lt;tt&amp;gt;pppp&amp;lt;/tt&amp;gt;: {{TODO|Assumed pan value, same as for note-on}}&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is silent, 0xF is full volume.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[Camoto]]&lt;br /&gt;
| Platform = Linux/Win&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes; except GUS&lt;br /&gt;
| canModify = Yes; except GUS&lt;br /&gt;
| canExport = Yes&lt;br /&gt;
| canImport = Yes; except GUS&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://sbfmdrv.blogspot.com.au/2015/12/renaissance-cdfm-music.html CDFM Tracker]&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
This file format was reverse engineered by [[User:Malvineous|Malvineous]].  If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=CDFM_Format&amp;diff=9105</id>
		<title>CDFM Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=CDFM_Format&amp;diff=9105"/>
		<updated>2020-07-13T14:28:25Z</updated>

		<summary type="html">&lt;p&gt;Saga: Revert previous changes; they only apply to C67, the source format used by CDFM Tracker. Add information about detuned voices.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{NeedMoreInfo}}&lt;br /&gt;
{{Music Infobox&lt;br /&gt;
 | Type = Custom&lt;br /&gt;
 | Instruments = OPL&lt;br /&gt;
 | Instruments2 = PCM&lt;br /&gt;
 | NumChannels = 13&lt;br /&gt;
 | NumTracks = 1&lt;br /&gt;
 | NumPatterns = 128&lt;br /&gt;
 | NumOrders = 256&lt;br /&gt;
 | Tags = None&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Zone 66}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[CDFM Format]] was developed by the demogroup Renaissance for their Amnesia demo, and was later used in their game [[Zone 66]].  It consists of either nine Adlib channels (for Adlib hardware), nine OPL and four PCM channels (for Sound Blaster hardware) or patches to be played as MIDI instruments (for GUS hardware.)&lt;br /&gt;
&lt;br /&gt;
In Zone 66, most songs have hardware-specific versions, even where the SB song could drop the PCM channels and be played on Adlib.  In these cases the PCM drum channels have been replaced with OPL instruments.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file begins with a header.  Those fields marked &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;GUS only] are missing entirely in SoundBlaster/AdLib songs, and those fields marked &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;AdLib/SB only] are missing entirely in the GUS variant of the song format.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || sampleOffset || &#039;&#039;&#039;[GUS only]&#039;&#039;&#039; Offset of instrument samples from start of file&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || tempo || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Playback speed, larger is slower&amp;lt;br/&amp;gt;&#039;&#039;&#039;[GUS only]&#039;&#039;&#039; Unknown, always 0x66, changing has no effect&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || patternListSize || Size of pattern list&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numPatterns || Number of patterns in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numDigInst || Number of PCM or GUS instruments in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numOPLInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Number of OPL instruments in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || loopDest || Index into &amp;lt;tt&amp;gt;patternOrder&amp;lt;/tt&amp;gt; for next pattern to play after the final one when looping the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || sampleOffset || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Offset of instrument samples from start of file&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[patternListSize] || patternOrder || Order of patterns in the song, &amp;lt;tt&amp;gt;patternListSize&amp;lt;/tt&amp;gt; bytes in length&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE[numPatterns] || patternOffset || Offset of each pattern&#039;s data, relative to the start of the pattern data&lt;br /&gt;
|-&lt;br /&gt;
| PCM_INST[numDigInst] || pcmInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; 16 bytes of info for each digital (PCM) instrument&lt;br /&gt;
|-&lt;br /&gt;
| OPL_INST[numOPLInst] || oplInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; 11-byte instrument patch for each FM (OPL) instrument&lt;br /&gt;
|-&lt;br /&gt;
| GUS_INST[numDigInst] || gusInst || &#039;&#039;&#039;[GUS only]&#039;&#039;&#039; 11 bytes of info for each GUS patch&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pattern data immediately follows.  The &amp;lt;tt&amp;gt;patternOffset&amp;lt;/tt&amp;gt; values are relative to this position, so a value of 0x00000000 corresponds to the first byte here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;PCM_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || address_ptr || Used to place address of sample start in memory - ignore when reading, write as 0x00000000&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Length of sample, in bytes&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Offset of loop return, in bytes, relative to start of sample&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopEnd || Offset of loop trigger, in bytes, relative to start of sample.  Use 0x00FFFFFF for no loop.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The PCM instruments begin at &amp;lt;tt&amp;gt;sampleOffset&amp;lt;/tt&amp;gt; and are raw (no header) 8-bit &#039;&#039;&#039;unsigned&#039;&#039;&#039; PCM data.  If the sample loops, as soon as playback reaches &amp;lt;tt&amp;gt;loopEnd&amp;lt;/tt&amp;gt; (which could be before the end of the sample), playback will immediately jump to &amp;lt;tt&amp;gt;loopStart&amp;lt;/tt&amp;gt;.  The middle-C frequency for all PCM instruments is fixed at 8287 Hz (ProTracker standard).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;OPL_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!OPL base register!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iFeedback||0xC0||Feedback/connection&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModChar||0x20||Modulator characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModScale||0x40||Modulator key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModAttack||0x60||Modulator attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModSustain||0x80||Modulator sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModWaveSel||0xE0||Modulator wave select&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarChar||0x23||Carrier characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarScale||0x43||Carrier key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarAttack||0x63||Carrier attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarSustain||0x83||Carrier sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarWaveSel||0xE3||Carrier wave select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The OPL base registers in this list are for the two operators controlling the first OPL channel.  Adjust them accordingly for the relevant OPL channel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;GUS_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || flags || Bitfield: 1={{TODO|Makes pitch higher}}, 2=loop, 16={{TODO|unknown - mutes instrument}}&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || rate || Playback sampling rate for pitch to be middle-C&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Sample offset, in bytes, of loop start&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Length of sample, in bytes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All sample data is 8-bit &#039;&#039;&#039;signed&#039;&#039;&#039;.  If the loop bit is set (i.e. &amp;lt;tt&amp;gt;flags &amp;amp; 2&amp;lt;/tt&amp;gt;) then when the end of the sample is reached playback jumps immediately to the byte offset indicated by &amp;lt;tt&amp;gt;loopStart&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Tempo ==&lt;br /&gt;
&lt;br /&gt;
All songs use the standard module speed/tempo system.  The tempo is fixed at 144, and the speed can be changed per song.  For SB/AdLib songs, the speed is set once with the value obtained from the file header, while GUS songs include a &#039;set speed&#039; command at the start of each pattern.&lt;br /&gt;
&lt;br /&gt;
== Pattern data (SB/AdLib) ==&lt;br /&gt;
&lt;br /&gt;
The musical score data for SoundBlaster/AdLib files consists of a sequence of variable-length commands, in the following format:&lt;br /&gt;
&lt;br /&gt;
=== 0x00-0x0C: Play note ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2 !! Byte 3&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || &amp;lt;tt&amp;gt;jfffnnnn&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;iiiivvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Play a note on the given channel.&lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x00 through 0x0C.  The value controls the channel used for the note:&lt;br /&gt;
** 0x00: digital 1&lt;br /&gt;
** 0x03: digital 4&lt;br /&gt;
** 0x04: FM 1&lt;br /&gt;
** 0x0C: FM 9&lt;br /&gt;
** 0x0D-0x0F: Invalid&lt;br /&gt;
* &amp;lt;tt&amp;gt;j&amp;lt;/tt&amp;gt;: High (fifth) bit of instrument number.&lt;br /&gt;
* &amp;lt;tt&amp;gt;fff&amp;lt;/tt&amp;gt;: The octave of the note to play.  Middle-C is within octave 2 for digital channels (they have 4 octaves). FM channels have 7 octaves, and the middle-C is in octave 4.&lt;br /&gt;
* &amp;lt;tt&amp;gt;nnnn&amp;lt;/tt&amp;gt;: The number of the note to play within the octave (0-11).&lt;br /&gt;
* &amp;lt;tt&amp;gt;iiii&amp;lt;/tt&amp;gt;: The lower four bits of the instrument to use.  A value of zero uses the first instrument.  This is the first PCM instrument on a digital channel, and the first OPL instrument on an FM channel.&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is almost silent, 0xF is full volume. Notes can be played with zero velocity and then faded in with subsequent volume change commands. Volume is linear for both digital and FM channels, which needs to be translated for FM channels (the OPL chip has a logarithmic volume curve).&lt;br /&gt;
&lt;br /&gt;
Note that for FM channels, the channel number modulo 4 is added to the resulting fnum OPL parameter. This causes the note to be slightly detuned, which is used in the Zone 66 soundtrack to fatten some sounds by playing them on two neighbouring FM channels.&lt;br /&gt;
&lt;br /&gt;
=== 0x20-0x2C: Set volume ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x20 || &amp;lt;tt&amp;gt;0000vvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Set the volume of the playing note on the given channel.  &lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x20 through 0x2C, with the lower four bits representing the channel number as with playing a note.&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is silent, 0xF is full volume.&lt;br /&gt;
&lt;br /&gt;
=== 0x40: Delay ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x40 || &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Delay for the given number of ticks before continuing with the next event.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;: Number of ticks to wait&lt;br /&gt;
&lt;br /&gt;
=== 0x60: End of pattern ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
|-&lt;br /&gt;
| 0x60&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This must be the last command in each pattern.  Playback will jump to the next pattern in the sequence specified in the song header.&lt;br /&gt;
&lt;br /&gt;
=== 0x80: Unknown ===&lt;br /&gt;
&lt;br /&gt;
This command is not used in any known files and crashes Zone 66.  Its purpose, or perhaps incomplete intended purpose, is unknown.&lt;br /&gt;
&lt;br /&gt;
== Pattern data (GUS) ==&lt;br /&gt;
&lt;br /&gt;
The musical score data for GUS files also consists of a sequence of variable-length commands, however the commands are different from the ones used in SB/AdLib files.  The commands are in the following format:&lt;br /&gt;
&lt;br /&gt;
=== 0x00: Delay ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x01 || &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Delay for the given number of ticks before continuing with the next event.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;: Number of ticks to wait&lt;br /&gt;
&lt;br /&gt;
=== 0x01: Set speed ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x01 || &amp;lt;tt&amp;gt;ssssssss&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Adjust the song playback speed.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;ssssssss&amp;lt;/tt&amp;gt;: New speed.  This is the same as the &#039;speed&#039; in standard .mod files (i.e. the number of frames per row), with the module tempo fixed at 144.&lt;br /&gt;
&lt;br /&gt;
=== 0x02: End of pattern ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
|-&lt;br /&gt;
| 0x02&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This must be the last command in each pattern.  Playback will jump to the next pattern in the sequence specified in the song header.&lt;br /&gt;
&lt;br /&gt;
=== 0x40-0x4F: Play note ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2 !! Byte 3 !! Byte 4&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || &amp;lt;tt&amp;gt;ffffffff&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;ppppvvvv&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;iiiiiiii&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Play a note on the given channel.&lt;br /&gt;
&lt;br /&gt;
* The command byte is always 0x40 through 0x4F.  The value controls the channel used for the note:&lt;br /&gt;
** 0x00: GUS channel 1&lt;br /&gt;
** 0x01: GUS channel 2&lt;br /&gt;
** 0x0F: GUS channel 16 {{TODO|Assumed, please confirm}}&lt;br /&gt;
* &amp;lt;tt&amp;gt;ffffffff&amp;lt;/tt&amp;gt;: Note.  Add 25 to this value (i.e. transpose up by two octaves and one note) to obtain standard MIDI note numbers.&lt;br /&gt;
* &amp;lt;tt&amp;gt;pppp&amp;lt;/tt&amp;gt;: Panning, 0=centre, 1=full right, 15=full left&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Velocity, logarithmic, 0=silent, 1=1%, 2=4%, 3=7% ... 12=49.8%, 13=60%, 14=74.9%, 15=100%&lt;br /&gt;
* &amp;lt;tt&amp;gt;iiiiiiii&amp;lt;/tt&amp;gt;: Instrument, 0=first, 1=second, etc.&lt;br /&gt;
&lt;br /&gt;
=== 0x80-0x8F: Set volume ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x80 || &amp;lt;tt&amp;gt;ppppvvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Set the volume of the playing note on the given channel.  &lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x80 through 0x8F, with the lower four bits representing the channel number as with playing a note.&lt;br /&gt;
* &amp;lt;tt&amp;gt;pppp&amp;lt;/tt&amp;gt;: {{TODO|Assumed pan value, same as for note-on}}&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is silent, 0xF is full volume.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[Camoto]]&lt;br /&gt;
| Platform = Linux/Win&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes; except GUS&lt;br /&gt;
| canModify = Yes; except GUS&lt;br /&gt;
| canExport = Yes&lt;br /&gt;
| canImport = Yes; except GUS&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://sbfmdrv.blogspot.com.au/2015/12/renaissance-cdfm-music.html CDFM Tracker]&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
This file format was reverse engineered by [[User:Malvineous|Malvineous]].  If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=CDFM_Format&amp;diff=9104</id>
		<title>CDFM Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=CDFM_Format&amp;diff=9104"/>
		<updated>2020-07-13T13:54:09Z</updated>

		<summary type="html">&lt;p&gt;Saga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{NeedMoreInfo}}&lt;br /&gt;
{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = OPL&lt;br /&gt;
 | Instruments2 = PCM&lt;br /&gt;
 | NumChannels = 13&lt;br /&gt;
 | NumTracks = 1&lt;br /&gt;
 | NumPatterns = 128&lt;br /&gt;
 | NumOrders = 256&lt;br /&gt;
 | Tags = None&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Zone 66}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[CDFM Format]] was developed by the demogroup Renaissance for their Amnesia demo, and was later used in their game [[Zone 66]].  It consists of either nine Adlib channels (for Adlib hardware), nine OPL and four PCM channels (for Sound Blaster hardware) or patches to be played as MIDI instruments (for GUS hardware.)&lt;br /&gt;
&lt;br /&gt;
In Zone 66, most songs have hardware-specific versions, even where the SB song could drop the PCM channels and be played on Adlib.  In these cases the PCM drum channels have been replaced with OPL instruments.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file begins with a header.  Those fields marked &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;GUS only] are missing entirely in SoundBlaster/AdLib songs, and those fields marked &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;AdLib/SB only] are missing entirely in the GUS variant of the song format.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || sampleOffset || &#039;&#039;&#039;[GUS only]&#039;&#039;&#039; Offset of instrument samples from start of file&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || tempo || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Playback speed, larger is slower&amp;lt;br/&amp;gt;&#039;&#039;&#039;[GUS only]&#039;&#039;&#039; Unknown, always 0x66, changing has no effect&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || patternListSize || Size of pattern list&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numPatterns || Number of patterns in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numDigInst || Number of PCM or GUS instruments in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numOPLInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Number of OPL instruments in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || loopDest || Index into &amp;lt;tt&amp;gt;patternOrder&amp;lt;/tt&amp;gt; for next pattern to play after the final one when looping the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || sampleOffset || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Offset of instrument samples from start of file&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[patternListSize] || patternOrder || Order of patterns in the song, &amp;lt;tt&amp;gt;patternListSize&amp;lt;/tt&amp;gt; bytes in length&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE[numPatterns] || patternOffset || Offset of each pattern&#039;s data, relative to the start of the pattern data&lt;br /&gt;
|-&lt;br /&gt;
| PCM_INST[numDigInst] || pcmInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; 16 bytes of info for each digital (PCM) instrument&lt;br /&gt;
|-&lt;br /&gt;
| OPL_INST[numOPLInst] || oplInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; 11-byte instrument patch for each FM (OPL) instrument&lt;br /&gt;
|-&lt;br /&gt;
| GUS_INST[numDigInst] || gusInst || &#039;&#039;&#039;[GUS only]&#039;&#039;&#039; 11 bytes of info for each GUS patch&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pattern data immediately follows.  The &amp;lt;tt&amp;gt;patternOffset&amp;lt;/tt&amp;gt; values are relative to this position, so a value of 0x00000000 corresponds to the first byte here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;PCM_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || address_ptr || Used to place address of sample start in memory - ignore when reading, write as 0x00000000&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Length of sample, in bytes&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Offset of loop return, in bytes, relative to start of sample&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopEnd || Offset of loop trigger, in bytes, relative to start of sample.  Use 0x00FFFFFF for no loop.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The PCM instruments begin at &amp;lt;tt&amp;gt;sampleOffset&amp;lt;/tt&amp;gt; and are raw (no header) 8-bit &#039;&#039;&#039;unsigned&#039;&#039;&#039; PCM data.  If the sample loops, as soon as playback reaches &amp;lt;tt&amp;gt;loopEnd&amp;lt;/tt&amp;gt; (which could be before the end of the sample), playback will immediately jump to &amp;lt;tt&amp;gt;loopStart&amp;lt;/tt&amp;gt;.  The middle-C frequency for all PCM instruments is fixed at 8287 Hz (ProTracker standard).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;OPL_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!OPL base register!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iFeedback||0xC0||Feedback/connection&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModChar||0x20||Modulator characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModScale||0x40||Modulator key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModAttack||0x60||Modulator attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModSustain||0x80||Modulator sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModWaveSel||0xE0||Modulator wave select&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarChar||0x23||Carrier characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarScale||0x43||Carrier key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarAttack||0x63||Carrier attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarSustain||0x83||Carrier sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarWaveSel||0xE3||Carrier wave select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The OPL base registers in this list are for the two operators controlling the first OPL channel.  Adjust them accordingly for the relevant OPL channel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;GUS_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || flags || Bitfield: 1={{TODO|Makes pitch higher}}, 2=loop, 16={{TODO|unknown - mutes instrument}}&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || rate || Playback sampling rate for pitch to be middle-C&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Sample offset, in bytes, of loop start&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Length of sample, in bytes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All sample data is 8-bit &#039;&#039;&#039;signed&#039;&#039;&#039;.  If the loop bit is set (i.e. &amp;lt;tt&amp;gt;flags &amp;amp; 2&amp;lt;/tt&amp;gt;) then when the end of the sample is reached playback jumps immediately to the byte offset indicated by &amp;lt;tt&amp;gt;loopStart&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Tempo ==&lt;br /&gt;
&lt;br /&gt;
All songs use the standard module speed/tempo system.  The tempo is fixed at 144, and the speed can be changed per song.  For SB/AdLib songs, the speed is set once with the value obtained from the file header, while GUS songs include a &#039;set speed&#039; command at the start of each pattern.&lt;br /&gt;
&lt;br /&gt;
== Pattern data (SB/AdLib) ==&lt;br /&gt;
&lt;br /&gt;
The musical score data for SoundBlaster/AdLib files consists of a sequence of variable-length commands, in the following format:&lt;br /&gt;
&lt;br /&gt;
=== 0x00-0x0C: Play note ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2 !! Byte 3&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || &amp;lt;tt&amp;gt;jfffnnnn&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;iiiivvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Play a note on the given channel.&lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x00 through 0x0C.  The value controls the channel used for the note:&lt;br /&gt;
** 0x00: digital 1&lt;br /&gt;
** 0x03: digital 4&lt;br /&gt;
** 0x04: FM 1&lt;br /&gt;
** 0x0C: FM 9&lt;br /&gt;
** 0x0D-0x0F: Invalid&lt;br /&gt;
* &amp;lt;tt&amp;gt;j&amp;lt;/tt&amp;gt;: High (fifth) bit of instrument number.&lt;br /&gt;
* &amp;lt;tt&amp;gt;fff&amp;lt;/tt&amp;gt;: The octave of the note to play.  Middle-C is within octave 2 for digital channels (they have 4 octaves). FM channels have 7 octaves, and the middle-C is in octave 4.&lt;br /&gt;
* &amp;lt;tt&amp;gt;nnnn&amp;lt;/tt&amp;gt;: The number of the note to play within the octave (0-11).&lt;br /&gt;
* &amp;lt;tt&amp;gt;iiii&amp;lt;/tt&amp;gt;: The lower four bits of the instrument to use.  A value of zero uses the first instrument.  This is the first PCM instrument on a digital channel, and the first OPL instrument on an FM channel.&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is almost silent, 0xF is full volume. Notes can be played with zero velocity and then faded in with subsequent volume change commands. Volume is linear for both digital and FM channels, which needs to be translated for FM channels (the OPL chip has a logarithmic volume curve).&lt;br /&gt;
&lt;br /&gt;
=== 0x20-0x2C: Set volume ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x20 || &amp;lt;tt&amp;gt;0000vvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Set the volume of the playing note on the given channel.  &lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x20 through 0x2C, with the lower four bits representing the channel number as with playing a note.&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is silent, 0xF is full volume.&lt;br /&gt;
&lt;br /&gt;
=== 0x40: Delay ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x40 || &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Delay for the given number of ticks before continuing with the next event.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;: Number of ticks to wait&lt;br /&gt;
&lt;br /&gt;
=== 0x60: End of pattern ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
|-&lt;br /&gt;
| 0x60&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This must be the last command in each pattern.  Playback will jump to the next pattern in the sequence specified in the song header.&lt;br /&gt;
&lt;br /&gt;
=== 0x80: Unknown ===&lt;br /&gt;
&lt;br /&gt;
This command is not used in any known files and crashes Zone 66.  Its purpose, or perhaps incomplete intended purpose, is unknown.&lt;br /&gt;
&lt;br /&gt;
== Pattern data (GUS) ==&lt;br /&gt;
&lt;br /&gt;
The musical score data for GUS files also consists of a sequence of variable-length commands, however the commands are different from the ones used in SB/AdLib files.  The commands are in the following format:&lt;br /&gt;
&lt;br /&gt;
=== 0x00: Delay ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x01 || &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Delay for the given number of ticks before continuing with the next event.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;: Number of ticks to wait&lt;br /&gt;
&lt;br /&gt;
=== 0x01: Set speed ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x01 || &amp;lt;tt&amp;gt;ssssssss&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Adjust the song playback speed.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;ssssssss&amp;lt;/tt&amp;gt;: New speed.  This is the same as the &#039;speed&#039; in standard .mod files (i.e. the number of frames per row), with the module tempo fixed at 144.&lt;br /&gt;
&lt;br /&gt;
=== 0x02: End of pattern ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
|-&lt;br /&gt;
| 0x02&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This must be the last command in each pattern.  Playback will jump to the next pattern in the sequence specified in the song header.&lt;br /&gt;
&lt;br /&gt;
=== 0x40-0x4F: Play note ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2 !! Byte 3 !! Byte 4&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || &amp;lt;tt&amp;gt;ffffffff&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;ppppvvvv&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;iiiiiiii&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Play a note on the given channel.&lt;br /&gt;
&lt;br /&gt;
* The command byte is always 0x40 through 0x4F.  The value controls the channel used for the note:&lt;br /&gt;
** 0x00: GUS channel 1&lt;br /&gt;
** 0x01: GUS channel 2&lt;br /&gt;
** 0x0F: GUS channel 16 {{TODO|Assumed, please confirm}}&lt;br /&gt;
* &amp;lt;tt&amp;gt;ffffffff&amp;lt;/tt&amp;gt;: Note.  Add 25 to this value (i.e. transpose up by two octaves and one note) to obtain standard MIDI note numbers.&lt;br /&gt;
* &amp;lt;tt&amp;gt;pppp&amp;lt;/tt&amp;gt;: Panning, 0=centre, 1=full right, 15=full left&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Velocity, logarithmic, 0=silent, 1=1%, 2=4%, 3=7% ... 12=49.8%, 13=60%, 14=74.9%, 15=100%&lt;br /&gt;
* &amp;lt;tt&amp;gt;iiiiiiii&amp;lt;/tt&amp;gt;: Instrument, 0=first, 1=second, etc.&lt;br /&gt;
&lt;br /&gt;
=== 0x80-0x8F: Set volume ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x80 || &amp;lt;tt&amp;gt;ppppvvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Set the volume of the playing note on the given channel.  &lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x80 through 0x8F, with the lower four bits representing the channel number as with playing a note.&lt;br /&gt;
* &amp;lt;tt&amp;gt;pppp&amp;lt;/tt&amp;gt;: {{TODO|Assumed pan value, same as for note-on}}&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is silent, 0xF is full volume.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[Camoto]]&lt;br /&gt;
| Platform = Linux/Win&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes; except GUS&lt;br /&gt;
| canModify = Yes; except GUS&lt;br /&gt;
| canExport = Yes&lt;br /&gt;
| canImport = Yes; except GUS&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://sbfmdrv.blogspot.com.au/2015/12/renaissance-cdfm-music.html CDFM Tracker]&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [https://openmpt.org OpenMPT]&lt;br /&gt;
| Platform = Windows/Wine&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canExport = Yes&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
This file format was reverse engineered by [[User:Malvineous|Malvineous]].  If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=CDFM_Format&amp;diff=9103</id>
		<title>CDFM Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=CDFM_Format&amp;diff=9103"/>
		<updated>2020-07-13T13:53:47Z</updated>

		<summary type="html">&lt;p&gt;Saga: Change from Custom to Tracker type; add OpenMPT to list of tools&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{NeedMoreInfo}}&lt;br /&gt;
{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = OPL&lt;br /&gt;
 | Instruments2 = PCM&lt;br /&gt;
 | NumChannels = 13&lt;br /&gt;
 | NumTracks = 1&lt;br /&gt;
 | NumPatterns = 128&lt;br /&gt;
 | NumOrders = 256&lt;br /&gt;
 | Tags = None&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Zone 66}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[CDFM Format]] was developed by the demogroup Renaissance for their Amnesia demo, and was later used in their game [[Zone 66]].  It consists of either nine Adlib channels (for Adlib hardware), nine OPL and four PCM channels (for Sound Blaster hardware) or patches to be played as MIDI instruments (for GUS hardware.)&lt;br /&gt;
&lt;br /&gt;
In Zone 66, most songs have hardware-specific versions, even where the SB song could drop the PCM channels and be played on Adlib.  In these cases the PCM drum channels have been replaced with OPL instruments.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file begins with a header.  Those fields marked &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;GUS only] are missing entirely in SoundBlaster/AdLib songs, and those fields marked &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;AdLib/SB only] are missing entirely in the GUS variant of the song format.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || sampleOffset || &#039;&#039;&#039;[GUS only]&#039;&#039;&#039; Offset of instrument samples from start of file&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || tempo || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Playback speed, larger is slower&amp;lt;br/&amp;gt;&#039;&#039;&#039;[GUS only]&#039;&#039;&#039; Unknown, always 0x66, changing has no effect&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || patternListSize || Size of pattern list&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numPatterns || Number of patterns in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numDigInst || Number of PCM or GUS instruments in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numOPLInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Number of OPL instruments in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || loopDest || Index into &amp;lt;tt&amp;gt;patternOrder&amp;lt;/tt&amp;gt; for next pattern to play after the final one when looping the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || sampleOffset || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Offset of instrument samples from start of file&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[patternListSize] || patternOrder || Order of patterns in the song, &amp;lt;tt&amp;gt;patternListSize&amp;lt;/tt&amp;gt; bytes in length&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE[numPatterns] || patternOffset || Offset of each pattern&#039;s data, relative to the start of the pattern data&lt;br /&gt;
|-&lt;br /&gt;
| PCM_INST[numDigInst] || pcmInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; 16 bytes of info for each digital (PCM) instrument&lt;br /&gt;
|-&lt;br /&gt;
| OPL_INST[numOPLInst] || oplInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; 11-byte instrument patch for each FM (OPL) instrument&lt;br /&gt;
|-&lt;br /&gt;
| GUS_INST[numDigInst] || gusInst || &#039;&#039;&#039;[GUS only]&#039;&#039;&#039; 11 bytes of info for each GUS patch&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pattern data immediately follows.  The &amp;lt;tt&amp;gt;patternOffset&amp;lt;/tt&amp;gt; values are relative to this position, so a value of 0x00000000 corresponds to the first byte here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;PCM_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || address_ptr || Used to place address of sample start in memory - ignore when reading, write as 0x00000000&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Length of sample, in bytes&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Offset of loop return, in bytes, relative to start of sample&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopEnd || Offset of loop trigger, in bytes, relative to start of sample.  Use 0x00FFFFFF for no loop.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The PCM instruments begin at &amp;lt;tt&amp;gt;sampleOffset&amp;lt;/tt&amp;gt; and are raw (no header) 8-bit &#039;&#039;&#039;unsigned&#039;&#039;&#039; PCM data.  If the sample loops, as soon as playback reaches &amp;lt;tt&amp;gt;loopEnd&amp;lt;/tt&amp;gt; (which could be before the end of the sample), playback will immediately jump to &amp;lt;tt&amp;gt;loopStart&amp;lt;/tt&amp;gt;.  The middle-C frequency for all PCM instruments is fixed at 8287 Hz (ProTracker standard).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;OPL_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!OPL base register!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iFeedback||0xC0||Feedback/connection&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModChar||0x20||Modulator characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModScale||0x40||Modulator key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModAttack||0x60||Modulator attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModSustain||0x80||Modulator sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModWaveSel||0xE0||Modulator wave select&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarChar||0x23||Carrier characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarScale||0x43||Carrier key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarAttack||0x63||Carrier attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarSustain||0x83||Carrier sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarWaveSel||0xE3||Carrier wave select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The OPL base registers in this list are for the two operators controlling the first OPL channel.  Adjust them accordingly for the relevant OPL channel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;GUS_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || flags || Bitfield: 1={{TODO|Makes pitch higher}}, 2=loop, 16={{TODO|unknown - mutes instrument}}&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || rate || Playback sampling rate for pitch to be middle-C&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Sample offset, in bytes, of loop start&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Length of sample, in bytes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All sample data is 8-bit &#039;&#039;&#039;signed&#039;&#039;&#039;.  If the loop bit is set (i.e. &amp;lt;tt&amp;gt;flags &amp;amp; 2&amp;lt;/tt&amp;gt;) then when the end of the sample is reached playback jumps immediately to the byte offset indicated by &amp;lt;tt&amp;gt;loopStart&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Tempo ==&lt;br /&gt;
&lt;br /&gt;
All songs use the standard module speed/tempo system.  The tempo is fixed at 144, and the speed can be changed per song.  For SB/AdLib songs, the speed is set once with the value obtained from the file header, while GUS songs include a &#039;set speed&#039; command at the start of each pattern.&lt;br /&gt;
&lt;br /&gt;
== Pattern data (SB/AdLib) ==&lt;br /&gt;
&lt;br /&gt;
The musical score data for SoundBlaster/AdLib files consists of a sequence of variable-length commands, in the following format:&lt;br /&gt;
&lt;br /&gt;
=== 0x00-0x0C: Play note ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2 !! Byte 3&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || &amp;lt;tt&amp;gt;jfffnnnn&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;iiiivvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Play a note on the given channel.&lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x00 through 0x0C.  The value controls the channel used for the note:&lt;br /&gt;
** 0x00: digital 1&lt;br /&gt;
** 0x03: digital 4&lt;br /&gt;
** 0x04: FM 1&lt;br /&gt;
** 0x0C: FM 9&lt;br /&gt;
** 0x0D-0x0F: Invalid&lt;br /&gt;
* &amp;lt;tt&amp;gt;j&amp;lt;/tt&amp;gt;: High (fifth) bit of instrument number.&lt;br /&gt;
* &amp;lt;tt&amp;gt;fff&amp;lt;/tt&amp;gt;: The octave of the note to play.  Middle-C is within octave 2 for digital channels (they have 4 octaves). FM channels have 7 octaves, and the middle-C is in octave 4.&lt;br /&gt;
* &amp;lt;tt&amp;gt;nnnn&amp;lt;/tt&amp;gt;: The number of the note to play within the octave (0-11).&lt;br /&gt;
* &amp;lt;tt&amp;gt;iiii&amp;lt;/tt&amp;gt;: The lower four bits of the instrument to use.  A value of zero uses the first instrument.  This is the first PCM instrument on a digital channel, and the first OPL instrument on an FM channel.&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is almost silent, 0xF is full volume. Notes can be played with zero velocity and then faded in with subsequent volume change commands. Volume is linear for both digital and FM channels, which needs to be translated for FM channels (the OPL chip has a logarithmic volume curve).&lt;br /&gt;
&lt;br /&gt;
=== 0x20-0x2C: Set volume ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x20 || &amp;lt;tt&amp;gt;0000vvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Set the volume of the playing note on the given channel.  &lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x20 through 0x2C, with the lower four bits representing the channel number as with playing a note.&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is silent, 0xF is full volume.&lt;br /&gt;
&lt;br /&gt;
=== 0x40: Delay ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x40 || &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Delay for the given number of ticks before continuing with the next event.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;: Number of ticks to wait&lt;br /&gt;
&lt;br /&gt;
=== 0x60: End of pattern ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
|-&lt;br /&gt;
| 0x60&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This must be the last command in each pattern.  Playback will jump to the next pattern in the sequence specified in the song header.&lt;br /&gt;
&lt;br /&gt;
=== 0x80: Unknown ===&lt;br /&gt;
&lt;br /&gt;
This command is not used in any known files and crashes Zone 66.  Its purpose, or perhaps incomplete intended purpose, is unknown.&lt;br /&gt;
&lt;br /&gt;
== Pattern data (GUS) ==&lt;br /&gt;
&lt;br /&gt;
The musical score data for GUS files also consists of a sequence of variable-length commands, however the commands are different from the ones used in SB/AdLib files.  The commands are in the following format:&lt;br /&gt;
&lt;br /&gt;
=== 0x00: Delay ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x01 || &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Delay for the given number of ticks before continuing with the next event.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;: Number of ticks to wait&lt;br /&gt;
&lt;br /&gt;
=== 0x01: Set speed ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x01 || &amp;lt;tt&amp;gt;ssssssss&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Adjust the song playback speed.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;ssssssss&amp;lt;/tt&amp;gt;: New speed.  This is the same as the &#039;speed&#039; in standard .mod files (i.e. the number of frames per row), with the module tempo fixed at 144.&lt;br /&gt;
&lt;br /&gt;
=== 0x02: End of pattern ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
|-&lt;br /&gt;
| 0x02&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This must be the last command in each pattern.  Playback will jump to the next pattern in the sequence specified in the song header.&lt;br /&gt;
&lt;br /&gt;
=== 0x40-0x4F: Play note ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2 !! Byte 3 !! Byte 4&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || &amp;lt;tt&amp;gt;ffffffff&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;ppppvvvv&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;iiiiiiii&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Play a note on the given channel.&lt;br /&gt;
&lt;br /&gt;
* The command byte is always 0x40 through 0x4F.  The value controls the channel used for the note:&lt;br /&gt;
** 0x00: GUS channel 1&lt;br /&gt;
** 0x01: GUS channel 2&lt;br /&gt;
** 0x0F: GUS channel 16 {{TODO|Assumed, please confirm}}&lt;br /&gt;
* &amp;lt;tt&amp;gt;ffffffff&amp;lt;/tt&amp;gt;: Note.  Add 25 to this value (i.e. transpose up by two octaves and one note) to obtain standard MIDI note numbers.&lt;br /&gt;
* &amp;lt;tt&amp;gt;pppp&amp;lt;/tt&amp;gt;: Panning, 0=centre, 1=full right, 15=full left&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Velocity, logarithmic, 0=silent, 1=1%, 2=4%, 3=7% ... 12=49.8%, 13=60%, 14=74.9%, 15=100%&lt;br /&gt;
* &amp;lt;tt&amp;gt;iiiiiiii&amp;lt;/tt&amp;gt;: Instrument, 0=first, 1=second, etc.&lt;br /&gt;
&lt;br /&gt;
=== 0x80-0x8F: Set volume ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x80 || &amp;lt;tt&amp;gt;ppppvvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Set the volume of the playing note on the given channel.  &lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x80 through 0x8F, with the lower four bits representing the channel number as with playing a note.&lt;br /&gt;
* &amp;lt;tt&amp;gt;pppp&amp;lt;/tt&amp;gt;: {{TODO|Assumed pan value, same as for note-on}}&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is silent, 0xF is full volume.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[Camoto]]&lt;br /&gt;
| Platform = Linux/Win&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes; except GUS&lt;br /&gt;
| canModify = Yes; except GUS&lt;br /&gt;
| canExport = Yes&lt;br /&gt;
| canImport = Yes; except GUS&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://sbfmdrv.blogspot.com.au/2015/12/renaissance-cdfm-music.html CDFM Tracker]&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [OpenMPT https://openmpt.org]&lt;br /&gt;
| Platform = Windows/Wine&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canExport = Yes&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
This file format was reverse engineered by [[User:Malvineous|Malvineous]].  If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=S3M_Format&amp;diff=9099</id>
		<title>S3M Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=S3M_Format&amp;diff=9099"/>
		<updated>2020-07-07T08:44:24Z</updated>

		<summary type="html">&lt;p&gt;Saga: /* File format */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | Instruments2 = OPL&lt;br /&gt;
 | NumChannels = 32&lt;br /&gt;
 | NumTracks = 255&lt;br /&gt;
 | NumPatterns = 65,536&lt;br /&gt;
 | NumOrders = 65,536&lt;br /&gt;
 | Tags = Title, instrument names&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Unreal Tournament}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[S3M Format]] is used to save modules composed in ScreamTracker 3.  A number of games support music in this format, however it is primarily used for composing independent songs unrelated to games.&lt;br /&gt;
&lt;br /&gt;
The format is notable both for its popularity, as well as for being one of the few that support both FM/OPL and sampled instruments.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file begins with a header.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Song title, must be null-terminated&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || sig1 || Signature byte, always 0x1A&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || type || Song type, always 0x10 for S3M&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || reserved || Always 0x0000&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || orderCount || Number of entries in the order table, should be even&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || instrumentCount || Number of instruments in the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || patternPtrCount || Number of pattern parapointers in the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || flags || See below&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || trackerVersion || upper four bits is tracker ID, lower 12 bits is tracker version&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || sampleType || 1=signed samples [deprecated], 2=unsigned samples&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || sig2 || Signature: &amp;quot;SCRM&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || globalVolume || &lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || initialSpeed || Frames per row, can be changed later with &amp;lt;tt&amp;gt;A&amp;lt;/tt&amp;gt; command&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || initialTempo || Frames per second, can be changed later with &amp;lt;tt&amp;gt;T&amp;lt;/tt&amp;gt; command&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || masterVolume || bit 7: 1=stereo, 0=mono, bits 6-0: volume&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || ultraClickRemoval || Number of channels to use for click removal on real GUS hardware&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || defaultPan || 252=read pan values in header, anything else ignores pan values in header&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[8] || reserved || Unused, some trackers store data here&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || ptrSpecial || Parapointer to additional data, if &amp;lt;tt&amp;gt;flags&amp;lt;/tt&amp;gt; has bit 7 set&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[32] || channelSettings || See below&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[orderCount] || orderList || Which order patterns are played in&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE[instrumentCount] || ptrInstruments || List of parapointers to each instrument&#039;s data&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE[patternPtrCount] || ptrPatterns || List of parapointers to each pattern&#039;s data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Flags are one or more values below:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Bit !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || ST2 vibrato [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 2 || ST2 tempo [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 4 || Amiga slides [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 8 || 0vol optimisations - automatically turn off looping notes when the volume is zero for more than two rows&lt;br /&gt;
|-&lt;br /&gt;
| 4 || 16 || Amiga limits - ignore notes beyond Amiga hardware limits (as Amiga does.)  Sliding up stops at B#5.  Also affects other Amiga compatibility issues.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || 32 || Enable SoundBlaster filter/sfx [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 64 || ST3.00 volume slides - perform volume slides on first row as well.  Set implicitly if &amp;lt;tt&amp;gt;trackerVersion&amp;lt;/tt&amp;gt; is 0x1300.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 128 || &amp;lt;tt&amp;gt;ptrSpecial&amp;lt;/tt&amp;gt; is valid&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Known &amp;lt;tt&amp;gt;trackerVersion&amp;lt;/tt&amp;gt; values are:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x1300 || ScreamTracker 3.00&lt;br /&gt;
|-&lt;br /&gt;
| 0x1301 || ScreamTracker 3.01&lt;br /&gt;
|-&lt;br /&gt;
| 0x1303 || ScreamTracker 3.03&lt;br /&gt;
|-&lt;br /&gt;
| 0x1320 || ScreamTracker 3.20&lt;br /&gt;
|-&lt;br /&gt;
| 0x2xyy || Imago Orpheus x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x3xyy || Impulse Tracker x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x4nnn || Schism Tracker (old BeRoTracker version from between 2004 and 2012 identify as 0x4100)&lt;br /&gt;
|-&lt;br /&gt;
| 0x5xyy || OpenMPT x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x6xyy || BeRoTracker x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x7xyy || CreamTracker x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0xCA00 || Camoto/libgamemusic&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;channelSettings&amp;lt;/tt&amp;gt; is 32 values indicating the audio channel assignments for each of the 32 S3M channels.  Unused channels should be set to 255.  If the high bit is set, a channel is disabled (muted). Note that Scream Tracker 3 does not even process global effects (such as tempo changes) on muted channels. &lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 to 7 || Left PCM channels 1 to 8&lt;br /&gt;
|-&lt;br /&gt;
| 8 to 15 || Right PCM channels 1 to 8&lt;br /&gt;
|-&lt;br /&gt;
| 16 to 24 || Adlib melody channel 1-9&lt;br /&gt;
|-&lt;br /&gt;
| 25 || Adlib percussion channel: bass drum&lt;br /&gt;
|-&lt;br /&gt;
| 26 || Adlib percussion channel: snare drum&lt;br /&gt;
|-&lt;br /&gt;
| 27 || Adlib percussion channel: tom tom&lt;br /&gt;
|-&lt;br /&gt;
| 28 || Adlib percussion channel: top cymbal&lt;br /&gt;
|-&lt;br /&gt;
| 29 || Adlib percussion channel: hi-hat&lt;br /&gt;
|-&lt;br /&gt;
| 30 to 127 || Unused/invalid&lt;br /&gt;
|-&lt;br /&gt;
| 128 to 254 || Same as above + 128 (disabled)&lt;br /&gt;
|-&lt;br /&gt;
| 255 || Channel unused&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Adlib percussion channels are not implemented in Scream Tracker 3. All they do is showing a different channel type in the channel setup, but they don&#039;t do anything. There is no percussion instrument format defined, either.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;orderList&amp;lt;/tt&amp;gt; contains the index of each pattern to be played.  The first entry in this array is the index of the first pattern to play, the second entry is the second pattern, etc.  If an entry is 0xFE then it is a &amp;quot;marker pattern&amp;quot; and is skipped during playback, and an entry of 0xFF signifies the end of the song.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;ptrInstruments&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ptrPatterns&amp;lt;/tt&amp;gt; are arrays of parapointers to the start of the instrument and pattern data.  Each parapointer is an offset from the start of the file, in units of 16 bytes (a &amp;quot;paragraph&amp;quot;).  To convert this into a normal byte-level file offset, multiply it by 16 (or shift-left by 4.)&lt;br /&gt;
&lt;br /&gt;
By convention these blocks follow the header above, but this is not a requirement and they can occur at any point in the file.&lt;br /&gt;
&lt;br /&gt;
=== Timing ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;initialTempo&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;initialSpeed&amp;lt;/tt&amp;gt; values are the ones to use until optionally changed during playback, with the A and T effects respectively.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;initialTempo&amp;lt;/tt&amp;gt; value controls how many audio frames are generated per second.  If this value is 50, then there should be 50 audio frames per second.  Obviously the more audio frames per second, the shorter each frame is going to be.  To calculate the length of each frame, a formula like this can be used:&lt;br /&gt;
&lt;br /&gt;
    frame length in seconds = 1 / initialTempo&lt;br /&gt;
     0.02 seconds per frame = 1 / 50&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;initialSpeed&amp;lt;/tt&amp;gt; value controls how many audio frames comprise a single row of the song.  If the value is 3, then there are three audio frames per row.  For certain effects, they are updated once per frame (i.e. the effect changes between rows.)&lt;br /&gt;
&lt;br /&gt;
To calculate playback speed, both these values need to be taken into account.  The tempo value controls the length of each audio frame, while the speed value controls how quickly the rows are turned into those audio frames.  For example, to calculate the number of rows per second:&lt;br /&gt;
&lt;br /&gt;
    rowsPerSecond = initialTempo / initialSpeed&lt;br /&gt;
&lt;br /&gt;
=== Instruments ===&lt;br /&gt;
&lt;br /&gt;
At the offset given by an instrument&#039;s parapointer, the data has a header as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || type || 0=empty instrument (message only), 1=PCM instrument&lt;br /&gt;
|-&lt;br /&gt;
| char[12] || filename || Original instrument filename in DOS 8.3 format, no terminating null&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || empty instrument (message only)&lt;br /&gt;
|-&lt;br /&gt;
| 1 || PCM instrument&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Adlib melody instrument&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Adlib percussive: bass drum&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Adlib percussive: snare&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Adlib percussive: tom tom&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Adlib percussive: top cymbal&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Adlib percussive: hi-hat&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The data following the header depends on whether the instrument is PCM or Adlib.&lt;br /&gt;
{{TODO|What if the instrument is empty, is there any trailing data?}}&lt;br /&gt;
&lt;br /&gt;
==== PCM ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || ptrDataH || Upper eight bits of parapointer to sample data, relative to start of S3M file&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || ptrDataL || Lower 16 bits of parapointer to sample data, relative to start of S3M file&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Sample data length, in bytes.  S3M is limited to 64000 and ignores upper 16 bits.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Offset of loop start in bytes, relative to start of sample data.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopEnd || Offset of loop end in bytes, relative to start of sample data.&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Default volume of sample, 0-63 inclusive.&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || reserved || Always 0x00&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || pack || 0=unpacked, 1=DP30ADPCM [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || flags || Sum: 1=loop on, 2=stereo (data is &amp;lt;tt&amp;gt;length&amp;lt;/tt&amp;gt; bytes for left channel then &amp;lt;tt&amp;gt;length&amp;lt;/tt&amp;gt; bytes for right channel), 4=16-bit little-endian sample&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || c2spd || Sample rate for middle-C note (C-4)&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[12] || internal || Always zero, used in-memory during playback&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Sample title, for display to user.  Must be null-terminated.&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || sig || Signature: &amp;quot;SCRS&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ScreamTracker stores the above instrument structures at the start of the file, but stores the sample data at the end of the file (after the pattern data.)  This is not the only way to store it though.&lt;br /&gt;
&lt;br /&gt;
==== Adlib ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[3] || reserved || Always 0x00 0x00 0x00&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[12] || oplValues || See below&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Default volume of instrument, 0-63 inclusive.&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || dsk || {{TODO|Unknown}}&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || reserved || Always 0x0000&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || c2spd || Sample rate for middle-C note (C-4), see below.&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[12] || unused || Always zero&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Sample title, for display to user.  Must be null-terminated.&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || sig || Signature: &amp;quot;SCRI&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;oplValues&amp;lt;/tt&amp;gt; are stored as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!rowspan=2| Byte index !!rowspan=2| Operator !!rowspan=2| OPL base register !!colspan=8| Bits&lt;br /&gt;
|-&lt;br /&gt;
!width=100| 7 !!width=100| 6 !!width=100| 5 !!width=100| 4 !!width=100| 3 !!width=100| 2 !!width=100| 1 !!width=100| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0 || Modulator || 0x20 ||align=center rowspan=2| Tremolo? ||align=center rowspan=2| Vibrato? ||align=center rowspan=2| Sustain? ||align=center rowspan=2| KSR? ||align=center rowspan=2 colspan=4| Freq. mult.&lt;br /&gt;
|-&lt;br /&gt;
| 1 || Carrier || 0x23&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Modulator || 0x40 ||align=center rowspan=2| Scale level (bit 0) ||align=center rowspan=2| Scale level (bit 1) ||align=center rowspan=2 colspan=6| Output level (0=loudest, 63=silent)&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Carrier || 0x43&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Modulator || 0x60 ||align=center rowspan=2 colspan=4| Attack rate ||align=center rowspan=2 colspan=4| Decay rate&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Carrier || 0x63&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Modulator || 0x80 ||align=center rowspan=2 colspan=4| Sustain rate ||align=center rowspan=2 colspan=4| Release rate&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Carrier || 0x83&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Modulator || 0xE0 ||align=center rowspan=2 colspan=8| Wave select&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Carrier || 0xE3&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Modulator || 0xC0 ||align=center colspan=7| Feedback ||align=center| Connection&lt;br /&gt;
|-&lt;br /&gt;
| 11 || - || - ||align=center colspan=8| Unused, set to 0x00&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;c2spd&amp;lt;/tt&amp;gt; sets the instrument tuning.  It translates the note freq just like with PCM instruments.  The default value of 8363 (as with PCM instruments) means that middle-C plays at about 261.63 Hz (A440 pitch standard), and e.g. doubling it also doubles the middle-C frequency, as with samples.&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The value packing is almost identical to that used in the [[SBI Format]], just the bytes are in a different order.&lt;br /&gt;
* The ST3 docs say bytes 2-3 bits 5-0 are &amp;quot;63-volume&amp;quot; but this is to make the values match PCM samples.  The value in the file matches the value sent to the OPL chip.&lt;br /&gt;
* The Scale Level bits in bytes 2-3 are swapped.  The ST3 technical docs have a typo that suggest Scale Level (bit 1) actually overflows into &amp;quot;bit 8&amp;quot; of the OPL register, but testing this in ST3 shows this is not the case and the bit order is merely swapped.&lt;br /&gt;
* The ST3 docs say bytes 6-7 have the sustain rate stored as &amp;quot;15-sustain&amp;quot;, which is from a editor UI perspective - the value can be sent as-is to the OPL chip.&lt;br /&gt;
&lt;br /&gt;
=== Patterns ===&lt;br /&gt;
&lt;br /&gt;
At the offset given by a pattern&#039;s parapointer, packed data is present and will need to be unpacked.  The following structure appears at the start of each pattern&#039;s data:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || packed_len || Length of packed data for all 64 rows, in bytes&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[packed_len - 2] || packed_data || Packed row data, described below&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;packed_len&amp;lt;/tt&amp;gt; includes its own length, so as it is two bytes long, the length of the packed data will be two bytes less than this value.  The first byte in &amp;lt;tt&amp;gt;packed_data&amp;lt;/tt&amp;gt; is a bitfield called &amp;lt;tt&amp;gt;what&amp;lt;/tt&amp;gt;, and it is broken up as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!width=100| 7 !!width=100| 6 !!width=100| 5 !!width=100| 4 !!width=100| 3 !!width=100| 2 !!width=100| 1 !!width=100| 0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;command&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;info&amp;lt;/tt&amp;gt; present&lt;br /&gt;
| &amp;lt;tt&amp;gt;volume&amp;lt;/tt&amp;gt; present&lt;br /&gt;
| &amp;lt;tt&amp;gt;note&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;instrument&amp;lt;/tt&amp;gt; present&lt;br /&gt;
|colspan=5 align=center| Channel number&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If the whole byte is zero then it signals the end of the row.  This byte and the ones following are further described in the following table.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || what || 0=end of row, lower five bits (&amp;lt;tt&amp;gt;what &amp;amp; 0x1F&amp;lt;/tt&amp;gt;) are channel number&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || note || Note number (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x20&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || instrument || Instrument number (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x20&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Volume level (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x40&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || command || Effect type (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x80&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || info || Effect value (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x80&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
After these bytes the process repeats with another &amp;lt;tt&amp;gt;what&amp;lt;/tt&amp;gt; value.  When &amp;lt;tt&amp;gt;what&amp;lt;/tt&amp;gt; is 0x00 the end of the row has been reached.  After the 64th row has been reached, the pattern ends and &amp;lt;tt&amp;gt;packed_len&amp;lt;/tt&amp;gt; bytes will have been read.&lt;br /&gt;
&lt;br /&gt;
Be aware that &amp;lt;tt&amp;gt;channel&amp;lt;/tt&amp;gt; is a value between 0 and 31 inclusive, which corresponds to an entry in the &amp;lt;tt&amp;gt;channelSettings&amp;lt;/tt&amp;gt; field in the header.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;volume&amp;lt;/tt&amp;gt; field is 0 for silent, 64 for full volume (note this is 65 unique values), or 255 for &#039;ignore&#039; (shown as &amp;quot;..&amp;quot; in the tracker.)  If the value is 255 or missing entirely, the instrument&#039;s default volume is used (the &amp;lt;tt&amp;gt;volume&amp;lt;/tt&amp;gt; value from the instrument settings.)&lt;br /&gt;
&lt;br /&gt;
The upper four bits of &amp;lt;tt&amp;gt;note&amp;lt;/tt&amp;gt; store the octave, and the lower four bits store the semitone (with 0=C, 1=C#, up to 11=B)&lt;br /&gt;
&lt;br /&gt;
=== Effects ===&lt;br /&gt;
&lt;br /&gt;
==== 0x01/A: Set speed ====&lt;br /&gt;
&lt;br /&gt;
Set &#039;&#039;speed&#039;&#039; (one of the two tempo variables.)  Data byte is new speed.  A value of 0 causes the event to be ignored.&lt;br /&gt;
&lt;br /&gt;
==== 0x02/B: Order jump ====&lt;br /&gt;
&lt;br /&gt;
After the current row has finished playing, the next row is the first row in order given by the data byte.  0 means the start of the song {{TODO|Confirm this}}.&lt;br /&gt;
&lt;br /&gt;
==== 0x03/C: Jump to row ====&lt;br /&gt;
&lt;br /&gt;
After the current row has finished playing, the next row is played from the next pattern in the order sequence.  The row in this next pattern is given by the data byte, but the data byte is decimal-as-hex.  So a value of 0x12 should be treated as decimal 12.  These formulae will calculate the correct row (to/from the S3M value):&lt;br /&gt;
&lt;br /&gt;
 row = (data &amp;gt;&amp;gt; 4) * 10 + (data &amp;amp; 0x0f)    // Read S3M into variable&lt;br /&gt;
 data = ((row / 10) &amp;lt;&amp;lt; 4) | (row % 10)     // Write variable to S3M&lt;br /&gt;
&lt;br /&gt;
The first row in the pattern is 0.  If the decoded data value is larger than 63, the effect is ignored.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://schismtracker.org/ SchismTracker]&lt;br /&gt;
| Platform = Windows/Linux&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canExport = .it + more&lt;br /&gt;
| canImport = [[MOD Format|.mod]] .it + more&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = Yes&lt;br /&gt;
| notes = Can play OPL and PCM simultaneously&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = ScreamTracker 3&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canExport = [[MOD Format|.mod]]&lt;br /&gt;
| canImport = [[MOD Format|.mod]]&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = Yes&lt;br /&gt;
| notes = Official tool&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
&lt;br /&gt;
Much of this information was combined from the following sites:&lt;br /&gt;
&lt;br /&gt;
* TECH.DOC distributed with ScreamTracker 3&lt;br /&gt;
* [http://wiki.multimedia.cx/index.php?title=Scream_Tracker_3_Module S3M on the MultimediaWiki]&lt;br /&gt;
* [http://schismtracker.org/wiki/FS3MDOC.TXT FS3MDOC.TXT] - S3M Player Tutorial&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=S3M_Format&amp;diff=9098</id>
		<title>S3M Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=S3M_Format&amp;diff=9098"/>
		<updated>2020-07-07T08:40:24Z</updated>

		<summary type="html">&lt;p&gt;Saga: Clarify Adlib percussion channels&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | Instruments2 = OPL&lt;br /&gt;
 | NumChannels = 32&lt;br /&gt;
 | NumTracks = 255&lt;br /&gt;
 | NumPatterns = 65,536&lt;br /&gt;
 | NumOrders = 65,536&lt;br /&gt;
 | Tags = Title, instrument names&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Unreal Tournament}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[S3M Format]] is used to save modules composed in ScreamTracker 3.  A number of games support music in this format, however it is primarily used for composing independent songs unrelated to games.&lt;br /&gt;
&lt;br /&gt;
The format is notable both for its popularity, as well as for being one of the few that support both FM/OPL and sampled instruments.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file begins with a header.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Song title, must be null-terminated&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || sig1 || Signature byte, always 0x1A&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || type || Song type, always 0x10 for S3M&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || reserved || Always 0x0000&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || orderCount || Number of entries in the order table, should be even&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || instrumentCount || Number of instruments in the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || patternPtrCount || Number of pattern parapointers in the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || flags || See below&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || trackerVersion || upper four bits is tracker ID, lower 12 bits is tracker version&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || sampleType || 1=signed samples [deprecated], 2=unsigned samples&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || sig2 || Signature: &amp;quot;SCRM&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || globalVolume || &lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || initialSpeed || Frames per row, can be changed later with &amp;lt;tt&amp;gt;A&amp;lt;/tt&amp;gt; command&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || initialTempo || Frames per second, can be changed later with &amp;lt;tt&amp;gt;T&amp;lt;/tt&amp;gt; command&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || masterVolume || bit 7: 1=stereo, 0=mono, bits 6-0: volume&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || ultraClickRemoval || Number of channels to use for click removal on real GUS hardware&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || defaultPan || 252=read pan values in header, anything else ignores pan values in header&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[8] || reserved || Unused, some trackers store data here&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || ptrSpecial || Parapointer to additional data, if &amp;lt;tt&amp;gt;flags&amp;lt;/tt&amp;gt; has bit 7 set&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[32] || channelSettings || See below&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[orderCount] || orderList || Which order patterns are played in&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE[instrumentCount] || ptrInstruments || List of parapointers to each instrument&#039;s data&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE[patternPtrCount] || ptrPatterns || List of parapointers to each pattern&#039;s data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Flags are one or more values below:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Bit !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || ST2 vibrato [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 2 || ST2 tempo [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 4 || Amiga slides [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 8 || 0vol optimisations - automatically turn off looping notes when the volume is zero for more than two rows&lt;br /&gt;
|-&lt;br /&gt;
| 4 || 16 || Amiga limits - ignore notes beyond Amiga hardware limits (as Amiga does.)  Sliding up stops at B#5.  Also affects other Amiga compatibility issues.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || 32 || Enable SoundBlaster filter/sfx [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 64 || ST3.00 volume slides - perform volume slides on first row as well.  Set implicitly if &amp;lt;tt&amp;gt;trackerVersion&amp;lt;/tt&amp;gt; is 0x1300.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 128 || &amp;lt;tt&amp;gt;ptrSpecial&amp;lt;/tt&amp;gt; is valid&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Known &amp;lt;tt&amp;gt;trackerVersion&amp;lt;/tt&amp;gt; values are:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x1300 || ScreamTracker 3.00&lt;br /&gt;
|-&lt;br /&gt;
| 0x1301 || ScreamTracker 3.01&lt;br /&gt;
|-&lt;br /&gt;
| 0x1303 || ScreamTracker 3.03&lt;br /&gt;
|-&lt;br /&gt;
| 0x1320 || ScreamTracker 3.20&lt;br /&gt;
|-&lt;br /&gt;
| 0x2nyy || Imago Orpheus x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x3nyy || Impulse Tracker x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x4nnn || Schism Tracker (old BeRoTracker version from between 2004 and 2012 identify as 0x4100)&lt;br /&gt;
|-&lt;br /&gt;
| 0x5nyy || OpenMPT x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x6nyy || BeRoTracker x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x7nyy || CreamTracker x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0xCA00 || Camoto/libgamemusic&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;channelSettings&amp;lt;/tt&amp;gt; is 32 values indicating the audio channel assignments for each of the 32 S3M channels.  Unused channels should be set to 255.  If the high bit is set, a channel is disabled (muted). Note that Scream Tracker 3 does not even process global effects (such as tempo changes) on muted channels. &lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 to 7 || Left PCM channels 1 to 8&lt;br /&gt;
|-&lt;br /&gt;
| 8 to 15 || Right PCM channels 1 to 8&lt;br /&gt;
|-&lt;br /&gt;
| 16 to 24 || Adlib melody channel 1-9&lt;br /&gt;
|-&lt;br /&gt;
| 25 || Adlib percussion channel: bass drum&lt;br /&gt;
|-&lt;br /&gt;
| 26 || Adlib percussion channel: snare drum&lt;br /&gt;
|-&lt;br /&gt;
| 27 || Adlib percussion channel: tom tom&lt;br /&gt;
|-&lt;br /&gt;
| 28 || Adlib percussion channel: top cymbal&lt;br /&gt;
|-&lt;br /&gt;
| 29 || Adlib percussion channel: hi-hat&lt;br /&gt;
|-&lt;br /&gt;
| 30 to 127 || Unused/invalid&lt;br /&gt;
|-&lt;br /&gt;
| 128 to 254 || Same as above + 128 (disabled)&lt;br /&gt;
|-&lt;br /&gt;
| 255 || Channel unused&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Adlib percussion channels are not implemented in Scream Tracker 3. All they do is showing a different channel type in the channel setup, but they don&#039;t do anything. There is no percussion instrument format defined, either.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;orderList&amp;lt;/tt&amp;gt; contains the index of each pattern to be played.  The first entry in this array is the index of the first pattern to play, the second entry is the second pattern, etc.  If an entry is 0xFE then it is a &amp;quot;marker pattern&amp;quot; and is skipped during playback, and an entry of 0xFF signifies the end of the song.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;ptrInstruments&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ptrPatterns&amp;lt;/tt&amp;gt; are arrays of parapointers to the start of the instrument and pattern data.  Each parapointer is an offset from the start of the file, in units of 16 bytes (a &amp;quot;paragraph&amp;quot;).  To convert this into a normal byte-level file offset, multiply it by 16 (or shift-left by 4.)&lt;br /&gt;
&lt;br /&gt;
By convention these blocks follow the header above, but this is not a requirement and they can occur at any point in the file.&lt;br /&gt;
&lt;br /&gt;
=== Timing ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;initialTempo&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;initialSpeed&amp;lt;/tt&amp;gt; values are the ones to use until optionally changed during playback, with the A and T effects respectively.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;initialTempo&amp;lt;/tt&amp;gt; value controls how many audio frames are generated per second.  If this value is 50, then there should be 50 audio frames per second.  Obviously the more audio frames per second, the shorter each frame is going to be.  To calculate the length of each frame, a formula like this can be used:&lt;br /&gt;
&lt;br /&gt;
    frame length in seconds = 1 / initialTempo&lt;br /&gt;
     0.02 seconds per frame = 1 / 50&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;initialSpeed&amp;lt;/tt&amp;gt; value controls how many audio frames comprise a single row of the song.  If the value is 3, then there are three audio frames per row.  For certain effects, they are updated once per frame (i.e. the effect changes between rows.)&lt;br /&gt;
&lt;br /&gt;
To calculate playback speed, both these values need to be taken into account.  The tempo value controls the length of each audio frame, while the speed value controls how quickly the rows are turned into those audio frames.  For example, to calculate the number of rows per second:&lt;br /&gt;
&lt;br /&gt;
    rowsPerSecond = initialTempo / initialSpeed&lt;br /&gt;
&lt;br /&gt;
=== Instruments ===&lt;br /&gt;
&lt;br /&gt;
At the offset given by an instrument&#039;s parapointer, the data has a header as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || type || 0=empty instrument (message only), 1=PCM instrument&lt;br /&gt;
|-&lt;br /&gt;
| char[12] || filename || Original instrument filename in DOS 8.3 format, no terminating null&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || empty instrument (message only)&lt;br /&gt;
|-&lt;br /&gt;
| 1 || PCM instrument&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Adlib melody instrument&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Adlib percussive: bass drum&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Adlib percussive: snare&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Adlib percussive: tom tom&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Adlib percussive: top cymbal&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Adlib percussive: hi-hat&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The data following the header depends on whether the instrument is PCM or Adlib.&lt;br /&gt;
{{TODO|What if the instrument is empty, is there any trailing data?}}&lt;br /&gt;
&lt;br /&gt;
==== PCM ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || ptrDataH || Upper eight bits of parapointer to sample data, relative to start of S3M file&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || ptrDataL || Lower 16 bits of parapointer to sample data, relative to start of S3M file&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Sample data length, in bytes.  S3M is limited to 64000 and ignores upper 16 bits.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Offset of loop start in bytes, relative to start of sample data.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopEnd || Offset of loop end in bytes, relative to start of sample data.&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Default volume of sample, 0-63 inclusive.&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || reserved || Always 0x00&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || pack || 0=unpacked, 1=DP30ADPCM [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || flags || Sum: 1=loop on, 2=stereo (data is &amp;lt;tt&amp;gt;length&amp;lt;/tt&amp;gt; bytes for left channel then &amp;lt;tt&amp;gt;length&amp;lt;/tt&amp;gt; bytes for right channel), 4=16-bit little-endian sample&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || c2spd || Sample rate for middle-C note (C-4)&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[12] || internal || Always zero, used in-memory during playback&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Sample title, for display to user.  Must be null-terminated.&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || sig || Signature: &amp;quot;SCRS&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ScreamTracker stores the above instrument structures at the start of the file, but stores the sample data at the end of the file (after the pattern data.)  This is not the only way to store it though.&lt;br /&gt;
&lt;br /&gt;
==== Adlib ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[3] || reserved || Always 0x00 0x00 0x00&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[12] || oplValues || See below&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Default volume of instrument, 0-63 inclusive.&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || dsk || {{TODO|Unknown}}&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || reserved || Always 0x0000&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || c2spd || Sample rate for middle-C note (C-4), see below.&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[12] || unused || Always zero&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Sample title, for display to user.  Must be null-terminated.&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || sig || Signature: &amp;quot;SCRI&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;oplValues&amp;lt;/tt&amp;gt; are stored as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!rowspan=2| Byte index !!rowspan=2| Operator !!rowspan=2| OPL base register !!colspan=8| Bits&lt;br /&gt;
|-&lt;br /&gt;
!width=100| 7 !!width=100| 6 !!width=100| 5 !!width=100| 4 !!width=100| 3 !!width=100| 2 !!width=100| 1 !!width=100| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0 || Modulator || 0x20 ||align=center rowspan=2| Tremolo? ||align=center rowspan=2| Vibrato? ||align=center rowspan=2| Sustain? ||align=center rowspan=2| KSR? ||align=center rowspan=2 colspan=4| Freq. mult.&lt;br /&gt;
|-&lt;br /&gt;
| 1 || Carrier || 0x23&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Modulator || 0x40 ||align=center rowspan=2| Scale level (bit 0) ||align=center rowspan=2| Scale level (bit 1) ||align=center rowspan=2 colspan=6| Output level (0=loudest, 63=silent)&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Carrier || 0x43&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Modulator || 0x60 ||align=center rowspan=2 colspan=4| Attack rate ||align=center rowspan=2 colspan=4| Decay rate&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Carrier || 0x63&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Modulator || 0x80 ||align=center rowspan=2 colspan=4| Sustain rate ||align=center rowspan=2 colspan=4| Release rate&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Carrier || 0x83&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Modulator || 0xE0 ||align=center rowspan=2 colspan=8| Wave select&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Carrier || 0xE3&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Modulator || 0xC0 ||align=center colspan=7| Feedback ||align=center| Connection&lt;br /&gt;
|-&lt;br /&gt;
| 11 || - || - ||align=center colspan=8| Unused, set to 0x00&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;c2spd&amp;lt;/tt&amp;gt; sets the instrument tuning.  It translates the note freq just like with PCM instruments.  The default value of 8363 (as with PCM instruments) means that middle-C plays at about 261.63 Hz (A440 pitch standard), and e.g. doubling it also doubles the middle-C frequency, as with samples.&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The value packing is almost identical to that used in the [[SBI Format]], just the bytes are in a different order.&lt;br /&gt;
* The ST3 docs say bytes 2-3 bits 5-0 are &amp;quot;63-volume&amp;quot; but this is to make the values match PCM samples.  The value in the file matches the value sent to the OPL chip.&lt;br /&gt;
* The Scale Level bits in bytes 2-3 are swapped.  The ST3 technical docs have a typo that suggest Scale Level (bit 1) actually overflows into &amp;quot;bit 8&amp;quot; of the OPL register, but testing this in ST3 shows this is not the case and the bit order is merely swapped.&lt;br /&gt;
* The ST3 docs say bytes 6-7 have the sustain rate stored as &amp;quot;15-sustain&amp;quot;, which is from a editor UI perspective - the value can be sent as-is to the OPL chip.&lt;br /&gt;
&lt;br /&gt;
=== Patterns ===&lt;br /&gt;
&lt;br /&gt;
At the offset given by a pattern&#039;s parapointer, packed data is present and will need to be unpacked.  The following structure appears at the start of each pattern&#039;s data:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || packed_len || Length of packed data for all 64 rows, in bytes&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[packed_len - 2] || packed_data || Packed row data, described below&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;packed_len&amp;lt;/tt&amp;gt; includes its own length, so as it is two bytes long, the length of the packed data will be two bytes less than this value.  The first byte in &amp;lt;tt&amp;gt;packed_data&amp;lt;/tt&amp;gt; is a bitfield called &amp;lt;tt&amp;gt;what&amp;lt;/tt&amp;gt;, and it is broken up as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!width=100| 7 !!width=100| 6 !!width=100| 5 !!width=100| 4 !!width=100| 3 !!width=100| 2 !!width=100| 1 !!width=100| 0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;command&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;info&amp;lt;/tt&amp;gt; present&lt;br /&gt;
| &amp;lt;tt&amp;gt;volume&amp;lt;/tt&amp;gt; present&lt;br /&gt;
| &amp;lt;tt&amp;gt;note&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;instrument&amp;lt;/tt&amp;gt; present&lt;br /&gt;
|colspan=5 align=center| Channel number&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If the whole byte is zero then it signals the end of the row.  This byte and the ones following are further described in the following table.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || what || 0=end of row, lower five bits (&amp;lt;tt&amp;gt;what &amp;amp; 0x1F&amp;lt;/tt&amp;gt;) are channel number&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || note || Note number (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x20&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || instrument || Instrument number (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x20&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Volume level (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x40&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || command || Effect type (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x80&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || info || Effect value (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x80&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
After these bytes the process repeats with another &amp;lt;tt&amp;gt;what&amp;lt;/tt&amp;gt; value.  When &amp;lt;tt&amp;gt;what&amp;lt;/tt&amp;gt; is 0x00 the end of the row has been reached.  After the 64th row has been reached, the pattern ends and &amp;lt;tt&amp;gt;packed_len&amp;lt;/tt&amp;gt; bytes will have been read.&lt;br /&gt;
&lt;br /&gt;
Be aware that &amp;lt;tt&amp;gt;channel&amp;lt;/tt&amp;gt; is a value between 0 and 31 inclusive, which corresponds to an entry in the &amp;lt;tt&amp;gt;channelSettings&amp;lt;/tt&amp;gt; field in the header.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;volume&amp;lt;/tt&amp;gt; field is 0 for silent, 64 for full volume (note this is 65 unique values), or 255 for &#039;ignore&#039; (shown as &amp;quot;..&amp;quot; in the tracker.)  If the value is 255 or missing entirely, the instrument&#039;s default volume is used (the &amp;lt;tt&amp;gt;volume&amp;lt;/tt&amp;gt; value from the instrument settings.)&lt;br /&gt;
&lt;br /&gt;
The upper four bits of &amp;lt;tt&amp;gt;note&amp;lt;/tt&amp;gt; store the octave, and the lower four bits store the semitone (with 0=C, 1=C#, up to 11=B)&lt;br /&gt;
&lt;br /&gt;
=== Effects ===&lt;br /&gt;
&lt;br /&gt;
==== 0x01/A: Set speed ====&lt;br /&gt;
&lt;br /&gt;
Set &#039;&#039;speed&#039;&#039; (one of the two tempo variables.)  Data byte is new speed.  A value of 0 causes the event to be ignored.&lt;br /&gt;
&lt;br /&gt;
==== 0x02/B: Order jump ====&lt;br /&gt;
&lt;br /&gt;
After the current row has finished playing, the next row is the first row in order given by the data byte.  0 means the start of the song {{TODO|Confirm this}}.&lt;br /&gt;
&lt;br /&gt;
==== 0x03/C: Jump to row ====&lt;br /&gt;
&lt;br /&gt;
After the current row has finished playing, the next row is played from the next pattern in the order sequence.  The row in this next pattern is given by the data byte, but the data byte is decimal-as-hex.  So a value of 0x12 should be treated as decimal 12.  These formulae will calculate the correct row (to/from the S3M value):&lt;br /&gt;
&lt;br /&gt;
 row = (data &amp;gt;&amp;gt; 4) * 10 + (data &amp;amp; 0x0f)    // Read S3M into variable&lt;br /&gt;
 data = ((row / 10) &amp;lt;&amp;lt; 4) | (row % 10)     // Write variable to S3M&lt;br /&gt;
&lt;br /&gt;
The first row in the pattern is 0.  If the decoded data value is larger than 63, the effect is ignored.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://schismtracker.org/ SchismTracker]&lt;br /&gt;
| Platform = Windows/Linux&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canExport = .it + more&lt;br /&gt;
| canImport = [[MOD Format|.mod]] .it + more&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = Yes&lt;br /&gt;
| notes = Can play OPL and PCM simultaneously&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = ScreamTracker 3&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canExport = [[MOD Format|.mod]]&lt;br /&gt;
| canImport = [[MOD Format|.mod]]&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = Yes&lt;br /&gt;
| notes = Official tool&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
&lt;br /&gt;
Much of this information was combined from the following sites:&lt;br /&gt;
&lt;br /&gt;
* TECH.DOC distributed with ScreamTracker 3&lt;br /&gt;
* [http://wiki.multimedia.cx/index.php?title=Scream_Tracker_3_Module S3M on the MultimediaWiki]&lt;br /&gt;
* [http://schismtracker.org/wiki/FS3MDOC.TXT FS3MDOC.TXT] - S3M Player Tutorial&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=S3M_Format&amp;diff=9097</id>
		<title>S3M Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=S3M_Format&amp;diff=9097"/>
		<updated>2020-07-07T08:37:30Z</updated>

		<summary type="html">&lt;p&gt;Saga: Properly document disabled/mued channels&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | Instruments2 = OPL&lt;br /&gt;
 | NumChannels = 32&lt;br /&gt;
 | NumTracks = 255&lt;br /&gt;
 | NumPatterns = 65,536&lt;br /&gt;
 | NumOrders = 65,536&lt;br /&gt;
 | Tags = Title, instrument names&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Unreal Tournament}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[S3M Format]] is used to save modules composed in ScreamTracker 3.  A number of games support music in this format, however it is primarily used for composing independent songs unrelated to games.&lt;br /&gt;
&lt;br /&gt;
The format is notable both for its popularity, as well as for being one of the few that support both FM/OPL and sampled instruments.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file begins with a header.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Song title, must be null-terminated&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || sig1 || Signature byte, always 0x1A&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || type || Song type, always 0x10 for S3M&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || reserved || Always 0x0000&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || orderCount || Number of entries in the order table, should be even&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || instrumentCount || Number of instruments in the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || patternPtrCount || Number of pattern parapointers in the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || flags || See below&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || trackerVersion || upper four bits is tracker ID, lower 12 bits is tracker version&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || sampleType || 1=signed samples [deprecated], 2=unsigned samples&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || sig2 || Signature: &amp;quot;SCRM&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || globalVolume || &lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || initialSpeed || Frames per row, can be changed later with &amp;lt;tt&amp;gt;A&amp;lt;/tt&amp;gt; command&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || initialTempo || Frames per second, can be changed later with &amp;lt;tt&amp;gt;T&amp;lt;/tt&amp;gt; command&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || masterVolume || bit 7: 1=stereo, 0=mono, bits 6-0: volume&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || ultraClickRemoval || Number of channels to use for click removal on real GUS hardware&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || defaultPan || 252=read pan values in header, anything else ignores pan values in header&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[8] || reserved || Unused, some trackers store data here&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || ptrSpecial || Parapointer to additional data, if &amp;lt;tt&amp;gt;flags&amp;lt;/tt&amp;gt; has bit 7 set&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[32] || channelSettings || See below&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[orderCount] || orderList || Which order patterns are played in&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE[instrumentCount] || ptrInstruments || List of parapointers to each instrument&#039;s data&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE[patternPtrCount] || ptrPatterns || List of parapointers to each pattern&#039;s data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Flags are one or more values below:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Bit !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || ST2 vibrato [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 2 || ST2 tempo [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 4 || Amiga slides [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 8 || 0vol optimisations - automatically turn off looping notes when the volume is zero for more than two rows&lt;br /&gt;
|-&lt;br /&gt;
| 4 || 16 || Amiga limits - ignore notes beyond Amiga hardware limits (as Amiga does.)  Sliding up stops at B#5.  Also affects other Amiga compatibility issues.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || 32 || Enable SoundBlaster filter/sfx [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 64 || ST3.00 volume slides - perform volume slides on first row as well.  Set implicitly if &amp;lt;tt&amp;gt;trackerVersion&amp;lt;/tt&amp;gt; is 0x1300.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 128 || &amp;lt;tt&amp;gt;ptrSpecial&amp;lt;/tt&amp;gt; is valid&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Known &amp;lt;tt&amp;gt;trackerVersion&amp;lt;/tt&amp;gt; values are:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x1300 || ScreamTracker 3.00&lt;br /&gt;
|-&lt;br /&gt;
| 0x1301 || ScreamTracker 3.01&lt;br /&gt;
|-&lt;br /&gt;
| 0x1303 || ScreamTracker 3.03&lt;br /&gt;
|-&lt;br /&gt;
| 0x1320 || ScreamTracker 3.20&lt;br /&gt;
|-&lt;br /&gt;
| 0x2nyy || Imago Orpheus x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x3nyy || Impulse Tracker x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x4nnn || Schism Tracker (old BeRoTracker version from between 2004 and 2012 identify as 0x4100)&lt;br /&gt;
|-&lt;br /&gt;
| 0x5nyy || OpenMPT x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x6nyy || BeRoTracker x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x7nyy || CreamTracker x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0xCA00 || Camoto/libgamemusic&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;channelSettings&amp;lt;/tt&amp;gt; is 32 values indicating the audio channel assignments for each of the 32 S3M channels.  Unused channels should be set to 255.  If the high bit is set, a channel is disabled (muted). Note that Scream Tracker 3 does not even process global effects (such as tempo changes) on muted channels. &lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 to 7 || Left PCM channels 1 to 8&lt;br /&gt;
|-&lt;br /&gt;
| 8 to 15 || Right PCM channels 1 to 8&lt;br /&gt;
|-&lt;br /&gt;
| 16 to 24 || Adlib melody channel 1-9&lt;br /&gt;
|-&lt;br /&gt;
| 25 || Adlib percussion channel: bass drum&lt;br /&gt;
|-&lt;br /&gt;
| 26 || Adlib percussion channel: snare drum&lt;br /&gt;
|-&lt;br /&gt;
| 27 || Adlib percussion channel: tom tom&lt;br /&gt;
|-&lt;br /&gt;
| 28 || Adlib percussion channel: top cymbal&lt;br /&gt;
|-&lt;br /&gt;
| 29 || Adlib percussion channel: hi-hat&lt;br /&gt;
|-&lt;br /&gt;
| 30 to 127 || Unused/invalid&lt;br /&gt;
|-&lt;br /&gt;
| 128 to 254 || Same as above + 128 (disabled)&lt;br /&gt;
|-&lt;br /&gt;
| 255 || Channel unused&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;orderList&amp;lt;/tt&amp;gt; contains the index of each pattern to be played.  The first entry in this array is the index of the first pattern to play, the second entry is the second pattern, etc.  If an entry is 0xFE then it is a &amp;quot;marker pattern&amp;quot; and is skipped during playback, and an entry of 0xFF signifies the end of the song.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;ptrInstruments&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ptrPatterns&amp;lt;/tt&amp;gt; are arrays of parapointers to the start of the instrument and pattern data.  Each parapointer is an offset from the start of the file, in units of 16 bytes (a &amp;quot;paragraph&amp;quot;).  To convert this into a normal byte-level file offset, multiply it by 16 (or shift-left by 4.)&lt;br /&gt;
&lt;br /&gt;
By convention these blocks follow the header above, but this is not a requirement and they can occur at any point in the file.&lt;br /&gt;
&lt;br /&gt;
=== Timing ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;initialTempo&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;initialSpeed&amp;lt;/tt&amp;gt; values are the ones to use until optionally changed during playback, with the A and T effects respectively.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;initialTempo&amp;lt;/tt&amp;gt; value controls how many audio frames are generated per second.  If this value is 50, then there should be 50 audio frames per second.  Obviously the more audio frames per second, the shorter each frame is going to be.  To calculate the length of each frame, a formula like this can be used:&lt;br /&gt;
&lt;br /&gt;
    frame length in seconds = 1 / initialTempo&lt;br /&gt;
     0.02 seconds per frame = 1 / 50&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;initialSpeed&amp;lt;/tt&amp;gt; value controls how many audio frames comprise a single row of the song.  If the value is 3, then there are three audio frames per row.  For certain effects, they are updated once per frame (i.e. the effect changes between rows.)&lt;br /&gt;
&lt;br /&gt;
To calculate playback speed, both these values need to be taken into account.  The tempo value controls the length of each audio frame, while the speed value controls how quickly the rows are turned into those audio frames.  For example, to calculate the number of rows per second:&lt;br /&gt;
&lt;br /&gt;
    rowsPerSecond = initialTempo / initialSpeed&lt;br /&gt;
&lt;br /&gt;
=== Instruments ===&lt;br /&gt;
&lt;br /&gt;
At the offset given by an instrument&#039;s parapointer, the data has a header as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || type || 0=empty instrument (message only), 1=PCM instrument&lt;br /&gt;
|-&lt;br /&gt;
| char[12] || filename || Original instrument filename in DOS 8.3 format, no terminating null&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || empty instrument (message only)&lt;br /&gt;
|-&lt;br /&gt;
| 1 || PCM instrument&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Adlib melody instrument&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Adlib percussive: bass drum&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Adlib percussive: snare&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Adlib percussive: tom tom&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Adlib percussive: top cymbal&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Adlib percussive: hi-hat&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The data following the header depends on whether the instrument is PCM or Adlib.&lt;br /&gt;
{{TODO|What if the instrument is empty, is there any trailing data?}}&lt;br /&gt;
&lt;br /&gt;
==== PCM ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || ptrDataH || Upper eight bits of parapointer to sample data, relative to start of S3M file&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || ptrDataL || Lower 16 bits of parapointer to sample data, relative to start of S3M file&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Sample data length, in bytes.  S3M is limited to 64000 and ignores upper 16 bits.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Offset of loop start in bytes, relative to start of sample data.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopEnd || Offset of loop end in bytes, relative to start of sample data.&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Default volume of sample, 0-63 inclusive.&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || reserved || Always 0x00&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || pack || 0=unpacked, 1=DP30ADPCM [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || flags || Sum: 1=loop on, 2=stereo (data is &amp;lt;tt&amp;gt;length&amp;lt;/tt&amp;gt; bytes for left channel then &amp;lt;tt&amp;gt;length&amp;lt;/tt&amp;gt; bytes for right channel), 4=16-bit little-endian sample&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || c2spd || Sample rate for middle-C note (C-4)&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[12] || internal || Always zero, used in-memory during playback&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Sample title, for display to user.  Must be null-terminated.&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || sig || Signature: &amp;quot;SCRS&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ScreamTracker stores the above instrument structures at the start of the file, but stores the sample data at the end of the file (after the pattern data.)  This is not the only way to store it though.&lt;br /&gt;
&lt;br /&gt;
==== Adlib ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[3] || reserved || Always 0x00 0x00 0x00&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[12] || oplValues || See below&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Default volume of instrument, 0-63 inclusive.&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || dsk || {{TODO|Unknown}}&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || reserved || Always 0x0000&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || c2spd || Sample rate for middle-C note (C-4), see below.&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[12] || unused || Always zero&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Sample title, for display to user.  Must be null-terminated.&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || sig || Signature: &amp;quot;SCRI&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;oplValues&amp;lt;/tt&amp;gt; are stored as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!rowspan=2| Byte index !!rowspan=2| Operator !!rowspan=2| OPL base register !!colspan=8| Bits&lt;br /&gt;
|-&lt;br /&gt;
!width=100| 7 !!width=100| 6 !!width=100| 5 !!width=100| 4 !!width=100| 3 !!width=100| 2 !!width=100| 1 !!width=100| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0 || Modulator || 0x20 ||align=center rowspan=2| Tremolo? ||align=center rowspan=2| Vibrato? ||align=center rowspan=2| Sustain? ||align=center rowspan=2| KSR? ||align=center rowspan=2 colspan=4| Freq. mult.&lt;br /&gt;
|-&lt;br /&gt;
| 1 || Carrier || 0x23&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Modulator || 0x40 ||align=center rowspan=2| Scale level (bit 0) ||align=center rowspan=2| Scale level (bit 1) ||align=center rowspan=2 colspan=6| Output level (0=loudest, 63=silent)&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Carrier || 0x43&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Modulator || 0x60 ||align=center rowspan=2 colspan=4| Attack rate ||align=center rowspan=2 colspan=4| Decay rate&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Carrier || 0x63&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Modulator || 0x80 ||align=center rowspan=2 colspan=4| Sustain rate ||align=center rowspan=2 colspan=4| Release rate&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Carrier || 0x83&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Modulator || 0xE0 ||align=center rowspan=2 colspan=8| Wave select&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Carrier || 0xE3&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Modulator || 0xC0 ||align=center colspan=7| Feedback ||align=center| Connection&lt;br /&gt;
|-&lt;br /&gt;
| 11 || - || - ||align=center colspan=8| Unused, set to 0x00&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;c2spd&amp;lt;/tt&amp;gt; sets the instrument tuning.  It translates the note freq just like with PCM instruments.  The default value of 8363 (as with PCM instruments) means that middle-C plays at about 261.63 Hz (A440 pitch standard), and e.g. doubling it also doubles the middle-C frequency, as with samples.&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The value packing is almost identical to that used in the [[SBI Format]], just the bytes are in a different order.&lt;br /&gt;
* The ST3 docs say bytes 2-3 bits 5-0 are &amp;quot;63-volume&amp;quot; but this is to make the values match PCM samples.  The value in the file matches the value sent to the OPL chip.&lt;br /&gt;
* The Scale Level bits in bytes 2-3 are swapped.  The ST3 technical docs have a typo that suggest Scale Level (bit 1) actually overflows into &amp;quot;bit 8&amp;quot; of the OPL register, but testing this in ST3 shows this is not the case and the bit order is merely swapped.&lt;br /&gt;
* The ST3 docs say bytes 6-7 have the sustain rate stored as &amp;quot;15-sustain&amp;quot;, which is from a editor UI perspective - the value can be sent as-is to the OPL chip.&lt;br /&gt;
&lt;br /&gt;
=== Patterns ===&lt;br /&gt;
&lt;br /&gt;
At the offset given by a pattern&#039;s parapointer, packed data is present and will need to be unpacked.  The following structure appears at the start of each pattern&#039;s data:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || packed_len || Length of packed data for all 64 rows, in bytes&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[packed_len - 2] || packed_data || Packed row data, described below&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;packed_len&amp;lt;/tt&amp;gt; includes its own length, so as it is two bytes long, the length of the packed data will be two bytes less than this value.  The first byte in &amp;lt;tt&amp;gt;packed_data&amp;lt;/tt&amp;gt; is a bitfield called &amp;lt;tt&amp;gt;what&amp;lt;/tt&amp;gt;, and it is broken up as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!width=100| 7 !!width=100| 6 !!width=100| 5 !!width=100| 4 !!width=100| 3 !!width=100| 2 !!width=100| 1 !!width=100| 0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;command&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;info&amp;lt;/tt&amp;gt; present&lt;br /&gt;
| &amp;lt;tt&amp;gt;volume&amp;lt;/tt&amp;gt; present&lt;br /&gt;
| &amp;lt;tt&amp;gt;note&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;instrument&amp;lt;/tt&amp;gt; present&lt;br /&gt;
|colspan=5 align=center| Channel number&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If the whole byte is zero then it signals the end of the row.  This byte and the ones following are further described in the following table.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || what || 0=end of row, lower five bits (&amp;lt;tt&amp;gt;what &amp;amp; 0x1F&amp;lt;/tt&amp;gt;) are channel number&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || note || Note number (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x20&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || instrument || Instrument number (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x20&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Volume level (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x40&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || command || Effect type (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x80&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || info || Effect value (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x80&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
After these bytes the process repeats with another &amp;lt;tt&amp;gt;what&amp;lt;/tt&amp;gt; value.  When &amp;lt;tt&amp;gt;what&amp;lt;/tt&amp;gt; is 0x00 the end of the row has been reached.  After the 64th row has been reached, the pattern ends and &amp;lt;tt&amp;gt;packed_len&amp;lt;/tt&amp;gt; bytes will have been read.&lt;br /&gt;
&lt;br /&gt;
Be aware that &amp;lt;tt&amp;gt;channel&amp;lt;/tt&amp;gt; is a value between 0 and 31 inclusive, which corresponds to an entry in the &amp;lt;tt&amp;gt;channelSettings&amp;lt;/tt&amp;gt; field in the header.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;volume&amp;lt;/tt&amp;gt; field is 0 for silent, 64 for full volume (note this is 65 unique values), or 255 for &#039;ignore&#039; (shown as &amp;quot;..&amp;quot; in the tracker.)  If the value is 255 or missing entirely, the instrument&#039;s default volume is used (the &amp;lt;tt&amp;gt;volume&amp;lt;/tt&amp;gt; value from the instrument settings.)&lt;br /&gt;
&lt;br /&gt;
The upper four bits of &amp;lt;tt&amp;gt;note&amp;lt;/tt&amp;gt; store the octave, and the lower four bits store the semitone (with 0=C, 1=C#, up to 11=B)&lt;br /&gt;
&lt;br /&gt;
=== Effects ===&lt;br /&gt;
&lt;br /&gt;
==== 0x01/A: Set speed ====&lt;br /&gt;
&lt;br /&gt;
Set &#039;&#039;speed&#039;&#039; (one of the two tempo variables.)  Data byte is new speed.  A value of 0 causes the event to be ignored.&lt;br /&gt;
&lt;br /&gt;
==== 0x02/B: Order jump ====&lt;br /&gt;
&lt;br /&gt;
After the current row has finished playing, the next row is the first row in order given by the data byte.  0 means the start of the song {{TODO|Confirm this}}.&lt;br /&gt;
&lt;br /&gt;
==== 0x03/C: Jump to row ====&lt;br /&gt;
&lt;br /&gt;
After the current row has finished playing, the next row is played from the next pattern in the order sequence.  The row in this next pattern is given by the data byte, but the data byte is decimal-as-hex.  So a value of 0x12 should be treated as decimal 12.  These formulae will calculate the correct row (to/from the S3M value):&lt;br /&gt;
&lt;br /&gt;
 row = (data &amp;gt;&amp;gt; 4) * 10 + (data &amp;amp; 0x0f)    // Read S3M into variable&lt;br /&gt;
 data = ((row / 10) &amp;lt;&amp;lt; 4) | (row % 10)     // Write variable to S3M&lt;br /&gt;
&lt;br /&gt;
The first row in the pattern is 0.  If the decoded data value is larger than 63, the effect is ignored.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://schismtracker.org/ SchismTracker]&lt;br /&gt;
| Platform = Windows/Linux&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canExport = .it + more&lt;br /&gt;
| canImport = [[MOD Format|.mod]] .it + more&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = Yes&lt;br /&gt;
| notes = Can play OPL and PCM simultaneously&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = ScreamTracker 3&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canExport = [[MOD Format|.mod]]&lt;br /&gt;
| canImport = [[MOD Format|.mod]]&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = Yes&lt;br /&gt;
| notes = Official tool&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
&lt;br /&gt;
Much of this information was combined from the following sites:&lt;br /&gt;
&lt;br /&gt;
* TECH.DOC distributed with ScreamTracker 3&lt;br /&gt;
* [http://wiki.multimedia.cx/index.php?title=Scream_Tracker_3_Module S3M on the MultimediaWiki]&lt;br /&gt;
* [http://schismtracker.org/wiki/FS3MDOC.TXT FS3MDOC.TXT] - S3M Player Tutorial&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=S3M_Format&amp;diff=7636</id>
		<title>S3M Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=S3M_Format&amp;diff=7636"/>
		<updated>2018-06-12T21:31:54Z</updated>

		<summary type="html">&lt;p&gt;Saga: Update trackerVersion table&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | Instruments2 = OPL&lt;br /&gt;
 | NumChannels = 32&lt;br /&gt;
 | NumTracks = 255&lt;br /&gt;
 | NumPatterns = 65,536&lt;br /&gt;
 | NumOrders = 65,536&lt;br /&gt;
 | Tags = Title, instrument names&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Unreal Tournament}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[S3M Format]] is used to save modules composed in ScreamTracker 3.  A number of games support music in this format, however it is primarily used for composing independent songs unrelated to games.&lt;br /&gt;
&lt;br /&gt;
The format is notable both for its popularity, as well as for being one of the few that support both FM/OPL and sampled instruments.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file begins with a header.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Song title, must be null-terminated&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || sig1 || Signature byte, always 0x1A&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || type || Song type, always 0x10 for S3M&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || reserved || Always 0x0000&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || orderCount || Number of entries in the order table, should be even&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || instrumentCount || Number of instruments in the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || patternPtrCount || Number of pattern parapointers in the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || flags || See below&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || trackerVersion || upper four bits is tracker ID, lower 12 bits is tracker version&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || sampleType || 1=signed samples [deprecated], 2=unsigned samples&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || sig2 || Signature: &amp;quot;SCRM&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || globalVolume || &lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || initialSpeed || Frames per row, can be changed later with &amp;lt;tt&amp;gt;A&amp;lt;/tt&amp;gt; command&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || initialTempo || Frames per second, can be changed later with &amp;lt;tt&amp;gt;T&amp;lt;/tt&amp;gt; command&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || masterVolume || bit 7: 1=stereo, 0=mono, bits 6-0: volume&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || ultraClickRemoval || Number of channels to use for click removal on real GUS hardware&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || defaultPan || 252=read pan values in header, anything else ignores pan values in header&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[8] || reserved || Unused, some trackers store data here&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || ptrSpecial || Parapointer to additional data, if &amp;lt;tt&amp;gt;flags&amp;lt;/tt&amp;gt; has bit 7 set&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[32] || channelSettings || See below&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[orderCount] || orderList || Which order patterns are played in&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE[instrumentCount] || ptrInstruments || List of parapointers to each instrument&#039;s data&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE[patternPtrCount] || ptrPatterns || List of parapointers to each pattern&#039;s data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Flags are one or more values below:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Bit !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || ST2 vibrato [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 2 || ST2 tempo [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 4 || Amiga slides [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 8 || 0vol optimisations - automatically turn off looping notes when the volume is zero for more than two rows&lt;br /&gt;
|-&lt;br /&gt;
| 4 || 16 || Amiga limits - ignore notes beyond Amiga hardware limits (as Amiga does.)  Sliding up stops at B#5.  Also affects other Amiga compatibility issues.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || 32 || Enable SoundBlaster filter/sfx [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 64 || ST3.00 volume slides - perform volume slides on first row as well.  Set implicitly if &amp;lt;tt&amp;gt;trackerVersion&amp;lt;/tt&amp;gt; is 0x1300.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 128 || &amp;lt;tt&amp;gt;ptrSpecial&amp;lt;/tt&amp;gt; is valid&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Known &amp;lt;tt&amp;gt;trackerVersion&amp;lt;/tt&amp;gt; values are:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x1300 || ScreamTracker 3.00&lt;br /&gt;
|-&lt;br /&gt;
| 0x1301 || ScreamTracker 3.01&lt;br /&gt;
|-&lt;br /&gt;
| 0x1303 || ScreamTracker 3.03&lt;br /&gt;
|-&lt;br /&gt;
| 0x1320 || ScreamTracker 3.20&lt;br /&gt;
|-&lt;br /&gt;
| 0x2nyy || Imago Orpheus x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x3nyy || Impulse Tracker x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x4nnn || Schism Tracker (old BeRoTracker version from between 2004 and 2012 identify as 0x4100)&lt;br /&gt;
|-&lt;br /&gt;
| 0x5nyy || OpenMPT x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x6nyy || BeRoTracker x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x7nyy || CreamTracker x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0xCA00 || Camoto/libgamemusic&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;channelSettings&amp;lt;/tt&amp;gt; is 32 values indicating the audio channel assignments for each of the 32 S3M channels.  Unused channels should be set to 255.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 to 7 || Left PCM channels 1 to 8&lt;br /&gt;
|-&lt;br /&gt;
| 8 to 15 || Right PCM channels 1 to 8&lt;br /&gt;
|-&lt;br /&gt;
| 16 to 24 || Adlib melody channel 1-9&lt;br /&gt;
|-&lt;br /&gt;
| 25 || Adlib percussion channel: bass drum&lt;br /&gt;
|-&lt;br /&gt;
| 26 || Adlib percussion channel: snare drum&lt;br /&gt;
|-&lt;br /&gt;
| 27 || Adlib percussion channel: tom tom&lt;br /&gt;
|-&lt;br /&gt;
| 28 || Adlib percussion channel: top cymbal&lt;br /&gt;
|-&lt;br /&gt;
| 29 || Adlib percussion channel: hi-hat&lt;br /&gt;
|-&lt;br /&gt;
| 30 to 127 || Unused/invalid&lt;br /&gt;
|-&lt;br /&gt;
| 128 to 254 || Unused/invalid (but channel disabled)&lt;br /&gt;
|-&lt;br /&gt;
| 255 || Channel unused&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;orderList&amp;lt;/tt&amp;gt; contains the index of each pattern to be played.  The first entry in this array is the index of the first pattern to play, the second entry is the second pattern, etc.  If an entry is 0xFE then it is a &amp;quot;marker pattern&amp;quot; and is skipped during playback, and an entry of 0xFF signifies the end of the song.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;ptrInstruments&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ptrPatterns&amp;lt;/tt&amp;gt; are arrays of parapointers to the start of the instrument and pattern data.  Each parapointer is an offset from the start of the file, in units of 16 bytes (a &amp;quot;paragraph&amp;quot;).  To convert this into a normal byte-level file offset, multiply it by 16 (or shift-left by 4.)&lt;br /&gt;
&lt;br /&gt;
By convention these blocks follow the header above, but this is not a requirement and they can occur at any point in the file.&lt;br /&gt;
&lt;br /&gt;
=== Timing ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;initialTempo&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;initialSpeed&amp;lt;/tt&amp;gt; values are the ones to use until optionally changed during playback, with the A and T effects respectively.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;initialTempo&amp;lt;/tt&amp;gt; value controls how many audio frames are generated per second.  If this value is 50, then there should be 50 audio frames per second.  Obviously the more audio frames per second, the shorter each frame is going to be.  To calculate the length of each frame, a formula like this can be used:&lt;br /&gt;
&lt;br /&gt;
    frame length in seconds = 1 / initialTempo&lt;br /&gt;
     0.02 seconds per frame = 1 / 50&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;initialSpeed&amp;lt;/tt&amp;gt; value controls how many audio frames comprise a single row of the song.  If the value is 3, then there are three audio frames per row.  For certain effects, they are updated once per frame (i.e. the effect changes between rows.)&lt;br /&gt;
&lt;br /&gt;
To calculate playback speed, both these values need to be taken into account.  The tempo value controls the length of each audio frame, while the speed value controls how quickly the rows are turned into those audio frames.  For example, to calculate the number of rows per second:&lt;br /&gt;
&lt;br /&gt;
    rowsPerSecond = initialTempo / initialSpeed&lt;br /&gt;
&lt;br /&gt;
=== Instruments ===&lt;br /&gt;
&lt;br /&gt;
At the offset given by an instrument&#039;s parapointer, the data has a header as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || type || 0=empty instrument (message only), 1=PCM instrument&lt;br /&gt;
|-&lt;br /&gt;
| char[12] || filename || Original instrument filename in DOS 8.3 format, no terminating null&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || empty instrument (message only)&lt;br /&gt;
|-&lt;br /&gt;
| 1 || PCM instrument&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Adlib melody instrument&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Adlib percussive: bass drum&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Adlib percussive: snare&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Adlib percussive: tom tom&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Adlib percussive: top cymbal&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Adlib percussive: hi-hat&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The data following the header depends on whether the instrument is PCM or Adlib.&lt;br /&gt;
{{TODO|What if the instrument is empty, is there any trailing data?}}&lt;br /&gt;
&lt;br /&gt;
==== PCM ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || ptrDataH || Upper eight bits of parapointer to sample data, relative to start of S3M file&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || ptrDataL || Lower 16 bits of parapointer to sample data, relative to start of S3M file&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Sample data length, in bytes.  S3M is limited to 64000 and ignores upper 16 bits.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Offset of loop start in bytes, relative to start of sample data.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopEnd || Offset of loop end in bytes, relative to start of sample data.&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Default volume of sample, 0-63 inclusive.&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || reserved || Always 0x00&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || pack || 0=unpacked, 1=DP30ADPCM [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || flags || Sum: 1=loop on, 2=stereo (data is &amp;lt;tt&amp;gt;length&amp;lt;/tt&amp;gt; bytes for left channel then &amp;lt;tt&amp;gt;length&amp;lt;/tt&amp;gt; bytes for right channel), 4=16-bit little-endian sample&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || c2spd || Sample rate for middle-C note (C-4)&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[12] || internal || Always zero, used in-memory during playback&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Sample title, for display to user.  Must be null-terminated.&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || sig || Signature: &amp;quot;SCRS&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ScreamTracker stores the above instrument structures at the start of the file, but stores the sample data at the end of the file (after the pattern data.)  This is not the only way to store it though.&lt;br /&gt;
&lt;br /&gt;
==== Adlib ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[3] || reserved || Always 0x00 0x00 0x00&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[12] || oplValues || See below&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Default volume of instrument, 0-63 inclusive.&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || dsk || {{TODO|Unknown}}&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || reserved || Always 0x0000&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || c2spd || Sample rate for middle-C note (C-4), see below.&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[12] || unused || Always zero&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Sample title, for display to user.  Must be null-terminated.&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || sig || Signature: &amp;quot;SCRI&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;oplValues&amp;lt;/tt&amp;gt; are stored as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!rowspan=2| Byte index !!rowspan=2| Operator !!rowspan=2| OPL base register !!colspan=8| Bits&lt;br /&gt;
|-&lt;br /&gt;
!width=100| 7 !!width=100| 6 !!width=100| 5 !!width=100| 4 !!width=100| 3 !!width=100| 2 !!width=100| 1 !!width=100| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0 || Modulator || 0x20 ||align=center rowspan=2| Tremolo? ||align=center rowspan=2| Vibrato? ||align=center rowspan=2| Sustain? ||align=center rowspan=2| KSR? ||align=center rowspan=2 colspan=4| Freq. mult.&lt;br /&gt;
|-&lt;br /&gt;
| 1 || Carrier || 0x23&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Modulator || 0x40 ||align=center rowspan=2| Scale level (bit 0) ||align=center rowspan=2| Scale level (bit 1) ||align=center rowspan=2 colspan=6| Output level (0=loudest, 63=silent)&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Carrier || 0x43&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Modulator || 0x60 ||align=center rowspan=2 colspan=4| Attack rate ||align=center rowspan=2 colspan=4| Decay rate&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Carrier || 0x63&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Modulator || 0x80 ||align=center rowspan=2 colspan=4| Sustain rate ||align=center rowspan=2 colspan=4| Release rate&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Carrier || 0x83&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Modulator || 0xE0 ||align=center rowspan=2 colspan=8| Wave select&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Carrier || 0xE3&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Modulator || 0xC0 ||align=center colspan=7| Feedback ||align=center| Connection&lt;br /&gt;
|-&lt;br /&gt;
| 11 || - || - ||align=center colspan=8| Unused, set to 0x00&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;c2spd&amp;lt;/tt&amp;gt; sets the instrument tuning.  It translates the note freq just like with PCM instruments.  The default value of 8363 (as with PCM instruments) means that middle-C plays at about 261.63 Hz (A440 pitch standard), and e.g. doubling it also doubles the middle-C frequency, as with samples.&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The value packing is almost identical to that used in the [[SBI Format]], just the bytes are in a different order.&lt;br /&gt;
* The ST3 docs say bytes 2-3 bits 5-0 are &amp;quot;63-volume&amp;quot; but this is to make the values match PCM samples.  The value in the file matches the value sent to the OPL chip.&lt;br /&gt;
* The Scale Level bits in bytes 2-3 are swapped.  The ST3 technical docs have a typo that suggest Scale Level (bit 1) actually overflows into &amp;quot;bit 8&amp;quot; of the OPL register, but testing this in ST3 shows this is not the case and the bit order is merely swapped.&lt;br /&gt;
* The ST3 docs say bytes 6-7 have the sustain rate stored as &amp;quot;15-sustain&amp;quot;, which is from a editor UI perspective - the value can be sent as-is to the OPL chip.&lt;br /&gt;
&lt;br /&gt;
=== Patterns ===&lt;br /&gt;
&lt;br /&gt;
At the offset given by a pattern&#039;s parapointer, packed data is present and will need to be unpacked.  The following structure appears at the start of each pattern&#039;s data:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || packed_len || Length of packed data for all 64 rows, in bytes&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[packed_len - 2] || packed_data || Packed row data, described below&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;packed_len&amp;lt;/tt&amp;gt; includes its own length, so as it is two bytes long, the length of the packed data will be two bytes less than this value.  The first byte in &amp;lt;tt&amp;gt;packed_data&amp;lt;/tt&amp;gt; is a bitfield called &amp;lt;tt&amp;gt;what&amp;lt;/tt&amp;gt;, and it is broken up as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!width=100| 7 !!width=100| 6 !!width=100| 5 !!width=100| 4 !!width=100| 3 !!width=100| 2 !!width=100| 1 !!width=100| 0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;command&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;info&amp;lt;/tt&amp;gt; present&lt;br /&gt;
| &amp;lt;tt&amp;gt;volume&amp;lt;/tt&amp;gt; present&lt;br /&gt;
| &amp;lt;tt&amp;gt;note&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;instrument&amp;lt;/tt&amp;gt; present&lt;br /&gt;
|colspan=5 align=center| Channel number&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If the whole byte is zero then it signals the end of the row.  This byte and the ones following are further described in the following table.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || what || 0=end of row, lower five bits (&amp;lt;tt&amp;gt;what &amp;amp; 0x1F&amp;lt;/tt&amp;gt;) are channel number&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || note || Note number (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x20&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || instrument || Instrument number (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x20&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Volume level (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x40&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || command || Effect type (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x80&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || info || Effect value (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x80&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
After these bytes the process repeats with another &amp;lt;tt&amp;gt;what&amp;lt;/tt&amp;gt; value.  When &amp;lt;tt&amp;gt;what&amp;lt;/tt&amp;gt; is 0x00 the end of the row has been reached.  After the 64th row has been reached, the pattern ends and &amp;lt;tt&amp;gt;packed_len&amp;lt;/tt&amp;gt; bytes will have been read.&lt;br /&gt;
&lt;br /&gt;
Be aware that &amp;lt;tt&amp;gt;channel&amp;lt;/tt&amp;gt; is a value between 0 and 31 inclusive, which corresponds to an entry in the &amp;lt;tt&amp;gt;channelSettings&amp;lt;/tt&amp;gt; field in the header.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;volume&amp;lt;/tt&amp;gt; field is 0 for silent, 64 for full volume (note this is 65 unique values), or 255 for &#039;ignore&#039; (shown as &amp;quot;..&amp;quot; in the tracker.)  If the value is 255 or missing entirely, the instrument&#039;s default volume is used (the &amp;lt;tt&amp;gt;volume&amp;lt;/tt&amp;gt; value from the instrument settings.)&lt;br /&gt;
&lt;br /&gt;
The upper four bits of &amp;lt;tt&amp;gt;note&amp;lt;/tt&amp;gt; store the octave, and the lower four bits store the semitone (with 0=C, 1=C#, up to 11=B)&lt;br /&gt;
&lt;br /&gt;
=== Effects ===&lt;br /&gt;
&lt;br /&gt;
==== 0x01/A: Set speed ====&lt;br /&gt;
&lt;br /&gt;
Set &#039;&#039;speed&#039;&#039; (one of the two tempo variables.)  Data byte is new speed.  A value of 0 causes the event to be ignored.&lt;br /&gt;
&lt;br /&gt;
==== 0x02/B: Order jump ====&lt;br /&gt;
&lt;br /&gt;
After the current row has finished playing, the next row is the first row in order given by the data byte.  0 means the start of the song {{TODO|Confirm this}}.&lt;br /&gt;
&lt;br /&gt;
==== 0x03/C: Jump to row ====&lt;br /&gt;
&lt;br /&gt;
After the current row has finished playing, the next row is played from the next pattern in the order sequence.  The row in this next pattern is given by the data byte, but the data byte is decimal-as-hex.  So a value of 0x12 should be treated as decimal 12.  These formulae will calculate the correct row (to/from the S3M value):&lt;br /&gt;
&lt;br /&gt;
 row = (data &amp;gt;&amp;gt; 4) * 10 + (data &amp;amp; 0x0f)    // Read S3M into variable&lt;br /&gt;
 data = ((row / 10) &amp;lt;&amp;lt; 4) | (row % 10)     // Write variable to S3M&lt;br /&gt;
&lt;br /&gt;
The first row in the pattern is 0.  If the decoded data value is larger than 63, the effect is ignored.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://schismtracker.org/ SchismTracker]&lt;br /&gt;
| Platform = Windows/Linux&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canExport = .it + more&lt;br /&gt;
| canImport = [[MOD Format|.mod]] .it + more&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = Yes&lt;br /&gt;
| notes = Can play OPL and PCM simultaneously&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = ScreamTracker 3&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canExport = [[MOD Format|.mod]]&lt;br /&gt;
| canImport = [[MOD Format|.mod]]&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = Yes&lt;br /&gt;
| notes = Official tool&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
&lt;br /&gt;
Much of this information was combined from the following sites:&lt;br /&gt;
&lt;br /&gt;
* TECH.DOC distributed with ScreamTracker 3&lt;br /&gt;
* [http://wiki.multimedia.cx/index.php?title=Scream_Tracker_3_Module S3M on the MultimediaWiki]&lt;br /&gt;
* [http://schismtracker.org/wiki/FS3MDOC.TXT FS3MDOC.TXT] - S3M Player Tutorial&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=S3M_Format&amp;diff=7635</id>
		<title>S3M Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=S3M_Format&amp;diff=7635"/>
		<updated>2018-06-12T21:30:09Z</updated>

		<summary type="html">&lt;p&gt;Saga: Clarify how pitch works for AdLib instruments.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | Instruments2 = OPL&lt;br /&gt;
 | NumChannels = 32&lt;br /&gt;
 | NumTracks = 255&lt;br /&gt;
 | NumPatterns = 65,536&lt;br /&gt;
 | NumOrders = 65,536&lt;br /&gt;
 | Tags = Title, instrument names&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Unreal Tournament}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[S3M Format]] is used to save modules composed in ScreamTracker 3.  A number of games support music in this format, however it is primarily used for composing independent songs unrelated to games.&lt;br /&gt;
&lt;br /&gt;
The format is notable both for its popularity, as well as for being one of the few that support both FM/OPL and sampled instruments.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file begins with a header.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Song title, must be null-terminated&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || sig1 || Signature byte, always 0x1A&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || type || Song type, always 0x10 for S3M&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || reserved || Always 0x0000&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || orderCount || Number of entries in the order table, should be even&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || instrumentCount || Number of instruments in the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || patternPtrCount || Number of pattern parapointers in the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || flags || See below&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || trackerVersion || upper four bits is tracker ID, lower 12 bits is tracker version&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || sampleType || 1=signed samples [deprecated], 2=unsigned samples&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || sig2 || Signature: &amp;quot;SCRM&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || globalVolume || &lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || initialSpeed || Frames per row, can be changed later with &amp;lt;tt&amp;gt;A&amp;lt;/tt&amp;gt; command&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || initialTempo || Frames per second, can be changed later with &amp;lt;tt&amp;gt;T&amp;lt;/tt&amp;gt; command&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || masterVolume || bit 7: 1=stereo, 0=mono, bits 6-0: volume&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || ultraClickRemoval || Number of channels to use for click removal on real GUS hardware&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || defaultPan || 252=read pan values in header, anything else ignores pan values in header&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[8] || reserved || Unused, some trackers store data here&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || ptrSpecial || Parapointer to additional data, if &amp;lt;tt&amp;gt;flags&amp;lt;/tt&amp;gt; has bit 7 set&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[32] || channelSettings || See below&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[orderCount] || orderList || Which order patterns are played in&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE[instrumentCount] || ptrInstruments || List of parapointers to each instrument&#039;s data&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE[patternPtrCount] || ptrPatterns || List of parapointers to each pattern&#039;s data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Flags are one or more values below:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Bit !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || ST2 vibrato [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 2 || ST2 tempo [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 4 || Amiga slides [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 8 || 0vol optimisations - automatically turn off looping notes when the volume is zero for more than two rows&lt;br /&gt;
|-&lt;br /&gt;
| 4 || 16 || Amiga limits - ignore notes beyond Amiga hardware limits (as Amiga does.)  Sliding up stops at B#5.  Also affects other Amiga compatibility issues.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || 32 || Enable SoundBlaster filter/sfx [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 64 || ST3.00 volume slides - perform volume slides on first row as well.  Set implicitly if &amp;lt;tt&amp;gt;trackerVersion&amp;lt;/tt&amp;gt; is 0x1300.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 128 || &amp;lt;tt&amp;gt;ptrSpecial&amp;lt;/tt&amp;gt; is valid&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Known &amp;lt;tt&amp;gt;trackerVersion&amp;lt;/tt&amp;gt; values are:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x1300 || ScreamTracker 3.00&lt;br /&gt;
|-&lt;br /&gt;
| 0x1301 || ScreamTracker 3.01&lt;br /&gt;
|-&lt;br /&gt;
| 0x1303 || ScreamTracker 3.03&lt;br /&gt;
|-&lt;br /&gt;
| 0x1320 || ScreamTracker 3.20&lt;br /&gt;
|-&lt;br /&gt;
| 0x2nyy || Imago Orpheus x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x3nyy || Impulse Tracker x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x4nnn || Schism Tracker&lt;br /&gt;
|-&lt;br /&gt;
| 0x5nyy || OpenMPT x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0xCA00 || Camoto/libgamemusic&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;channelSettings&amp;lt;/tt&amp;gt; is 32 values indicating the audio channel assignments for each of the 32 S3M channels.  Unused channels should be set to 255.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 to 7 || Left PCM channels 1 to 8&lt;br /&gt;
|-&lt;br /&gt;
| 8 to 15 || Right PCM channels 1 to 8&lt;br /&gt;
|-&lt;br /&gt;
| 16 to 24 || Adlib melody channel 1-9&lt;br /&gt;
|-&lt;br /&gt;
| 25 || Adlib percussion channel: bass drum&lt;br /&gt;
|-&lt;br /&gt;
| 26 || Adlib percussion channel: snare drum&lt;br /&gt;
|-&lt;br /&gt;
| 27 || Adlib percussion channel: tom tom&lt;br /&gt;
|-&lt;br /&gt;
| 28 || Adlib percussion channel: top cymbal&lt;br /&gt;
|-&lt;br /&gt;
| 29 || Adlib percussion channel: hi-hat&lt;br /&gt;
|-&lt;br /&gt;
| 30 to 127 || Unused/invalid&lt;br /&gt;
|-&lt;br /&gt;
| 128 to 254 || Unused/invalid (but channel disabled)&lt;br /&gt;
|-&lt;br /&gt;
| 255 || Channel unused&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;orderList&amp;lt;/tt&amp;gt; contains the index of each pattern to be played.  The first entry in this array is the index of the first pattern to play, the second entry is the second pattern, etc.  If an entry is 0xFE then it is a &amp;quot;marker pattern&amp;quot; and is skipped during playback, and an entry of 0xFF signifies the end of the song.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;ptrInstruments&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ptrPatterns&amp;lt;/tt&amp;gt; are arrays of parapointers to the start of the instrument and pattern data.  Each parapointer is an offset from the start of the file, in units of 16 bytes (a &amp;quot;paragraph&amp;quot;).  To convert this into a normal byte-level file offset, multiply it by 16 (or shift-left by 4.)&lt;br /&gt;
&lt;br /&gt;
By convention these blocks follow the header above, but this is not a requirement and they can occur at any point in the file.&lt;br /&gt;
&lt;br /&gt;
=== Timing ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;initialTempo&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;initialSpeed&amp;lt;/tt&amp;gt; values are the ones to use until optionally changed during playback, with the A and T effects respectively.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;initialTempo&amp;lt;/tt&amp;gt; value controls how many audio frames are generated per second.  If this value is 50, then there should be 50 audio frames per second.  Obviously the more audio frames per second, the shorter each frame is going to be.  To calculate the length of each frame, a formula like this can be used:&lt;br /&gt;
&lt;br /&gt;
    frame length in seconds = 1 / initialTempo&lt;br /&gt;
     0.02 seconds per frame = 1 / 50&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;initialSpeed&amp;lt;/tt&amp;gt; value controls how many audio frames comprise a single row of the song.  If the value is 3, then there are three audio frames per row.  For certain effects, they are updated once per frame (i.e. the effect changes between rows.)&lt;br /&gt;
&lt;br /&gt;
To calculate playback speed, both these values need to be taken into account.  The tempo value controls the length of each audio frame, while the speed value controls how quickly the rows are turned into those audio frames.  For example, to calculate the number of rows per second:&lt;br /&gt;
&lt;br /&gt;
    rowsPerSecond = initialTempo / initialSpeed&lt;br /&gt;
&lt;br /&gt;
=== Instruments ===&lt;br /&gt;
&lt;br /&gt;
At the offset given by an instrument&#039;s parapointer, the data has a header as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || type || 0=empty instrument (message only), 1=PCM instrument&lt;br /&gt;
|-&lt;br /&gt;
| char[12] || filename || Original instrument filename in DOS 8.3 format, no terminating null&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || empty instrument (message only)&lt;br /&gt;
|-&lt;br /&gt;
| 1 || PCM instrument&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Adlib melody instrument&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Adlib percussive: bass drum&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Adlib percussive: snare&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Adlib percussive: tom tom&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Adlib percussive: top cymbal&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Adlib percussive: hi-hat&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The data following the header depends on whether the instrument is PCM or Adlib.&lt;br /&gt;
{{TODO|What if the instrument is empty, is there any trailing data?}}&lt;br /&gt;
&lt;br /&gt;
==== PCM ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || ptrDataH || Upper eight bits of parapointer to sample data, relative to start of S3M file&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || ptrDataL || Lower 16 bits of parapointer to sample data, relative to start of S3M file&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Sample data length, in bytes.  S3M is limited to 64000 and ignores upper 16 bits.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Offset of loop start in bytes, relative to start of sample data.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopEnd || Offset of loop end in bytes, relative to start of sample data.&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Default volume of sample, 0-63 inclusive.&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || reserved || Always 0x00&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || pack || 0=unpacked, 1=DP30ADPCM [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || flags || Sum: 1=loop on, 2=stereo (data is &amp;lt;tt&amp;gt;length&amp;lt;/tt&amp;gt; bytes for left channel then &amp;lt;tt&amp;gt;length&amp;lt;/tt&amp;gt; bytes for right channel), 4=16-bit little-endian sample&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || c2spd || Sample rate for middle-C note (C-4)&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[12] || internal || Always zero, used in-memory during playback&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Sample title, for display to user.  Must be null-terminated.&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || sig || Signature: &amp;quot;SCRS&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ScreamTracker stores the above instrument structures at the start of the file, but stores the sample data at the end of the file (after the pattern data.)  This is not the only way to store it though.&lt;br /&gt;
&lt;br /&gt;
==== Adlib ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[3] || reserved || Always 0x00 0x00 0x00&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[12] || oplValues || See below&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Default volume of instrument, 0-63 inclusive.&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || dsk || {{TODO|Unknown}}&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || reserved || Always 0x0000&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || c2spd || Sample rate for middle-C note (C-4), see below.&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[12] || unused || Always zero&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Sample title, for display to user.  Must be null-terminated.&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || sig || Signature: &amp;quot;SCRI&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;oplValues&amp;lt;/tt&amp;gt; are stored as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!rowspan=2| Byte index !!rowspan=2| Operator !!rowspan=2| OPL base register !!colspan=8| Bits&lt;br /&gt;
|-&lt;br /&gt;
!width=100| 7 !!width=100| 6 !!width=100| 5 !!width=100| 4 !!width=100| 3 !!width=100| 2 !!width=100| 1 !!width=100| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0 || Modulator || 0x20 ||align=center rowspan=2| Tremolo? ||align=center rowspan=2| Vibrato? ||align=center rowspan=2| Sustain? ||align=center rowspan=2| KSR? ||align=center rowspan=2 colspan=4| Freq. mult.&lt;br /&gt;
|-&lt;br /&gt;
| 1 || Carrier || 0x23&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Modulator || 0x40 ||align=center rowspan=2| Scale level (bit 0) ||align=center rowspan=2| Scale level (bit 1) ||align=center rowspan=2 colspan=6| Output level (0=loudest, 63=silent)&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Carrier || 0x43&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Modulator || 0x60 ||align=center rowspan=2 colspan=4| Attack rate ||align=center rowspan=2 colspan=4| Decay rate&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Carrier || 0x63&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Modulator || 0x80 ||align=center rowspan=2 colspan=4| Sustain rate ||align=center rowspan=2 colspan=4| Release rate&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Carrier || 0x83&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Modulator || 0xE0 ||align=center rowspan=2 colspan=8| Wave select&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Carrier || 0xE3&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Modulator || 0xC0 ||align=center colspan=7| Feedback ||align=center| Connection&lt;br /&gt;
|-&lt;br /&gt;
| 11 || - || - ||align=center colspan=8| Unused, set to 0x00&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;c2spd&amp;lt;/tt&amp;gt; sets the instrument tuning.  It translates the note freq just like with PCM instruments.  The default value of 8363 (as with PCM instruments) means that middle-C plays at about 261.63 Hz (A440 pitch standard), and e.g. doubling it also doubles the middle-C frequency, as with samples.&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The value packing is almost identical to that used in the [[SBI Format]], just the bytes are in a different order.&lt;br /&gt;
* The ST3 docs say bytes 2-3 bits 5-0 are &amp;quot;63-volume&amp;quot; but this is to make the values match PCM samples.  The value in the file matches the value sent to the OPL chip.&lt;br /&gt;
* The Scale Level bits in bytes 2-3 are swapped.  The ST3 technical docs have a typo that suggest Scale Level (bit 1) actually overflows into &amp;quot;bit 8&amp;quot; of the OPL register, but testing this in ST3 shows this is not the case and the bit order is merely swapped.&lt;br /&gt;
* The ST3 docs say bytes 6-7 have the sustain rate stored as &amp;quot;15-sustain&amp;quot;, which is from a editor UI perspective - the value can be sent as-is to the OPL chip.&lt;br /&gt;
&lt;br /&gt;
=== Patterns ===&lt;br /&gt;
&lt;br /&gt;
At the offset given by a pattern&#039;s parapointer, packed data is present and will need to be unpacked.  The following structure appears at the start of each pattern&#039;s data:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || packed_len || Length of packed data for all 64 rows, in bytes&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[packed_len - 2] || packed_data || Packed row data, described below&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;packed_len&amp;lt;/tt&amp;gt; includes its own length, so as it is two bytes long, the length of the packed data will be two bytes less than this value.  The first byte in &amp;lt;tt&amp;gt;packed_data&amp;lt;/tt&amp;gt; is a bitfield called &amp;lt;tt&amp;gt;what&amp;lt;/tt&amp;gt;, and it is broken up as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!width=100| 7 !!width=100| 6 !!width=100| 5 !!width=100| 4 !!width=100| 3 !!width=100| 2 !!width=100| 1 !!width=100| 0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;command&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;info&amp;lt;/tt&amp;gt; present&lt;br /&gt;
| &amp;lt;tt&amp;gt;volume&amp;lt;/tt&amp;gt; present&lt;br /&gt;
| &amp;lt;tt&amp;gt;note&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;instrument&amp;lt;/tt&amp;gt; present&lt;br /&gt;
|colspan=5 align=center| Channel number&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If the whole byte is zero then it signals the end of the row.  This byte and the ones following are further described in the following table.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || what || 0=end of row, lower five bits (&amp;lt;tt&amp;gt;what &amp;amp; 0x1F&amp;lt;/tt&amp;gt;) are channel number&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || note || Note number (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x20&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || instrument || Instrument number (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x20&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Volume level (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x40&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || command || Effect type (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x80&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || info || Effect value (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x80&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
After these bytes the process repeats with another &amp;lt;tt&amp;gt;what&amp;lt;/tt&amp;gt; value.  When &amp;lt;tt&amp;gt;what&amp;lt;/tt&amp;gt; is 0x00 the end of the row has been reached.  After the 64th row has been reached, the pattern ends and &amp;lt;tt&amp;gt;packed_len&amp;lt;/tt&amp;gt; bytes will have been read.&lt;br /&gt;
&lt;br /&gt;
Be aware that &amp;lt;tt&amp;gt;channel&amp;lt;/tt&amp;gt; is a value between 0 and 31 inclusive, which corresponds to an entry in the &amp;lt;tt&amp;gt;channelSettings&amp;lt;/tt&amp;gt; field in the header.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;volume&amp;lt;/tt&amp;gt; field is 0 for silent, 64 for full volume (note this is 65 unique values), or 255 for &#039;ignore&#039; (shown as &amp;quot;..&amp;quot; in the tracker.)  If the value is 255 or missing entirely, the instrument&#039;s default volume is used (the &amp;lt;tt&amp;gt;volume&amp;lt;/tt&amp;gt; value from the instrument settings.)&lt;br /&gt;
&lt;br /&gt;
The upper four bits of &amp;lt;tt&amp;gt;note&amp;lt;/tt&amp;gt; store the octave, and the lower four bits store the semitone (with 0=C, 1=C#, up to 11=B)&lt;br /&gt;
&lt;br /&gt;
=== Effects ===&lt;br /&gt;
&lt;br /&gt;
==== 0x01/A: Set speed ====&lt;br /&gt;
&lt;br /&gt;
Set &#039;&#039;speed&#039;&#039; (one of the two tempo variables.)  Data byte is new speed.  A value of 0 causes the event to be ignored.&lt;br /&gt;
&lt;br /&gt;
==== 0x02/B: Order jump ====&lt;br /&gt;
&lt;br /&gt;
After the current row has finished playing, the next row is the first row in order given by the data byte.  0 means the start of the song {{TODO|Confirm this}}.&lt;br /&gt;
&lt;br /&gt;
==== 0x03/C: Jump to row ====&lt;br /&gt;
&lt;br /&gt;
After the current row has finished playing, the next row is played from the next pattern in the order sequence.  The row in this next pattern is given by the data byte, but the data byte is decimal-as-hex.  So a value of 0x12 should be treated as decimal 12.  These formulae will calculate the correct row (to/from the S3M value):&lt;br /&gt;
&lt;br /&gt;
 row = (data &amp;gt;&amp;gt; 4) * 10 + (data &amp;amp; 0x0f)    // Read S3M into variable&lt;br /&gt;
 data = ((row / 10) &amp;lt;&amp;lt; 4) | (row % 10)     // Write variable to S3M&lt;br /&gt;
&lt;br /&gt;
The first row in the pattern is 0.  If the decoded data value is larger than 63, the effect is ignored.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://schismtracker.org/ SchismTracker]&lt;br /&gt;
| Platform = Windows/Linux&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canExport = .it + more&lt;br /&gt;
| canImport = [[MOD Format|.mod]] .it + more&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = Yes&lt;br /&gt;
| notes = Can play OPL and PCM simultaneously&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = ScreamTracker 3&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canExport = [[MOD Format|.mod]]&lt;br /&gt;
| canImport = [[MOD Format|.mod]]&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = Yes&lt;br /&gt;
| notes = Official tool&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
&lt;br /&gt;
Much of this information was combined from the following sites:&lt;br /&gt;
&lt;br /&gt;
* TECH.DOC distributed with ScreamTracker 3&lt;br /&gt;
* [http://wiki.multimedia.cx/index.php?title=Scream_Tracker_3_Module S3M on the MultimediaWiki]&lt;br /&gt;
* [http://schismtracker.org/wiki/FS3MDOC.TXT FS3MDOC.TXT] - S3M Player Tutorial&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=CDFM_Format&amp;diff=7634</id>
		<title>CDFM Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=CDFM_Format&amp;diff=7634"/>
		<updated>2018-06-12T21:23:36Z</updated>

		<summary type="html">&lt;p&gt;Saga: Add pattern/order limits from Composer 670&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{NeedMoreInfo}}&lt;br /&gt;
{{Music Infobox&lt;br /&gt;
 | Type = Custom&lt;br /&gt;
 | Instruments = OPL&lt;br /&gt;
 | Instruments2 = PCM&lt;br /&gt;
 | NumChannels = 13&lt;br /&gt;
 | NumTracks = 1&lt;br /&gt;
 | NumPatterns = 128&lt;br /&gt;
 | NumOrders = 256&lt;br /&gt;
 | Tags = None&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Zone 66}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[CDFM Format]] was developed by the demogroup Renaissance for their Amnesia demo, and was later used in their game [[Zone 66]].  It consists of either nine Adlib channels (for Adlib hardware), nine OPL and four PCM channels (for Sound Blaster hardware) or patches to be played as MIDI instruments (for GUS hardware.)&lt;br /&gt;
&lt;br /&gt;
In Zone 66, most songs have hardware-specific versions, even where the SB song could drop the PCM channels and be played on Adlib.  In these cases the PCM drum channels have been replaced with OPL instruments.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file begins with a header.  Those fields marked &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;GUS only] are missing entirely in SoundBlaster/AdLib songs, and those fields marked &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;AdLib/SB only] are missing entirely in the GUS variant of the song format.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || sampleOffset || &#039;&#039;&#039;[GUS only]&#039;&#039;&#039; Offset of instrument samples from start of file&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || tempo || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Playback speed, larger is slower&amp;lt;br/&amp;gt;&#039;&#039;&#039;[GUS only]&#039;&#039;&#039; Unknown, always 0x66, changing has no effect&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || patternListSize || Size of pattern list&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numPatterns || Number of patterns in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numDigInst || Number of PCM or GUS instruments in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numOPLInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Number of OPL instruments in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || loopDest || Index into &amp;lt;tt&amp;gt;patternOrder&amp;lt;/tt&amp;gt; for next pattern to play after the final one when looping the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || sampleOffset || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Offset of instrument samples from start of file&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[patternListSize] || patternOrder || Order of patterns in the song, &amp;lt;tt&amp;gt;patternListSize&amp;lt;/tt&amp;gt; bytes in length&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE[numPatterns] || patternOffset || Offset of each pattern&#039;s data, relative to the start of the pattern data&lt;br /&gt;
|-&lt;br /&gt;
| PCM_INST[numDigInst] || pcmInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; 16 bytes of info for each digital (PCM) instrument&lt;br /&gt;
|-&lt;br /&gt;
| OPL_INST[numOPLInst] || oplInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; 11-byte instrument patch for each FM (OPL) instrument&lt;br /&gt;
|-&lt;br /&gt;
| GUS_INST[numDigInst] || gusInst || &#039;&#039;&#039;[GUS only]&#039;&#039;&#039; 11 bytes of info for each GUS patch&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pattern data immediately follows.  The &amp;lt;tt&amp;gt;patternOffset&amp;lt;/tt&amp;gt; values are relative to this position, so a value of 0x00000000 corresponds to the first byte here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;PCM_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || address_ptr || Used to place address of sample start in memory - ignore when reading, write as 0x00000000&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Length of sample, in bytes&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Offset of loop return, in bytes, relative to start of sample&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopEnd || Offset of loop trigger, in bytes, relative to start of sample.  Use 0x00FFFFFF for no loop.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The PCM instruments begin at &amp;lt;tt&amp;gt;sampleOffset&amp;lt;/tt&amp;gt; and are raw (no header) 8-bit &#039;&#039;&#039;unsigned&#039;&#039;&#039; PCM data.  If the sample loops, as soon as playback reaches &amp;lt;tt&amp;gt;loopEnd&amp;lt;/tt&amp;gt; (which could be before the end of the sample), playback will immediately jump to &amp;lt;tt&amp;gt;loopStart&amp;lt;/tt&amp;gt;.  The middle-C frequency for all PCM instruments is fixed at 8287 Hz (ProTracker standard).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;OPL_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!OPL base register!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iFeedback||0xC0||Feedback/connection&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModChar||0x20||Modulator characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModScale||0x40||Modulator key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModAttack||0x60||Modulator attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModSustain||0x80||Modulator sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModWaveSel||0xE0||Modulator wave select&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarChar||0x23||Carrier characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarScale||0x43||Carrier key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarAttack||0x63||Carrier attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarSustain||0x83||Carrier sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarWaveSel||0xE3||Carrier wave select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The OPL base registers in this list are for the two operators controlling the first OPL channel.  Adjust them accordingly for the relevant OPL channel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;GUS_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || flags || Bitfield: 1={{TODO|Makes pitch higher}}, 2=loop, 16={{TODO|unknown - mutes instrument}}&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || rate || Playback sampling rate for pitch to be middle-C&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Sample offset, in bytes, of loop start&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Length of sample, in bytes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All sample data is 8-bit &#039;&#039;&#039;signed&#039;&#039;&#039;.  If the loop bit is set (i.e. &amp;lt;tt&amp;gt;flags &amp;amp; 2&amp;lt;/tt&amp;gt;) then when the end of the sample is reached playback jumps immediately to the byte offset indicated by &amp;lt;tt&amp;gt;loopStart&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Tempo ==&lt;br /&gt;
&lt;br /&gt;
All songs use the standard module speed/tempo system.  The tempo is fixed at 144, and the speed can be changed per song.  For SB/AdLib songs, the speed is set once with the value obtained from the file header, while GUS songs include a &#039;set speed&#039; command at the start of each pattern.&lt;br /&gt;
&lt;br /&gt;
== Pattern data (SB/AdLib) ==&lt;br /&gt;
&lt;br /&gt;
The musical score data for SoundBlaster/AdLib files consists of a sequence of variable-length commands, in the following format:&lt;br /&gt;
&lt;br /&gt;
=== 0x00-0x0C: Play note ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2 !! Byte 3&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || &amp;lt;tt&amp;gt;jfffnnnn&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;iiiivvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Play a note on the given channel.&lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x00 through 0x0C.  The value controls the channel used for the note:&lt;br /&gt;
** 0x00: digital 1&lt;br /&gt;
** 0x03: digital 4&lt;br /&gt;
** 0x04: FM 1&lt;br /&gt;
** 0x0C: FM 9&lt;br /&gt;
** 0x0D-0x0F: Invalid&lt;br /&gt;
* &amp;lt;tt&amp;gt;j&amp;lt;/tt&amp;gt;: High (fifth) bit of instrument number.&lt;br /&gt;
* &amp;lt;tt&amp;gt;fff&amp;lt;/tt&amp;gt;: The octave of the note to play.  Middle-C is within octave 2 for digital channels (they have 4 octaves). FM channels have 7 octaves, and the middle-C is in octave 4.&lt;br /&gt;
* &amp;lt;tt&amp;gt;nnnn&amp;lt;/tt&amp;gt;: The number of the note to play within the octave (0-11).&lt;br /&gt;
* &amp;lt;tt&amp;gt;iiii&amp;lt;/tt&amp;gt;: The lower four bits of the instrument to use.  A value of zero uses the first instrument.  This is the first PCM instrument on a digital channel, and the first OPL instrument on an FM channel.&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is almost silent, 0xF is full volume. Notes can be played with zero velocity and then faded in with subsequent volume change commands. Volume is linear for both digital and FM channels, which needs to be translated for FM channels (the OPL chip has a logarithmic volume curve).&lt;br /&gt;
&lt;br /&gt;
=== 0x20-0x2C: Set volume ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x20 || &amp;lt;tt&amp;gt;0000vvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Set the volume of the playing note on the given channel.  &lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x20 through 0x2C, with the lower four bits representing the channel number as with playing a note.&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is silent, 0xF is full volume.&lt;br /&gt;
&lt;br /&gt;
=== 0x40: Delay ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x40 || &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Delay for the given number of ticks before continuing with the next event.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;: Number of ticks to wait&lt;br /&gt;
&lt;br /&gt;
=== 0x60: End of pattern ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
|-&lt;br /&gt;
| 0x60&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This must be the last command in each pattern.  Playback will jump to the next pattern in the sequence specified in the song header.&lt;br /&gt;
&lt;br /&gt;
=== 0x80: Unknown ===&lt;br /&gt;
&lt;br /&gt;
This command is not used in any known files and crashes Zone 66.  Its purpose, or perhaps incomplete intended purpose, is unknown.&lt;br /&gt;
&lt;br /&gt;
== Pattern data (GUS) ==&lt;br /&gt;
&lt;br /&gt;
The musical score data for GUS files also consists of a sequence of variable-length commands, however the commands are different from the ones used in SB/AdLib files.  The commands are in the following format:&lt;br /&gt;
&lt;br /&gt;
=== 0x00: Delay ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x01 || &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Delay for the given number of ticks before continuing with the next event.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;: Number of ticks to wait&lt;br /&gt;
&lt;br /&gt;
=== 0x01: Set speed ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x01 || &amp;lt;tt&amp;gt;ssssssss&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Adjust the song playback speed.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;ssssssss&amp;lt;/tt&amp;gt;: New speed.  This is the same as the &#039;speed&#039; in standard .mod files (i.e. the number of frames per row), with the module tempo fixed at 144.&lt;br /&gt;
&lt;br /&gt;
=== 0x02: End of pattern ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
|-&lt;br /&gt;
| 0x02&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This must be the last command in each pattern.  Playback will jump to the next pattern in the sequence specified in the song header.&lt;br /&gt;
&lt;br /&gt;
=== 0x40-0x4F: Play note ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2 !! Byte 3 !! Byte 4&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || &amp;lt;tt&amp;gt;ffffffff&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;ppppvvvv&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;iiiiiiii&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Play a note on the given channel.&lt;br /&gt;
&lt;br /&gt;
* The command byte is always 0x40 through 0x4F.  The value controls the channel used for the note:&lt;br /&gt;
** 0x00: GUS channel 1&lt;br /&gt;
** 0x01: GUS channel 2&lt;br /&gt;
** 0x0F: GUS channel 16 {{TODO|Assumed, please confirm}}&lt;br /&gt;
* &amp;lt;tt&amp;gt;ffffffff&amp;lt;/tt&amp;gt;: Note.  Add 25 to this value (i.e. transpose up by two octaves and one note) to obtain standard MIDI note numbers.&lt;br /&gt;
* &amp;lt;tt&amp;gt;pppp&amp;lt;/tt&amp;gt;: Panning, 0=centre, 1=full right, 15=full left&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Velocity, logarithmic, 0=silent, 1=1%, 2=4%, 3=7% ... 12=49.8%, 13=60%, 14=74.9%, 15=100%&lt;br /&gt;
* &amp;lt;tt&amp;gt;iiiiiiii&amp;lt;/tt&amp;gt;: Instrument, 0=first, 1=second, etc.&lt;br /&gt;
&lt;br /&gt;
=== 0x80-0x8F: Set volume ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x80 || &amp;lt;tt&amp;gt;ppppvvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Set the volume of the playing note on the given channel.  &lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x80 through 0x8F, with the lower four bits representing the channel number as with playing a note.&lt;br /&gt;
* &amp;lt;tt&amp;gt;pppp&amp;lt;/tt&amp;gt;: {{TODO|Assumed pan value, same as for note-on}}&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is silent, 0xF is full volume.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[Camoto]]&lt;br /&gt;
| Platform = Linux/Win&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes; except GUS&lt;br /&gt;
| canModify = Yes; except GUS&lt;br /&gt;
| canExport = Yes&lt;br /&gt;
| canImport = Yes; except GUS&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://sbfmdrv.blogspot.com.au/2015/12/renaissance-cdfm-music.html CDFM Tracker]&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
This file format was reverse engineered by [[User:Malvineous|Malvineous]].  If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=CDFM_Format&amp;diff=7633</id>
		<title>CDFM Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=CDFM_Format&amp;diff=7633"/>
		<updated>2018-06-09T23:04:51Z</updated>

		<summary type="html">&lt;p&gt;Saga: /* Pattern data (SB/AdLib) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{NeedMoreInfo}}&lt;br /&gt;
{{Music Infobox&lt;br /&gt;
 | Type = Custom&lt;br /&gt;
 | Instruments = OPL&lt;br /&gt;
 | Instruments2 = PCM&lt;br /&gt;
 | NumChannels = 13&lt;br /&gt;
 | NumTracks = 1&lt;br /&gt;
 | Tags = None&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Zone 66}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[CDFM Format]] was developed by the demogroup Renaissance for their Amnesia demo, and was later used in their game [[Zone 66]].  It consists of either nine Adlib channels (for Adlib hardware), nine OPL and four PCM channels (for Sound Blaster hardware) or patches to be played as MIDI instruments (for GUS hardware.)&lt;br /&gt;
&lt;br /&gt;
In Zone 66, most songs have hardware-specific versions, even where the SB song could drop the PCM channels and be played on Adlib.  In these cases the PCM drum channels have been replaced with OPL instruments.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file begins with a header.  Those fields marked &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;GUS only] are missing entirely in SoundBlaster/AdLib songs, and those fields marked &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;AdLib/SB only] are missing entirely in the GUS variant of the song format.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || sampleOffset || &#039;&#039;&#039;[GUS only]&#039;&#039;&#039; Offset of instrument samples from start of file&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || tempo || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Playback speed, larger is slower&amp;lt;br/&amp;gt;&#039;&#039;&#039;[GUS only]&#039;&#039;&#039; Unknown, always 0x66, changing has no effect&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || patternListSize || Size of pattern list&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numPatterns || Number of patterns in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numDigInst || Number of PCM or GUS instruments in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numOPLInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Number of OPL instruments in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || loopDest || Index into &amp;lt;tt&amp;gt;patternOrder&amp;lt;/tt&amp;gt; for next pattern to play after the final one when looping the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || sampleOffset || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Offset of instrument samples from start of file&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[patternListSize] || patternOrder || Order of patterns in the song, &amp;lt;tt&amp;gt;patternListSize&amp;lt;/tt&amp;gt; bytes in length&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE[numPatterns] || patternOffset || Offset of each pattern&#039;s data, relative to the start of the pattern data&lt;br /&gt;
|-&lt;br /&gt;
| PCM_INST[numDigInst] || pcmInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; 16 bytes of info for each digital (PCM) instrument&lt;br /&gt;
|-&lt;br /&gt;
| OPL_INST[numOPLInst] || oplInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; 11-byte instrument patch for each FM (OPL) instrument&lt;br /&gt;
|-&lt;br /&gt;
| GUS_INST[numDigInst] || gusInst || &#039;&#039;&#039;[GUS only]&#039;&#039;&#039; 11 bytes of info for each GUS patch&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pattern data immediately follows.  The &amp;lt;tt&amp;gt;patternOffset&amp;lt;/tt&amp;gt; values are relative to this position, so a value of 0x00000000 corresponds to the first byte here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;PCM_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || address_ptr || Used to place address of sample start in memory - ignore when reading, write as 0x00000000&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Length of sample, in bytes&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Offset of loop return, in bytes, relative to start of sample&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopEnd || Offset of loop trigger, in bytes, relative to start of sample.  Use 0x00FFFFFF for no loop.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The PCM instruments begin at &amp;lt;tt&amp;gt;sampleOffset&amp;lt;/tt&amp;gt; and are raw (no header) 8-bit unsigned PCM data.  If the sample loops, as soon as playback reaches &amp;lt;tt&amp;gt;loopEnd&amp;lt;/tt&amp;gt; (which could be before the end of the sample), playback will immediately jump to &amp;lt;tt&amp;gt;loopStart&amp;lt;/tt&amp;gt;.  The middle-C frequency for all PCM instruments is fixed at 8287 Hz (ProTracker standard).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;OPL_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!OPL base register!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iFeedback||0xC0||Feedback/connection&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModChar||0x20||Modulator characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModScale||0x40||Modulator key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModAttack||0x60||Modulator attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModSustain||0x80||Modulator sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModWaveSel||0xE0||Modulator wave select&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarChar||0x23||Carrier characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarScale||0x43||Carrier key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarAttack||0x63||Carrier attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarSustain||0x83||Carrier sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarWaveSel||0xE3||Carrier wave select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The OPL base registers in this list are for the two operators controlling the first OPL channel.  Adjust them accordingly for the relevant OPL channel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;GUS_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || flags || Bitfield: 1={{TODO|stereo? Makes pitch higher}}, 2=loop, 16={{TODO|unknown - mutes instrument}}&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || rate || Playback sampling rate for pitch to be middle-C&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Sample offset, in bytes, of loop start&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Length of sample, in bytes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All sample data is 8-bit &#039;&#039;&#039;signed&#039;&#039;&#039;.  If the loop bit is set (i.e. &amp;lt;tt&amp;gt;flags &amp;amp; 2&amp;lt;/tt&amp;gt;) then when the end of the sample is reached playback jumps immediately to the byte offset indicated by &amp;lt;tt&amp;gt;loopStart&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Tempo ==&lt;br /&gt;
&lt;br /&gt;
All songs use the standard module speed/tempo system.  The tempo is fixed at 144, and the speed can be changed per song.  For SB/AdLib songs, the speed is set once with the value obtained from the file header, while GUS songs include a &#039;set speed&#039; command at the start of each pattern.&lt;br /&gt;
&lt;br /&gt;
== Pattern data (SB/AdLib) ==&lt;br /&gt;
&lt;br /&gt;
The musical score data for SoundBlaster/AdLib files consists of a sequence of variable-length commands, in the following format:&lt;br /&gt;
&lt;br /&gt;
=== 0x00-0x0C: Play note ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2 !! Byte 3&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || &amp;lt;tt&amp;gt;jfffnnnn&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;iiiivvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Play a note on the given channel.&lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x00 through 0x0C.  The value controls the channel used for the note:&lt;br /&gt;
** 0x00: digital 1&lt;br /&gt;
** 0x03: digital 4&lt;br /&gt;
** 0x04: FM 1&lt;br /&gt;
** 0x0C: FM 9&lt;br /&gt;
** 0x0D-0x0F: Invalid&lt;br /&gt;
* &amp;lt;tt&amp;gt;j&amp;lt;/tt&amp;gt;: High (fifth) bit of instrument number.&lt;br /&gt;
* &amp;lt;tt&amp;gt;fff&amp;lt;/tt&amp;gt;: The octave of the note to play.  Middle-C is within octave 2 for digital channels (they have 4 octaves). FM channels have 7 octaves, and the middle-C is in octave 4.&lt;br /&gt;
* &amp;lt;tt&amp;gt;nnnn&amp;lt;/tt&amp;gt;: The number of the note to play within the octave (0-11).&lt;br /&gt;
* &amp;lt;tt&amp;gt;iiii&amp;lt;/tt&amp;gt;: The lower four bits of the instrument to use.  A value of zero uses the first instrument.  This is the first PCM instrument on a digital channel, and the first OPL instrument on an FM channel.&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is almost silent, 0xF is full volume. Notes can be played with zero velocity and then faded in with subsequent volume change commands. Volume is linear for both digital and FM channels, which needs to be translated for FM channels (the OPL chip has a logarithmic volume curve).&lt;br /&gt;
&lt;br /&gt;
=== 0x20-0x2C: Set volume ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x20 || &amp;lt;tt&amp;gt;0000vvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Set the volume of the playing note on the given channel.  &lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x20 through 0x2C, with the lower four bits representing the channel number as with playing a note.&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is silent, 0xF is full volume.&lt;br /&gt;
&lt;br /&gt;
=== 0x40: Delay ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x40 || &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Delay for the given number of ticks before continuing with the next event.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;: Number of ticks to wait&lt;br /&gt;
&lt;br /&gt;
=== 0x60: End of pattern ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
|-&lt;br /&gt;
| 0x60&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This must be the last command in each pattern.  Playback will jump to the next pattern in the sequence specified in the song header.&lt;br /&gt;
&lt;br /&gt;
=== 0x80: Unknown ===&lt;br /&gt;
&lt;br /&gt;
This command is not used in any known files and crashes Zone 66.  Its purpose, or perhaps incomplete intended purpose, is unknown.&lt;br /&gt;
&lt;br /&gt;
== Pattern data (GUS) ==&lt;br /&gt;
&lt;br /&gt;
The musical score data for GUS files also consists of a sequence of variable-length commands, however the commands are different from the ones used in SB/AdLib files.  The commands are in the following format:&lt;br /&gt;
&lt;br /&gt;
=== 0x00: Delay ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x01 || &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Delay for the given number of ticks before continuing with the next event.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;: Number of ticks to wait&lt;br /&gt;
&lt;br /&gt;
=== 0x01: Set speed ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x01 || &amp;lt;tt&amp;gt;ssssssss&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Adjust the song playback speed.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;ssssssss&amp;lt;/tt&amp;gt;: New speed.  This is the same as the &#039;speed&#039; in standard .mod files (i.e. the number of frames per row), with the module tempo fixed at 144.&lt;br /&gt;
&lt;br /&gt;
=== 0x02: End of pattern ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
|-&lt;br /&gt;
| 0x02&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This must be the last command in each pattern.  Playback will jump to the next pattern in the sequence specified in the song header.&lt;br /&gt;
&lt;br /&gt;
=== 0x40-0x4F: Play note ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2 !! Byte 3 !! Byte 4&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || &amp;lt;tt&amp;gt;ffffffff&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;ppppvvvv&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;iiiiiiii&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Play a note on the given channel.&lt;br /&gt;
&lt;br /&gt;
* The command byte is always 0x40 through 0x4F.  The value controls the channel used for the note:&lt;br /&gt;
** 0x00: GUS channel 1&lt;br /&gt;
** 0x01: GUS channel 2&lt;br /&gt;
** 0x0F: GUS channel 16 {{TODO|Assumed, please confirm}}&lt;br /&gt;
* &amp;lt;tt&amp;gt;ffffffff&amp;lt;/tt&amp;gt;: Note.  Add 25 to this value (i.e. transpose up by two octaves and one note) to obtain standard MIDI note numbers.&lt;br /&gt;
* &amp;lt;tt&amp;gt;pppp&amp;lt;/tt&amp;gt;: Panning, 0=centre, 1=full right, 15=full left&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Velocity, logarithmic, 0=silent, 1=1%, 2=4%, 3=7% ... 12=49.8%, 13=60%, 14=74.9%, 15=100%&lt;br /&gt;
* &amp;lt;tt&amp;gt;iiiiiiii&amp;lt;/tt&amp;gt;: Instrument, 0=first, 1=second, etc.&lt;br /&gt;
&lt;br /&gt;
=== 0x80-0x8F: Set volume ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x80 || &amp;lt;tt&amp;gt;ppppvvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Set the volume of the playing note on the given channel.  &lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x80 through 0x8F, with the lower four bits representing the channel number as with playing a note.&lt;br /&gt;
* &amp;lt;tt&amp;gt;pppp&amp;lt;/tt&amp;gt;: {{TODO|Assumed pan value, same as for note-on}}&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is silent, 0xF is full volume.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[Camoto]]&lt;br /&gt;
| Platform = Linux/Win&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes; except GUS&lt;br /&gt;
| canModify = Yes; except GUS&lt;br /&gt;
| canExport = Yes&lt;br /&gt;
| canImport = Yes; except GUS&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://sbfmdrv.blogspot.com.au/2015/12/renaissance-cdfm-music.html CDFM Tracker]&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
This file format was reverse engineered by [[User:Malvineous|Malvineous]].  If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=CDFM_Format&amp;diff=7632</id>
		<title>CDFM Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=CDFM_Format&amp;diff=7632"/>
		<updated>2018-06-08T23:43:16Z</updated>

		<summary type="html">&lt;p&gt;Saga: Can access more than 16 instruments (source: 670 to C67 conversion source)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{NeedMoreInfo}}&lt;br /&gt;
{{Music Infobox&lt;br /&gt;
 | Type = Custom&lt;br /&gt;
 | Instruments = OPL&lt;br /&gt;
 | Instruments2 = PCM&lt;br /&gt;
 | NumChannels = 13&lt;br /&gt;
 | NumTracks = 1&lt;br /&gt;
 | Tags = None&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Zone 66}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[CDFM Format]] was developed by the demogroup Renaissance for their Amnesia demo, and was later used in their game [[Zone 66]].  It consists of either nine Adlib channels (for Adlib hardware), nine OPL and four PCM channels (for Sound Blaster hardware) or patches to be played as MIDI instruments (for GUS hardware.)&lt;br /&gt;
&lt;br /&gt;
In Zone 66, most songs have hardware-specific versions, even where the SB song could drop the PCM channels and be played on Adlib.  In these cases the PCM drum channels have been replaced with OPL instruments.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file begins with a header.  Those fields marked &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;GUS only] are missing entirely in SoundBlaster/AdLib songs, and those fields marked &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;AdLib/SB only] are missing entirely in the GUS variant of the song format.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || sampleOffset || &#039;&#039;&#039;[GUS only]&#039;&#039;&#039; Offset of instrument samples from start of file&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || tempo || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Playback speed, larger is slower&amp;lt;br/&amp;gt;&#039;&#039;&#039;[GUS only]&#039;&#039;&#039; Unknown, always 0x66, changing has no effect&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || patternListSize || Size of pattern list&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numPatterns || Number of patterns in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numDigInst || Number of PCM or GUS instruments in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || numOPLInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Number of OPL instruments in song&lt;br /&gt;
|-&lt;br /&gt;
| BYTE || loopDest || Index into &amp;lt;tt&amp;gt;patternOrder&amp;lt;/tt&amp;gt; for next pattern to play after the final one when looping the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || sampleOffset || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; Offset of instrument samples from start of file&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[patternListSize] || patternOrder || Order of patterns in the song, &amp;lt;tt&amp;gt;patternListSize&amp;lt;/tt&amp;gt; bytes in length&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE[numPatterns] || patternOffset || Offset of each pattern&#039;s data, relative to the start of the pattern data&lt;br /&gt;
|-&lt;br /&gt;
| PCM_INST[numDigInst] || pcmInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; 16 bytes of info for each digital (PCM) instrument&lt;br /&gt;
|-&lt;br /&gt;
| OPL_INST[numOPLInst] || oplInst || &#039;&#039;&#039;[Adlib/SB only]&#039;&#039;&#039; 11-byte instrument patch for each FM (OPL) instrument&lt;br /&gt;
|-&lt;br /&gt;
| GUS_INST[numDigInst] || gusInst || &#039;&#039;&#039;[GUS only]&#039;&#039;&#039; 11 bytes of info for each GUS patch&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pattern data immediately follows.  The &amp;lt;tt&amp;gt;patternOffset&amp;lt;/tt&amp;gt; values are relative to this position, so a value of 0x00000000 corresponds to the first byte here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;PCM_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || address_ptr || Used to place address of sample start in memory - ignore when reading, write as 0x00000000&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Length of sample, in bytes&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Offset of loop return, in bytes, relative to start of sample&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopEnd || Offset of loop trigger, in bytes, relative to start of sample.  Use 0x00FFFFFF for no loop.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The PCM instruments begin at &amp;lt;tt&amp;gt;sampleOffset&amp;lt;/tt&amp;gt; and are raw (no header) 8-bit unsigned PCM data.  If the sample loops, as soon as playback reaches &amp;lt;tt&amp;gt;loopEnd&amp;lt;/tt&amp;gt; (which could be before the end of the sample), playback will immediately jump to &amp;lt;tt&amp;gt;loopStart&amp;lt;/tt&amp;gt;.  The middle-C frequency for all PCM instruments is fixed at 8287 Hz (ProTracker standard).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;OPL_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!OPL base register!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iFeedback||0xC0||Feedback/connection&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModChar||0x20||Modulator characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModScale||0x40||Modulator key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModAttack||0x60||Modulator attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModSustain||0x80||Modulator sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModWaveSel||0xE0||Modulator wave select&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarChar||0x23||Carrier characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarScale||0x43||Carrier key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarAttack||0x63||Carrier attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarSustain||0x83||Carrier sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarWaveSel||0xE3||Carrier wave select&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The OPL base registers in this list are for the two operators controlling the first OPL channel.  Adjust them accordingly for the relevant OPL channel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;GUS_INST&amp;lt;/tt&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || flags || Bitfield: 1={{TODO|stereo? Makes pitch higher}}, 2=loop, 16={{TODO|unknown - mutes instrument}}&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || rate || Playback sampling rate for pitch to be middle-C&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Sample offset, in bytes, of loop start&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Length of sample, in bytes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All sample data is 8-bit &#039;&#039;&#039;signed&#039;&#039;&#039;.  If the loop bit is set (i.e. &amp;lt;tt&amp;gt;flags &amp;amp; 2&amp;lt;/tt&amp;gt;) then when the end of the sample is reached playback jumps immediately to the byte offset indicated by &amp;lt;tt&amp;gt;loopStart&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Tempo ==&lt;br /&gt;
&lt;br /&gt;
All songs use the standard module speed/tempo system.  The tempo is fixed at 144, and the speed can be changed per song.  For SB/AdLib songs, the speed is set once with the value obtained from the file header, while GUS songs include a &#039;set speed&#039; command at the start of each pattern.&lt;br /&gt;
&lt;br /&gt;
== Pattern data (SB/AdLib) ==&lt;br /&gt;
&lt;br /&gt;
The musical score data for SoundBlaster/AdLib files consists of a sequence of variable-length commands, in the following format:&lt;br /&gt;
&lt;br /&gt;
=== 0x00-0x0C: Play note ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2 !! Byte 3&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || &amp;lt;tt&amp;gt;jfffnnnn&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;iiiivvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Play a note on the given channel.&lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x00 through 0x0C.  The value controls the channel used for the note:&lt;br /&gt;
** 0x00: digital 1&lt;br /&gt;
** 0x03: digital 4&lt;br /&gt;
** 0x04: FM 1&lt;br /&gt;
** 0x0C: FM 9&lt;br /&gt;
** 0x0D-0x0F: Invalid&lt;br /&gt;
* &amp;lt;tt&amp;gt;j&amp;lt;/tt&amp;gt;: High (fifth) bit of instrument number.&lt;br /&gt;
* &amp;lt;tt&amp;gt;fff&amp;lt;/tt&amp;gt;: The octave of the note to play.  Middle-C is within octave 2.&lt;br /&gt;
* &amp;lt;tt&amp;gt;nnnn&amp;lt;/tt&amp;gt;: The number of the note to play within the octave (0-11).&lt;br /&gt;
* &amp;lt;tt&amp;gt;iiii&amp;lt;/tt&amp;gt;: The lower four bits of the instrument to use.  A value of zero uses the first instrument.  This is the first PCM instrument on a digital channel, and the first OPL instrument on an FM channel.&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is silent, 0xF is full volume.  Notes can be played with zero velocity and then faded in with subsequent volume change commands.&lt;br /&gt;
&lt;br /&gt;
=== 0x20-0x2C: Set volume ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x20 || &amp;lt;tt&amp;gt;0000vvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Set the volume of the playing note on the given channel.  &lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x20 through 0x2C, with the lower four bits representing the channel number as with playing a note.&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is silent, 0xF is full volume.&lt;br /&gt;
&lt;br /&gt;
=== 0x40: Delay ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x40 || &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Delay for the given number of ticks before continuing with the next event.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;: Number of ticks to wait&lt;br /&gt;
&lt;br /&gt;
=== 0x60: End of pattern ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
|-&lt;br /&gt;
| 0x60&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This must be the last command in each pattern.  Playback will jump to the next pattern in the sequence specified in the song header.&lt;br /&gt;
&lt;br /&gt;
=== 0x80: Unknown ===&lt;br /&gt;
&lt;br /&gt;
This command is not used in any known files and crashes Zone 66.  Its purpose, or perhaps incomplete intended purpose, is unknown.&lt;br /&gt;
&lt;br /&gt;
== Pattern data (GUS) ==&lt;br /&gt;
&lt;br /&gt;
The musical score data for GUS files also consists of a sequence of variable-length commands, however the commands are different from the ones used in SB/AdLib files.  The commands are in the following format:&lt;br /&gt;
&lt;br /&gt;
=== 0x00: Delay ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x01 || &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Delay for the given number of ticks before continuing with the next event.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;tttttttt&amp;lt;/tt&amp;gt;: Number of ticks to wait&lt;br /&gt;
&lt;br /&gt;
=== 0x01: Set speed ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x01 || &amp;lt;tt&amp;gt;ssssssss&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Adjust the song playback speed.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;ssssssss&amp;lt;/tt&amp;gt;: New speed.  This is the same as the &#039;speed&#039; in standard .mod files (i.e. the number of frames per row), with the module tempo fixed at 144.&lt;br /&gt;
&lt;br /&gt;
=== 0x02: End of pattern ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
|-&lt;br /&gt;
| 0x02&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This must be the last command in each pattern.  Playback will jump to the next pattern in the sequence specified in the song header.&lt;br /&gt;
&lt;br /&gt;
=== 0x40-0x4F: Play note ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2 !! Byte 3 !! Byte 4&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || &amp;lt;tt&amp;gt;ffffffff&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;ppppvvvv&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt;iiiiiiii&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Play a note on the given channel.&lt;br /&gt;
&lt;br /&gt;
* The command byte is always 0x40 through 0x4F.  The value controls the channel used for the note:&lt;br /&gt;
** 0x00: GUS channel 1&lt;br /&gt;
** 0x01: GUS channel 2&lt;br /&gt;
** 0x0F: GUS channel 16 {{TODO|Assumed, please confirm}}&lt;br /&gt;
* &amp;lt;tt&amp;gt;ffffffff&amp;lt;/tt&amp;gt;: Note.  Add 25 to this value (i.e. transpose up by two octaves and one note) to obtain standard MIDI note numbers.&lt;br /&gt;
* &amp;lt;tt&amp;gt;pppp&amp;lt;/tt&amp;gt;: Panning, 0=centre, 1=full right, 15=full left&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Velocity, logarithmic, 0=silent, 1=1%, 2=4%, 3=7% ... 12=49.8%, 13=60%, 14=74.9%, 15=100%&lt;br /&gt;
* &amp;lt;tt&amp;gt;iiiiiiii&amp;lt;/tt&amp;gt;: Instrument, 0=first, 1=second, etc.&lt;br /&gt;
&lt;br /&gt;
=== 0x80-0x8F: Set volume ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Command !! Byte 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x80 || &amp;lt;tt&amp;gt;ppppvvvv&amp;lt;/tt&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Set the volume of the playing note on the given channel.  &lt;br /&gt;
&lt;br /&gt;
* The command byte is 0x80 through 0x8F, with the lower four bits representing the channel number as with playing a note.&lt;br /&gt;
* &amp;lt;tt&amp;gt;pppp&amp;lt;/tt&amp;gt;: {{TODO|Assumed pan value, same as for note-on}}&lt;br /&gt;
* &amp;lt;tt&amp;gt;vvvv&amp;lt;/tt&amp;gt;: Note volume/velocity.  0x0 is silent, 0xF is full volume.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[Camoto]]&lt;br /&gt;
| Platform = Linux/Win&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes; except GUS&lt;br /&gt;
| canModify = Yes; except GUS&lt;br /&gt;
| canExport = Yes&lt;br /&gt;
| canImport = Yes; except GUS&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://sbfmdrv.blogspot.com.au/2015/12/renaissance-cdfm-music.html CDFM Tracker]&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = N/A&lt;br /&gt;
| editMetadata = N/A&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
This file format was reverse engineered by [[User:Malvineous|Malvineous]].  If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=S3M_Format&amp;diff=7577</id>
		<title>S3M Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=S3M_Format&amp;diff=7577"/>
		<updated>2018-05-31T18:04:28Z</updated>

		<summary type="html">&lt;p&gt;Saga: Clarification on Sustain value&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | Instruments2 = OPL&lt;br /&gt;
 | NumChannels = 32&lt;br /&gt;
 | NumTracks = 255&lt;br /&gt;
 | NumPatterns = 65,536&lt;br /&gt;
 | NumOrders = 65,536&lt;br /&gt;
 | Tags = Title, instrument names&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Unreal Tournament}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[S3M Format]] is used to save modules composed in ScreamTracker 3.  A number of games support music in this format, however it is primarily used for composing independent songs unrelated to games.&lt;br /&gt;
&lt;br /&gt;
The format is notable both for its popularity, as well as for being one of the few that support both FM/OPL and sampled instruments.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file begins with a header.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Song title, must be null-terminated&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || sig1 || Signature byte, always 0x1A&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || type || Song type, always 0x10 for S3M&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || reserved || Always 0x0000&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || orderCount || Number of entries in the order table, should be even&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || instrumentCount || Number of instruments in the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || patternPtrCount || Number of pattern parapointers in the song&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || flags || See below&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || trackerVersion || upper four bits is tracker ID, lower 12 bits is tracker version&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || sampleType || 1=signed samples [deprecated], 2=unsigned samples&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || sig2 || Signature: &amp;quot;SCRM&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || globalVolume || &lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || initialSpeed || Frames per row, can be changed later with &amp;lt;tt&amp;gt;A&amp;lt;/tt&amp;gt; command&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || initialTempo || Frames per second, can be changed later with &amp;lt;tt&amp;gt;T&amp;lt;/tt&amp;gt; command&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || masterVolume || bit 7: 1=stereo, 0=mono, bits 6-0: volume&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || ultraClickRemoval || Number of channels to use for click removal on real GUS hardware&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || defaultPan || 252=read pan values in header, anything else ignores pan values in header&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[8] || reserved || Unused, some trackers store data here&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || ptrSpecial || Parapointer to additional data, if &amp;lt;tt&amp;gt;flags&amp;lt;/tt&amp;gt; has bit 7 set&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[32] || channelSettings || See below&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[orderCount] || orderList || Which order patterns are played in&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE[instrumentCount] || ptrInstruments || List of parapointers to each instrument&#039;s data&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE[patternPtrCount] || ptrPatterns || List of parapointers to each pattern&#039;s data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Flags are one or more values below:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Bit !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 1 || ST2 vibrato [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 2 || ST2 tempo [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 4 || Amiga slides [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 8 || 0vol optimisations - automatically turn off looping notes when the volume is zero for more than two rows&lt;br /&gt;
|-&lt;br /&gt;
| 4 || 16 || Amiga limits - ignore notes beyond Amiga hardware limits (as Amiga does.)  Sliding up stops at B#5.  Also affects other Amiga compatibility issues.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || 32 || Enable SoundBlaster filter/sfx [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| 6 || 64 || ST3.00 volume slides - perform volume slides on first row as well.  Set implicitly if &amp;lt;tt&amp;gt;trackerVersion&amp;lt;/tt&amp;gt; is 0x1300.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || 128 || &amp;lt;tt&amp;gt;ptrSpecial&amp;lt;/tt&amp;gt; is valid&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Known &amp;lt;tt&amp;gt;trackerVersion&amp;lt;/tt&amp;gt; values are:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x1300 || ScreamTracker 3.00&lt;br /&gt;
|-&lt;br /&gt;
| 0x1301 || ScreamTracker 3.01&lt;br /&gt;
|-&lt;br /&gt;
| 0x1303 || ScreamTracker 3.03&lt;br /&gt;
|-&lt;br /&gt;
| 0x1320 || ScreamTracker 3.20&lt;br /&gt;
|-&lt;br /&gt;
| 0x2nyy || Imago Orpheus x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x3nyy || Impulse Tracker x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0x4nnn || Schism Tracker&lt;br /&gt;
|-&lt;br /&gt;
| 0x5nyy || OpenMPT x.yy&lt;br /&gt;
|-&lt;br /&gt;
| 0xCA00 || Camoto/libgamemusic&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;channelSettings&amp;lt;/tt&amp;gt; is 32 values indicating the audio channel assignments for each of the 32 S3M channels.  Unused channels should be set to 255.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 to 7 || Left PCM channels 1 to 8&lt;br /&gt;
|-&lt;br /&gt;
| 8 to 15 || Right PCM channels 1 to 8&lt;br /&gt;
|-&lt;br /&gt;
| 16 to 24 || Adlib melody channel 1-9&lt;br /&gt;
|-&lt;br /&gt;
| 25 || Adlib percussion channel: bass drum&lt;br /&gt;
|-&lt;br /&gt;
| 26 || Adlib percussion channel: snare drum&lt;br /&gt;
|-&lt;br /&gt;
| 27 || Adlib percussion channel: tom tom&lt;br /&gt;
|-&lt;br /&gt;
| 28 || Adlib percussion channel: top cymbal&lt;br /&gt;
|-&lt;br /&gt;
| 29 || Adlib percussion channel: hi-hat&lt;br /&gt;
|-&lt;br /&gt;
| 30 to 127 || Unused/invalid&lt;br /&gt;
|-&lt;br /&gt;
| 128 to 254 || Unused/invalid (but channel disabled)&lt;br /&gt;
|-&lt;br /&gt;
| 255 || Channel unused&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;orderList&amp;lt;/tt&amp;gt; contains the index of each pattern to be played.  The first entry in this array is the index of the first pattern to play, the second entry is the second pattern, etc.  If an entry is 0xFE then it is a &amp;quot;marker pattern&amp;quot; and is skipped during playback, and an entry of 0xFF signifies the end of the song.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;ptrInstruments&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ptrPatterns&amp;lt;/tt&amp;gt; are arrays of parapointers to the start of the instrument and pattern data.  Each parapointer is an offset from the start of the file, in units of 16 bytes (a &amp;quot;paragraph&amp;quot;).  To convert this into a normal byte-level file offset, multiply it by 16 (or shift-left by 4.)&lt;br /&gt;
&lt;br /&gt;
By convention these blocks follow the header above, but this is not a requirement and they can occur at any point in the file.&lt;br /&gt;
&lt;br /&gt;
=== Timing ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;initialTempo&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;initialSpeed&amp;lt;/tt&amp;gt; values are the ones to use until optionally changed during playback, with the A and T effects respectively.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;initialTempo&amp;lt;/tt&amp;gt; value controls how many audio frames are generated per second.  If this value is 50, then there should be 50 audio frames per second.  Obviously the more audio frames per second, the shorter each frame is going to be.  To calculate the length of each frame, a formula like this can be used:&lt;br /&gt;
&lt;br /&gt;
    frame length in seconds = 1 / initialTempo&lt;br /&gt;
     0.02 seconds per frame = 1 / 50&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;initialSpeed&amp;lt;/tt&amp;gt; value controls how many audio frames comprise a single row of the song.  If the value is 3, then there are three audio frames per row.  For certain effects, they are updated once per frame (i.e. the effect changes between rows.)&lt;br /&gt;
&lt;br /&gt;
To calculate playback speed, both these values need to be taken into account.  The tempo value controls the length of each audio frame, while the speed value controls how quickly the rows are turned into those audio frames.  For example, to calculate the number of rows per second:&lt;br /&gt;
&lt;br /&gt;
    rowsPerSecond = initialTempo / initialSpeed&lt;br /&gt;
&lt;br /&gt;
=== Instruments ===&lt;br /&gt;
&lt;br /&gt;
At the offset given by an instrument&#039;s parapointer, the data has a header as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || type || 0=empty instrument (message only), 1=PCM instrument&lt;br /&gt;
|-&lt;br /&gt;
| char[12] || filename || Original instrument filename in DOS 8.3 format, no terminating null&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || empty instrument (message only)&lt;br /&gt;
|-&lt;br /&gt;
| 1 || PCM instrument&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Adlib melody instrument&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Adlib percussive: bass drum&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Adlib percussive: snare&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Adlib percussive: tom tom&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Adlib percussive: top cymbal&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Adlib percussive: hi-hat&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The data following the header depends on whether the instrument is PCM or Adlib.&lt;br /&gt;
{{TODO|What if the instrument is empty, is there any trailing data?}}&lt;br /&gt;
&lt;br /&gt;
==== PCM ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || ptrDataH || Upper eight bits of parapointer to sample data, relative to start of S3M file&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || ptrDataL || Lower 16 bits of parapointer to sample data, relative to start of S3M file&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Sample data length, in bytes.  S3M is limited to 64000 and ignores upper 16 bits.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Offset of loop start in bytes, relative to start of sample data.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopEnd || Offset of loop end in bytes, relative to start of sample data.&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Default volume of sample, 0-63 inclusive.&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || reserved || Always 0x00&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || pack || 0=unpacked, 1=DP30ADPCM [deprecated]&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || flags || Sum: 1=loop on, 2=stereo (data is &amp;lt;tt&amp;gt;length&amp;lt;/tt&amp;gt; bytes for left channel then &amp;lt;tt&amp;gt;length&amp;lt;/tt&amp;gt; bytes for right channel), 4=16-bit little-endian sample&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || c2spd || Sample rate for middle-C note (C-4)&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[12] || internal || Always zero, used in-memory during playback&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Sample title, for display to user.  Must be null-terminated.&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || sig || Signature: &amp;quot;SCRS&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ScreamTracker stores the above instrument structures at the start of the file, but stores the sample data at the end of the file (after the pattern data.)  This is not the only way to store it though.&lt;br /&gt;
&lt;br /&gt;
==== Adlib ====&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[3] || reserved || Always 0x00 0x00 0x00&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[12] || oplValues || See below&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Default volume of instrument, 0-63 inclusive.&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || dsk || {{TODO|Unknown}}&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || reserved || Always 0x0000&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || c2spd || Sample rate for middle-C note (C-4), see below.&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[12] || unused || Always zero&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Sample title, for display to user.  Must be null-terminated.&lt;br /&gt;
|-&lt;br /&gt;
| char[4] || sig || Signature: &amp;quot;SCRI&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;oplValues&amp;lt;/tt&amp;gt; are stored as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!rowspan=2| Byte index !!rowspan=2| Operator !!rowspan=2| OPL base register !!colspan=8| Bits&lt;br /&gt;
|-&lt;br /&gt;
!width=100| 7 !!width=100| 6 !!width=100| 5 !!width=100| 4 !!width=100| 3 !!width=100| 2 !!width=100| 1 !!width=100| 0&lt;br /&gt;
|-&lt;br /&gt;
| 0 || Modulator || 0x20 ||align=center rowspan=2| Tremolo? ||align=center rowspan=2| Vibrato? ||align=center rowspan=2| Sustain? ||align=center rowspan=2| KSR? ||align=center rowspan=2 colspan=4| Freq. mult.&lt;br /&gt;
|-&lt;br /&gt;
| 1 || Carrier || 0x23&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Modulator || 0x40 ||align=center rowspan=2| Scale level (bit 0) ||align=center rowspan=2| Scale level (bit 1) ||align=center rowspan=2 colspan=6| Output level (0=loudest, 63=silent)&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Carrier || 0x43&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Modulator || 0x60 ||align=center rowspan=2 colspan=4| Attack rate ||align=center rowspan=2 colspan=4| Decay rate&lt;br /&gt;
|-&lt;br /&gt;
| 5 || Carrier || 0x63&lt;br /&gt;
|-&lt;br /&gt;
| 6 || Modulator || 0x80 ||align=center rowspan=2 colspan=4| Sustain rate ||align=center rowspan=2 colspan=4| Release rate&lt;br /&gt;
|-&lt;br /&gt;
| 7 || Carrier || 0x83&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Modulator || 0xE0 ||align=center rowspan=2 colspan=8| Wave select&lt;br /&gt;
|-&lt;br /&gt;
| 9 || Carrier || 0xE3&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Modulator || 0xC0 ||align=center colspan=7| Feedback ||align=center| Connection&lt;br /&gt;
|-&lt;br /&gt;
| 11 || - || - ||align=center colspan=8| Unused, set to 0x00&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;c2spd&amp;lt;/tt&amp;gt; sets the instrument tuning.  It scales the note freq {{TODO|somehow}} - the exact formula is unknown.  The default value is 8363 as with PCM instruments, and increasing this by roughly 10 tunes the note up by one OPL F-num (approx 0.7Hz in OPL block 2).&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The value packing is almost identical to that used in the [[SBI Format]], just the bytes are in a different order.&lt;br /&gt;
* The ST3 docs say bytes 2-3 bits 5-0 are &amp;quot;63-volume&amp;quot; but this is to make the values match PCM samples.  The value in the file matches the value sent to the OPL chip.&lt;br /&gt;
* The Scale Level bits in bytes 2-3 are swapped.  The ST3 technical docs have a typo that suggest Scale Level (bit 1) actually overflows into &amp;quot;bit 8&amp;quot; of the OPL register, but testing this in ST3 shows this is not the case and the bit order is merely swapped.&lt;br /&gt;
* The ST3 docs say bytes 6-7 have the sustain rate stored as &amp;quot;15-sustain&amp;quot;, which is from a editor UI perspective - the value can be sent as-is to the OPL chip.&lt;br /&gt;
&lt;br /&gt;
=== Patterns ===&lt;br /&gt;
&lt;br /&gt;
At the offset given by a pattern&#039;s parapointer, packed data is present and will need to be unpacked.  The following structure appears at the start of each pattern&#039;s data:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || packed_len || Length of packed data for all 64 rows, in bytes&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[packed_len - 2] || packed_data || Packed row data, described below&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;packed_len&amp;lt;/tt&amp;gt; includes its own length, so as it is two bytes long, the length of the packed data will be two bytes less than this value.  The first byte in &amp;lt;tt&amp;gt;packed_data&amp;lt;/tt&amp;gt; is a bitfield called &amp;lt;tt&amp;gt;what&amp;lt;/tt&amp;gt;, and it is broken up as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!width=100| 7 !!width=100| 6 !!width=100| 5 !!width=100| 4 !!width=100| 3 !!width=100| 2 !!width=100| 1 !!width=100| 0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;tt&amp;gt;command&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;info&amp;lt;/tt&amp;gt; present&lt;br /&gt;
| &amp;lt;tt&amp;gt;volume&amp;lt;/tt&amp;gt; present&lt;br /&gt;
| &amp;lt;tt&amp;gt;note&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;instrument&amp;lt;/tt&amp;gt; present&lt;br /&gt;
|colspan=5 align=center| Channel number&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If the whole byte is zero then it signals the end of the row.  This byte and the ones following are further described in the following table.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || what || 0=end of row, lower five bits (&amp;lt;tt&amp;gt;what &amp;amp; 0x1F&amp;lt;/tt&amp;gt;) are channel number&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || note || Note number (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x20&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || instrument || Instrument number (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x20&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Volume level (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x40&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || command || Effect type (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x80&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || info || Effect value (only present if &amp;lt;tt&amp;gt;what &amp;amp; 0x80&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
After these bytes the process repeats with another &amp;lt;tt&amp;gt;what&amp;lt;/tt&amp;gt; value.  When &amp;lt;tt&amp;gt;what&amp;lt;/tt&amp;gt; is 0x00 the end of the row has been reached.  After the 64th row has been reached, the pattern ends and &amp;lt;tt&amp;gt;packed_len&amp;lt;/tt&amp;gt; bytes will have been read.&lt;br /&gt;
&lt;br /&gt;
Be aware that &amp;lt;tt&amp;gt;channel&amp;lt;/tt&amp;gt; is a value between 0 and 31 inclusive, which corresponds to an entry in the &amp;lt;tt&amp;gt;channelSettings&amp;lt;/tt&amp;gt; field in the header.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;volume&amp;lt;/tt&amp;gt; field is 0 for silent, 64 for full volume (note this is 65 unique values), or 255 for &#039;ignore&#039; (shown as &amp;quot;..&amp;quot; in the tracker.)  If the value is 255 or missing entirely, the instrument&#039;s default volume is used (the &amp;lt;tt&amp;gt;volume&amp;lt;/tt&amp;gt; value from the instrument settings.)&lt;br /&gt;
&lt;br /&gt;
The upper four bits of &amp;lt;tt&amp;gt;note&amp;lt;/tt&amp;gt; store the octave, and the lower four bits store the semitone (with 0=C, 1=C#, up to 11=B)&lt;br /&gt;
&lt;br /&gt;
=== Effects ===&lt;br /&gt;
&lt;br /&gt;
==== 0x01/A: Set speed ====&lt;br /&gt;
&lt;br /&gt;
Set &#039;&#039;speed&#039;&#039; (one of the two tempo variables.)  Data byte is new speed.  A value of 0 causes the event to be ignored.&lt;br /&gt;
&lt;br /&gt;
==== 0x02/B: Order jump ====&lt;br /&gt;
&lt;br /&gt;
After the current row has finished playing, the next row is the first row in order given by the data byte.  0 means the start of the song {{TODO|Confirm this}}.&lt;br /&gt;
&lt;br /&gt;
==== 0x03/C: Jump to row ====&lt;br /&gt;
&lt;br /&gt;
After the current row has finished playing, the next row is played from the next pattern in the order sequence.  The row in this next pattern is given by the data byte, but the data byte is decimal-as-hex.  So a value of 0x12 should be treated as decimal 12.  These formulae will calculate the correct row (to/from the S3M value):&lt;br /&gt;
&lt;br /&gt;
 row = (data &amp;gt;&amp;gt; 4) * 10 + (data &amp;amp; 0x0f)    // Read S3M into variable&lt;br /&gt;
 data = ((row / 10) &amp;lt;&amp;lt; 4) | (row % 10)     // Write variable to S3M&lt;br /&gt;
&lt;br /&gt;
The first row in the pattern is 0.  If the decoded data value is larger than 63, the effect is ignored.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [http://schismtracker.org/ SchismTracker]&lt;br /&gt;
| Platform = Windows/Linux&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canExport = .it + more&lt;br /&gt;
| canImport = [[MOD Format|.mod]] .it + more&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = Yes&lt;br /&gt;
| notes = Can play OPL and PCM simultaneously&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = ScreamTracker 3&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canExport = [[MOD Format|.mod]]&lt;br /&gt;
| canImport = [[MOD Format|.mod]]&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = Yes&lt;br /&gt;
| notes = Official tool&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
&lt;br /&gt;
Much of this information was combined from the following sites:&lt;br /&gt;
&lt;br /&gt;
* TECH.DOC distributed with ScreamTracker 3&lt;br /&gt;
* [http://wiki.multimedia.cx/index.php?title=Scream_Tracker_3_Module S3M on the MultimediaWiki]&lt;br /&gt;
* [http://schismtracker.org/wiki/FS3MDOC.TXT FS3MDOC.TXT] - S3M Player Tutorial&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=SBI_Format&amp;diff=7576</id>
		<title>SBI Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=SBI_Format&amp;diff=7576"/>
		<updated>2018-05-31T18:01:43Z</updated>

		<summary type="html">&lt;p&gt;Saga: /* Instrument settings */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Instrument-only&lt;br /&gt;
 | Instruments = OPL&lt;br /&gt;
 | NumChannels = 1&lt;br /&gt;
 | NumTracks = 0&lt;br /&gt;
 | Tags = Title&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;SBI (Sound Blaster Instrument) Format&#039;&#039;&#039; stores a single instrument suitable for playback on a sound card with an OPL2 or OPL3 chip.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file is structured as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name!! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][4] || signature || &amp;quot;SBI&amp;quot; followed by 0x1A&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][32] || name || Instrument title (must be NULL-terminated)&lt;br /&gt;
|-&lt;br /&gt;
| [[BYTE]][16] || inst || Instrument settings (see below)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Instrument settings ===&lt;br /&gt;
&lt;br /&gt;
The instrument is in the following format.  This is identical to the format used for each instrument in [[CMF Format]] songs and [[IBK Format]] instrument banks.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!OPL base register!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModChar||0x20||Modulator characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarChar||0x23||Carrier characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModScale||0x40||Modulator key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarScale||0x43||Carrier key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModAttack||0x60||Modulator attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarAttack||0x63||Carrier attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModSustain||0x80||Modulator sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarSustain||0x83||Carrier sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModWaveSel||0xE0||Modulator wave select&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarWaveSel||0xE3||Carrier wave select&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iFeedback||0xC0||Feedback/connection&lt;br /&gt;
|-&lt;br /&gt;
|[[BYTE]][5]&lt;br /&gt;
|colspan=3|Padding to bring instrument definition up to 16 bytes. Sometimes a byte is missing, resulting a 51-byte file rather than a 52-byte file. It is probably safer to not expect this padding to exist at all.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Percussive instruments ====&lt;br /&gt;
&lt;br /&gt;
There is no indication as to whether a given instrument should be played in melodic or percussive mode.  Playing an instrument destined for one mode in the other usually sounds quite bad.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[SBTimbre]]&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Yes; [[SBI Format|.sbi]]&lt;br /&gt;
| canImport = Yes; many&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = Can import or export instruments in SBI format&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[SBANK]]&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Yes; many&lt;br /&gt;
| canImport = Yes; many&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = Сan convert SBI between [[AdLib Instrument Format|AdLib INS]] format&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[OPL3 Bank Editor]]&lt;br /&gt;
| Platform = Linux, Windows, macOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Yes; many&lt;br /&gt;
| canImport = Yes; many&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = Can import or export instruments in SBI format&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=SBI_Format&amp;diff=7575</id>
		<title>SBI Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=SBI_Format&amp;diff=7575"/>
		<updated>2018-05-31T18:01:19Z</updated>

		<summary type="html">&lt;p&gt;Saga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Instrument-only&lt;br /&gt;
 | Instruments = OPL&lt;br /&gt;
 | NumChannels = 1&lt;br /&gt;
 | NumTracks = 0&lt;br /&gt;
 | Tags = Title&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;SBI (Sound Blaster Instrument) Format&#039;&#039;&#039; stores a single instrument suitable for playback on a sound card with an OPL2 or OPL3 chip.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file is structured as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name!! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][4] || signature || &amp;quot;SBI&amp;quot; followed by 0x1A&lt;br /&gt;
|-&lt;br /&gt;
| [[char]][32] || name || Instrument title (must be NULL-terminated)&lt;br /&gt;
|-&lt;br /&gt;
| [[BYTE]][16] || inst || Instrument settings (see below)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Instrument settings ===&lt;br /&gt;
&lt;br /&gt;
The instrument is in the following format.  This is identical to the format used for each instrument in [[CMF Format]] songs and [[IBK Format]] instrument banks.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!OPL base register!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModChar||0x20||Modulator characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarChar||0x23||Carrier characteristic (Mult, KSR, EG, VIB and AM flags)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModScale||0x40||Modulator key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarScale||0x43||Carrier key scaling/output level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModAttack||0x60||Modulator attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarAttack||0x63||Carrier attack/decay level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModSustain||0x80||Modulator sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarSustain||0x83||Carrier sustain/release level&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iModWaveSel||0xE0||Modulator wave select&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iCarWaveSel||0xE3||Carrier wave select&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT8]]||iFeedback||0xC0||Feedback/connection&lt;br /&gt;
|-&lt;br /&gt;
|[[BYTE]][5]&lt;br /&gt;
|colspan=3|Padding to bring instrument definition up to 16 bytes. Sometimes a byte is missing, resulting a 51-byte file rather than a 52-byte file. It is probably the safer to not expect this padding to exist at all.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Percussive instruments ====&lt;br /&gt;
&lt;br /&gt;
There is no indication as to whether a given instrument should be played in melodic or percussive mode.  Playing an instrument destined for one mode in the other usually sounds quite bad.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[SBTimbre]]&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Yes; [[SBI Format|.sbi]]&lt;br /&gt;
| canImport = Yes; many&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = Can import or export instruments in SBI format&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[SBANK]]&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Yes; many&lt;br /&gt;
| canImport = Yes; many&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = Сan convert SBI between [[AdLib Instrument Format|AdLib INS]] format&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[OPL3 Bank Editor]]&lt;br /&gt;
| Platform = Linux, Windows, macOS&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Yes; many&lt;br /&gt;
| canImport = Yes; many&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = Can import or export instruments in SBI format&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=DSIK_Module_Format&amp;diff=7453</id>
		<title>DSIK Module Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=DSIK_Module_Format&amp;diff=7453"/>
		<updated>2018-03-12T19:13:21Z</updated>

		<summary type="html">&lt;p&gt;Saga: Some corrections&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 16&lt;br /&gt;
 | NumTracks = 1&lt;br /&gt;
 | NumPatterns = 65,535 (only 255 playable)&lt;br /&gt;
 | NumOrders = 128&lt;br /&gt;
 | Tags = Title, instrument names, instrument filenames&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Trugg}}&lt;br /&gt;
   {{Game|Flying Tiger}}&lt;br /&gt;
   {{Game|Rollin}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The [[DSIK Module Format]] is the music format used by the &#039;&#039;Digital Sound Interface Kit&#039;&#039; by Carlos Hasan.  This was a C and Pascal library for game authors to simplify sound card programming.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The file is a &#039;&#039;&#039;non-standard&#039;&#039;&#039; [[Resource Interchange File Format (RIFF)]] structure.  It is exactly the same as a standard RIFF file, except that the padding bytes between chunks have been omitted.  So if the length of a chunk is an odd number, the padding byte should not be included and the following chunk will not start on a word boundary.&lt;br /&gt;
&lt;br /&gt;
The files are composed of the following chunks:&lt;br /&gt;
&lt;br /&gt;
* RIFF (type: DSMF)&lt;br /&gt;
** SONG&lt;br /&gt;
** INST&lt;br /&gt;
** PATT&lt;br /&gt;
&lt;br /&gt;
The data in each chunk is explained below.&lt;br /&gt;
&lt;br /&gt;
=== SONG chunk ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Song title, null-terminated&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || version || File version&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || flags ||&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || pad ||&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || numOrders || Number of valid entries in &amp;lt;tt&amp;gt;orders&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || numSamples ||&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || numPatterns ||&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || numChannels ||&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volGlobal || Global volume&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volMaster || Master volume&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || initialSpeed ||&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || initialBPM ||&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[16] || channelMap ||&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[128] || orders || Order list.  First value is index of first pattern to play, etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== INST chunk ===&lt;br /&gt;
&lt;br /&gt;
This chunk stores all the instruments in the song.  There are multiple &#039;&#039;&#039;INST&#039;&#039;&#039; chunks in the file, one per instrument.  The data in each chunk is as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| char[13] || filename || Instrument filename, null-terminated&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || flags || Zero or more of: 1=loop active, 2=signed PCM, 4=packed PCM, 64=delta PCM&lt;br /&gt;
|-&lt;br /&gt;
| UINT8 || volume || Default volume of the sample if not volume is given when a note is played.  The range is from 0 (silent) to 64 (loudest), note this is 65 different values.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || length || Length of the sample data, in bytes.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopStart || Position of the loop start point, in bytes, relative to the start of the sample data.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || loopEnd || Position of the loop end point, in bytes, relative to the start of the sample data.&lt;br /&gt;
|-&lt;br /&gt;
| UINT32LE || address_ptr || Used internally for holding in-memory address of sample data, ignore when reading and write as zero.&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || midCRate || Default is 8363&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || period || Default for middle-C is 428&lt;br /&gt;
|-&lt;br /&gt;
| char[28] || title || Sample name, null-terminated&lt;br /&gt;
|-&lt;br /&gt;
| BYTE[length] || data || Sample data, 8-bit mono PCM&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Sample data must be 8-bit mono PCM, signed or unsigned based on &amp;lt;tt&amp;gt;flags&amp;lt;/tt&amp;gt; {{TODO|Confirm that signed PCM actually works}}.  Other formats are rejected by the DSIK library.  Some samples appear to be truncated .wav files and still have the &#039;data&#039; fourcc visible, however this is not part of the format and these bytes will be played as audio data, causing an audible click at the start of playback.&lt;br /&gt;
&lt;br /&gt;
The period is calculated from a sample rate (in Hertz) as &amp;lt;code&amp;gt;period = 8363 * 428 / Hertz&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PATT chunk ===&lt;br /&gt;
&lt;br /&gt;
This chunk stores all the patterns in the song.  There are multiple &#039;&#039;&#039;PATT&#039;&#039;&#039; chunks in the file, one per pattern.  The data in each chunk is as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Data type !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| UINT16LE || length || Length of pattern data, in bytes, including this length field also&lt;br /&gt;
|-&lt;br /&gt;
| UINT8[length - 2] || data || Pattern data, see below&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pattern data is comprised of a flag byte, followed by a variable number of data bytes depending on the value of the flag.  This is very similar to [[S3M Format]] but the bit fields are different.  The flag byte is broken down as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!width=100| 7 !!width=100| 6 !!width=100| 5 !!width=100| 4 !!width=100| 3 !!width=100| 2 !!width=100| 1 !!width=100| 0&lt;br /&gt;
|-&lt;br /&gt;
| Note present&lt;br /&gt;
| Instrument present&lt;br /&gt;
| Volume present&lt;br /&gt;
| Command present&lt;br /&gt;
|colspan=4 align=center| Channel number&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* If the entire value is zero, the row number is incremented and the next flag is read.  Otherwise:&lt;br /&gt;
* If the flag indicates a note is present, the next byte is the note.   Note numbers are semitones, with note 49 being middle C, note 50 being C#4, note 51 being D4, etc.  Adding 11 to the note number will turn them into standard MIDI note numbers.&lt;br /&gt;
* If an instrument is present, the next byte is the zero-based index of the instrument to use.&lt;br /&gt;
* If a volume is present, the next byte is the volume for this note/channel.  The range is from 0 (silent) to 64 (loudest), note this is 65 different values.&lt;br /&gt;
* If a command is present, the next two bytes are the command and value respectively.  Standard .mod commands appear to be used {{TODO|Confirm}}&lt;br /&gt;
&lt;br /&gt;
After these bytes have been read, the next flag byte is read.  Once 64 rows have been read, the end of the pattern data should have been reached.&lt;br /&gt;
&lt;br /&gt;
If the instrument is read but it is zero, then the previous instrument on that channel should be used instead (same as S3M).&lt;br /&gt;
&lt;br /&gt;
Effects 0x00 through 0x0F are the same as in MOD files. The OpenMPT code references effect IDs greater than 0x0F but no such commands have been found in the wild.&lt;br /&gt;
&lt;br /&gt;
Effect 0x08 is 7-bit panning (0x00 = left, 0x80 = right) with parameter 0xA4 enabling surround. DSIK is quite possibly the origin of this panning scheme which was later adopted by other S3M players.&lt;br /&gt;
&lt;br /&gt;
=== Timing ===&lt;br /&gt;
&lt;br /&gt;
See [[S3M Format#Timing]] for a discussion on timing using the &amp;lt;tt&amp;gt;initialBPM&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;initialSpeed&amp;lt;/tt&amp;gt; values.&lt;br /&gt;
&lt;br /&gt;
=== Design issues ===&lt;br /&gt;
&lt;br /&gt;
The file format suffers from a number of design inconsistencies:&lt;br /&gt;
&lt;br /&gt;
* The &#039;&#039;&#039;DSMF&#039;&#039;&#039; format should have been registered with Microsoft as it is in uppercase, however this does not appear to have been done&lt;br /&gt;
* The &#039;&#039;&#039;INST&#039;&#039;&#039; and &#039;&#039;&#039;PATT&#039;&#039;&#039; chunks should have been placed inside &#039;&#039;&#039;LIST&#039;&#039;&#039; chunks, in the spirit of the RIFF format&lt;br /&gt;
* The instrument chunk includes a length field for the sample data, however this is redundant as the chunk itself already has a length.  The two length fields do make it possible to store additional data between the end of the sample data and the end of the chunk, which would normally be ignored, however it seems simpler to just define a new chunk type if new data needs to be stored without breaking backwards compatibility.&lt;br /&gt;
* The instrument chunk stores an address field even though this is only used during playback and does not need to be stored in the file.&lt;br /&gt;
* The pattern chunk also has an extra field to store the length of the pattern data.  However the value in this field includes the length of the field itself, making the value identical to the RIFF chunk&#039;s length field.  The result is that the identical value is written twice, once as a 32-bit value for the RIFF PATT chunk and then immediately again as a 16-bit value.&lt;br /&gt;
* The number of instruments and patterns is stored in the &#039;&#039;&#039;SONG&#039;&#039;&#039; chunk, however this is redundant as the values can be calculated from the number of &#039;&#039;&#039;INST&#039;&#039;&#039; and &#039;&#039;&#039;PATT&#039;&#039;&#039; chunks respectively.&lt;br /&gt;
* There is a 16-bit value for the number of orders, allowing up to 65,535 orders in the song, yet there is a fixed-length array allowing only 128 orders.&lt;br /&gt;
* The pattern count is 16-bit allowing up to 65,536 patterns in the song, but the order list is made up of 8-bit values, meaning only the first 256 patterns can be played.&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
{{BeginFileFormatTools|Type=audio}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = [[Camoto]]&lt;br /&gt;
| Platform = Linux/Windows&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = Yes&lt;br /&gt;
| canExport = Many&lt;br /&gt;
| canImport = Many&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = Yes&lt;br /&gt;
| notes = Minimal support for effects&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = Chronos Module Converter&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = [[MOD Format|.mod]] .stm [[S3M Format|.s3m]] .mtm .dsm .psm&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = Most accurate for converting .dsm to .s3m&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = DSIK&#039;s &amp;lt;tt&amp;gt;conv.exe&amp;lt;/tt&amp;gt;&lt;br /&gt;
| Platform = DOS&lt;br /&gt;
| canPlay = No&lt;br /&gt;
| canCreate = Yes&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = [[MOD Format|.mod]] .stm [[S3M Format|.s3m]] .669 .mtm&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = Yes&lt;br /&gt;
| notes = Official tool&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = ModPlug&lt;br /&gt;
| Platform = Windows&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = No&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
| notes = Plays at wrong tempo (no support for effect 0x0F)&lt;br /&gt;
}}&lt;br /&gt;
{{FileFormatTool&lt;br /&gt;
| Name = OpenMPT&lt;br /&gt;
| Platform = Any&lt;br /&gt;
| canPlay = Yes&lt;br /&gt;
| canCreate = No&lt;br /&gt;
| canModify = No&lt;br /&gt;
| canExport = Many&lt;br /&gt;
| canImport = No&lt;br /&gt;
| editHidden = No&lt;br /&gt;
| editMetadata = No&lt;br /&gt;
}}&lt;br /&gt;
{{EndFileFormatTools}}&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
&lt;br /&gt;
* The original Digital Sound Interface Kit library is available as &amp;lt;tt&amp;gt;dsik_c.zip&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;dsik_pas.zip&amp;lt;/tt&amp;gt; for the C and Pascal versions respectively, from various FTP sites such as [http://ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/wgt/ lanet.lv]&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
This file format was documented by [[User:Malvineous|Malvineous]] by reading the DSIK sample code, with the pattern data documented from reading the OpenMPT source code.  If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;br /&gt;
&lt;br /&gt;
[[Category:DSIK]]&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=7094</id>
		<title>ProTracker Studio Module</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=7094"/>
		<updated>2017-05-19T11:48:47Z</updated>

		<summary type="html">&lt;p&gt;Saga: Do not call it &amp;quot;old&amp;quot; format when it in fact appears to be newer.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 1-256 (PSM) / 1-32 (PSM16)&lt;br /&gt;
 | NumTracks = unlimited (PSM) / 1 (PSM16)&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Epic Pinball}}&lt;br /&gt;
   {{Game|Extreme Pinball}}&lt;br /&gt;
   {{Game|Jazz Jackrabbit}}&lt;br /&gt;
   {{Game|One Must Fall}}&lt;br /&gt;
   {{Game|Silverball}}&lt;br /&gt;
   {{Game|Sinaria}}&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;ProTracker Studio Module&#039;&#039;&#039; (PSM) file format is used for the music in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]].  The file format is named after ProTracker, an Amiga program, though this program was probably actually not used to write PSM files. One Must Fall&#039;s music was written in Multitracker, and the music for Jazz Jackrabbit, Epic Pinball and Extreme Pinball probably in Scream Tracker.&lt;br /&gt;
&lt;br /&gt;
There are two file types that use the extension .PSM; they are both used by Epic Megagames&#039; MASI sound system, but are used by different versions of the system. The two formats are:&lt;br /&gt;
&lt;br /&gt;
* PSM New Format: Used by Jazz Jackrabbit, Epic Pinball, Extreme Pinball, One Must Fall, Sinaria (in this game with slight differences, see below), newest PSM format&lt;br /&gt;
* PSM 16:         Used by Silverball, an older version of the format which is closer to ScreamTracker-style modules.&lt;br /&gt;
&lt;br /&gt;
The most common of the two PSM formats is the new format, and most programs that try to interpret PSM files will be expecting this. For example, ModPlug Player cannot open Silverball files as these are in the PSM 16 format.&lt;br /&gt;
&lt;br /&gt;
There are actually two slightly different variants of the new formats: A common one used in several games, and one used in the game Sinaria. It is not entirely clear if the format used in Sinaria is newer or older - in some ways, like the effect interpretation, it resembles PSM16 more than the new format, so it could be an earlier version of the new PSM format. But Sinaria was released later than or around the same time as most other games using the new PSM format, so maybe it just took really long to develop. The format not used in Sinaria will be called &amp;quot;regular&amp;quot; in this document.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM New Format =&lt;br /&gt;
&lt;br /&gt;
This format is used by [[:Category:Epic Megagames|Epic]] games in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]]. It is notable for consisting of a number of segments (chunks) and sub segments. It bears the 4-byte signature &#039;PSM &#039; at the file start.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Song segment&lt;br /&gt;
 Samples&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 12 bytes long:&lt;br /&gt;
&lt;br /&gt;
 File header:&lt;br /&gt;
 0   4  ID     &#039;PSM &#039;; indicates file is PSM format&lt;br /&gt;
 4   4  Size   Filesize - 12&lt;br /&gt;
 8   4  ID2    &#039;FILE&#039;; indicates start of file info&lt;br /&gt;
&lt;br /&gt;
After the header, some chunks follow in IFF-style. You should not expect chunks to come up in the same order as they are described here. A good way to handle chunks is to read the 4-Byte ID and the 4-Byte size field first, then evaluate the ID and decide what to do next based on this ID. Note that the size field does not include the ID and itself; it only holds the size of the chunk &#039;&#039;content&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Title segment ==&lt;br /&gt;
&lt;br /&gt;
This segment is optional, and one of the few segments that can be absent when playing PSM files in most programs. (Most programs expect all other segments to exist, even if they are not vital.)&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;TITL&#039;; indicates a title follows&lt;br /&gt;
 4   4  Size   Size of title as dword after this dword&lt;br /&gt;
 8   ?  Title  Song title&lt;br /&gt;
&lt;br /&gt;
== Song info segment ==&lt;br /&gt;
&lt;br /&gt;
This segment seems to indicate the beginning of the song data and is not really relevant when parsing.&lt;br /&gt;
&lt;br /&gt;
 12  4  ID     &#039;SDFT&#039;; indicates start of format info&lt;br /&gt;
 16  4  Size   Size of next header as dword, (8)&lt;br /&gt;
 20  8  Song   &#039;MAINSONG&#039;; indicates song type. No other song types are known.&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
Each pattern is stored in its own PBOD chunk. Note that there are two possible formats for this chunk; one is used in the &amp;quot;regular&amp;quot; format (as used in Epic Pinball, Extreme Pinball, Jazz Jackrabbit, One Must Fall) and the other in the &amp;quot;Sinaria&amp;quot; format (as used in Sinaria)&lt;br /&gt;
&lt;br /&gt;
 Pattern segment:&lt;br /&gt;
 0   4  ID     &#039;PBOD&#039;; indicates a pattern follows (Pattern BODy)&lt;br /&gt;
 4   4  Size   Length of pattern data as dword, after this dword&lt;br /&gt;
 4   4  Size   Same value again.&lt;br /&gt;
&lt;br /&gt;
 Pattern:&lt;br /&gt;
 0 4/8  Number Pattern ID. See note below.&lt;br /&gt;
 4   2  Row n  Number of rows in ALL channels in pattern (64 usually, but can differ.) as word.&lt;br /&gt;
 6   ?  Data   Contains pattern data as a number of rows of interlaced channels (12341234...)&lt;br /&gt;
               &#039;&#039;Usual&#039;&#039; settings is 64 rows of 4 channels. Epic Pinball has shorter patterns for example, but they also include a &amp;quot;break to row&amp;quot; command at the end of the pattern.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; There are two variants of the format. In the &amp;quot;regular&amp;quot; variant, the pattern ID is 4 bytes long and starts with a &#039;P&#039;, followed by an integer number which is the pattern number, padded to 4 bytes with spaces. Caution: This number might or might not be zero-padded; In some files, the ID of the first pattern could be &#039;P0  &#039;, but there are also files where it is &#039;P00 &#039;!. In C/C++, you could use atoi() to parse this value.&lt;br /&gt;
In the format used in the game Sinaria, This field is 8 bytes long instead of 4 bytes, and the first 4 bytes read &amp;quot;PATT&amp;quot;, so the first pattern could be for example &#039;PATT0   &#039;. You may want to deal with this by first reading for bytes, and if they are equal to &amp;quot;PATT&amp;quot;, read four more bytes for the pattern ID.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Pattern row channel entry:&lt;br /&gt;
 ?   1  Flags  Contains four flags that indicate which pattern data follows&lt;br /&gt;
 +1  1  Chan   The channel this data belongs to.&lt;br /&gt;
 +2  1  Note   Present if bit 7 in Flags is set. Pitch, $01 is C-1, etc... The octaves&lt;br /&gt;
               are aligned by 16, i.e. B-1 is $0C but the next note, C-2, is $10.&lt;br /&gt;
 +3  1  Ins    Present if bit 6 in Flags is set. Instrument used, 0-31&lt;br /&gt;
 +4  1  Vol    Present if bit 5 in Flags is set. Volume change to, 0-63 = 0-127; optional&lt;br /&gt;
 +5  1  Effect Present if bit 4 in Flags is set. Effect to use, volume slide, Portamanto...&lt;br /&gt;
 +6  x  Eff Am Present if bit 4 in Flags is set. Parameter of effect, e.g amount of slide&lt;br /&gt;
&lt;br /&gt;
Each row consists of a word giving the size of the row (Including the word) followed by the channel data. A channel is only included if it has data in it, but a totally empty row is still included. So an &#039;empty&#039; row (Where none of the channels have data.) thus consists of just a word of value 2.&lt;br /&gt;
&lt;br /&gt;
Each channel entry consists of between 3-7 bytes. The first byte is a flag that shows what data follows. (The highest four bits indicate whether there are bytes for the following four variables; Note ($80), Instrument ($40), Volume ($20), Effect AND Effect parameter ($10). Thus 5 bytes are represented by a combination of 4 possibilities.) The next byte identifies the channel (Since each channel may or may not be present.) starting at 0 for channel 1. The remaining 5 bytes may or may not be present depending on their flag and contain data for Note, Instrument(Sample) used, Volume change for channel, Effect and Effect parameter.&lt;br /&gt;
&lt;br /&gt;
There are several things to note about this; Effect and Effect magnitude MUST occur together. Sample numbers, like channels are numbered starting at 0, not 1. Magnitudes (For effect AND volume) are from 0-127, not 0-64 as in other formats.&lt;br /&gt;
&lt;br /&gt;
=== Effect conversion ===&lt;br /&gt;
&lt;br /&gt;
Note that this table is guaranteed to be correct; Most effects seem to be converted correctly, though. Note that these values are not correct for the PSM files that can be found in the game Sinaria. Leave out all divisions and it will be correct again.&lt;br /&gt;
&lt;br /&gt;
 PSM Command   Param length  S3M Command&lt;br /&gt;
 &lt;br /&gt;
  Volume commands&lt;br /&gt;
    1           1 Byte        DxF - fine volside up&lt;br /&gt;
    2           1 Byte        Dx0 - volslide up&lt;br /&gt;
    3           1 Byte        DFx - fine volslide down&lt;br /&gt;
    4           1 Byte        D0x - volslide down&lt;br /&gt;
 &lt;br /&gt;
 Portamento commands&lt;br /&gt;
    B           1 Byte        FFx - fine porta up (divide x by 4)&lt;br /&gt;
    C           1 Byte        Fxx - porta up (if x &amp;lt; 4, use FFx, else divide x by 4)&lt;br /&gt;
    D           1 Byte        EFx - fine porta down (divide x by 4)&lt;br /&gt;
    E           1 Byte        Exx - porta down (if x &amp;lt; 4, use EFx, else divide x by 4)&lt;br /&gt;
    F           1 Byte        Gxx - portamento (divide x by 4)&lt;br /&gt;
   10           1 Byte        S1x - glissando control&lt;br /&gt;
   11           1 Byte        Lx0 - tone porta + volslide up&lt;br /&gt;
   12           1 Byte        L0x - tone porta + volslide down&lt;br /&gt;
    &lt;br /&gt;
 Vibrato&lt;br /&gt;
   15           1 Byte        Hxy - vibrato&lt;br /&gt;
   16           1 Byte        S3x - vibrato waveform&lt;br /&gt;
   17           1 Byte        K0x - vibrato + volslide up&lt;br /&gt;
   18           1 Byte        Kx0 - vibrato + volslide down&lt;br /&gt;
   	&lt;br /&gt;
 Tremolo			&lt;br /&gt;
   1F           1 Byte        Rxy - tremolo&lt;br /&gt;
   20           1 Byte        S4x - tremolo waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample commands&lt;br /&gt;
   29           3 Bytes       Oxx - offset (xx corresponds to the 2nd byte)&lt;br /&gt;
   2A           1 Byte        Q0x - retrigger&lt;br /&gt;
   2B           1 Byte        SCx - note cut&lt;br /&gt;
   2C           1 Byte        SDx - note delay&lt;br /&gt;
 &lt;br /&gt;
 Position change&lt;br /&gt;
   33           2 Bytes       Bxx - position jump - ignored by PLAY.EXE&lt;br /&gt;
   34           1 Byte        Cxx - break to row&lt;br /&gt;
                                    PLAY.EXE entirely ignores the parameter (it always breaks to the first&lt;br /&gt;
                                    row), so it is maybe best to do this in your own player as well.&lt;br /&gt;
                                    If the original file was an S3M, the parameter is double-BCD-encoded,&lt;br /&gt;
                                    i.e. on top of the original format&#039;s BCD encoding, the same encoding&lt;br /&gt;
                                    is applied again. to translate into the correct target row in binary,&lt;br /&gt;
                                    apply this twice: param = (param &amp;amp; 0xF0) * 10 + (param &amp;amp; 0x0F)&lt;br /&gt;
                                    For MOD files, the parameter is a normal binary number.&lt;br /&gt;
   35           1 Byte        SBx - pattern loop&lt;br /&gt;
   36           1 Byte        SEx - pattern delay&lt;br /&gt;
  &lt;br /&gt;
 Speed change&lt;br /&gt;
   3D           1 Byte        Axx - set speed&lt;br /&gt;
   3E           1 Byte        Txx - set tempo&lt;br /&gt;
 &lt;br /&gt;
 Misc. commands&lt;br /&gt;
   47           1 Byte        Jxy - arpeggio&lt;br /&gt;
   48           1 Byte        S2x - set finetune&lt;br /&gt;
   49           1 Byte        S8x - set balance&lt;br /&gt;
&lt;br /&gt;
Effect interpretation is slightly different in Sinaria&#039;s format. Slide command parameters are more like in PSM16.&lt;br /&gt;
&lt;br /&gt;
== Song segment ==&lt;br /&gt;
&lt;br /&gt;
This segment contains most of the important data used to play the song. It contains several sub-segments, each of the same format as a normal segment, but contained in the song segment. Note that there might be more than one song segment and thus, more than one order list, default speed, default tempo, etc... For example, in Extreme Pinball, all the different jingles and mission songs are stored as separate SONG chunks. It is up to the developer to find a clever way of managing / playing several sub songs.&lt;br /&gt;
&lt;br /&gt;
 Segment structure:&lt;br /&gt;
 0   4  ID     &#039;SONG&#039; indicates start of song structure&lt;br /&gt;
 4   4  Size   Size of song structure, including all sub-segments&lt;br /&gt;
 8   9  Type   Type of song this is for; This is &#039;MAINSONG &#039; in almost all PSM files. Extreme Pinball has several SONG items with different types!&lt;br /&gt;
 17  1  Comp   Compression, for PSM = 1 (Uncompressed)&lt;br /&gt;
 18  1  Chan   Number of channels, usually, but not always, 4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Date sub-segment ===&lt;br /&gt;
&lt;br /&gt;
This dates the file and is used by some programs. It is usually the first sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DATE&#039; indicates date data&lt;br /&gt;
 4   4  Size   Size of date segment (6)&lt;br /&gt;
 8   6  Date   Date as text, YYMMDD&lt;br /&gt;
&lt;br /&gt;
This can also be used as a way to heuristically detect if the regular or Sinara version of the format is being used. Sinaria&#039;s song dates are: 800211, 940902, 940903, 940906, 940914, 941213&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Order sub-segment ===&lt;br /&gt;
&lt;br /&gt;
The order list describes how patterns are arranged in the song. This allows the same pattern of instruments to be played more than once in a song (e.g. a chorus). without the pattern data having to be duplicated. There should be only one order. In most module formats, the order list only consists of pattern indices, but in the PSM format it resembles a tiny scripting language that can do more than just list patterns. For example, It typically contains chunks that set the tempo of the song and the channel panning. In theory, these chunks can occur between two pattern chunks, changing the tempo or panning of a pattern without having to duplicate the pattern data, but in practice this feature is not used, so it can be ignored when writing a PSM loader.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;OPLH&#039; indicates start of pattern placement order&lt;br /&gt;
 4   4  Size   Size of order segment&lt;br /&gt;
 8   2  Cnt.   Number of following chunks&lt;br /&gt;
&lt;br /&gt;
Now, the following chunks may follow until the end of the &amp;quot;OPLH&amp;quot; chunk is reached. Every chunk is identified by its first byte:&lt;br /&gt;
* $00 (1 Byte): End (Nothing follows)&lt;br /&gt;
* $01 (5/9 Bytes): Order list item follows (e.g. &amp;quot;P0  &amp;quot;, &amp;quot;P12 &amp;quot; in regular format or &amp;quot;PATT0   &amp;quot; in Sinaria format, see above) - join those to get the complete order list.&lt;br /&gt;
* $02: Play Range: N/A&lt;br /&gt;
* $03: Jump Loop: N/A&lt;br /&gt;
* $04 (3 Bytes): This 16-bit value indicates the &amp;quot;restart chunk&amp;quot;. If the end of the subsong is reached, it will jump back to this chunk. In many cases, this would be 4th chunk (not 3rd chunk, as the chunk index is starting at 0!), which is a panning index in most PSMs - So you would just go to the nearest order list item that&#039;s following this chunk. However, this can also point to a valid order list chunk.&lt;br /&gt;
* $05: Channel Flip: N/A&lt;br /&gt;
* $06: Transpose: N/A&lt;br /&gt;
* $07 (2 Bytes): Next byte sets the speed (ticks/row) for this subtune&lt;br /&gt;
* $08 (2 Bytes): Next byte sets the tempo for this subtune&lt;br /&gt;
* $0C (7 Bytes): Sample map table: This chunk is always $0C $00 $FF $00 $00 $01 $00. This seems to be an unfinished feature of the order list scripting language. It appears that this maps e.g. what is &amp;quot;I0&amp;quot; in the file to sample 1. Only the fourth and fifth byte ($00 $00) actually seem to do something: They translate the sample number in the pattern to different instruments in the file.&lt;br /&gt;
* $0D (4 Bytes): Channel panning index. Next byte is channel number (Start at 0), then initial pan ($00 ... $FF) and a byte follow. The byte seems to tell what to do with the previous pan position (0 - use it, 2 - ignore it, make this channel surround, 4 - set to center).&lt;br /&gt;
* $0E (3 Bytes): Channel volume index. Next byte is channel number (Start at 0), then volume ($00 ... $FF). $FF in most cases. Some OMF 2097 tracks use a lower volume.&lt;br /&gt;
&lt;br /&gt;
N/A: This chunk does nothing or freezes MASI. There is no need to implement this.&lt;br /&gt;
&lt;br /&gt;
=== Pattern list ===&lt;br /&gt;
&lt;br /&gt;
This is simply a list of all the patterns used in the file. You do not really need to parse this, it seems to be a purely informational chunk.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;PATT&#039; indicates start of pattern list&lt;br /&gt;
 4   4  Size   Size of pattern list after this&lt;br /&gt;
 8   4  Size   Same as above&lt;br /&gt;
 12  4x Pat    An ordered list &#039;P0  &#039;, &#039;P1  &#039;... for all patterns in the file, each entry 4 bytes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sample list sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Similar to the above, this is a list of all the samples used in the file. It is usually the last sub-segment in the song segment and you do not really need to parse this.&lt;br /&gt;
&lt;br /&gt;
  0  4   ID     &#039;DSAM&#039;; indicates start of sample list, used to say what samples are &#039;full&#039;&lt;br /&gt;
                Any samples not on this list will be ignored, even if they have data&lt;br /&gt;
  4  4   Size   Size of list after this&lt;br /&gt;
  8  4   Size   Same value as above&lt;br /&gt;
  12 15x Entry  Sample entries, one for each sample in the file, each entry 15 bytes&lt;br /&gt;
&lt;br /&gt;
 Sample entry:&lt;br /&gt;
 0   8  Format Sample format, padded with spaces (END, RAG2...) This is important to some programs&lt;br /&gt;
 8   4  ID     &#039;I0  &#039;, &#039;I1  &#039;... the sample ID (&#039;I&#039; means &#039;Instrument&#039;). Again, be sure to accept both &#039;I0  &#039; and &#039;I00 &#039;!&lt;br /&gt;
 12  2  Num    The sample number, 0,1,2... for the sample&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
Samples are the raw sound data that makes up the instruments on the song. The actual format depends on the sample format. Samples have information in their headers which allows data to be played at different pitches (Speeds.) and to loop from and to various points in the data. This is by far the largest part of the file, since the raw data takes up so much space.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DSMP&#039; indicates start of sample&lt;br /&gt;
 4   4  Size   Size of following sample as &#039;DSMP&#039; + dword from end of word&lt;br /&gt;
 8   9  Flags  If highest bit is set, then sample is looped&lt;br /&gt;
 9   8  Songn. Filename of the original module (without extension)&lt;br /&gt;
 17  4  INSx   Last digit of sample (Instrument) number, 0-9; with 31 instruments possible&lt;br /&gt;
               Only last digit is shown. E.g 1st, 11th, 21st and 31st sample is &#039;INS0&#039;&lt;br /&gt;
 21  33 Name   Defines the instrument name or file, usually a .st or line of text&lt;br /&gt;
 54  51 Header Sample parameters (Can also 58 bytes long, padded with nuls)&lt;br /&gt;
               Byte 1-6 are unknown (but apparently always $00 $00 $00 $00 $00 $FF)&lt;br /&gt;
               Bytes 7-8 is instrument number&lt;br /&gt;
               Bytes 9-12 are sample length&lt;br /&gt;
               Bytes 13-16 are loop start&lt;br /&gt;
               Bytes 17-20 are loop end (all $FF means at end of sample)&lt;br /&gt;
               Bytes 21-22 are unknown (second byte could be finetune in Sinaria, but seems to be unused)&lt;br /&gt;
               Byte 23 is default volume&lt;br /&gt;
               Bytes 24-27 are unknwon&lt;br /&gt;
               Bytes 28-31 is frequency (Sample rate). MASI ignores the upper 16 bits, even if they are non-zero.&lt;br /&gt;
               19 $00-bytes follow (padding?)&lt;br /&gt;
 105 ?  Data   Music data in 8-bit mono format&lt;br /&gt;
&lt;br /&gt;
The sample header is slightly different in Sinaria&#039;s format: INSx is 8 bytes long (like the PATT IDs), and the last 21 $00-bytes are just 16 bytes (so that the struct is 96 bytes large in both formats).&lt;br /&gt;
&lt;br /&gt;
The PSM new format, along with the PSM 16 format use delta-encoded samples, something to make the file smaller when zipped. &#039;Deltas&#039;, convert a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. It has the effect that if a single byte in the sample is changed, the entire sample will be degraded. This use of deltas varies slightly from that of the PSM 16. The &#039;start value&#039; of the string is assumed to be $80 (128) and the first byte will thus turn this into the first desired value, the second delta converts the first value to the second, and so on.) All deltas are signed, 1-byte values, but loop (Thus 10 - 20 = -10 can also be considered as 10 + 236 = 246). An example of this is as follows:&lt;br /&gt;
&lt;br /&gt;
 RAW:   (128) 64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: -64  0   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Encryption ==&lt;br /&gt;
&lt;br /&gt;
CONVERT.EXE can produce &amp;quot;encrypted&amp;quot; PSM files with the /K command line switch. The encryption scheme is simple: It adds 1 to the first byte, 2 to the second, 3 to the third, and so until, for the entire file. It does not appear like any game made use of this feature, though.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM 16 =&lt;br /&gt;
&lt;br /&gt;
This is the format used in [[Silverball]], early versions of Epic Pinball and possibly other games. The designation &#039;Protracker Studio 16 format&#039; was given to it by the only reliable source of information on this format, and may not be the official designation.&lt;br /&gt;
&lt;br /&gt;
The format bears many similarities to the S3M format; the file is set out roughly the same, patterns and samples are similar, indeed, near identical and the functionality is similar. It also shows many similarities to the ProTracker MOD format and retains vestiges of Amiga compatibility.&lt;br /&gt;
&lt;br /&gt;
This format can be identified by its signature &#039;PSMþ&#039;, though files may lack this and still function.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Order&lt;br /&gt;
 Pan segment&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Sample data&lt;br /&gt;
 Sample headers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
 0    4  Sig      Signature, &#039;PSMþ&#039;&lt;br /&gt;
 4    59 Title    Song title, padded with nulls. Unlike other formats, this must also be terminated&lt;br /&gt;
                  with a null byte. (It sometimes is not terminated, though.)&lt;br /&gt;
 62   1           This must be $1A to end the song name, like in S3M format.&lt;br /&gt;
 64   1  Type     Song type, First bit: 0 - Module (w/samp.), 1 - Song (w/o samples)&lt;br /&gt;
                  Second bit: 0 - 3 octave Protracker, 1 - 5 octave; remaining bits reserved.&lt;br /&gt;
 65   1  PSM v    PSM format version, $10 for this format (Hence the name PSM 16) = &#039;v1.00&#039;.&lt;br /&gt;
                  Sometimes, this is also $01, but there&#039;s no difference in the format itself.&lt;br /&gt;
 66   1  Patt v   Pattern version, 0 or 1. 0 means the pattern is stored in the module are in the 32&lt;br /&gt;
                  channel file format.  A 1 signifies the patterns as being stored as a 255&lt;br /&gt;
                  channel format. (I have not found any PSM16 modules that have this format.)&lt;br /&gt;
 67   1   Speed   Song speed&lt;br /&gt;
 68   1   BPM     Beats per minute, the default Amiga BPM value. (The only reason that the Amiga BPM&lt;br /&gt;
                  format is still followed here is that it allows more control over the final hz value.)&lt;br /&gt;
                  Range: 32 to 255.&lt;br /&gt;
 69   1   Vol     Master volume of song, 0-255&lt;br /&gt;
 70   2   Len     Song length, 0-255. The number of patterns to play in the song, in total.&lt;br /&gt;
 72   2   Ordlen  The number of orders actually stored at the order offset. It was hoped that the&lt;br /&gt;
                  PSM 16 format would allow multiple orders, so this would be the length of the first&lt;br /&gt;
                  order. This doesn&#039;t appea to ahve happened, and is usually the same as the previous value.&lt;br /&gt;
 74   2   Patnum  Number of patterns in the song. 1-255&lt;br /&gt;
 76   2   Sampnum Number of samples and &#039;sample structures&#039; in song, 1-255&lt;br /&gt;
 78   2   NCIS    Number of channels in song to PLAY. 1-32. &lt;br /&gt;
 80   2   NCP     Number of Channels to Process; describes the MAXIMUM number of channels to process.&lt;br /&gt;
                  As an example, when converting 669 files,  NCP = 9 because some track information &lt;br /&gt;
                  is in Channel 8, but the Number of Channels to Play was set to 8, (Channel numbers&lt;br /&gt;
                  to play from 0 to 7.) 1-32&lt;br /&gt;
 82   4   Ordoff  Location of order in header&lt;br /&gt;
 86   4   Panoff  Location of pan positions in header&lt;br /&gt;
 90   4   Patoff  Location of patterns in header&lt;br /&gt;
 94   4   Sampoff Location of sample headers in header&lt;br /&gt;
 98   4   Commoff Location of comments in header&lt;br /&gt;
 102  4   Patsiz  Total pattern size; the total size of all the patterns loaded from the pattern offset.&lt;br /&gt;
 106  40  Fillers 10 fillers, to be used for any possible expansions.&lt;br /&gt;
&lt;br /&gt;
It is important to notice that the offsets point to the first byte &#039;&#039;&#039;after&#039;&#039;&#039; the chunk ID, i.e. &amp;quot;Ordoff&amp;quot; points to the first byte after &amp;quot;PORD&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Order and Pan positions ==&lt;br /&gt;
&lt;br /&gt;
These are two separate segments, pointed to in the header. They may be anywhere, but usually follow the header sometimes after an amount of blank space. They are often padded with blank space. They are basically lists.&lt;br /&gt;
&lt;br /&gt;
Order: This segment is pointed to in the header, and sets the PSM 16 format apart. The PSM 16 format was designed to be much more like the MOD format, allowing game designers to set flags to switch from one set of patterns to another, in effect allowing one file to contain more than one song. (For example a boss flag might make the music switch from a clam patterns 1-4 to a racy and dangerous patterns 5-7.)&lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    Signature, not needed, &#039;PORD&#039;&lt;br /&gt;
 4    ?   Ords   Pattern numbers and order. There will be [Ordlen] bytes of patterns&lt;br /&gt;
 ?    2   Lang   Order language, not implemented, so left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pan Positions: &lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    &#039;PPAN&#039;&lt;br /&gt;
 4    12  Pan    Pan positions; empty positions left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
 0    2   Size   Size of pattern, including these bytes&lt;br /&gt;
 2    1   Len    Length of pattern, in rows. Max length is 64 rows.&lt;br /&gt;
 3    1   Chan   Number of channels in pattern, 1-32&lt;br /&gt;
 4    ?   Data   Pattern data&lt;br /&gt;
&lt;br /&gt;
This is similar to the previous two segments, except actual pattern data is stored here. Patterns are very similar to the S3M format, and consist of y rows of x channels. Each row contains a number of channels and ends with a byte of value 0. Each channel is between 2-6+ bytes long. A totally empty channel is represented by a single byte of value 0.&lt;br /&gt;
&lt;br /&gt;
Each channel starts with a flag byte, abcddddd, where a,b and c indicate whether there is a note and instrument, volume or special effect and effect magnitude in the following data, and dddd is the channel number (0-31, used since a given channel may or may not be present in a row.)&lt;br /&gt;
&lt;br /&gt;
The usual maximum length of a channel entry is 6 bytes (1 flag byte, 2 Note AND instrument bytes, 1 volume byte and two Effect and Effect magnitude bytes.) Thus Note&amp;amp;ins\Eff&amp;amp;Eff mag must always occur together.&lt;br /&gt;
&lt;br /&gt;
Like S3M, volume range is 0-64, as is special magnitude. However, special effects range from 0-255, like PSM New Format.&lt;br /&gt;
&lt;br /&gt;
=== Effects conversion ===&lt;br /&gt;
&lt;br /&gt;
 ###  Co  MOD  Description               Arguments&lt;br /&gt;
 ---  --  ---  -----------               ---------&lt;br /&gt;
 Volume Commands&lt;br /&gt;
   1  A1   EA  Fine Volume Slide Up      B xx xx=speed&lt;br /&gt;
   2  A2   A   Volume Slide Up           B xx xx=speed&lt;br /&gt;
   3  A3   EB  Fine Volume Slide Down    B xx xx=speed&lt;br /&gt;
   4  A4   A   Volume Slide Down         B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Portamento Commands&lt;br /&gt;
  10  B0   E1  Fine Porta Up             B xx xx=speed&lt;br /&gt;
  11  B1   1   Portamento Up             B xx xx=speed&lt;br /&gt;
  12  B2   E2  Fine Porta Down           B xx xx=speed&lt;br /&gt;
  13  B3   2   Portamento Down           B xx xx=speed&lt;br /&gt;
  14  B4   3   Tone Portamento           B xx xx=speed&lt;br /&gt;
  15  B5   E3  Set Glissando Control     B xx xx=0 - Off, 1 - On&lt;br /&gt;
  16  B6   5   Tone Port+Vol Slide Up    B xx xx=speed&lt;br /&gt;
  17  B7   5   Tone Port+Vol Slide Down  B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Vibrato Commands&lt;br /&gt;
  20  C0   4   Vibrato                   B xy x=speed, y=depth&lt;br /&gt;
  21  C1   E4  Set Vibrato Waveform      B x  x=Waveform&lt;br /&gt;
  21  C2   6   Vibrato+Vol Slide Up      B xx xx=speed&lt;br /&gt;
  22  C3   6   Vibrato+Vol Slide Down    B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Tremolo Commands&lt;br /&gt;
  30  D0   7   Tremolo                   B xy x=speed, y=depth&lt;br /&gt;
  31  D1   E7  Set Tremolo Control       B x  x=Waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample Commands&lt;br /&gt;
  40  E0   9   Sample Offset             3B Position for offset change (0-1,048,575)&lt;br /&gt;
  41  E1   E9  Retrig Note               B xx xx=tick to retrigger sample&lt;br /&gt;
  42  E2   EC  Note Cut                  B xx xx=tick to cut note&lt;br /&gt;
  43  E3   ED  Note Delay                B xx xx=ticks to delay note&lt;br /&gt;
 &lt;br /&gt;
 Pos. Change Commands&lt;br /&gt;
  50  F0   B   Position Jump             B xx xx=order position&lt;br /&gt;
  51  F1   D   Pattern Break             B xx Skip to line xx in next pattern&lt;br /&gt;
  52  F2   E6  Jump Loop                 B xx xx=number of loops  0 Set&lt;br /&gt;
  53  F3   EE  Pattern Delay             B xx xx=notes to delay pattern&lt;br /&gt;
 &lt;br /&gt;
 Speed Change Cmds&lt;br /&gt;
  60  G0   F   Set Regular Speed         B xx xx=speed&lt;br /&gt;
  61  G1   F   Set BPM                   B xx xx=BPM (32-255)&lt;br /&gt;
 &lt;br /&gt;
 Misc. Commands&lt;br /&gt;
  70  H0   0   Arpeggio                  B xy x=semitone #1, y=semitone #2&lt;br /&gt;
  71  H1   E5  Set Finetune              B xx xx=finetune&lt;br /&gt;
  72  H2       Set Balance               B xx xx=Balance (0-15)&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
 Sample segment&lt;br /&gt;
 0    4   ID     &#039;PSAM&#039; (Psm SAMple)&lt;br /&gt;
 4    ?  Data    Sample data&lt;br /&gt;
&lt;br /&gt;
 Sample header segment&lt;br /&gt;
 0    4   ID     &#039;PSAH&#039; (Psm SAmple Header)&lt;br /&gt;
 4    ?  Data    Sample headers&lt;br /&gt;
&lt;br /&gt;
 Sample header&lt;br /&gt;
 0    13  Name   Sample filename, terminated with a null.&lt;br /&gt;
 13   24  Desc   Sample description or comments.&lt;br /&gt;
 37   4   Offs   Location of raw sample data in file&lt;br /&gt;
 43   4   Mem    This is the physical offset in RAM/DRAM of the sample. (Often blank.)&lt;br /&gt;
 45   2   Num    Sample number, 1-255&lt;br /&gt;
 47   1   Type   Sample type: (In some games left blank; if this is the case then the&lt;br /&gt;
                 sample format is END, as used in most PSM New Format files)&lt;br /&gt;
                 Bit 0: 0 - Digital, 1 - Synthesized&lt;br /&gt;
                 Bit 2: 0 - 8-bit, 1 - 16-bit&lt;br /&gt;
                 Bit 3: 0 - Signed, 1 - Unsigned&lt;br /&gt;
                 Bit 4: 0 - Deltas, 1 - Raw&lt;br /&gt;
                 Bit 5: 0 - Loop normally, 1 - Bidirectional&lt;br /&gt;
                 Bit 6: 1 - Gravis patch (unsupported)&lt;br /&gt;
                 Bit 7: 0 - No loop, 1 - Loop sample&lt;br /&gt;
 48   4   Len    Sample length, in bytes.&lt;br /&gt;
 52   4   Rep st Sample repeat start; if sample loops, the loop starts here.&lt;br /&gt;
 56   4   Rep fn Sample repeat end, if sample loops, it ends here. If this is less than the sample&lt;br /&gt;
                 repeat start, the sample loops backwards.&lt;br /&gt;
 60   1   Tune   Fine tune; range 0-15, Tune 0-7 = 0-7; tune -1 - -8 = 8-15&lt;br /&gt;
 61   1   Vol    Sample volume, 0-64&lt;br /&gt;
 62   2   Freq   This is the frequency for the sample at a C of Octave 2.&lt;br /&gt;
                 Typical values are 8,000 hz to 8,448 hz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like in S3M, sample headers are stored separately from the raw sample data.&lt;br /&gt;
&lt;br /&gt;
A type of sample storage used often, like in the PSM New Format is &#039;Deltas&#039;, which converts a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte, often making them compress better using general-purpose file compression tools. Thus:&lt;br /&gt;
&lt;br /&gt;
 RAW:        64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: 11  64   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
This is done to make files more compressible, but doesn&#039;t seem to be used much.&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.shikadi.net/files/psm2scrm.zip psm2scrm.zip] - DOS program to convert .PSM songs into ScreamTracker .S3M format, suitable for playing in your favourite tracker/module player. Works only with PSM New Format and is not nearly as accurate as OpenMPT.&lt;br /&gt;
* [https://openmpt.org OpenMPT] 1.18 and newer can load all PSM and PSM16 files.&lt;br /&gt;
* [https://openmpt.org/legacy_software ModPlug Tracker] and OpenMPT 1.17 can play the files and save them as S3M. More complex songs don&#039;t load correctly though. Works only with new format.&lt;br /&gt;
* [http://kode54.foobar2000.org/ foo_dumb] is a plugin for various module formats for the Foobar2k media player. It supports both PSM16 and PSM and is similar to OpenMPT in playback quality.&lt;br /&gt;
* [http://ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/mxinfo/epictest.zip EPICTEST] is a demonstration of the Epic Megagames MASI. It contains CONVERT.EXE which can be used to convert modules to the new PSM format.&lt;br /&gt;
* [http://www.jazz2online.com/J2Ov2/downloads/info.php?levelID=5471#29435] JJ1MOD can convert S3M files to new PSM, though often with errors (Though these are usually only detectable with older programs such as game executables.) It is currently the only utility able to do this, and works only with New Format.&lt;br /&gt;
&lt;br /&gt;
= Notes =&lt;br /&gt;
&lt;br /&gt;
The New PSM format was reverse engineered by Levellord and tidied up by Levellass. It is possible there may be minor errors in the sample format information, especially since this is poorly documented.&lt;br /&gt;
Some format definitions have been updated and corrected by Johannes Schultz of the OpenMPT development team.&lt;br /&gt;
&lt;br /&gt;
The PSM16 format documentation was found on Wotsit and written up by Levellass (this appears to be an official document from the MASI developer). More info is needed.&lt;br /&gt;
&lt;br /&gt;
In all formats the following table shows how note bytes are converted into actual notes: (PSM new format has the widest range, 0-255)&lt;br /&gt;
&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;br /&gt;
           | C-0   0 | C-1  12 | C-2  24 | C-3  36 | C-4  48 |&lt;br /&gt;
           | C#0   1 | C#1  13 | C#2  25 | C#3  37 | C#4  49 |&lt;br /&gt;
           | D-0   2 | D-1  14 | D-2  26 | D-3  38 | D-4  50 |&lt;br /&gt;
           | D#0   3 | D#1  15 | D#2  27 | D#3  39 | D#4  51 |&lt;br /&gt;
           | E-0   4 | E-1  16 | E-2  28 | E-3  40 | E-4  52 |&lt;br /&gt;
           | F-0   5 | F-1  17 | F-2  29 | F-3  41 | F-4  53 |&lt;br /&gt;
           | F#0   6 | F#1  18 | F#2  30 | F#3  42 | F#4  54 |&lt;br /&gt;
           | G-0   7 | G-1  19 | G-2  31 | G-3  43 | G-4  55 |&lt;br /&gt;
           | G#0   8 | G#1  20 | G#2  32 | G#3  44 | G#4  56 |&lt;br /&gt;
           | A-0   9 | A-1  21 | A-2  33 | A-3  45 | A-4  57 |&lt;br /&gt;
           | A#0  10 | A#1  22 | A#2  34 | A#3  46 | A#4  58 |&lt;br /&gt;
           | B-0  11 | B-1  23 | B-2  35 | B-3  47 | B-4  59 |&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=7012</id>
		<title>ProTracker Studio Module</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=7012"/>
		<updated>2016-12-12T23:48:16Z</updated>

		<summary type="html">&lt;p&gt;Saga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 1-256 (PSM) / 1-32 (PSM16)&lt;br /&gt;
 | NumTracks = unlimited (PSM) / 1 (PSM16)&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Epic Pinball}}&lt;br /&gt;
   {{Game|Extreme Pinball}}&lt;br /&gt;
   {{Game|Jazz Jackrabbit}}&lt;br /&gt;
   {{Game|One Must Fall}}&lt;br /&gt;
   {{Game|Silverball}}&lt;br /&gt;
   {{Game|Sinaria}}&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;ProTracker Studio Module&#039;&#039;&#039; (PSM) file format is used for the music in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]].  The file format is named after ProTracker, an Amiga program, though this program was probably actually not used to write PSM files. One Must Fall&#039;s music was written in Multitracker, and the music for Jazz Jackrabbit, Epic Pinball and Extreme Pinball probably in Scream Tracker.&lt;br /&gt;
&lt;br /&gt;
There are two file types that use the extension .PSM; they are both used by Epic Megagames&#039; MASI sound system, but are used by different versions of the system. The two formats are:&lt;br /&gt;
&lt;br /&gt;
* PSM New Format: Used by Jazz Jackrabbit, Epic Pinball, Extreme Pinball, One Must Fall, Sinaria (in this game with slight differences, see below), newest PSM format&lt;br /&gt;
* PSM 16:         Used by Silverball, an older version of the format which is closer to ScreamTracker-style modules.&lt;br /&gt;
&lt;br /&gt;
The most common of the two PSM formats is the new format, and most programs that try to interpret PSM files will be expecting this. For example, ModPlug Player cannot open Silverball files as these are in the PSM 16 format.&lt;br /&gt;
&lt;br /&gt;
There are actually two slightly different variants of the new formats: A common one used in several games, and one used in the game Sinaria. It is not entirely clear if the format used in Sinaria is newer or older - in some ways, like the effect interpretation, it resembles PSM16 more than the new format, so it could be an earlier version of the new PSM format. But Sinaria was released later than or around the same time as most other games using the new PSM format, so maybe it just took really long to develop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM New Format =&lt;br /&gt;
&lt;br /&gt;
This format is used by [[:Category:Epic Megagames|Epic]] games in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]]. It is notable for consisting of a number of segments (chunks) and sub segments. It bears the 4-byte signature &#039;PSM &#039; at the file start.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Song segment&lt;br /&gt;
 Samples&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 12 bytes long:&lt;br /&gt;
&lt;br /&gt;
 File header:&lt;br /&gt;
 0   4  ID     &#039;PSM &#039;; indicates file is PSM format&lt;br /&gt;
 4   4  Size   Filesize - 12&lt;br /&gt;
 8   4  ID2    &#039;FILE&#039;; indicates start of file info&lt;br /&gt;
&lt;br /&gt;
After the header, some chunks follow in IFF-style. You should not expect chunks to come up in the same order as they are described here. A good way to handle chunks is to read the 4-Byte ID and the 4-Byte size field first, then evaluate the ID and decide what to do next based on this ID. Note that the size field does not include the ID and itself; it only holds the size of the chunk &#039;&#039;content&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Title segment ==&lt;br /&gt;
&lt;br /&gt;
This segment is optional, and one of the few segments that can be absent when playing PSM files in most programs. (Most programs expect all other segments to exist, even if they are not vital.)&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;TITL&#039;; indicates a title follows&lt;br /&gt;
 4   4  Size   Size of title as dword after this dword&lt;br /&gt;
 8   ?  Title  Song title&lt;br /&gt;
&lt;br /&gt;
== Song info segment ==&lt;br /&gt;
&lt;br /&gt;
This segment seems to indicate the beginning of the song data and is not really relevant when parsing.&lt;br /&gt;
&lt;br /&gt;
 12  4  ID     &#039;SDFT&#039;; indicates start of format info&lt;br /&gt;
 16  4  Size   Size of next header as dword, (8)&lt;br /&gt;
 20  8  Song   &#039;MAINSONG&#039;; indicates song type. No other song types are known.&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
Each pattern is stored in its own PBOD chunk. Note that there are two possible formats for this chunk; one is used in the &amp;quot;old&amp;quot; format (as used in Epic Pinball, Extreme Pinball, Jazz Jackrabbit, One Must Fall) and the other in the &amp;quot;new&amp;quot; format (as used in Sinaria)&lt;br /&gt;
&lt;br /&gt;
 Pattern segment:&lt;br /&gt;
 0   4  ID     &#039;PBOD&#039;; indicates a pattern follows (Pattern BODy)&lt;br /&gt;
 4   4  Size   Length of pattern data as dword, after this dword&lt;br /&gt;
 4   4  Size   Same value again.&lt;br /&gt;
&lt;br /&gt;
 Pattern:&lt;br /&gt;
 0 4/8  Number Pattern ID. See note below.&lt;br /&gt;
 4   2  Row n  Number of rows in ALL channels in pattern (64 usually, but can differ.) as word.&lt;br /&gt;
 6   ?  Data   Contains pattern data as a number of rows of interlaced channels (12341234...)&lt;br /&gt;
               &#039;&#039;Usual&#039;&#039; settings is 64 rows of 4 channels. Epic Pinball has shorter patterns for example, but they also include a &amp;quot;break to row&amp;quot; command at the end of the pattern.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; There are two variants of the format. In the most common variant, the pattern ID is 4 bytes long and starts with a &#039;P&#039;, followed by an integer number which is the pattern number, padded to 4 bytes with spaces. Caution: This number might or might not be zero-padded; In some files, the ID of the first pattern could be &#039;P0  &#039;, but there are also files where it is &#039;P00 &#039;!. In C/C++, you could use atoi() to parse this value.&lt;br /&gt;
In the format used in the game Sinaria, This field is 8 bytes long instead of 4 bytes, and the first 4 bytes read &amp;quot;PATT&amp;quot;, so the first pattern could be for example &#039;PATT0   &#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Pattern row channel entry:&lt;br /&gt;
 ?   1  Flags  Contains four flags that indicate which pattern data follows&lt;br /&gt;
 +1  1  Chan   The channel this data belongs to.&lt;br /&gt;
 +2  1  Note   Present if bit 7 in Flags is set. Pitch, $01 is C-1, etc... The octaves&lt;br /&gt;
               are aligned by 16, i.e. B-1 is $0C but the next note, C-2, is $10.&lt;br /&gt;
 +3  1  Ins    Present if bit 6 in Flags is set. Instrument used, 0-31&lt;br /&gt;
 +4  1  Vol    Present if bit 5 in Flags is set. Volume change to, 0-63 = 0-127; optional&lt;br /&gt;
 +5  1  Effect Present if bit 4 in Flags is set. Effect to use, volume slide, Portamanto...&lt;br /&gt;
 +6  x  Eff Am Present if bit 4 in Flags is set. Parameter of effect, e.g amount of slide&lt;br /&gt;
&lt;br /&gt;
Each row consists of a word giving the size of the row (Including the word) followed by the channel data. A channel is only included if it has data in it, but a totally empty row is still included. So an &#039;empty&#039; row (Where none of the channels have data.) thus consists of just a word of value 2.&lt;br /&gt;
&lt;br /&gt;
Each channel entry consists of between 3-7 bytes. The first byte is a flag that shows what data follows. (The highest four bits indicate whether there are bytes for the following four variables; Note ($80), Instrument ($40), Volume ($20), Effect AND Effect parameter ($10). Thus 5 bytes are represented by a combination of 4 possibilities.) The next byte identifies the channel (Since each channel may or may not be present.) starting at 0 for channel 1. The remaining 5 bytes may or may not be present depending on their flag and contain data for Note, Instrument(Sample) used, Volume change for channel, Effect and Effect parameter.&lt;br /&gt;
&lt;br /&gt;
There are several things to note about this; Effect and Effect magnitude MUST occur together. Sample numbers, like channels are numbered starting at 0, not 1. Magnitudes (For effect AND volume) are from 0-127, not 0-64 as in other formats.&lt;br /&gt;
&lt;br /&gt;
=== Effect conversion ===&lt;br /&gt;
&lt;br /&gt;
Note that this table is guaranteed to be correct; Most effects seem to be converted correctly, though. Note that these values are not correct for the PSM files that can be found in the game Sinaria. Leave out all divisions and it will be correct again.&lt;br /&gt;
&lt;br /&gt;
 PSM Command   Param length  S3M Command&lt;br /&gt;
 &lt;br /&gt;
  Volume commands&lt;br /&gt;
    1           1 Byte        DxF - fine volside up&lt;br /&gt;
    2           1 Byte        Dx0 - volslide up&lt;br /&gt;
    3           1 Byte        DFx - fine volslide down&lt;br /&gt;
    4           1 Byte        D0x - volslide down&lt;br /&gt;
 &lt;br /&gt;
 Portamento commands&lt;br /&gt;
    B           1 Byte        FFx - fine porta up (divide x by 4)&lt;br /&gt;
    C           1 Byte        Fxx - porta up (if x &amp;lt; 4, use FFx, else divide x by 4)&lt;br /&gt;
    D           1 Byte        EFx - fine porta down (divide x by 4)&lt;br /&gt;
    E           1 Byte        Exx - porta down (if x &amp;lt; 4, use EFx, else divide x by 4)&lt;br /&gt;
    F           1 Byte        Gxx - portamento (divide x by 4)&lt;br /&gt;
   10           1 Byte        S1x - glissando control&lt;br /&gt;
   11           1 Byte        Lx0 - tone porta + volslide up&lt;br /&gt;
   12           1 Byte        L0x - tone porta + volslide down&lt;br /&gt;
    &lt;br /&gt;
 Vibrato&lt;br /&gt;
   15           1 Byte        Hxy - vibrato&lt;br /&gt;
   16           1 Byte        S3x - vibrato waveform&lt;br /&gt;
   17           1 Byte        K0x - vibrato + volslide up&lt;br /&gt;
   18           1 Byte        Kx0 - vibrato + volslide down&lt;br /&gt;
   	&lt;br /&gt;
 Tremolo			&lt;br /&gt;
   1F           1 Byte        Rxy - tremolo&lt;br /&gt;
   20           1 Byte        S4x - tremolo waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample commands&lt;br /&gt;
   29           3 Bytes       Oxx - offset (xx corresponds to the 2nd byte)&lt;br /&gt;
   2A           1 Byte        Q0x - retrigger&lt;br /&gt;
   2B           1 Byte        SCx - note cut&lt;br /&gt;
   2C           1 Byte        SDx - note delay&lt;br /&gt;
 &lt;br /&gt;
 Position change&lt;br /&gt;
   33           2 Bytes       Bxx - position jump - ignored by PLAY.EXE&lt;br /&gt;
   34           1 Byte        Cxx - break to row&lt;br /&gt;
                                    PLAY.EXE entirely ignores the parameter (it always breaks to the first&lt;br /&gt;
                                    row), so it is maybe best to do this in your own player as well.&lt;br /&gt;
                                    If the original file was an S3M, the parameter is double-BCD-encoded,&lt;br /&gt;
                                    i.e. on top of the original format&#039;s BCD encoding, the same encoding&lt;br /&gt;
                                    is applied again. to translate into the correct target row in binary,&lt;br /&gt;
                                    apply this twice: param = (param &amp;amp; 0xF0) * 10 + (param &amp;amp; 0x0F)&lt;br /&gt;
                                    For MOD files, the parameter is a normal binary number.&lt;br /&gt;
   35           1 Byte        SBx - pattern loop&lt;br /&gt;
   36           1 Byte        SEx - pattern delay&lt;br /&gt;
  &lt;br /&gt;
 Speed change&lt;br /&gt;
   3D           1 Byte        Axx - set speed&lt;br /&gt;
   3E           1 Byte        Txx - set tempo&lt;br /&gt;
 &lt;br /&gt;
 Misc. commands&lt;br /&gt;
   47           1 Byte        Jxy - arpeggio&lt;br /&gt;
   48           1 Byte        S2x - set finetune&lt;br /&gt;
   49           1 Byte        S8x - set balance&lt;br /&gt;
&lt;br /&gt;
Effect interpretation is slightly different in Sinaria&#039;s format. Slide command parameters are more like in PSM16.&lt;br /&gt;
&lt;br /&gt;
== Song segment ==&lt;br /&gt;
&lt;br /&gt;
This segment contains most of the important data used to play the song. It contains several sub-segments, each of the same format as a normal segment, but contained in the song segment. Note that there might be more than one song segment and thus, more than one order list, default speed, default tempo, etc... For example, in Extreme Pinball, all the different jingles and mission songs are stored as separate SONG chunks. It is up to the developer to find a clever way of managing / playing several sub songs.&lt;br /&gt;
&lt;br /&gt;
 Segment structure:&lt;br /&gt;
 0   4  ID     &#039;SONG&#039; indicates start of song structure&lt;br /&gt;
 4   4  Size   Size of song structure, including all sub-segments&lt;br /&gt;
 8   9  Type   Type of song this is for; This is &#039;MAINSONG &#039; in almost all PSM files. Extreme Pinball has several SONG items with different types!&lt;br /&gt;
 17  1  Comp   Compression, for PSM = 1 (Uncompressed)&lt;br /&gt;
 18  1  Chan   Number of channels, usually, but not always, 4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Date sub-segment ===&lt;br /&gt;
&lt;br /&gt;
This dates the file and is used by some programs. It is usually the first sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DATE&#039; indicates date data&lt;br /&gt;
 4   4  Size   Size of date segment (6)&lt;br /&gt;
 8   6  Date   Date as text, YYMMDD&lt;br /&gt;
&lt;br /&gt;
This can also be used as a way to heuristically detect if the new version of the format is being used. Sinaria&#039;s song dates are: 800211, 940902, 940903, 940906, 940914, 941213&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Order sub-segment ===&lt;br /&gt;
&lt;br /&gt;
The order list describes how patterns are arranged in the song. This allows the same pattern of instruments to be played more than once in a song (e.g. a chorus). without the pattern data having to be duplicated. There should be only one order. In most module formats, the order list only consists of pattern indices, but in the PSM format it resembles a tiny scripting language that can do more than just list patterns. For example, It typically contains chunks that set the tempo of the song and the channel panning. In theory, these chunks can occur between two pattern chunks, changing the tempo or panning of a pattern without having to duplicate the pattern data, but in practice this feature is not used, so it can be ignored when writing a PSM loader.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;OPLH&#039; indicates start of pattern placement order&lt;br /&gt;
 4   4  Size   Size of order segment&lt;br /&gt;
 8   2  Cnt.   Number of following chunks&lt;br /&gt;
&lt;br /&gt;
Now, the following chunks may follow until the end of the &amp;quot;OPLH&amp;quot; chunk is reached. Every chunk is identified by its first byte:&lt;br /&gt;
* $00 (1 Byte): End (Nothing follows)&lt;br /&gt;
* $01 (5/9 Bytes): Order list item follows (e.g. &amp;quot;P0  &amp;quot;, &amp;quot;P12 &amp;quot; in old format or &amp;quot;PATT0   &amp;quot; in Sinaria format, see above) - join those to get the complete order list.&lt;br /&gt;
* $02: Play Range: N/A&lt;br /&gt;
* $03: Jump Loop: N/A&lt;br /&gt;
* $04 (3 Bytes): This 16-bit value indicates the &amp;quot;restart chunk&amp;quot;. If the end of the subsong is reached, it will jump back to this chunk. In many cases, this would be 4th chunk (not 3rd chunk, as the chunk index is starting at 0!), which is a panning index in most PSMs - So you would just go to the nearest order list item that&#039;s following this chunk. However, this can also point to a valid order list chunk.&lt;br /&gt;
* $05: Channel Flip: N/A&lt;br /&gt;
* $06: Transpose: N/A&lt;br /&gt;
* $07 (2 Bytes): Next byte sets the speed (ticks/row) for this subtune&lt;br /&gt;
* $08 (2 Bytes): Next byte sets the tempo for this subtune&lt;br /&gt;
* $0C (7 Bytes): Sample map table: This chunk is always $0C $00 $FF $00 $00 $01 $00. This seems to be an unfinished feature of the order list scripting language. It appears that this maps e.g. what is &amp;quot;I0&amp;quot; in the file to sample 1. Only the fourth and fifth byte ($00 $00) actually seem to do something: They translate the sample number in the pattern to different instruments in the file.&lt;br /&gt;
* $0D (4 Bytes): Channel panning index. Next byte is channel number (Start at 0), then initial pan ($00 ... $FF) and a byte follow. The byte seems to tell what to do with the previous pan position (0 - use it, 2 - ignore it, make this channel surround, 4 - set to center).&lt;br /&gt;
* $0E (3 Bytes): Channel volume index. Next byte is channel number (Start at 0), then volume ($00 ... $FF). $FF in most cases. Some OMF 2097 tracks use a lower volume.&lt;br /&gt;
&lt;br /&gt;
N/A: This chunk does nothing or freezes MASI. There is no need to implement this.&lt;br /&gt;
&lt;br /&gt;
=== Pattern list ===&lt;br /&gt;
&lt;br /&gt;
This is simply a list of all the patterns used in the file. You do not really need to parse this, it seems to be a purely informational chunk.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;PATT&#039; indicates start of pattern list&lt;br /&gt;
 4   4  Size   Size of pattern list after this&lt;br /&gt;
 8   4  Size   Same as above&lt;br /&gt;
 12  4x Pat    An ordered list &#039;P0  &#039;, &#039;P1  &#039;... for all patterns in the file, each entry 4 bytes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sample list sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Similar to the above, this is a list of all the samples used in the file. It is usually the last sub-segment in the song segment and you do not really need to parse this.&lt;br /&gt;
&lt;br /&gt;
  0  4   ID     &#039;DSAM&#039;; indicates start of sample list, used to say what samples are &#039;full&#039;&lt;br /&gt;
                Any samples not on this list will be ignored, even if they have data&lt;br /&gt;
  4  4   Size   Size of list after this&lt;br /&gt;
  8  4   Size   Same value as above&lt;br /&gt;
  12 15x Entry  Sample entries, one for each sample in the file, each entry 15 bytes&lt;br /&gt;
&lt;br /&gt;
 Sample entry:&lt;br /&gt;
 0   8  Format Sample format, padded with spaces (END, RAG2...) This is important to some programs&lt;br /&gt;
 8   4  ID     &#039;I0  &#039;, &#039;I1  &#039;... the sample ID (&#039;I&#039; means &#039;Instrument&#039;). Again, be sure to accept both &#039;I0  &#039; and &#039;I00 &#039;!&lt;br /&gt;
 12  2  Num    The sample number, 0,1,2... for the sample&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
Samples are the raw sound data that makes up the instruments on the song. The actual format depends on the sample format. Samples have information in their headers which allows data to be played at different pitches (Speeds.) and to loop from and to various points in the data. This is by far the largest part of the file, since the raw data takes up so much space.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DSMP&#039; indicates start of sample&lt;br /&gt;
 4   4  Size   Size of following sample as &#039;DSMP&#039; + dword from end of word&lt;br /&gt;
 8   9  Flags  If highest bit is set, then sample is looped&lt;br /&gt;
 9   8  Songn. Filename of the original module (without extension)&lt;br /&gt;
 17  4  INSx   Last digit of sample (Instrument) number, 0-9; with 31 instruments possible&lt;br /&gt;
               Only last digit is shown. E.g 1st, 11th, 21st and 31st sample is &#039;INS0&#039;&lt;br /&gt;
 21  33 Name   Defines the instrument name or file, usually a .st or line of text&lt;br /&gt;
 54  51 Header Sample parameters (Can also 58 bytes long, padded with nuls)&lt;br /&gt;
               Byte 1-6 are unknown (but apparently always $00 $00 $00 $00 $00 $FF)&lt;br /&gt;
               Bytes 7-8 is instrument number&lt;br /&gt;
               Bytes 9-12 are sample length&lt;br /&gt;
               Bytes 13-16 are loop start&lt;br /&gt;
               Bytes 17-20 are loop end (all $FF means at end of sample)&lt;br /&gt;
               Bytes 21-22 are unknown (second byte could be finetune in Sinaria, but seems to be unused)&lt;br /&gt;
               Byte 23 is default volume&lt;br /&gt;
               Bytes 24-27 are unknwon&lt;br /&gt;
               Bytes 28-31 is frequency (Sample rate). MASI ignores the upper 16 bits, even if they are non-zero.&lt;br /&gt;
               19 $00-bytes follow (padding?)&lt;br /&gt;
 105 ?  Data   Music data in 8-bit mono format&lt;br /&gt;
&lt;br /&gt;
The sample header is slightly different in Sinaria&#039;s format: INSx is 8 bytes long (like the PATT IDs), and the last 21 $00-bytes are just 16 bytes (so that the struct is 96 bytes large in both formats).&lt;br /&gt;
&lt;br /&gt;
The PSM new format, along with the PSM 16 format use delta-encoded samples, something to make the file smaller when zipped. &#039;Deltas&#039;, convert a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. It has the effect that if a single byte in the sample is changed, the entire sample will be degraded. This use of deltas varies slightly from that of the PSM 16. The &#039;start value&#039; of the string is assumed to be $80 (128) and the first byte will thus turn this into the first desired value, the second delta converts the first value to the second, and so on.) All deltas are signed, 1-byte values, but loop (Thus 10 - 20 = -10 can also be considered as 10 + 236 = 246). An example of this is as follows:&lt;br /&gt;
&lt;br /&gt;
 RAW:   (128) 64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: -64  0   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Encryption ==&lt;br /&gt;
&lt;br /&gt;
CONVERT.EXE can produce &amp;quot;encrypted&amp;quot; PSM files with the /K command line switch. The encryption scheme is simple: It adds 1 to the first byte, 2 to the second, 3 to the third, and so until, for the entire file. It does not appear like any game made use of this feature, though.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM 16 =&lt;br /&gt;
&lt;br /&gt;
This is the format used in [[Silverball]], early versions of Epic Pinball and possibly other games. The designation &#039;Protracker Studio 16 format&#039; was given to it by the only reliable source of information on this format, and may not be the official designation.&lt;br /&gt;
&lt;br /&gt;
The format bears many similarities to the S3M format; the file is set out roughly the same, patterns and samples are similar, indeed, near identical and the functionality is similar. It also shows many similarities to the ProTracker MOD format and retains vestiges of Amiga compatibility.&lt;br /&gt;
&lt;br /&gt;
This format can be identified by its signature &#039;PSMþ&#039;, though files may lack this and still function.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Order&lt;br /&gt;
 Pan segment&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Sample data&lt;br /&gt;
 Sample headers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
 0    4  Sig      Signature, &#039;PSMþ&#039;&lt;br /&gt;
 4    59 Title    Song title, padded with nulls. Unlike other formats, this must also be terminated&lt;br /&gt;
                  with a null byte. (It sometimes is not terminated, though.)&lt;br /&gt;
 62   1           This must be $1A to end the song name, like in S3M format.&lt;br /&gt;
 64   1  Type     Song type, First bit: 0 - Module (w/samp.), 1 - Song (w/o samples)&lt;br /&gt;
                  Second bit: 0 - 3 octave Protracker, 1 - 5 octave; remaining bits reserved.&lt;br /&gt;
 65   1  PSM v    PSM format version, $10 for this format (Hence the name PSM 16) = &#039;v1.00&#039;.&lt;br /&gt;
                  Sometimes, this is also $01, but there&#039;s no difference in the format itself.&lt;br /&gt;
 66   1  Patt v   Pattern version, 0 or 1. 0 means the pattern is stored in the module are in the 32&lt;br /&gt;
                  channel file format.  A 1 signifies the patterns as being stored as a 255&lt;br /&gt;
                  channel format. (I have not found any PSM16 modules that have this format.)&lt;br /&gt;
 67   1   Speed   Song speed&lt;br /&gt;
 68   1   BPM     Beats per minute, the default Amiga BPM value. (The only reason that the Amiga BPM&lt;br /&gt;
                  format is still followed here is that it allows more control over the final hz value.)&lt;br /&gt;
                  Range: 32 to 255.&lt;br /&gt;
 69   1   Vol     Master volume of song, 0-255&lt;br /&gt;
 70   2   Len     Song length, 0-255. The number of patterns to play in the song, in total.&lt;br /&gt;
 72   2   Ordlen  The number of orders actually stored at the order offset. It was hoped that the&lt;br /&gt;
                  PSM 16 format would allow multiple orders, so this would be the length of the first&lt;br /&gt;
                  order. This doesn&#039;t appea to ahve happened, and is usually the same as the previous value.&lt;br /&gt;
 74   2   Patnum  Number of patterns in the song. 1-255&lt;br /&gt;
 76   2   Sampnum Number of samples and &#039;sample structures&#039; in song, 1-255&lt;br /&gt;
 78   2   NCIS    Number of channels in song to PLAY. 1-32. &lt;br /&gt;
 80   2   NCP     Number of Channels to Process; describes the MAXIMUM number of channels to process.&lt;br /&gt;
                  As an example, when converting 669 files,  NCP = 9 because some track information &lt;br /&gt;
                  is in Channel 8, but the Number of Channels to Play was set to 8, (Channel numbers&lt;br /&gt;
                  to play from 0 to 7.) 1-32&lt;br /&gt;
 82   4   Ordoff  Location of order in header&lt;br /&gt;
 86   4   Panoff  Location of pan positions in header&lt;br /&gt;
 90   4   Patoff  Location of patterns in header&lt;br /&gt;
 94   4   Sampoff Location of sample headers in header&lt;br /&gt;
 98   4   Commoff Location of comments in header&lt;br /&gt;
 102  4   Patsiz  Total pattern size; the total size of all the patterns loaded from the pattern offset.&lt;br /&gt;
 106  40  Fillers 10 fillers, to be used for any possible expansions.&lt;br /&gt;
&lt;br /&gt;
It is important to notice that the offsets point to the first byte &#039;&#039;&#039;after&#039;&#039;&#039; the chunk ID, i.e. &amp;quot;Ordoff&amp;quot; points to the first byte after &amp;quot;PORD&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Order and Pan positions ==&lt;br /&gt;
&lt;br /&gt;
These are two separate segments, pointed to in the header. They may be anywhere, but usually follow the header sometimes after an amount of blank space. They are often padded with blank space. They are basically lists.&lt;br /&gt;
&lt;br /&gt;
Order: This segment is pointed to in the header, and sets the PSM 16 format apart. The PSM 16 format was designed to be much more like the MOD format, allowing game designers to set flags to switch from one set of patterns to another, in effect allowing one file to contain more than one song. (For example a boss flag might make the music switch from a clam patterns 1-4 to a racy and dangerous patterns 5-7.)&lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    Signature, not needed, &#039;PORD&#039;&lt;br /&gt;
 4    ?   Ords   Pattern numbers and order. There will be [Ordlen] bytes of patterns&lt;br /&gt;
 ?    2   Lang   Order language, not implemented, so left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pan Positions: &lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    &#039;PPAN&#039;&lt;br /&gt;
 4    12  Pan    Pan positions; empty positions left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
 0    2   Size   Size of pattern, including these bytes&lt;br /&gt;
 2    1   Len    Length of pattern, in rows. Max length is 64 rows.&lt;br /&gt;
 3    1   Chan   Number of channels in pattern, 1-32&lt;br /&gt;
 4    ?   Data   Pattern data&lt;br /&gt;
&lt;br /&gt;
This is similar to the previous two segments, except actual pattern data is stored here. Patterns are very similar to the S3M format, and consist of y rows of x channels. Each row contains a number of channels and ends with a byte of value 0. Each channel is between 2-6+ bytes long. A totally empty channel is represented by a single byte of value 0.&lt;br /&gt;
&lt;br /&gt;
Each channel starts with a flag byte, abcddddd, where a,b and c indicate whether there is a note and instrument, volume or special effect and effect magnitude in the following data, and dddd is the channel number (0-31, used since a given channel may or may not be present in a row.)&lt;br /&gt;
&lt;br /&gt;
The usual maximum length of a channel entry is 6 bytes (1 flag byte, 2 Note AND instrument bytes, 1 volume byte and two Effect and Effect magnitude bytes.) Thus Note&amp;amp;ins\Eff&amp;amp;Eff mag must always occur together.&lt;br /&gt;
&lt;br /&gt;
Like S3M, volume range is 0-64, as is special magnitude. However, special effects range from 0-255, like PSM New Format.&lt;br /&gt;
&lt;br /&gt;
=== Effects conversion ===&lt;br /&gt;
&lt;br /&gt;
 ###  Co  MOD  Description               Arguments&lt;br /&gt;
 ---  --  ---  -----------               ---------&lt;br /&gt;
 Volume Commands&lt;br /&gt;
   1  A1   EA  Fine Volume Slide Up      B xx xx=speed&lt;br /&gt;
   2  A2   A   Volume Slide Up           B xx xx=speed&lt;br /&gt;
   3  A3   EB  Fine Volume Slide Down    B xx xx=speed&lt;br /&gt;
   4  A4   A   Volume Slide Down         B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Portamento Commands&lt;br /&gt;
  10  B0   E1  Fine Porta Up             B xx xx=speed&lt;br /&gt;
  11  B1   1   Portamento Up             B xx xx=speed&lt;br /&gt;
  12  B2   E2  Fine Porta Down           B xx xx=speed&lt;br /&gt;
  13  B3   2   Portamento Down           B xx xx=speed&lt;br /&gt;
  14  B4   3   Tone Portamento           B xx xx=speed&lt;br /&gt;
  15  B5   E3  Set Glissando Control     B xx xx=0 - Off, 1 - On&lt;br /&gt;
  16  B6   5   Tone Port+Vol Slide Up    B xx xx=speed&lt;br /&gt;
  17  B7   5   Tone Port+Vol Slide Down  B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Vibrato Commands&lt;br /&gt;
  20  C0   4   Vibrato                   B xy x=speed, y=depth&lt;br /&gt;
  21  C1   E4  Set Vibrato Waveform      B x  x=Waveform&lt;br /&gt;
  21  C2   6   Vibrato+Vol Slide Up      B xx xx=speed&lt;br /&gt;
  22  C3   6   Vibrato+Vol Slide Down    B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Tremolo Commands&lt;br /&gt;
  30  D0   7   Tremolo                   B xy x=speed, y=depth&lt;br /&gt;
  31  D1   E7  Set Tremolo Control       B x  x=Waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample Commands&lt;br /&gt;
  40  E0   9   Sample Offset             3B Position for offset change (0-1,048,575)&lt;br /&gt;
  41  E1   E9  Retrig Note               B xx xx=tick to retrigger sample&lt;br /&gt;
  42  E2   EC  Note Cut                  B xx xx=tick to cut note&lt;br /&gt;
  43  E3   ED  Note Delay                B xx xx=ticks to delay note&lt;br /&gt;
 &lt;br /&gt;
 Pos. Change Commands&lt;br /&gt;
  50  F0   B   Position Jump             B xx xx=order position&lt;br /&gt;
  51  F1   D   Pattern Break             B xx Skip to line xx in next pattern&lt;br /&gt;
  52  F2   E6  Jump Loop                 B xx xx=number of loops  0 Set&lt;br /&gt;
  53  F3   EE  Pattern Delay             B xx xx=notes to delay pattern&lt;br /&gt;
 &lt;br /&gt;
 Speed Change Cmds&lt;br /&gt;
  60  G0   F   Set Regular Speed         B xx xx=speed&lt;br /&gt;
  61  G1   F   Set BPM                   B xx xx=BPM (32-255)&lt;br /&gt;
 &lt;br /&gt;
 Misc. Commands&lt;br /&gt;
  70  H0   0   Arpeggio                  B xy x=semitone #1, y=semitone #2&lt;br /&gt;
  71  H1   E5  Set Finetune              B xx xx=finetune&lt;br /&gt;
  72  H2       Set Balance               B xx xx=Balance (0-15)&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
 Sample segment&lt;br /&gt;
 0    4   ID     &#039;PSAM&#039; (Psm SAMple)&lt;br /&gt;
 4    ?  Data    Sample data&lt;br /&gt;
&lt;br /&gt;
 Sample header segment&lt;br /&gt;
 0    4   ID     &#039;PSAH&#039; (Psm SAmple Header)&lt;br /&gt;
 4    ?  Data    Sample headers&lt;br /&gt;
&lt;br /&gt;
 Sample header&lt;br /&gt;
 0    13  Name   Sample filename, terminated with a null.&lt;br /&gt;
 13   24  Desc   Sample description or comments.&lt;br /&gt;
 37   4   Offs   Location of raw sample data in file&lt;br /&gt;
 43   4   Mem    This is the physical offset in RAM/DRAM of the sample. (Often blank.)&lt;br /&gt;
 45   2   Num    Sample number, 1-255&lt;br /&gt;
 47   1   Type   Sample type: (In some games left blank; if this is the case then the&lt;br /&gt;
                 sample format is END, as used in most PSM New Format files)&lt;br /&gt;
                 Bit 0: 0 - Digital, 1 - Synthesized&lt;br /&gt;
                 Bit 2: 0 - 8-bit, 1 - 16-bit&lt;br /&gt;
                 Bit 3: 0 - Signed, 1 - Unsigned&lt;br /&gt;
                 Bit 4: 0 - Deltas, 1 - Raw&lt;br /&gt;
                 Bit 5: 0 - Loop normally, 1 - Bidirectional&lt;br /&gt;
                 Bit 6: 1 - Gravis patch (unsupported)&lt;br /&gt;
                 Bit 7: 0 - No loop, 1 - Loop sample&lt;br /&gt;
 48   4   Len    Sample length, in bytes.&lt;br /&gt;
 52   4   Rep st Sample repeat start; if sample loops, the loop starts here.&lt;br /&gt;
 56   4   Rep fn Sample repeat end, if sample loops, it ends here. If this is less than the sample&lt;br /&gt;
                 repeat start, the sample loops backwards.&lt;br /&gt;
 60   1   Tune   Fine tune; range 0-15, Tune 0-7 = 0-7; tune -1 - -8 = 8-15&lt;br /&gt;
 61   1   Vol    Sample volume, 0-64&lt;br /&gt;
 62   2   Freq   This is the frequency for the sample at a C of Octave 2.&lt;br /&gt;
                 Typical values are 8,000 hz to 8,448 hz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like in S3M, sample headers are stored separately from the raw sample data.&lt;br /&gt;
&lt;br /&gt;
A type of sample storage used often, like in the PSM New Format is &#039;Deltas&#039;, which converts a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte, often making them compress better using general-purpose file compression tools. Thus:&lt;br /&gt;
&lt;br /&gt;
 RAW:        64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: 11  64   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
This is done to make files more compressible, but doesn&#039;t seem to be used much.&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.shikadi.net/files/psm2scrm.zip psm2scrm.zip] - DOS program to convert .PSM songs into ScreamTracker .S3M format, suitable for playing in your favourite tracker/module player. Works only with PSM New Format and is not nearly as accurate as OpenMPT.&lt;br /&gt;
* [http://openmpt.org OpenMPT] 1.18 and newer can load all PSM and PSM16 files.&lt;br /&gt;
* [http://openmpt.org/legacy_software ModPlug Tracker] and OpenMPT 1.17 can play the files and save them as S3M. More complex songs don&#039;t load correctly though. Works only with new format.&lt;br /&gt;
* [http://kode54.foobar2000.org/ foo_dumb] is a plugin for various module formats for the Foobar2k media player. It supports both PSM16 and PSM and is similar to OpenMPT in playback quality.&lt;br /&gt;
* [http://ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/mxinfo/epictest.zip EPICTEST] is a demonstration of the Epic Megagames MASI. It contains CONVERT.EXE which can be used to convert modules to the new PSM format.&lt;br /&gt;
* [http://www.jazz2online.com/J2Ov2/downloads/info.php?levelID=5471#29435] JJ1MOD can convert S3M files to new PSM, though often with errors (Though these are usually only detectable with older programs such as game executables.) It is currently the only utility able to do this, and works only with New Format.&lt;br /&gt;
&lt;br /&gt;
= Notes =&lt;br /&gt;
&lt;br /&gt;
The New PSM format was reverse engineered by Levellord and tidied up by Levellass. It is possible there may be minor errors in the sample format information, especially since this is poorly documented.&lt;br /&gt;
Some format definitions have been updated and corrected by Johannes Schultz of the OpenMPT development team.&lt;br /&gt;
&lt;br /&gt;
The PSM16 format documentation was found on Wotsit and written up by Levellass (this appears to be an official document from the MASI developer). More info is needed.&lt;br /&gt;
&lt;br /&gt;
In all formats the following table shows how note bytes are converted into actual notes: (PSM new format has the widest range, 0-255)&lt;br /&gt;
&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;br /&gt;
           | C-0   0 | C-1  12 | C-2  24 | C-3  36 | C-4  48 |&lt;br /&gt;
           | C#0   1 | C#1  13 | C#2  25 | C#3  37 | C#4  49 |&lt;br /&gt;
           | D-0   2 | D-1  14 | D-2  26 | D-3  38 | D-4  50 |&lt;br /&gt;
           | D#0   3 | D#1  15 | D#2  27 | D#3  39 | D#4  51 |&lt;br /&gt;
           | E-0   4 | E-1  16 | E-2  28 | E-3  40 | E-4  52 |&lt;br /&gt;
           | F-0   5 | F-1  17 | F-2  29 | F-3  41 | F-4  53 |&lt;br /&gt;
           | F#0   6 | F#1  18 | F#2  30 | F#3  42 | F#4  54 |&lt;br /&gt;
           | G-0   7 | G-1  19 | G-2  31 | G-3  43 | G-4  55 |&lt;br /&gt;
           | G#0   8 | G#1  20 | G#2  32 | G#3  44 | G#4  56 |&lt;br /&gt;
           | A-0   9 | A-1  21 | A-2  33 | A-3  45 | A-4  57 |&lt;br /&gt;
           | A#0  10 | A#1  22 | A#2  34 | A#3  46 | A#4  58 |&lt;br /&gt;
           | B-0  11 | B-1  23 | B-2  35 | B-3  47 | B-4  59 |&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=6939</id>
		<title>ProTracker Studio Module</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=6939"/>
		<updated>2016-08-03T01:53:10Z</updated>

		<summary type="html">&lt;p&gt;Saga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 1-256 (PSM) / 1-32 (PSM16)&lt;br /&gt;
 | NumTracks = unlimited (PSM) / 1 (PSM16)&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Epic Pinball}}&lt;br /&gt;
   {{Game|Extreme Pinball}}&lt;br /&gt;
   {{Game|Jazz Jackrabbit}}&lt;br /&gt;
   {{Game|One Must Fall}}&lt;br /&gt;
   {{Game|Silverball}}&lt;br /&gt;
   {{Game|Sinaria}}&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;ProTracker Studio Module&#039;&#039;&#039; (PSM) file format is used for the music in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]].  The file format is named after ProTracker, an Amiga program, though this program was probably actually not used to write PSM files. One Must Fall&#039;s music was written in Multitracker, and the music for Jazz Jackrabbit, Epic Pinball and Extreme Pinball probably in Scream Tracker.&lt;br /&gt;
&lt;br /&gt;
There are two file types that use the extension .PSM; they are both used by Epic Megagames&#039; MASI sound system, but are used by different versions of the system. The two formats are:&lt;br /&gt;
&lt;br /&gt;
* PSM New Format: Used by Jazz Jackrabbit, Epic Pinball, Extreme Pinball, One Must Fall, Sinaria (in this game with slight differences, see below), newest PSM format&lt;br /&gt;
* PSM 16:         Used by Silverball, an older version of the format which is closer to ScreamTracker-style modules.&lt;br /&gt;
&lt;br /&gt;
The most common of the two PSM formats is the new format, and most programs that try to interpret PSM files will be expecting this. For example, ModPlug Player cannot open Silverball files as these are in the PSM 16 format.&lt;br /&gt;
&lt;br /&gt;
There are actually two slightly different variants of the new formats: A common one used in several games, and one used in the game Sinaria. It is not entirely clear if the format used in Sinaria is newer or older - in some ways, like the effect interpretation, it resembles PSM16 more than the new format, so it could be an earlier version of the new PSM format. But Sinaria was released later than or around the same time as most other games using the new PSM format, so maybe it just took really long to develop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM New Format =&lt;br /&gt;
&lt;br /&gt;
This format is used by [[:Category:Epic Megagames|Epic]] games in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]]. It is notable for consisting of a number of segments (chunks) and sub segments. It bears the 4-byte signature &#039;PSM &#039; at the file start.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Song segment&lt;br /&gt;
 Samples&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 12 bytes long:&lt;br /&gt;
&lt;br /&gt;
 File header:&lt;br /&gt;
 0   4  ID     &#039;PSM &#039;; indicates file is PSM format&lt;br /&gt;
 4   4  Size   Filesize - 12&lt;br /&gt;
 8   4  ID2    &#039;FILE&#039;; indicates start of file info&lt;br /&gt;
&lt;br /&gt;
After the header, some chunks follow in IFF-style. You should not expect chunks to come up in the same order as they are described here. A good way to handle chunks is to read the 4-Byte ID and the 4-Byte size field first, then evaluate the ID and decide what to do next based on this ID. Note that the size field does not include the ID and itself; it only holds the size of the chunk &#039;&#039;content&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Title segment ==&lt;br /&gt;
&lt;br /&gt;
This segment is optional, and one of the few segments that can be absent when playing PSM files in most programs. (Most programs expect all other segments to exist, even if they are not vital.)&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;TITL&#039;; indicates a title follows&lt;br /&gt;
 4   4  Size   Size of title as dword after this dword&lt;br /&gt;
 8   ?  Title  Song title&lt;br /&gt;
&lt;br /&gt;
== Song info segment ==&lt;br /&gt;
&lt;br /&gt;
This segment seems to indicate the beginning of the song data and is not really relevant when parsing.&lt;br /&gt;
&lt;br /&gt;
 12  4  ID     &#039;SDFT&#039;; indicates start of format info&lt;br /&gt;
 16  4  Size   Size of next header as dword, (8)&lt;br /&gt;
 20  8  Song   &#039;MAINSONG&#039;; indicates song type. No other song types are known.&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
Each pattern is stored in its own PBOD chunk. Note that there are two possible formats for this chunk; one is used in the &amp;quot;old&amp;quot; format (as used in Epic Pinball, Extreme Pinball, Jazz Jackrabbit, One Must Fall) and the other in the &amp;quot;new&amp;quot; format (as used in Sinaria)&lt;br /&gt;
&lt;br /&gt;
 Pattern segment:&lt;br /&gt;
 0   4  ID     &#039;PBOD&#039;; indicates a pattern follows (Pattern BODy)&lt;br /&gt;
 4   4  Size   Length of pattern data as dword, after this dword&lt;br /&gt;
 4   4  Size   Same value again.&lt;br /&gt;
&lt;br /&gt;
 Pattern:&lt;br /&gt;
 0 4/8  Number Pattern ID. See note below.&lt;br /&gt;
 4   2  Row n  Number of rows in ALL channels in pattern (64 usually, but can differ.) as word.&lt;br /&gt;
 6   ?  Data   Contains pattern data as a number of rows of interlaced channels (12341234...)&lt;br /&gt;
               &#039;&#039;Usual&#039;&#039; settings is 64 rows of 4 channels. Epic Pinball has shorter patterns for example, but they also include a &amp;quot;break to row&amp;quot; command at the end of the pattern.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; There are two variants of the format. In the most common variant, the pattern ID is 4 bytes long and starts with a &#039;P&#039;, followed by an integer number which is the pattern number, padded to 4 bytes with spaces. Caution: This number might or might not be zero-padded; In some files, the ID of the first pattern could be &#039;P0  &#039;, but there are also files where it is &#039;P00 &#039;!. In C/C++, you could use atoi() to parse this value.&lt;br /&gt;
In the format used in the game Sinaria, This field is 8 bytes long instead of 4 bytes, and the first 4 bytes read &amp;quot;PATT&amp;quot;, so the first pattern could be for example &#039;PATT0   &#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Pattern row channel entry:&lt;br /&gt;
 ?   1  Flags  Contains four flags that indicate which pattern data follows&lt;br /&gt;
 +1  1  Chan   The channel this data belongs to.&lt;br /&gt;
 +2  1  Note   Present if bit 7 in Flags is set. Pitch, $01 is C-1, etc... The octaves&lt;br /&gt;
               are aligned by 16, i.e. B-1 is $0C but the next note, C-2, is $10.&lt;br /&gt;
 +3  1  Ins    Present if bit 6 in Flags is set. Instrument used, 0-31&lt;br /&gt;
 +4  1  Vol    Present if bit 5 in Flags is set. Volume change to, 0-63 = 0-127; optional&lt;br /&gt;
 +5  1  Effect Present if bit 4 in Flags is set. Effect to use, volume slide, Portamanto...&lt;br /&gt;
 +6  x  Eff Am Present if bit 4 in Flags is set. Parameter of effect, e.g amount of slide&lt;br /&gt;
&lt;br /&gt;
Each row consists of a word giving the size of the row (Including the word) followed by the channel data. A channel is only included if it has data in it, but a totally empty row is still included. So an &#039;empty&#039; row (Where none of the channels have data.) thus consists of just a word of value 2.&lt;br /&gt;
&lt;br /&gt;
Each channel entry consists of between 3-7 bytes. The first byte is a flag that shows what data follows. (The highest four bits indicate whether there are bytes for the following four variables; Note ($80), Instrument ($40), Volume ($20), Effect AND Effect parameter ($10). Thus 5 bytes are represented by a combination of 4 possibilities.) The next byte identifies the channel (Since each channel may or may not be present.) starting at 0 for channel 1. The remaining 5 bytes may or may not be present depending on their flag and contain data for Note, Instrument(Sample) used, Volume change for channel, Effect and Effect parameter.&lt;br /&gt;
&lt;br /&gt;
There are several things to note about this; Effect and Effect magnitude MUST occur together. Sample numbers, like channels are numbered starting at 0, not 1. Magnitudes (For effect AND volume) are from 0-127, not 0-64 as in other formats.&lt;br /&gt;
&lt;br /&gt;
=== Effect conversion ===&lt;br /&gt;
&lt;br /&gt;
Note that this table is guaranteed to be correct; Most effects seem to be converted correctly, though. Note that these values are not correct for the PSM files that can be found in the game Sinaria. Leave out all divisions and it will be correct again.&lt;br /&gt;
&lt;br /&gt;
 PSM Command   Param length  S3M Command&lt;br /&gt;
 &lt;br /&gt;
  Volume commands&lt;br /&gt;
    1           1 Byte        DxF - fine volside up&lt;br /&gt;
    2           1 Byte        Dx0 - volslide up&lt;br /&gt;
    3           1 Byte        DFx - fine volslide down&lt;br /&gt;
    4           1 Byte        D0x - volslide down&lt;br /&gt;
 &lt;br /&gt;
 Portamento commands&lt;br /&gt;
    B           1 Byte        FFx - fine porta up (divide x by 4)&lt;br /&gt;
    C           1 Byte        Fxx - porta up (if x &amp;lt; 4, use FFx, else divide x by 4)&lt;br /&gt;
    D           1 Byte        EFx - fine porta down (divide x by 4)&lt;br /&gt;
    E           1 Byte        Exx - porta down (if x &amp;lt; 4, use EFx, else divide x by 4)&lt;br /&gt;
    F           1 Byte        Gxx - portamento (divide x by 4)&lt;br /&gt;
   10           1 Byte        S1x - glissando control&lt;br /&gt;
   11           1 Byte        Lx0 - tone porta + volslide up&lt;br /&gt;
   12           1 Byte        L0x - tone porta + volslide down&lt;br /&gt;
    &lt;br /&gt;
 Vibrato&lt;br /&gt;
   15           1 Byte        Hxy - vibrato&lt;br /&gt;
   16           1 Byte        S3x - vibrato waveform&lt;br /&gt;
   17           1 Byte        K0x - vibrato + volslide up&lt;br /&gt;
   18           1 Byte        Kx0 - vibrato + volslide down&lt;br /&gt;
   	&lt;br /&gt;
 Tremolo			&lt;br /&gt;
   1F           1 Byte        Rxy - tremolo&lt;br /&gt;
   20           1 Byte        S4x - tremolo waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample commands&lt;br /&gt;
   29           3 Bytes       Oxx - offset (xx corresponds to the 2nd byte)&lt;br /&gt;
   2A           1 Byte        Q0x - retrigger&lt;br /&gt;
   2B           1 Byte        SCx - note cut&lt;br /&gt;
   2C           1 Byte        SDx - note delay&lt;br /&gt;
 &lt;br /&gt;
 Position change&lt;br /&gt;
   33           2 Bytes       Bxx - position jump - ignored by PLAY.EXE&lt;br /&gt;
   34           1 Byte        Cxx - break to row&lt;br /&gt;
                                    PLAY.EXE entirely ignores the parameter (it always breaks to the first&lt;br /&gt;
                                    row), so it is maybe best to do this in your own player as well.&lt;br /&gt;
                                    If the original file was an S3M, the parameter is double-BCD-encoded,&lt;br /&gt;
                                    i.e. on top of the original format&#039;s BCD encoding, the same encoding&lt;br /&gt;
                                    is applied again. to translate into the correct target row in binary,&lt;br /&gt;
                                    apply this twice: param = (param &amp;amp; 0xF0) * 10 + (param &amp;amp; 0x0F)&lt;br /&gt;
                                    For MOD files, the parameter is a normal binary number.&lt;br /&gt;
   35           1 Byte        SBx - pattern loop&lt;br /&gt;
   36           1 Byte        SEx - pattern delay&lt;br /&gt;
  &lt;br /&gt;
 Speed change&lt;br /&gt;
   3D           1 Byte        Axx - set speed&lt;br /&gt;
   3E           1 Byte        Txx - set tempo&lt;br /&gt;
 &lt;br /&gt;
 Misc. commands&lt;br /&gt;
   47           1 Byte        Jxy - arpeggio&lt;br /&gt;
   48           1 Byte        S2x - set finetune&lt;br /&gt;
   49           1 Byte        S8x - set balance&lt;br /&gt;
&lt;br /&gt;
Effect interpretation is slightly different in Sinaria&#039;s format. Slide command parameters are more like in PSM16.&lt;br /&gt;
&lt;br /&gt;
== Song segment ==&lt;br /&gt;
&lt;br /&gt;
This segment contains most of the important data used to play the song. It contains several sub-segments, each of the same format as a normal segment, but contained in the song segment. Note that there might be more than one song segment and thus, more than one order list, default speed, default tempo, etc... For example, in Extreme Pinball, all the different jingles and mission songs are stored as separate SONG chunks. It is up to the developer to find a clever way of managing / playing several sub songs.&lt;br /&gt;
&lt;br /&gt;
 Segment structure:&lt;br /&gt;
 0   4  ID     &#039;SONG&#039; indicates start of song structure&lt;br /&gt;
 4   4  Size   Size of song structure, including all sub-segments&lt;br /&gt;
 8   9  Type   Type of song this is for; This is &#039;MAINSONG &#039; in almost all PSM files. Extreme Pinball has several SONG items with different types!&lt;br /&gt;
 17  1  Comp   Compression, for PSM = 1 (Uncompressed)&lt;br /&gt;
 18  1  Chan   Number of channels, usually, but not always, 4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Date sub-segment ===&lt;br /&gt;
&lt;br /&gt;
This dates the file and is used by some programs. It is usually the first sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DATE&#039; indicates date data&lt;br /&gt;
 4   4  Size   Size of date segment (6)&lt;br /&gt;
 8   6  Date   Date as text, YYMMDD&lt;br /&gt;
&lt;br /&gt;
This can also be used as a way to heuristically detect if the new version of the format is being used. Sinaria&#039;s song dates are: 800211, 940902, 940903, 940906, 940914, 941213&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Order sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Orders describe how patterns are arranged in the song. This allows the same pattern of instruments to be played more than once in a song (e.g. a chorus). without the pattern data having to be duplicated. There should be only one order. This section also contains basic song information. It usually follows the date sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;OPLH&#039; indicates start of pattern placement order&lt;br /&gt;
 4   4  Size   Size of order segment&lt;br /&gt;
 8   2  Cnt.   Number of following chunks&lt;br /&gt;
&lt;br /&gt;
Now, the following chunks may follow until the end of the &amp;quot;OPLH&amp;quot; chunk is reached. Every chunk is identified by the first byte:&lt;br /&gt;
* $00 (1 Byte): End (Nothing follows)&lt;br /&gt;
* $01 (5/9 Bytes): Order list item follows (e.g. &amp;quot;P0  &amp;quot;, &amp;quot;P12 &amp;quot; in old format or &amp;quot;PATT0   &amp;quot; in Sinaria format, see above) - join those to get the complete order list.&lt;br /&gt;
* $04 (3 Bytes): This 16-bit value indicates the &amp;quot;restart chunk&amp;quot;. If the end of the subsong is reached, it will jump back to this chunk. In many cases, this would be 4th chunk (no 3rd chunk, as the chunk index is starting at 0!), which is a panning index in most PSMs - So you would just go to the nearest order list item that&#039;s following this chunk. However, this can also point to a valid order list chunk.&lt;br /&gt;
* $07 (2 Bytes): Next byte is default speed for this subtune&lt;br /&gt;
* $08 (2 Bytes): Next byte is default tempo for this subtune&lt;br /&gt;
* $0C (7 Bytes): Sample map table(?): This chunk is always $0C $00 $FF $00 $00 $01 $00. The purpose is unknown.&lt;br /&gt;
* $0D (4 Bytes): Channel panning index. Next byte is channel number (Start at 0), then initial pan ($00 ... $FF) and a byte follow. The byte seems to tell what to do with the previous pan position (0 - use it, 2 - ignore it, make this channel surround, 4 - set to center).&lt;br /&gt;
* $0E (3 Bytes): Channel volume index. Next byte is channel number (Start at 0), then volume ($00 ... $FF). $FF in most cases. Some OMF 2097 tracks use a lower volume.&lt;br /&gt;
&lt;br /&gt;
=== Pattern list ===&lt;br /&gt;
&lt;br /&gt;
This is simply a list of all the patterns used in the file. You do not really need to parse this, it seems to be a purely informational chunk.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;PATT&#039; indicates start of pattern list&lt;br /&gt;
 4   4  Size   Size of pattern list after this&lt;br /&gt;
 8   4  Size   Same as above&lt;br /&gt;
 12  4x Pat    An ordered list &#039;P0  &#039;, &#039;P1  &#039;... for all patterns in the file, each entry 4 bytes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sample list sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Similar to the above, this is a list of all the samples used in the file. It is usually the last sub-segment in the song segment and you do not really need to parse this.&lt;br /&gt;
&lt;br /&gt;
  0  4   ID     &#039;DSAM&#039;; indicates start of sample list, used to say what samples are &#039;full&#039;&lt;br /&gt;
                Any samples not on this list will be ignored, even if they have data&lt;br /&gt;
  4  4   Size   Size of list after this&lt;br /&gt;
  8  4   Size   Same value as above&lt;br /&gt;
  12 15x Entry  Sample entries, one for each sample in the file, each entry 15 bytes&lt;br /&gt;
&lt;br /&gt;
 Sample entry:&lt;br /&gt;
 0   8  Format Sample format, padded with spaces (END, RAG2...) This is important to some programs&lt;br /&gt;
 8   4  ID     &#039;I0  &#039;, &#039;I1  &#039;... the sample ID (&#039;I&#039; means &#039;Instrument&#039;). Again, be sure to accept both &#039;I0  &#039; and &#039;I00 &#039;!&lt;br /&gt;
 12  2  Num    The sample number, 0,1,2... for the sample&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
Samples are the raw sound data that makes up the instruments on the song. The actual format depends on the sample format. Samples have information in their headers which allows data to be played at different pitches (Speeds.) and to loop from and to various points in the data. This is by far the largest part of the file, since the raw data takes up so much space.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DSMP&#039; indicates start of sample&lt;br /&gt;
 4   4  Size   Size of following sample as &#039;DSMP&#039; + dword from end of word&lt;br /&gt;
 8   9  Flags  If highest bit is set, then sample is looped&lt;br /&gt;
 9   8  Songn. Filename of the original module (without extension)&lt;br /&gt;
 17  4  INSx   Last digit of sample (Instrument) number, 0-9; with 31 instruments possible&lt;br /&gt;
               Only last digit is shown. E.g 1st, 11th, 21st and 31st sample is &#039;INS0&#039;&lt;br /&gt;
 21  33 Name   Defines the instrument name or file, usually a .st or line of text&lt;br /&gt;
 54  51 Header Sample parameters (Can also 58 bytes long, padded with nuls)&lt;br /&gt;
               Byte 1-6 are unknown (but apparently always $00 $00 $00 $00 $00 $FF)&lt;br /&gt;
               Bytes 7-8 is instrument number&lt;br /&gt;
               Bytes 9-12 are sample length&lt;br /&gt;
               Bytes 13-16 are loop start&lt;br /&gt;
               Bytes 17-20 are loop end (all $FF means at end of sample)&lt;br /&gt;
               Bytes 21-22 are unknown (second byte could be finetune in Sinaria, but seems to be unused)&lt;br /&gt;
               Byte 23 is default volume&lt;br /&gt;
               Bytes 24-27 are unknwon&lt;br /&gt;
               Bytes 28-31 is frequency (Sample rate). MASI ignores the upper 16 bits, even if they are non-zero.&lt;br /&gt;
               19 $00-bytes follow (padding?)&lt;br /&gt;
 105 ?  Data   Music data in 8-bit mono format&lt;br /&gt;
&lt;br /&gt;
The sample header is slightly different in Sinaria&#039;s format: INSx is 8 bytes long (like the PATT IDs), and the last 21 $00-bytes are just 16 bytes (so that the struct is 96 bytes large in both formats).&lt;br /&gt;
&lt;br /&gt;
The PSM new format, along with the PSM 16 format use delta-encoded samples, something to make the file smaller when zipped. &#039;Deltas&#039;, convert a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. It has the effect that if a single byte in the sample is changed, the entire sample will be degraded. This use of deltas varies slightly from that of the PSM 16. The &#039;start value&#039; of the string is assumed to be $80 (128) and the first byte will thus turn this into the first desired value, the second delta converts the first value to the second, and so on.) All deltas are signed, 1-byte values, but loop (Thus 10 - 20 = -10 can also be considered as 10 + 236 = 246). An example of this is as follows:&lt;br /&gt;
&lt;br /&gt;
 RAW:   (128) 64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: -64  0   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Encryption ==&lt;br /&gt;
&lt;br /&gt;
CONVERT.EXE can produce &amp;quot;encrypted&amp;quot; PSM files with the /K command line switch. The encryption scheme is simple: It adds 1 to the first byte, 2 to the second, 3 to the third, and so until, for the entire file. It does not appear like any game made use of this feature, though.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM 16 =&lt;br /&gt;
&lt;br /&gt;
This is the format used in [[Silverball]], early versions of Epic Pinball and possibly other games. The designation &#039;Protracker Studio 16 format&#039; was given to it by the only reliable source of information on this format, and may not be the official designation.&lt;br /&gt;
&lt;br /&gt;
The format bears many similarities to the S3M format; the file is set out roughly the same, patterns and samples are similar, indeed, near identical and the functionality is similar. It also shows many similarities to the ProTracker MOD format and retains vestiges of Amiga compatibility.&lt;br /&gt;
&lt;br /&gt;
This format can be identified by its signature &#039;PSMþ&#039;, though files may lack this and still function.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Order&lt;br /&gt;
 Pan segment&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Sample data&lt;br /&gt;
 Sample headers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
 0    4  Sig      Signature, &#039;PSMþ&#039;&lt;br /&gt;
 4    59 Title    Song title, padded with nulls. Unlike other formats, this must also be terminated&lt;br /&gt;
                  with a null byte. (It sometimes is not terminated, though.)&lt;br /&gt;
 62   1           This must be $1A to end the song name, like in S3M format.&lt;br /&gt;
 64   1  Type     Song type, First bit: 0 - Module (w/samp.), 1 - Song (w/o samples)&lt;br /&gt;
                  Second bit: 0 - 3 octave Protracker, 1 - 5 octave; remaining bits reserved.&lt;br /&gt;
 65   1  PSM v    PSM format version, $10 for this format (Hence the name PSM 16) = &#039;v1.00&#039;.&lt;br /&gt;
                  Sometimes, this is also $01, but there&#039;s no difference in the format itself.&lt;br /&gt;
 66   1  Patt v   Pattern version, 0 or 1. 0 means the pattern is stored in the module are in the 32&lt;br /&gt;
                  channel file format.  A 1 signifies the patterns as being stored as a 255&lt;br /&gt;
                  channel format. (I have not found any PSM16 modules that have this format.)&lt;br /&gt;
 67   1   Speed   Song speed&lt;br /&gt;
 68   1   BPM     Beats per minute, the default Amiga BPM value. (The only reason that the Amiga BPM&lt;br /&gt;
                  format is still followed here is that it allows more control over the final hz value.)&lt;br /&gt;
                  Range: 32 to 255.&lt;br /&gt;
 69   1   Vol     Master volume of song, 0-255&lt;br /&gt;
 70   2   Len     Song length, 0-255. The number of patterns to play in the song, in total.&lt;br /&gt;
 72   2   Ordlen  The number of orders actually stored at the order offset. It was hoped that the&lt;br /&gt;
                  PSM 16 format would allow multiple orders, so this would be the length of the first&lt;br /&gt;
                  order. This doesn&#039;t appea to ahve happened, and is usually the same as the previous value.&lt;br /&gt;
 74   2   Patnum  Number of patterns in the song. 1-255&lt;br /&gt;
 76   2   Sampnum Number of samples and &#039;sample structures&#039; in song, 1-255&lt;br /&gt;
 78   2   NCIS    Number of channels in song to PLAY. 1-32. &lt;br /&gt;
 80   2   NCP     Number of Channels to Process; describes the MAXIMUM number of channels to process.&lt;br /&gt;
                  As an example, when converting 669 files,  NCP = 9 because some track information &lt;br /&gt;
                  is in Channel 8, but the Number of Channels to Play was set to 8, (Channel numbers&lt;br /&gt;
                  to play from 0 to 7.) 1-32&lt;br /&gt;
 82   4   Ordoff  Location of order in header&lt;br /&gt;
 86   4   Panoff  Location of pan positions in header&lt;br /&gt;
 90   4   Patoff  Location of patterns in header&lt;br /&gt;
 94   4   Sampoff Location of sample headers in header&lt;br /&gt;
 98   4   Commoff Location of comments in header&lt;br /&gt;
 102  4   Patsiz  Total pattern size; the total size of all the patterns loaded from the pattern offset.&lt;br /&gt;
 106  40  Fillers 10 fillers, to be used for any possible expansions.&lt;br /&gt;
&lt;br /&gt;
It is important to notice that the offsets point to the first byte &#039;&#039;&#039;after&#039;&#039;&#039; the chunk ID, i.e. &amp;quot;Ordoff&amp;quot; points to the first byte after &amp;quot;PORD&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Order and Pan positions ==&lt;br /&gt;
&lt;br /&gt;
These are two separate segments, pointed to in the header. They may be anywhere, but usually follow the header sometimes after an amount of blank space. They are often padded with blank space. They are basically lists.&lt;br /&gt;
&lt;br /&gt;
Order: This segment is pointed to in the header, and sets the PSM 16 format apart. The PSM 16 format was designed to be much more like the MOD format, allowing game designers to set flags to switch from one set of patterns to another, in effect allowing one file to contain more than one song. (For example a boss flag might make the music switch from a clam patterns 1-4 to a racy and dangerous patterns 5-7.)&lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    Signature, not needed, &#039;PORD&#039;&lt;br /&gt;
 4    ?   Ords   Pattern numbers and order. There will be [Ordlen] bytes of patterns&lt;br /&gt;
 ?    2   Lang   Order language, not implemented, so left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pan Positions: &lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    &#039;PPAN&#039;&lt;br /&gt;
 4    12  Pan    Pan positions; empty positions left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
 0    2   Size   Size of pattern, including these bytes&lt;br /&gt;
 2    1   Len    Length of pattern, in rows. Max length is 64 rows.&lt;br /&gt;
 3    1   Chan   Number of channels in pattern, 1-32&lt;br /&gt;
 4    ?   Data   Pattern data&lt;br /&gt;
&lt;br /&gt;
This is similar to the previous two segments, except actual pattern data is stored here. Patterns are very similar to the S3M format, and consist of y rows of x channels. Each row contains a number of channels and ends with a byte of value 0. Each channel is between 2-6+ bytes long. A totally empty channel is represented by a single byte of value 0.&lt;br /&gt;
&lt;br /&gt;
Each channel starts with a flag byte, abcddddd, where a,b and c indicate whether there is a note and instrument, volume or special effect and effect magnitude in the following data, and dddd is the channel number (0-31, used since a given channel may or may not be present in a row.)&lt;br /&gt;
&lt;br /&gt;
The usual maximum length of a channel entry is 6 bytes (1 flag byte, 2 Note AND instrument bytes, 1 volume byte and two Effect and Effect magnitude bytes.) Thus Note&amp;amp;ins\Eff&amp;amp;Eff mag must always occur together.&lt;br /&gt;
&lt;br /&gt;
Like S3M, volume range is 0-64, as is special magnitude. However, special effects range from 0-255, like PSM New Format.&lt;br /&gt;
&lt;br /&gt;
=== Effects conversion ===&lt;br /&gt;
&lt;br /&gt;
 ###  Co  MOD  Description               Arguments&lt;br /&gt;
 ---  --  ---  -----------               ---------&lt;br /&gt;
 Volume Commands&lt;br /&gt;
   1  A1   EA  Fine Volume Slide Up      B xx xx=speed&lt;br /&gt;
   2  A2   A   Volume Slide Up           B xx xx=speed&lt;br /&gt;
   3  A3   EB  Fine Volume Slide Down    B xx xx=speed&lt;br /&gt;
   4  A4   A   Volume Slide Down         B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Portamento Commands&lt;br /&gt;
  10  B0   E1  Fine Porta Up             B xx xx=speed&lt;br /&gt;
  11  B1   1   Portamento Up             B xx xx=speed&lt;br /&gt;
  12  B2   E2  Fine Porta Down           B xx xx=speed&lt;br /&gt;
  13  B3   2   Portamento Down           B xx xx=speed&lt;br /&gt;
  14  B4   3   Tone Portamento           B xx xx=speed&lt;br /&gt;
  15  B5   E3  Set Glissando Control     B xx xx=0 - Off, 1 - On&lt;br /&gt;
  16  B6   5   Tone Port+Vol Slide Up    B xx xx=speed&lt;br /&gt;
  17  B7   5   Tone Port+Vol Slide Down  B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Vibrato Commands&lt;br /&gt;
  20  C0   4   Vibrato                   B xy x=speed, y=depth&lt;br /&gt;
  21  C1   E4  Set Vibrato Waveform      B x  x=Waveform&lt;br /&gt;
  21  C2   6   Vibrato+Vol Slide Up      B xx xx=speed&lt;br /&gt;
  22  C3   6   Vibrato+Vol Slide Down    B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Tremolo Commands&lt;br /&gt;
  30  D0   7   Tremolo                   B xy x=speed, y=depth&lt;br /&gt;
  31  D1   E7  Set Tremolo Control       B x  x=Waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample Commands&lt;br /&gt;
  40  E0   9   Sample Offset             3B Position for offset change (0-1,048,575)&lt;br /&gt;
  41  E1   E9  Retrig Note               B xx xx=tick to retrigger sample&lt;br /&gt;
  42  E2   EC  Note Cut                  B xx xx=tick to cut note&lt;br /&gt;
  43  E3   ED  Note Delay                B xx xx=ticks to delay note&lt;br /&gt;
 &lt;br /&gt;
 Pos. Change Commands&lt;br /&gt;
  50  F0   B   Position Jump             B xx xx=order position&lt;br /&gt;
  51  F1   D   Pattern Break             B xx Skip to line xx in next pattern&lt;br /&gt;
  52  F2   E6  Jump Loop                 B xx xx=number of loops  0 Set&lt;br /&gt;
  53  F3   EE  Pattern Delay             B xx xx=notes to delay pattern&lt;br /&gt;
 &lt;br /&gt;
 Speed Change Cmds&lt;br /&gt;
  60  G0   F   Set Regular Speed         B xx xx=speed&lt;br /&gt;
  61  G1   F   Set BPM                   B xx xx=BPM (32-255)&lt;br /&gt;
 &lt;br /&gt;
 Misc. Commands&lt;br /&gt;
  70  H0   0   Arpeggio                  B xy x=semitone #1, y=semitone #2&lt;br /&gt;
  71  H1   E5  Set Finetune              B xx xx=finetune&lt;br /&gt;
  72  H2       Set Balance               B xx xx=Balance (0-15)&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
 Sample segment&lt;br /&gt;
 0    4   ID     &#039;PSAM&#039; (Psm SAMple)&lt;br /&gt;
 4    ?  Data    Sample data&lt;br /&gt;
&lt;br /&gt;
 Sample header segment&lt;br /&gt;
 0    4   ID     &#039;PSAH&#039; (Psm SAmple Header)&lt;br /&gt;
 4    ?  Data    Sample headers&lt;br /&gt;
&lt;br /&gt;
 Sample header&lt;br /&gt;
 0    13  Name   Sample filename, terminated with a null.&lt;br /&gt;
 13   24  Desc   Sample description or comments.&lt;br /&gt;
 37   4   Offs   Location of raw sample data in file&lt;br /&gt;
 43   4   Mem    This is the physical offset in RAM/DRAM of the sample. (Often blank.)&lt;br /&gt;
 45   2   Num    Sample number, 1-255&lt;br /&gt;
 47   1   Type   Sample type: (In some games left blank; if this is the case then the&lt;br /&gt;
                 sample format is END, as used in most PSM New Format files)&lt;br /&gt;
                 Bit 0: 0 - Digital, 1 - Synthesized&lt;br /&gt;
                 Bit 2: 0 - 8-bit, 1 - 16-bit&lt;br /&gt;
                 Bit 3: 0 - Signed, 1 - Unsigned&lt;br /&gt;
                 Bit 4: 0 - Deltas, 1 - Raw&lt;br /&gt;
                 Bit 5: 0 - Loop normally, 1 - Bidirectional&lt;br /&gt;
                 Bit 6: 1 - Gravis patch (unsupported)&lt;br /&gt;
                 Bit 7: 0 - No loop, 1 - Loop sample&lt;br /&gt;
 48   4   Len    Sample length, in bytes.&lt;br /&gt;
 52   4   Rep st Sample repeat start; if sample loops, the loop starts here.&lt;br /&gt;
 56   4   Rep fn Sample repeat end, if sample loops, it ends here. If this is less than the sample&lt;br /&gt;
                 repeat start, the sample loops backwards.&lt;br /&gt;
 60   1   Tune   Fine tune; range 0-15, Tune 0-7 = 0-7; tune -1 - -8 = 8-15&lt;br /&gt;
 61   1   Vol    Sample volume, 0-64&lt;br /&gt;
 62   2   Freq   This is the frequency for the sample at a C of Octave 2.&lt;br /&gt;
                 Typical values are 8,000 hz to 8,448 hz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like in S3M, sample headers are stored separately from the raw sample data.&lt;br /&gt;
&lt;br /&gt;
A type of sample storage used often, like in the PSM New Format is &#039;Deltas&#039;, which converts a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte, often making them compress better using general-purpose file compression tools. Thus:&lt;br /&gt;
&lt;br /&gt;
 RAW:        64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: 11  64   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
This is done to make files more compressible, but doesn&#039;t seem to be used much.&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.shikadi.net/files/psm2scrm.zip psm2scrm.zip] - DOS program to convert .PSM songs into ScreamTracker .S3M format, suitable for playing in your favourite tracker/module player. Works only with PSM New Format and is not nearly as accurate as OpenMPT.&lt;br /&gt;
* [http://openmpt.org OpenMPT] 1.18 and newer can load all PSM and PSM16 files.&lt;br /&gt;
* [http://openmpt.org/legacy_software ModPlug Tracker] and OpenMPT 1.17 can play the files and save them as S3M. More complex songs don&#039;t load correctly though. Works only with new format.&lt;br /&gt;
* [http://kode54.foobar2000.org/ foo_dumb] is a plugin for various module formats for the Foobar2k media player. It supports both PSM16 and PSM and is similar to OpenMPT in playback quality.&lt;br /&gt;
* [http://ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/mxinfo/epictest.zip EPICTEST] is a demonstration of the Epic Megagames MASI. It contains CONVERT.EXE which can be used to convert modules to the new PSM format.&lt;br /&gt;
* [http://www.jazz2online.com/J2Ov2/downloads/info.php?levelID=5471#29435] JJ1MOD can convert S3M files to new PSM, though often with errors (Though these are usually only detectable with older programs such as game executables.) It is currently the only utility able to do this, and works only with New Format.&lt;br /&gt;
&lt;br /&gt;
= Notes =&lt;br /&gt;
&lt;br /&gt;
The New PSM format was reverse engineered by Levellord and tidied up by Levellass. It is possible there may be minor errors in the sample format information, especially since this is poorly documented.&lt;br /&gt;
Some format definitions have been updated and corrected by Johannes Schultz of the OpenMPT development team.&lt;br /&gt;
&lt;br /&gt;
The PSM16 format documentation was found on Wotsit and written up by Levellass (this appears to be an official document from the MASI developer). More info is needed.&lt;br /&gt;
&lt;br /&gt;
In all formats the following table shows how note bytes are converted into actual notes: (PSM new format has the widest range, 0-255)&lt;br /&gt;
&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;br /&gt;
           | C-0   0 | C-1  12 | C-2  24 | C-3  36 | C-4  48 |&lt;br /&gt;
           | C#0   1 | C#1  13 | C#2  25 | C#3  37 | C#4  49 |&lt;br /&gt;
           | D-0   2 | D-1  14 | D-2  26 | D-3  38 | D-4  50 |&lt;br /&gt;
           | D#0   3 | D#1  15 | D#2  27 | D#3  39 | D#4  51 |&lt;br /&gt;
           | E-0   4 | E-1  16 | E-2  28 | E-3  40 | E-4  52 |&lt;br /&gt;
           | F-0   5 | F-1  17 | F-2  29 | F-3  41 | F-4  53 |&lt;br /&gt;
           | F#0   6 | F#1  18 | F#2  30 | F#3  42 | F#4  54 |&lt;br /&gt;
           | G-0   7 | G-1  19 | G-2  31 | G-3  43 | G-4  55 |&lt;br /&gt;
           | G#0   8 | G#1  20 | G#2  32 | G#3  44 | G#4  56 |&lt;br /&gt;
           | A-0   9 | A-1  21 | A-2  33 | A-3  45 | A-4  57 |&lt;br /&gt;
           | A#0  10 | A#1  22 | A#2  34 | A#3  46 | A#4  58 |&lt;br /&gt;
           | B-0  11 | B-1  23 | B-2  35 | B-3  47 | B-4  59 |&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=6938</id>
		<title>ProTracker Studio Module</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=6938"/>
		<updated>2016-08-03T01:24:45Z</updated>

		<summary type="html">&lt;p&gt;Saga: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 1-256 (PSM) / 1-32 (PSM16)&lt;br /&gt;
 | NumTracks = unlimited (PSM) / 1 (PSM16)&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Epic Pinball}}&lt;br /&gt;
   {{Game|Extreme Pinball}}&lt;br /&gt;
   {{Game|Jazz Jackrabbit}}&lt;br /&gt;
   {{Game|One Must Fall}}&lt;br /&gt;
   {{Game|Silverball}}&lt;br /&gt;
   {{Game|Sinaria}}&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;ProTracker Studio Module&#039;&#039;&#039; (PSM) file format is used for the music in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]].  The file format is named after ProTracker, an Amiga program, though this program was probably actually not used to write PSM files. One Must Fall&#039;s music was written in Multitracker, and the music for Jazz Jackrabbit, Epic Pinball and Extreme Pinball probably in Scream Tracker.&lt;br /&gt;
&lt;br /&gt;
There are two file types that use the extension .PSM; they are both used by Epic Megagames&#039; MASI sound system, but are used by different versions of the system. The two formats are:&lt;br /&gt;
&lt;br /&gt;
* PSM New Format: Used by Jazz Jackrabbit, Epic Pinball, Extreme Pinball, One Must Fall, Sinaria (in this game with slight differences, see below), newest PSM format&lt;br /&gt;
* PSM 16:         Used by Silverball, an older version of the format which is closer to ScreamTracker-style modules.&lt;br /&gt;
&lt;br /&gt;
The most common of the two PSM formats is the new format, and most programs that try to interpret PSM files will be expecting this. For example, ModPlug Player cannot open Silverball files as these are in the PSM 16 format.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM New Format =&lt;br /&gt;
&lt;br /&gt;
This format is used by [[:Category:Epic Megagames|Epic]] games in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]]. It is notable for consisting of a number of segments (chunks) and sub segments. It bears the 4-byte signature &#039;PSM &#039; at the file start.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Song segment&lt;br /&gt;
 Samples&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 12 bytes long:&lt;br /&gt;
&lt;br /&gt;
 File header:&lt;br /&gt;
 0   4  ID     &#039;PSM &#039;; indicates file is PSM format&lt;br /&gt;
 4   4  Size   Filesize - 12&lt;br /&gt;
 8   4  ID2    &#039;FILE&#039;; indicates start of file info&lt;br /&gt;
&lt;br /&gt;
After the header, some chunks follow in IFF-style. You should not expect chunks to come up in the same order as they are described here. A good way to handle chunks is to read the 4-Byte ID and the 4-Byte size field first, then evaluate the ID and decide what to do next based on this ID. Note that the size field does not include the ID and itself; it only holds the size of the chunk &#039;&#039;content&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Title segment ==&lt;br /&gt;
&lt;br /&gt;
This segment is optional, and one of the few segments that can be absent when playing PSM files in most programs. (Most programs expect all other segments to exist, even if they are not vital.)&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;TITL&#039;; indicates a title follows&lt;br /&gt;
 4   4  Size   Size of title as dword after this dword&lt;br /&gt;
 8   ?  Title  Song title&lt;br /&gt;
&lt;br /&gt;
== Song info segment ==&lt;br /&gt;
&lt;br /&gt;
This segment seems to indicate the beginning of the song data and is not really relevant when parsing.&lt;br /&gt;
&lt;br /&gt;
 12  4  ID     &#039;SDFT&#039;; indicates start of format info&lt;br /&gt;
 16  4  Size   Size of next header as dword, (8)&lt;br /&gt;
 20  8  Song   &#039;MAINSONG&#039;; indicates song type. No other song types are known.&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
Each pattern is stored in its own PBOD chunk. Note that there are two possible formats for this chunk; one is used in the &amp;quot;old&amp;quot; format (as used in Epic Pinball, Extreme Pinball, Jazz Jackrabbit, One Must Fall) and the other in the &amp;quot;new&amp;quot; format (as used in Sinaria)&lt;br /&gt;
&lt;br /&gt;
 Pattern segment:&lt;br /&gt;
 0   4  ID     &#039;PBOD&#039;; indicates a pattern follows (Pattern BODy)&lt;br /&gt;
 4   4  Size   Length of pattern data as dword, after this dword&lt;br /&gt;
 4   4  Size   Same value again.&lt;br /&gt;
&lt;br /&gt;
 Pattern:&lt;br /&gt;
 0 4/8  Number Pattern ID. See note below.&lt;br /&gt;
 4   2  Row n  Number of rows in ALL channels in pattern (64 usually, but can differ.) as word.&lt;br /&gt;
 6   ?  Data   Contains pattern data as a number of rows of interlaced channels (12341234...)&lt;br /&gt;
               &#039;&#039;Usual&#039;&#039; settings is 64 rows of 4 channels. Epic Pinball has shorter patterns for example, but they also include a &amp;quot;break to row&amp;quot; command at the end of the pattern.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; There are two variants of the format. In the most common variant, the pattern ID is 4 bytes long and starts with a &#039;P&#039;, followed by an integer number which is the pattern number, padded to 4 bytes with spaces. Caution: This number might or might not be zero-padded; In some files, the ID of the first pattern could be &#039;P0  &#039;, but there are also files where it is &#039;P00 &#039;!. In C/C++, you could use atoi() to parse this value.&lt;br /&gt;
In the format used in the game Sinaria, This field is 8 bytes long instead of 4 bytes, and the first 4 bytes read &amp;quot;PATT&amp;quot;, so the first pattern could be for example &#039;PATT0   &#039;. It is not entirely clear if the format used in Sinaria is newer or older - in some ways, like the effect interpretation, it resembles PSM16 more than the new format, so it could be an earlier version of the new PSM format.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Pattern row channel entry:&lt;br /&gt;
 ?   1  Flags  Contains four flags that indicate which pattern data follows&lt;br /&gt;
 +1  1  Chan   The channel this data belongs to.&lt;br /&gt;
 +2  1  Note   Present if bit 7 in Flags is set. Pitch, $01 is C-1, etc... The octaves&lt;br /&gt;
               are aligned by 16, i.e. B-1 is $0C but the next note, C-2, is $10.&lt;br /&gt;
 +3  1  Ins    Present if bit 6 in Flags is set. Instrument used, 0-31&lt;br /&gt;
 +4  1  Vol    Present if bit 5 in Flags is set. Volume change to, 0-63 = 0-127; optional&lt;br /&gt;
 +5  1  Effect Present if bit 4 in Flags is set. Effect to use, volume slide, Portamanto...&lt;br /&gt;
 +6  x  Eff Am Present if bit 4 in Flags is set. Parameter of effect, e.g amount of slide&lt;br /&gt;
&lt;br /&gt;
Each row consists of a word giving the size of the row (Including the word) followed by the channel data. A channel is only included if it has data in it, but a totally empty row is still included. So an &#039;empty&#039; row (Where none of the channels have data.) thus consists of just a word of value 2.&lt;br /&gt;
&lt;br /&gt;
Each channel entry consists of between 3-7 bytes. The first byte is a flag that shows what data follows. (The highest four bits indicate whether there are bytes for the following four variables; Note ($80), Instrument ($40), Volume ($20), Effect AND Effect parameter ($10). Thus 5 bytes are represented by a combination of 4 possibilities.) The next byte identifies the channel (Since each channel may or may not be present.) starting at 0 for channel 1. The remaining 5 bytes may or may not be present depending on their flag and contain data for Note, Instrument(Sample) used, Volume change for channel, Effect and Effect parameter.&lt;br /&gt;
&lt;br /&gt;
There are several things to note about this; Effect and Effect magnitude MUST occur together. Sample numbers, like channels are numbered starting at 0, not 1. Magnitudes (For effect AND volume) are from 0-127, not 0-64 as in other formats.&lt;br /&gt;
&lt;br /&gt;
=== Effect conversion ===&lt;br /&gt;
&lt;br /&gt;
Note that this table is guaranteed to be correct; Most effects seem to be converted correctly, though. Note that these values are not correct for the PSM files that can be found in the game Sinaria. Leave out all divisions and it will be correct again.&lt;br /&gt;
&lt;br /&gt;
 PSM Command   Param length  S3M Command&lt;br /&gt;
 &lt;br /&gt;
  Volume commands&lt;br /&gt;
    1           1 Byte        DxF - fine volside up&lt;br /&gt;
    2           1 Byte        Dx0 - volslide up&lt;br /&gt;
    3           1 Byte        DFx - fine volslide down&lt;br /&gt;
    4           1 Byte        D0x - volslide down&lt;br /&gt;
 &lt;br /&gt;
 Portamento commands&lt;br /&gt;
    B           1 Byte        FFx - fine porta up (divide x by 4)&lt;br /&gt;
    C           1 Byte        Fxx - porta up (if x &amp;lt; 4, use FFx, else divide x by 4)&lt;br /&gt;
    D           1 Byte        EFx - fine porta down (divide x by 4)&lt;br /&gt;
    E           1 Byte        Exx - porta down (if x &amp;lt; 4, use EFx, else divide x by 4)&lt;br /&gt;
    F           1 Byte        Gxx - portamento (divide x by 4)&lt;br /&gt;
   10           1 Byte        S1x - glissando control&lt;br /&gt;
   11           1 Byte        Lx0 - tone porta + volslide up&lt;br /&gt;
   12           1 Byte        L0x - tone porta + volslide down&lt;br /&gt;
    &lt;br /&gt;
 Vibrato&lt;br /&gt;
   15           1 Byte        Hxy - vibrato&lt;br /&gt;
   16           1 Byte        S3x - vibrato waveform&lt;br /&gt;
   17           1 Byte        K0x - vibrato + volslide up&lt;br /&gt;
   18           1 Byte        Kx0 - vibrato + volslide down&lt;br /&gt;
   	&lt;br /&gt;
 Tremolo			&lt;br /&gt;
   1F           1 Byte        Rxy - tremolo&lt;br /&gt;
   20           1 Byte        S4x - tremolo waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample commands&lt;br /&gt;
   29           3 Bytes       Oxx - offset (xx corresponds to the 2nd byte)&lt;br /&gt;
   2A           1 Byte        Q0x - retrigger&lt;br /&gt;
   2B           1 Byte        SCx - note cut&lt;br /&gt;
   2C           1 Byte        SDx - note delay&lt;br /&gt;
 &lt;br /&gt;
 Position change&lt;br /&gt;
   33           2 Bytes       Bxx - position jump - ignored by PLAY.EXE&lt;br /&gt;
   34           1 Byte        Cxx - break to row&lt;br /&gt;
                                    PLAY.EXE entirely ignores the parameter (it always breaks to the first&lt;br /&gt;
                                    row), so it is maybe best to do this in your own player as well.&lt;br /&gt;
                                    If the original file was an S3M, the parameter is double-BCD-encoded,&lt;br /&gt;
                                    i.e. on top of the original format&#039;s BCD encoding, the same encoding&lt;br /&gt;
                                    is applied again. to translate into the correct target row in binary,&lt;br /&gt;
                                    apply this twice: param = (param &amp;amp; 0xF0) * 10 + (param &amp;amp; 0x0F)&lt;br /&gt;
                                    For MOD files, the parameter is a normal binary number.&lt;br /&gt;
   35           1 Byte        SBx - pattern loop&lt;br /&gt;
   36           1 Byte        SEx - pattern delay&lt;br /&gt;
  &lt;br /&gt;
 Speed change&lt;br /&gt;
   3D           1 Byte        Axx - set speed&lt;br /&gt;
   3E           1 Byte        Txx - set tempo&lt;br /&gt;
 &lt;br /&gt;
 Misc. commands&lt;br /&gt;
   47           1 Byte        Jxy - arpeggio&lt;br /&gt;
   48           1 Byte        S2x - set finetune&lt;br /&gt;
   49           1 Byte        S8x - set balance&lt;br /&gt;
&lt;br /&gt;
Effect interpretation is slightly different in Sinaria&#039;s format. Slide command parameters are more like in PSM16.&lt;br /&gt;
&lt;br /&gt;
== Song segment ==&lt;br /&gt;
&lt;br /&gt;
This segment contains most of the important data used to play the song. It contains several sub-segments, each of the same format as a normal segment, but contained in the song segment. Note that there might be more than one song segment and thus, more than one order list, default speed, default tempo, etc... For example, in Extreme Pinball, all the different jingles and mission songs are stored as separate SONG chunks. It is up to the developer to find a clever way of managing / playing several sub songs.&lt;br /&gt;
&lt;br /&gt;
 Segment structure:&lt;br /&gt;
 0   4  ID     &#039;SONG&#039; indicates start of song structure&lt;br /&gt;
 4   4  Size   Size of song structure, including all sub-segments&lt;br /&gt;
 8   9  Type   Type of song this is for; This is &#039;MAINSONG &#039; in almost all PSM files. Extreme Pinball has several SONG items with different types!&lt;br /&gt;
 17  1  Comp   Compression, for PSM = 1 (Uncompressed)&lt;br /&gt;
 18  1  Chan   Number of channels, usually, but not always, 4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Date sub-segment ===&lt;br /&gt;
&lt;br /&gt;
This dates the file and is used by some programs. It is usually the first sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DATE&#039; indicates date data&lt;br /&gt;
 4   4  Size   Size of date segment (6)&lt;br /&gt;
 8   6  Date   Date as text, YYMMDD&lt;br /&gt;
&lt;br /&gt;
This can also be used as a way to heuristically detect if the new version of the format is being used. Sinaria&#039;s song dates are: 800211, 940902, 940903, 940906, 940914, 941213&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Order sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Orders describe how patterns are arranged in the song. This allows the same pattern of instruments to be played more than once in a song (e.g. a chorus). without the pattern data having to be duplicated. There should be only one order. This section also contains basic song information. It usually follows the date sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;OPLH&#039; indicates start of pattern placement order&lt;br /&gt;
 4   4  Size   Size of order segment&lt;br /&gt;
 8   2  Cnt.   Number of following chunks&lt;br /&gt;
&lt;br /&gt;
Now, the following chunks may follow until the end of the &amp;quot;OPLH&amp;quot; chunk is reached. Every chunk is identified by the first byte:&lt;br /&gt;
* $00 (1 Byte): End (Nothing follows)&lt;br /&gt;
* $01 (5/9 Bytes): Order list item follows (e.g. &amp;quot;P0  &amp;quot;, &amp;quot;P12 &amp;quot; in old format or &amp;quot;PATT0   &amp;quot; in Sinaria format, see above) - join those to get the complete order list.&lt;br /&gt;
* $04 (3 Bytes): This 16-bit value indicates the &amp;quot;restart chunk&amp;quot;. If the end of the subsong is reached, it will jump back to this chunk. In many cases, this would be 4th chunk (no 3rd chunk, as the chunk index is starting at 0!), which is a panning index in most PSMs - So you would just go to the nearest order list item that&#039;s following this chunk. However, this can also point to a valid order list chunk.&lt;br /&gt;
* $07 (2 Bytes): Next byte is default speed for this subtune&lt;br /&gt;
* $08 (2 Bytes): Next byte is default tempo for this subtune&lt;br /&gt;
* $0C (7 Bytes): Sample map table(?): This chunk is always $0C $00 $FF $00 $00 $01 $00. The purpose is unknown.&lt;br /&gt;
* $0D (4 Bytes): Channel panning index. Next byte is channel number (Start at 0), then initial pan ($00 ... $FF) and a byte follow. The byte seems to tell what to do with the previous pan position (0 - use it, 2 - ignore it, make this channel surround, 4 - set to center).&lt;br /&gt;
* $0E (3 Bytes): Channel volume index. Next byte is channel number (Start at 0), then volume ($00 ... $FF). $FF in most cases. Some OMF 2097 tracks use a lower volume.&lt;br /&gt;
&lt;br /&gt;
=== Pattern list ===&lt;br /&gt;
&lt;br /&gt;
This is simply a list of all the patterns used in the file. You do not really need to parse this, it seems to be a purely informational chunk.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;PATT&#039; indicates start of pattern list&lt;br /&gt;
 4   4  Size   Size of pattern list after this&lt;br /&gt;
 8   4  Size   Same as above&lt;br /&gt;
 12  4x Pat    An ordered list &#039;P0  &#039;, &#039;P1  &#039;... for all patterns in the file, each entry 4 bytes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sample list sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Similar to the above, this is a list of all the samples used in the file. It is usually the last sub-segment in the song segment and you do not really need to parse this.&lt;br /&gt;
&lt;br /&gt;
  0  4   ID     &#039;DSAM&#039;; indicates start of sample list, used to say what samples are &#039;full&#039;&lt;br /&gt;
                Any samples not on this list will be ignored, even if they have data&lt;br /&gt;
  4  4   Size   Size of list after this&lt;br /&gt;
  8  4   Size   Same value as above&lt;br /&gt;
  12 15x Entry  Sample entries, one for each sample in the file, each entry 15 bytes&lt;br /&gt;
&lt;br /&gt;
 Sample entry:&lt;br /&gt;
 0   8  Format Sample format, padded with spaces (END, RAG2...) This is important to some programs&lt;br /&gt;
 8   4  ID     &#039;I0  &#039;, &#039;I1  &#039;... the sample ID (&#039;I&#039; means &#039;Instrument&#039;). Again, be sure to accept both &#039;I0  &#039; and &#039;I00 &#039;!&lt;br /&gt;
 12  2  Num    The sample number, 0,1,2... for the sample&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
Samples are the raw sound data that makes up the instruments on the song. The actual format depends on the sample format. Samples have information in their headers which allows data to be played at different pitches (Speeds.) and to loop from and to various points in the data. This is by far the largest part of the file, since the raw data takes up so much space.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DSMP&#039; indicates start of sample&lt;br /&gt;
 4   4  Size   Size of following sample as &#039;DSMP&#039; + dword from end of word&lt;br /&gt;
 8   9  Flags  If highest bit is set, then sample is looped&lt;br /&gt;
 9   8  Songn. Filename of the original module (without extension)&lt;br /&gt;
 17  4  INSx   Last digit of sample (Instrument) number, 0-9; with 31 instruments possible&lt;br /&gt;
               Only last digit is shown. E.g 1st, 11th, 21st and 31st sample is &#039;INS0&#039;&lt;br /&gt;
 21  33 Name   Defines the instrument name or file, usually a .st or line of text&lt;br /&gt;
 54  51 Header Sample parameters (Can also 58 bytes long, padded with nuls)&lt;br /&gt;
               Byte 1-6 are unknown (but apparently always $00 $00 $00 $00 $00 $FF)&lt;br /&gt;
               Bytes 7-8 is instrument number&lt;br /&gt;
               Bytes 9-12 are sample length&lt;br /&gt;
               Bytes 13-16 are loop start&lt;br /&gt;
               Bytes 17-20 are loop end (all $FF means at end of sample)&lt;br /&gt;
               Bytes 21-22 are unknown (second byte could be finetune in Sinaria, but seems to be unused)&lt;br /&gt;
               Byte 23 is default volume&lt;br /&gt;
               Bytes 24-27 are unknwon&lt;br /&gt;
               Bytes 28-31 is frequency (Sample rate). MASI ignores the upper 16 bits, even if they are non-zero.&lt;br /&gt;
               19 $00-bytes follow (padding?)&lt;br /&gt;
 105 ?  Data   Music data in 8-bit mono format&lt;br /&gt;
&lt;br /&gt;
The sample header is slightly different in Sinaria&#039;s format: INSx is 8 bytes long (like the PATT IDs), and the last 21 $00-bytes are just 16 bytes (so that the struct is 96 bytes large in both formats).&lt;br /&gt;
&lt;br /&gt;
The PSM new format, along with the PSM 16 format use delta-encoded samples, something to make the file smaller when zipped. &#039;Deltas&#039;, convert a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. It has the effect that if a single byte in the sample is changed, the entire sample will be degraded. This use of deltas varies slightly from that of the PSM 16. The &#039;start value&#039; of the string is assumed to be $80 (128) and the first byte will thus turn this into the first desired value, the second delta converts the first value to the second, and so on.) All deltas are signed, 1-byte values, but loop (Thus 10 - 20 = -10 can also be considered as 10 + 236 = 246). An example of this is as follows:&lt;br /&gt;
&lt;br /&gt;
 RAW:   (128) 64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: -64  0   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Encryption ==&lt;br /&gt;
&lt;br /&gt;
CONVERT.EXE can produce &amp;quot;encrypted&amp;quot; PSM files with the /K command line switch. The encryption scheme is simple: It adds 1 to the first byte, 2 to the second, 3 to the third, and so until, for the entire file. It does not appear like any game made use of this feature, though.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM 16 =&lt;br /&gt;
&lt;br /&gt;
This is the format used in [[Silverball]], early versions of Epic Pinball and possibly other games. The designation &#039;Protracker Studio 16 format&#039; was given to it by the only reliable source of information on this format, and may not be the official designation.&lt;br /&gt;
&lt;br /&gt;
The format bears many similarities to the S3M format; the file is set out roughly the same, patterns and samples are similar, indeed, near identical and the functionality is similar. It also shows many similarities to the ProTracker MOD format and retains vestiges of Amiga compatibility.&lt;br /&gt;
&lt;br /&gt;
This format can be identified by its signature &#039;PSMþ&#039;, though files may lack this and still function.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Order&lt;br /&gt;
 Pan segment&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Sample data&lt;br /&gt;
 Sample headers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
 0    4  Sig      Signature, &#039;PSMþ&#039;&lt;br /&gt;
 4    59 Title    Song title, padded with nulls. Unlike other formats, this must also be terminated&lt;br /&gt;
                  with a null byte. (It sometimes is not terminated, though.)&lt;br /&gt;
 62   1           This must be $1A to end the song name, like in S3M format.&lt;br /&gt;
 64   1  Type     Song type, First bit: 0 - Module (w/samp.), 1 - Song (w/o samples)&lt;br /&gt;
                  Second bit: 0 - 3 octave Protracker, 1 - 5 octave; remaining bits reserved.&lt;br /&gt;
 65   1  PSM v    PSM format version, $10 for this format (Hence the name PSM 16) = &#039;v1.00&#039;.&lt;br /&gt;
                  Sometimes, this is also $01, but there&#039;s no difference in the format itself.&lt;br /&gt;
 66   1  Patt v   Pattern version, 0 or 1. 0 means the pattern is stored in the module are in the 32&lt;br /&gt;
                  channel file format.  A 1 signifies the patterns as being stored as a 255&lt;br /&gt;
                  channel format. (I have not found any PSM16 modules that have this format.)&lt;br /&gt;
 67   1   Speed   Song speed&lt;br /&gt;
 68   1   BPM     Beats per minute, the default Amiga BPM value. (The only reason that the Amiga BPM&lt;br /&gt;
                  format is still followed here is that it allows more control over the final hz value.)&lt;br /&gt;
                  Range: 32 to 255.&lt;br /&gt;
 69   1   Vol     Master volume of song, 0-255&lt;br /&gt;
 70   2   Len     Song length, 0-255. The number of patterns to play in the song, in total.&lt;br /&gt;
 72   2   Ordlen  The number of orders actually stored at the order offset. It was hoped that the&lt;br /&gt;
                  PSM 16 format would allow multiple orders, so this would be the length of the first&lt;br /&gt;
                  order. This doesn&#039;t appea to ahve happened, and is usually the same as the previous value.&lt;br /&gt;
 74   2   Patnum  Number of patterns in the song. 1-255&lt;br /&gt;
 76   2   Sampnum Number of samples and &#039;sample structures&#039; in song, 1-255&lt;br /&gt;
 78   2   NCIS    Number of channels in song to PLAY. 1-32. &lt;br /&gt;
 80   2   NCP     Number of Channels to Process; describes the MAXIMUM number of channels to process.&lt;br /&gt;
                  As an example, when converting 669 files,  NCP = 9 because some track information &lt;br /&gt;
                  is in Channel 8, but the Number of Channels to Play was set to 8, (Channel numbers&lt;br /&gt;
                  to play from 0 to 7.) 1-32&lt;br /&gt;
 82   4   Ordoff  Location of order in header&lt;br /&gt;
 86   4   Panoff  Location of pan positions in header&lt;br /&gt;
 90   4   Patoff  Location of patterns in header&lt;br /&gt;
 94   4   Sampoff Location of sample headers in header&lt;br /&gt;
 98   4   Commoff Location of comments in header&lt;br /&gt;
 102  4   Patsiz  Total pattern size; the total size of all the patterns loaded from the pattern offset.&lt;br /&gt;
 106  40  Fillers 10 fillers, to be used for any possible expansions.&lt;br /&gt;
&lt;br /&gt;
It is important to notice that the offsets point to the first byte &#039;&#039;&#039;after&#039;&#039;&#039; the chunk ID, i.e. &amp;quot;Ordoff&amp;quot; points to the first byte after &amp;quot;PORD&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Order and Pan positions ==&lt;br /&gt;
&lt;br /&gt;
These are two separate segments, pointed to in the header. They may be anywhere, but usually follow the header sometimes after an amount of blank space. They are often padded with blank space. They are basically lists.&lt;br /&gt;
&lt;br /&gt;
Order: This segment is pointed to in the header, and sets the PSM 16 format apart. The PSM 16 format was designed to be much more like the MOD format, allowing game designers to set flags to switch from one set of patterns to another, in effect allowing one file to contain more than one song. (For example a boss flag might make the music switch from a clam patterns 1-4 to a racy and dangerous patterns 5-7.)&lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    Signature, not needed, &#039;PORD&#039;&lt;br /&gt;
 4    ?   Ords   Pattern numbers and order. There will be [Ordlen] bytes of patterns&lt;br /&gt;
 ?    2   Lang   Order language, not implemented, so left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pan Positions: &lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    &#039;PPAN&#039;&lt;br /&gt;
 4    12  Pan    Pan positions; empty positions left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
 0    2   Size   Size of pattern, including these bytes&lt;br /&gt;
 2    1   Len    Length of pattern, in rows. Max length is 64 rows.&lt;br /&gt;
 3    1   Chan   Number of channels in pattern, 1-32&lt;br /&gt;
 4    ?   Data   Pattern data&lt;br /&gt;
&lt;br /&gt;
This is similar to the previous two segments, except actual pattern data is stored here. Patterns are very similar to the S3M format, and consist of y rows of x channels. Each row contains a number of channels and ends with a byte of value 0. Each channel is between 2-6+ bytes long. A totally empty channel is represented by a single byte of value 0.&lt;br /&gt;
&lt;br /&gt;
Each channel starts with a flag byte, abcddddd, where a,b and c indicate whether there is a note and instrument, volume or special effect and effect magnitude in the following data, and dddd is the channel number (0-31, used since a given channel may or may not be present in a row.)&lt;br /&gt;
&lt;br /&gt;
The usual maximum length of a channel entry is 6 bytes (1 flag byte, 2 Note AND instrument bytes, 1 volume byte and two Effect and Effect magnitude bytes.) Thus Note&amp;amp;ins\Eff&amp;amp;Eff mag must always occur together.&lt;br /&gt;
&lt;br /&gt;
Like S3M, volume range is 0-64, as is special magnitude. However, special effects range from 0-255, like PSM New Format.&lt;br /&gt;
&lt;br /&gt;
=== Effects conversion ===&lt;br /&gt;
&lt;br /&gt;
 ###  Co  MOD  Description               Arguments&lt;br /&gt;
 ---  --  ---  -----------               ---------&lt;br /&gt;
 Volume Commands&lt;br /&gt;
   1  A1   EA  Fine Volume Slide Up      B xx xx=speed&lt;br /&gt;
   2  A2   A   Volume Slide Up           B xx xx=speed&lt;br /&gt;
   3  A3   EB  Fine Volume Slide Down    B xx xx=speed&lt;br /&gt;
   4  A4   A   Volume Slide Down         B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Portamento Commands&lt;br /&gt;
  10  B0   E1  Fine Porta Up             B xx xx=speed&lt;br /&gt;
  11  B1   1   Portamento Up             B xx xx=speed&lt;br /&gt;
  12  B2   E2  Fine Porta Down           B xx xx=speed&lt;br /&gt;
  13  B3   2   Portamento Down           B xx xx=speed&lt;br /&gt;
  14  B4   3   Tone Portamento           B xx xx=speed&lt;br /&gt;
  15  B5   E3  Set Glissando Control     B xx xx=0 - Off, 1 - On&lt;br /&gt;
  16  B6   5   Tone Port+Vol Slide Up    B xx xx=speed&lt;br /&gt;
  17  B7   5   Tone Port+Vol Slide Down  B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Vibrato Commands&lt;br /&gt;
  20  C0   4   Vibrato                   B xy x=speed, y=depth&lt;br /&gt;
  21  C1   E4  Set Vibrato Waveform      B x  x=Waveform&lt;br /&gt;
  21  C2   6   Vibrato+Vol Slide Up      B xx xx=speed&lt;br /&gt;
  22  C3   6   Vibrato+Vol Slide Down    B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Tremolo Commands&lt;br /&gt;
  30  D0   7   Tremolo                   B xy x=speed, y=depth&lt;br /&gt;
  31  D1   E7  Set Tremolo Control       B x  x=Waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample Commands&lt;br /&gt;
  40  E0   9   Sample Offset             3B Position for offset change (0-1,048,575)&lt;br /&gt;
  41  E1   E9  Retrig Note               B xx xx=tick to retrigger sample&lt;br /&gt;
  42  E2   EC  Note Cut                  B xx xx=tick to cut note&lt;br /&gt;
  43  E3   ED  Note Delay                B xx xx=ticks to delay note&lt;br /&gt;
 &lt;br /&gt;
 Pos. Change Commands&lt;br /&gt;
  50  F0   B   Position Jump             B xx xx=order position&lt;br /&gt;
  51  F1   D   Pattern Break             B xx Skip to line xx in next pattern&lt;br /&gt;
  52  F2   E6  Jump Loop                 B xx xx=number of loops  0 Set&lt;br /&gt;
  53  F3   EE  Pattern Delay             B xx xx=notes to delay pattern&lt;br /&gt;
 &lt;br /&gt;
 Speed Change Cmds&lt;br /&gt;
  60  G0   F   Set Regular Speed         B xx xx=speed&lt;br /&gt;
  61  G1   F   Set BPM                   B xx xx=BPM (32-255)&lt;br /&gt;
 &lt;br /&gt;
 Misc. Commands&lt;br /&gt;
  70  H0   0   Arpeggio                  B xy x=semitone #1, y=semitone #2&lt;br /&gt;
  71  H1   E5  Set Finetune              B xx xx=finetune&lt;br /&gt;
  72  H2       Set Balance               B xx xx=Balance (0-15)&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
 Sample segment&lt;br /&gt;
 0    4   ID     &#039;PSAM&#039; (Psm SAMple)&lt;br /&gt;
 4    ?  Data    Sample data&lt;br /&gt;
&lt;br /&gt;
 Sample header segment&lt;br /&gt;
 0    4   ID     &#039;PSAH&#039; (Psm SAmple Header)&lt;br /&gt;
 4    ?  Data    Sample headers&lt;br /&gt;
&lt;br /&gt;
 Sample header&lt;br /&gt;
 0    13  Name   Sample filename, terminated with a null.&lt;br /&gt;
 13   24  Desc   Sample description or comments.&lt;br /&gt;
 37   4   Offs   Location of raw sample data in file&lt;br /&gt;
 43   4   Mem    This is the physical offset in RAM/DRAM of the sample. (Often blank.)&lt;br /&gt;
 45   2   Num    Sample number, 1-255&lt;br /&gt;
 47   1   Type   Sample type: (In some games left blank; if this is the case then the&lt;br /&gt;
                 sample format is END, as used in most PSM New Format files)&lt;br /&gt;
                 Bit 0: 0 - Digital, 1 - Synthesized&lt;br /&gt;
                 Bit 2: 0 - 8-bit, 1 - 16-bit&lt;br /&gt;
                 Bit 3: 0 - Signed, 1 - Unsigned&lt;br /&gt;
                 Bit 4: 0 - Deltas, 1 - Raw&lt;br /&gt;
                 Bit 5: 0 - Loop normally, 1 - Bidirectional&lt;br /&gt;
                 Bit 6: 1 - Gravis patch (unsupported)&lt;br /&gt;
                 Bit 7: 0 - No loop, 1 - Loop sample&lt;br /&gt;
 48   4   Len    Sample length, in bytes.&lt;br /&gt;
 52   4   Rep st Sample repeat start; if sample loops, the loop starts here.&lt;br /&gt;
 56   4   Rep fn Sample repeat end, if sample loops, it ends here. If this is less than the sample&lt;br /&gt;
                 repeat start, the sample loops backwards.&lt;br /&gt;
 60   1   Tune   Fine tune; range 0-15, Tune 0-7 = 0-7; tune -1 - -8 = 8-15&lt;br /&gt;
 61   1   Vol    Sample volume, 0-64&lt;br /&gt;
 62   2   Freq   This is the frequency for the sample at a C of Octave 2.&lt;br /&gt;
                 Typical values are 8,000 hz to 8,448 hz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like in S3M, sample headers are stored separately from the raw sample data.&lt;br /&gt;
&lt;br /&gt;
A type of sample storage used often, like in the PSM New Format is &#039;Deltas&#039;, which converts a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte, often making them compress better using general-purpose file compression tools. Thus:&lt;br /&gt;
&lt;br /&gt;
 RAW:        64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: 11  64   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
This is done to make files more compressible, but doesn&#039;t seem to be used much.&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.shikadi.net/files/psm2scrm.zip psm2scrm.zip] - DOS program to convert .PSM songs into ScreamTracker .S3M format, suitable for playing in your favourite tracker/module player. Works only with PSM New Format and is not nearly as accurate as OpenMPT.&lt;br /&gt;
* [http://openmpt.org OpenMPT] 1.18 and newer can load all PSM and PSM16 files.&lt;br /&gt;
* [http://openmpt.org/legacy_software ModPlug Tracker] and OpenMPT 1.17 can play the files and save them as S3M. More complex songs don&#039;t load correctly though. Works only with new format.&lt;br /&gt;
* [http://kode54.foobar2000.org/ foo_dumb] is a plugin for various module formats for the Foobar2k media player. It supports both PSM16 and PSM and is similar to OpenMPT in playback quality.&lt;br /&gt;
* [http://ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/mxinfo/epictest.zip EPICTEST] is a demonstration of the Epic Megagames MASI. It contains CONVERT.EXE which can be used to convert modules to the new PSM format.&lt;br /&gt;
* [http://www.jazz2online.com/J2Ov2/downloads/info.php?levelID=5471#29435] JJ1MOD can convert S3M files to new PSM, though often with errors (Though these are usually only detectable with older programs such as game executables.) It is currently the only utility able to do this, and works only with New Format.&lt;br /&gt;
&lt;br /&gt;
= Notes =&lt;br /&gt;
&lt;br /&gt;
The New PSM format was reverse engineered by Levellord and tidied up by Levellass. It is possible there may be minor errors in the sample format information, especially since this is poorly documented.&lt;br /&gt;
Some format definitions have been updated and corrected by Johannes Schultz of the OpenMPT development team.&lt;br /&gt;
&lt;br /&gt;
The PSM16 format documentation was found on Wotsit and written up by Levellass (this appears to be an official document from the MASI developer). More info is needed.&lt;br /&gt;
&lt;br /&gt;
In all formats the following table shows how note bytes are converted into actual notes: (PSM new format has the widest range, 0-255)&lt;br /&gt;
&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;br /&gt;
           | C-0   0 | C-1  12 | C-2  24 | C-3  36 | C-4  48 |&lt;br /&gt;
           | C#0   1 | C#1  13 | C#2  25 | C#3  37 | C#4  49 |&lt;br /&gt;
           | D-0   2 | D-1  14 | D-2  26 | D-3  38 | D-4  50 |&lt;br /&gt;
           | D#0   3 | D#1  15 | D#2  27 | D#3  39 | D#4  51 |&lt;br /&gt;
           | E-0   4 | E-1  16 | E-2  28 | E-3  40 | E-4  52 |&lt;br /&gt;
           | F-0   5 | F-1  17 | F-2  29 | F-3  41 | F-4  53 |&lt;br /&gt;
           | F#0   6 | F#1  18 | F#2  30 | F#3  42 | F#4  54 |&lt;br /&gt;
           | G-0   7 | G-1  19 | G-2  31 | G-3  43 | G-4  55 |&lt;br /&gt;
           | G#0   8 | G#1  20 | G#2  32 | G#3  44 | G#4  56 |&lt;br /&gt;
           | A-0   9 | A-1  21 | A-2  33 | A-3  45 | A-4  57 |&lt;br /&gt;
           | A#0  10 | A#1  22 | A#2  34 | A#3  46 | A#4  58 |&lt;br /&gt;
           | B-0  11 | B-1  23 | B-2  35 | B-3  47 | B-4  59 |&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=6937</id>
		<title>ProTracker Studio Module</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=6937"/>
		<updated>2016-08-03T00:35:26Z</updated>

		<summary type="html">&lt;p&gt;Saga: /* Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 1-256 (PSM) / 1-32 (PSM16)&lt;br /&gt;
 | NumTracks = unlimited (PSM) / 1 (PSM16)&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Epic Pinball}}&lt;br /&gt;
   {{Game|Extreme Pinball}}&lt;br /&gt;
   {{Game|Jazz Jackrabbit}}&lt;br /&gt;
   {{Game|One Must Fall}}&lt;br /&gt;
   {{Game|Silverball}}&lt;br /&gt;
   {{Game|Sinaria}}&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;ProTracker Studio Module&#039;&#039;&#039; (PSM) file format is used for the music in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]].  The file format is named after ProTracker, an Amiga program, though this program was probably actually not used to write PSM files. One Must Fall&#039;s music was written in Multitracker, and the music for Jazz Jackrabbit, Epic Pinball and Extreme Pinball probably in Scream Tracker.&lt;br /&gt;
&lt;br /&gt;
There are two file types that use the extension .PSM; they are both used by Epic Megagames&#039; MASI sound system, but are used by different versions of the system. The two formats are:&lt;br /&gt;
&lt;br /&gt;
* PSM New Format: Used by Jazz Jackrabbit, Epic Pinball, Extreme Pinball, One Must Fall, Sinaria (in this game with slight differences, see below), newest PSM format&lt;br /&gt;
* PSM 16:         Used by Silverball, an older version of the format which is closer to ScreamTracker-style modules.&lt;br /&gt;
&lt;br /&gt;
The most common of the two PSM formats is the new format, and most programs that try to interpret PSM files will be expecting this. For example, ModPlug Player cannot open Silverball files as these are in the PSM 16 format.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM New Format =&lt;br /&gt;
&lt;br /&gt;
This format is used by [[:Category:Epic Megagames|Epic]] games in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]]. It is notable for consisting of a number of segments (chunks) and sub segments. It bears the 4-byte signature &#039;PSM &#039; at the file start.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Song segment&lt;br /&gt;
 Samples&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 12 bytes long:&lt;br /&gt;
&lt;br /&gt;
 File header:&lt;br /&gt;
 0   4  ID     &#039;PSM &#039;; indicates file is PSM format&lt;br /&gt;
 4   4  Size   Filesize - 12&lt;br /&gt;
 8   4  ID2    &#039;FILE&#039;; indicates start of file info&lt;br /&gt;
&lt;br /&gt;
After the header, some chunks follow in IFF-style. You should not expect chunks to come up in the same order as they are described here. A good way to handle chunks is to read the 4-Byte ID and the 4-Byte size field first, then evaluate the ID and decide what to do next based on this ID. Note that the size field does not include the ID and itself; it only holds the size of the chunk &#039;&#039;content&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Title segment ==&lt;br /&gt;
&lt;br /&gt;
This segment is optional, and one of the few segments that can be absent when playing PSM files in most programs. (Most programs expect all other segments to exist, even if they are not vital.)&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;TITL&#039;; indicates a title follows&lt;br /&gt;
 4   4  Size   Size of title as dword after this dword&lt;br /&gt;
 8   ?  Title  Song title&lt;br /&gt;
&lt;br /&gt;
== Song info segment ==&lt;br /&gt;
&lt;br /&gt;
This segment seems to indicate the beginning of the song data and is not really relevant when parsing.&lt;br /&gt;
&lt;br /&gt;
 12  4  ID     &#039;SDFT&#039;; indicates start of format info&lt;br /&gt;
 16  4  Size   Size of next header as dword, (8)&lt;br /&gt;
 20  8  Song   &#039;MAINSONG&#039;; indicates song type. No other song types are known.&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
Each pattern is stored in its own PBOD chunk. Note that there are two possible formats for this chunk; one is used in the &amp;quot;old&amp;quot; format (as used in Epic Pinball, Extreme Pinball, Jazz Jackrabbit, One Must Fall) and the other in the &amp;quot;new&amp;quot; format (as used in Sinaria)&lt;br /&gt;
&lt;br /&gt;
 Pattern segment:&lt;br /&gt;
 0   4  ID     &#039;PBOD&#039;; indicates a pattern follows (Pattern BODy)&lt;br /&gt;
 4   4  Size   Length of pattern data as dword, after this dword&lt;br /&gt;
 4   4  Size   Same value again.&lt;br /&gt;
&lt;br /&gt;
 Pattern:&lt;br /&gt;
 0 4/8  Number Pattern ID. See note below.&lt;br /&gt;
 4   2  Row n  Number of rows in ALL channels in pattern (64 usually, but can differ.) as word.&lt;br /&gt;
 6   ?  Data   Contains pattern data as a number of rows of interlaced channels (12341234...)&lt;br /&gt;
               &#039;&#039;Usual&#039;&#039; settings is 64 rows of 4 channels. Epic Pinball has shorter patterns for example, but they also include a &amp;quot;break to row&amp;quot; command at the end of the pattern.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; In the old format, this starts with a &#039;P&#039; and is followed by an integer number which is the pattern number, padded to 4 bytes with spaces. Caution: This number might or might not be zero-padded; In some files, the ID of the first pattern could be &#039;P0  &#039;, but there are also files where it is &#039;P00 &#039;!. In C/C++, you could use atoi() to parse this value. In the new format (Sinaria), This field is 8 bytes long instead of 4 bytes, and the first 4 bytes read &amp;quot;PATT&amp;quot;, so the first pattern could be for example &#039;PATT0   &#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Pattern row channel entry:&lt;br /&gt;
 ?   1  Flags  Contains four flags that indicate which pattern data follows&lt;br /&gt;
 +1  1  Chan   The channel this data belongs to.&lt;br /&gt;
 +2  1  Note   Present if bit 7 in Flags is set. Pitch, $01 is C-1, etc... The octaves&lt;br /&gt;
               are aligned by 16, i.e. B-1 is $0C but the next note, C-2, is $10.&lt;br /&gt;
 +3  1  Ins    Present if bit 6 in Flags is set. Instrument used, 0-31&lt;br /&gt;
 +4  1  Vol    Present if bit 5 in Flags is set. Volume change to, 0-63 = 0-127; optional&lt;br /&gt;
 +5  1  Effect Present if bit 4 in Flags is set. Effect to use, volume slide, Portamanto...&lt;br /&gt;
 +6  x  Eff Am Present if bit 4 in Flags is set. Parameter of effect, e.g amount of slide&lt;br /&gt;
&lt;br /&gt;
Each row consists of a word giving the size of the row (Including the word) followed by the channel data. A channel is only included if it has data in it, but a totally empty row is still included. So an &#039;empty&#039; row (Where none of the channels have data.) thus consists of just a word of value 2.&lt;br /&gt;
&lt;br /&gt;
Each channel entry consists of between 3-7 bytes. The first byte is a flag that shows what data follows. (The highest four bits indicate whether there are bytes for the following four variables; Note ($80), Instrument ($40), Volume ($20), Effect AND Effect parameter ($10). Thus 5 bytes are represented by a combination of 4 possibilities.) The next byte identifies the channel (Since each channel may or may not be present.) starting at 0 for channel 1. The remaining 5 bytes may or may not be present depending on their flag and contain data for Note, Instrument(Sample) used, Volume change for channel, Effect and Effect parameter.&lt;br /&gt;
&lt;br /&gt;
There are several things to note about this; Effect and Effect magnitude MUST occur together. Sample numbers, like channels are numbered starting at 0, not 1. Magnitudes (For effect AND volume) are from 0-127, not 0-64 as in other formats.&lt;br /&gt;
&lt;br /&gt;
=== Effect conversion ===&lt;br /&gt;
&lt;br /&gt;
Note that this table is guaranteed to be correct; Most effects seem to be converted correctly, though. Note that these values are not correct for the PSM files that can be found in the game Sinaria. Leave out all divisions and it will be correct again.&lt;br /&gt;
&lt;br /&gt;
 PSM Command   Param length  S3M Command&lt;br /&gt;
 &lt;br /&gt;
  Volume commands&lt;br /&gt;
    1           1 Byte        DxF - fine volside up&lt;br /&gt;
    2           1 Byte        Dx0 - volslide up&lt;br /&gt;
    3           1 Byte        DFx - fine volslide down&lt;br /&gt;
    4           1 Byte        D0x - volslide down&lt;br /&gt;
 &lt;br /&gt;
 Portamento commands&lt;br /&gt;
    B           1 Byte        FFx - fine porta up (divide x by 4)&lt;br /&gt;
    C           1 Byte        Fxx - porta up (if x &amp;lt; 4, use FFx, else divide x by 4)&lt;br /&gt;
    D           1 Byte        EFx - fine porta down (divide x by 4)&lt;br /&gt;
    E           1 Byte        Exx - porta down (if x &amp;lt; 4, use EFx, else divide x by 4)&lt;br /&gt;
    F           1 Byte        Gxx - portamento (divide x by 4)&lt;br /&gt;
   10           1 Byte        S1x - glissando control&lt;br /&gt;
   11           1 Byte        Lx0 - tone porta + volslide up&lt;br /&gt;
   12           1 Byte        L0x - tone porta + volslide down&lt;br /&gt;
    &lt;br /&gt;
 Vibrato&lt;br /&gt;
   15           1 Byte        Hxy - vibrato&lt;br /&gt;
   16           1 Byte        S3x - vibrato waveform&lt;br /&gt;
   17           1 Byte        K0x - vibrato + volslide up&lt;br /&gt;
   18           1 Byte        Kx0 - vibrato + volslide down&lt;br /&gt;
   	&lt;br /&gt;
 Tremolo			&lt;br /&gt;
   1F           1 Byte        Rxy - tremolo&lt;br /&gt;
   20           1 Byte        S4x - tremolo waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample commands&lt;br /&gt;
   29           3 Bytes       Oxx - offset (xx corresponds to the 2nd byte)&lt;br /&gt;
   2A           1 Byte        Q0x - retrigger&lt;br /&gt;
   2B           1 Byte        SCx - note cut&lt;br /&gt;
   2C           1 Byte        SDx - note delay&lt;br /&gt;
 &lt;br /&gt;
 Position change&lt;br /&gt;
   33           2 Bytes       Bxx - position jump - ignored by PLAY.EXE&lt;br /&gt;
   34           1 Byte        Cxx - break to row&lt;br /&gt;
                                    PLAY.EXE entirely ignores the parameter (it always breaks to the first&lt;br /&gt;
                                    row), so it is maybe best to do this in your own player as well.&lt;br /&gt;
                                    If the original file was an S3M, the parameter is double-BCD-encoded,&lt;br /&gt;
                                    i.e. on top of the original format&#039;s BCD encoding, the same encoding&lt;br /&gt;
                                    is applied again. to translate into the correct target row in binary,&lt;br /&gt;
                                    apply this twice: param = (param &amp;amp; 0xF0) * 10 + (param &amp;amp; 0x0F)&lt;br /&gt;
                                    For MOD files, the parameter is a normal binary number.&lt;br /&gt;
   35           1 Byte        SBx - pattern loop&lt;br /&gt;
   36           1 Byte        SEx - pattern delay&lt;br /&gt;
  &lt;br /&gt;
 Speed change&lt;br /&gt;
   3D           1 Byte        Axx - set speed&lt;br /&gt;
   3E           1 Byte        Txx - set tempo&lt;br /&gt;
 &lt;br /&gt;
 Misc. commands&lt;br /&gt;
   47           1 Byte        Jxy - arpeggio&lt;br /&gt;
   48           1 Byte        S2x - set finetune&lt;br /&gt;
   49           1 Byte        S8x - set balance&lt;br /&gt;
&lt;br /&gt;
Effect interpretation is different in Sinaria&#039;s new format. Slide command parameters are more like in PSM16.&lt;br /&gt;
&lt;br /&gt;
== Song segment ==&lt;br /&gt;
&lt;br /&gt;
This segment contains most of the important data used to play the song. It contains several sub-segments, each of the same format as a normal segment, but contained in the song segment. Note that there might be more than one song segment and thus, more than one order list, default speed, default tempo, etc... For example, in Extreme Pinball, all the different jingles and mission songs are stored as separate SONG chunks. It is up to the developer to find a clever way of managing / playing several sub songs.&lt;br /&gt;
&lt;br /&gt;
 Segment structure:&lt;br /&gt;
 0   4  ID     &#039;SONG&#039; indicates start of song structure&lt;br /&gt;
 4   4  Size   Size of song structure, including all sub-segments&lt;br /&gt;
 8   9  Type   Type of song this is for; This is &#039;MAINSONG &#039; in almost all PSM files. Extreme Pinball has several SONG items with different types!&lt;br /&gt;
 17  1  Comp   Compression, for PSM = 1 (Uncompressed)&lt;br /&gt;
 18  1  Chan   Number of channels, usually, but not always, 4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Date sub-segment ===&lt;br /&gt;
&lt;br /&gt;
This dates the file and is used by some programs. It is usually the first sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DATE&#039; indicates date data&lt;br /&gt;
 4   4  Size   Size of date segment (6)&lt;br /&gt;
 8   6  Date   Date as text, YYMMDD&lt;br /&gt;
&lt;br /&gt;
This can also be used as a way to heuristically detect if the new version of the format is being used. Sinaria&#039;s song dates are: 800211, 940902, 940903, 940906, 940914, 941213&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Order sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Orders describe how patterns are arranged in the song. This allows the same pattern of instruments to be played more than once in a song (e.g. a chorus). without the pattern data having to be duplicated. There should be only one order. This section also contains basic song information. It usually follows the date sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;OPLH&#039; indicates start of pattern placement order&lt;br /&gt;
 4   4  Size   Size of order segment&lt;br /&gt;
 8   2  Cnt.   Number of following chunks&lt;br /&gt;
&lt;br /&gt;
Now, the following chunks may follow until the end of the &amp;quot;OPLH&amp;quot; chunk is reached. Every chunk is identified by the first byte:&lt;br /&gt;
* $00 (1 Byte): End (Nothing follows)&lt;br /&gt;
* $01 (5/9 Bytes): Order list item follows (e.g. &amp;quot;P0  &amp;quot;, &amp;quot;P12 &amp;quot; in old format or &amp;quot;PATT0   &amp;quot; in new format, see above) - join those to get the complete order list.&lt;br /&gt;
* $04 (3 Bytes): This 16-bit value indicates the &amp;quot;restart chunk&amp;quot;. If the end of the subsong is reached, it will jump back to this chunk. In many cases, this would be 4th chunk (no 3rd chunk, as the chunk index is starting at 0!), which is a panning index in most PSMs - So you would just go to the nearest order list item that&#039;s following this chunk. However, this can also point to a valid order list chunk.&lt;br /&gt;
* $07 (2 Bytes): Next byte is default speed for this subtune&lt;br /&gt;
* $08 (2 Bytes): Next byte is default tempo for this subtune&lt;br /&gt;
* $0C (7 Bytes): Sample map table(?): This chunk is always $0C $00 $FF $00 $00 $01 $00. The purpose is unknown.&lt;br /&gt;
* $0D (4 Bytes): Channel panning index. Next byte is channel number (Start at 0), then initial pan ($00 ... $FF) and a byte follow. The byte seems to tell what to do with the previous pan position (0 - use it, 2 - ignore it, make this channel surround, 4 - set to center).&lt;br /&gt;
* $0E (3 Bytes): Channel volume index. Next byte is channel number (Start at 0), then volume ($00 ... $FF). $FF in most cases. Some OMF 2097 tracks use a lower volume.&lt;br /&gt;
&lt;br /&gt;
=== Pattern list ===&lt;br /&gt;
&lt;br /&gt;
This is simply a list of all the patterns used in the file. You do not really need to parse this, it seems to be a purely informational chunk.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;PATT&#039; indicates start of pattern list&lt;br /&gt;
 4   4  Size   Size of pattern list after this&lt;br /&gt;
 8   4  Size   Same as above&lt;br /&gt;
 12  4x Pat    An ordered list &#039;P0  &#039;, &#039;P1  &#039;... for all patterns in the file, each entry 4 bytes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sample list sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Similar to the above, this is a list of all the samples used in the file. It is usually the last sub-segment in the song segment and you do not really need to parse this.&lt;br /&gt;
&lt;br /&gt;
  0  4   ID     &#039;DSAM&#039;; indicates start of sample list, used to say what samples are &#039;full&#039;&lt;br /&gt;
                Any samples not on this list will be ignored, even if they have data&lt;br /&gt;
  4  4   Size   Size of list after this&lt;br /&gt;
  8  4   Size   Same value as above&lt;br /&gt;
  12 15x Entry  Sample entries, one for each sample in the file, each entry 15 bytes&lt;br /&gt;
&lt;br /&gt;
 Sample entry:&lt;br /&gt;
 0   8  Format Sample format, padded with spaces (END, RAG2...) This is important to some programs&lt;br /&gt;
 8   4  ID     &#039;I0  &#039;, &#039;I1  &#039;... the sample ID (&#039;I&#039; means &#039;Instrument&#039;). Again, be sure to accept both &#039;I0  &#039; and &#039;I00 &#039;!&lt;br /&gt;
 12  2  Num    The sample number, 0,1,2... for the sample&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
Samples are the raw sound data that makes up the instruments on the song. The actual format depends on the sample format. Samples have information in their headers which allows data to be played at different pitches (Speeds.) and to loop from and to various points in the data. This is by far the largest part of the file, since the raw data takes up so much space.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DSMP&#039; indicates start of sample&lt;br /&gt;
 4   4  Size   Size of following sample as &#039;DSMP&#039; + dword from end of word&lt;br /&gt;
 8   9  Flags  If highest bit is set, then sample is looped&lt;br /&gt;
 9   8  Songn. Filename of the original module (without extension)&lt;br /&gt;
 17  4  INSx   Last digit of sample (Instrument) number, 0-9; with 31 instruments possible&lt;br /&gt;
               Only last digit is shown. E.g 1st, 11th, 21st and 31st sample is &#039;INS0&#039;&lt;br /&gt;
 21  33 Name   Defines the instrument name or file, usually a .st or line of text&lt;br /&gt;
 54  51 Header Sample parameters (Can also 58 bytes long, padded with nuls)&lt;br /&gt;
               Byte 1-6 are unknown (but apparently always $00 $00 $00 $00 $00 $FF)&lt;br /&gt;
               Bytes 7-8 is instrument number&lt;br /&gt;
               Bytes 9-12 are sample length&lt;br /&gt;
               Bytes 13-16 are loop start&lt;br /&gt;
               Bytes 17-20 are loop end (all $FF means at end of sample)&lt;br /&gt;
               Bytes 21-22 are unknown (second byte could be default pan, but seems to be unused)&lt;br /&gt;
               Byte 23 is default volume&lt;br /&gt;
               Bytes 24-27 are unknwon&lt;br /&gt;
               Bytes 28-31 is frequency (Sample rate)&lt;br /&gt;
               19 $00-bytes follow&lt;br /&gt;
 105 ?  Data   Music data in 8-bit mono format&lt;br /&gt;
&lt;br /&gt;
The sample header is slightly different in Sinaria&#039;s new format: INSx is 8 bytes long (like the PATT IDs), and the last 21 $00-bytes are just 16 bytes.&lt;br /&gt;
&lt;br /&gt;
The PSM new format, along with the PSM 16 format use delta-encoded samples, something to make the file smaller when zipped. &#039;Deltas&#039;, convert a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. It has the effect that if a single byte in the sample is changed, the entire sample will be degraded. This use of deltas varies slightly from that of the PSM 16. The &#039;start value&#039; of the string is assumed to be $80 (128) and the first byte will thus turn this into the first desired value, the second delta converts the first value to the second, and so on.) All deltas are signed, 1-byte values, but loop (Thus 10 - 20 = -10 can also be considered as 10 + 236 = 246). An example of this is as follows:&lt;br /&gt;
&lt;br /&gt;
 RAW:   (128) 64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: -64  0   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Encryption ==&lt;br /&gt;
&lt;br /&gt;
CONVERT.EXE can produce &amp;quot;encrypted&amp;quot; PSM files with the /K command line switch. The encryption scheme is simple: It adds 1 to the first byte, 2 to the second, 3 to the third, and so until, for the entire file. It does not appear like any game made use of this feature, though.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM 16 =&lt;br /&gt;
&lt;br /&gt;
This is the format used in [[Silverball]], early versions of Epic Pinball and possibly other games. The designation &#039;Protracker Studio 16 format&#039; was given to it by the only reliable source of information on this format, and may not be the official designation.&lt;br /&gt;
&lt;br /&gt;
The format bears many similarities to the S3M format; the file is set out roughly the same, patterns and samples are similar, indeed, near identical and the functionality is similar. It also shows many similarities to the ProTracker MOD format and retains vestiges of Amiga compatibility.&lt;br /&gt;
&lt;br /&gt;
This format can be identified by its signature &#039;PSMþ&#039;, though files may lack this and still function.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Order&lt;br /&gt;
 Pan segment&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Sample data&lt;br /&gt;
 Sample headers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
 0    4  Sig      Signature, &#039;PSMþ&#039;&lt;br /&gt;
 4    59 Title    Song title, padded with nulls. Unlike other formats, this must also be terminated&lt;br /&gt;
                  with a null byte. (It sometimes is not terminated, though.)&lt;br /&gt;
 62   1           This must be $1A to end the song name, like in S3M format.&lt;br /&gt;
 64   1  Type     Song type, First bit: 0 - Module (w/samp.), 1 - Song (w/o samples)&lt;br /&gt;
                  Second bit: 0 - 3 octave Protracker, 1 - 5 octave; remaining bits reserved.&lt;br /&gt;
 65   1  PSM v    PSM format version, $10 for this format (Hence the name PSM 16) = &#039;v1.00&#039;.&lt;br /&gt;
                  Sometimes, this is also $01, but there&#039;s no difference in the format itself.&lt;br /&gt;
 66   1  Patt v   Pattern version, 0 or 1. 0 means the pattern is stored in the module are in the 32&lt;br /&gt;
                  channel file format.  A 1 signifies the patterns as being stored as a 255&lt;br /&gt;
                  channel format. (I have not found any PSM16 modules that have this format.)&lt;br /&gt;
 67   1   Speed   Song speed&lt;br /&gt;
 68   1   BPM     Beats per minute, the default Amiga BPM value. (The only reason that the Amiga BPM&lt;br /&gt;
                  format is still followed here is that it allows more control over the final hz value.)&lt;br /&gt;
                  Range: 32 to 255.&lt;br /&gt;
 69   1   Vol     Master volume of song, 0-255&lt;br /&gt;
 70   2   Len     Song length, 0-255. The number of patterns to play in the song, in total.&lt;br /&gt;
 72   2   Ordlen  The number of orders actually stored at the order offset. It was hoped that the&lt;br /&gt;
                  PSM 16 format would allow multiple orders, so this would be the length of the first&lt;br /&gt;
                  order. This doesn&#039;t appea to ahve happened, and is usually the same as the previous value.&lt;br /&gt;
 74   2   Patnum  Number of patterns in the song. 1-255&lt;br /&gt;
 76   2   Sampnum Number of samples and &#039;sample structures&#039; in song, 1-255&lt;br /&gt;
 78   2   NCIS    Number of channels in song to PLAY. 1-32. &lt;br /&gt;
 80   2   NCP     Number of Channels to Process; describes the MAXIMUM number of channels to process.&lt;br /&gt;
                  As an example, when converting 669 files,  NCP = 9 because some track information &lt;br /&gt;
                  is in Channel 8, but the Number of Channels to Play was set to 8, (Channel numbers&lt;br /&gt;
                  to play from 0 to 7.) 1-32&lt;br /&gt;
 82   4   Ordoff  Location of order in header&lt;br /&gt;
 86   4   Panoff  Location of pan positions in header&lt;br /&gt;
 90   4   Patoff  Location of patterns in header&lt;br /&gt;
 94   4   Sampoff Location of sample headers in header&lt;br /&gt;
 98   4   Commoff Location of comments in header&lt;br /&gt;
 102  4   Patsiz  Total pattern size; the total size of all the patterns loaded from the pattern offset.&lt;br /&gt;
 106  40  Fillers 10 fillers, to be used for any possible expansions.&lt;br /&gt;
&lt;br /&gt;
It is important to notice that the offsets point to the first byte &#039;&#039;&#039;after&#039;&#039;&#039; the chunk ID, i.e. &amp;quot;Ordoff&amp;quot; points to the first byte after &amp;quot;PORD&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Order and Pan positions ==&lt;br /&gt;
&lt;br /&gt;
These are two separate segments, pointed to in the header. They may be anywhere, but usually follow the header sometimes after an amount of blank space. They are often padded with blank space. They are basically lists.&lt;br /&gt;
&lt;br /&gt;
Order: This segment is pointed to in the header, and sets the PSM 16 format apart. The PSM 16 format was designed to be much more like the MOD format, allowing game designers to set flags to switch from one set of patterns to another, in effect allowing one file to contain more than one song. (For example a boss flag might make the music switch from a clam patterns 1-4 to a racy and dangerous patterns 5-7.)&lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    Signature, not needed, &#039;PORD&#039;&lt;br /&gt;
 4    ?   Ords   Pattern numbers and order. There will be [Ordlen] bytes of patterns&lt;br /&gt;
 ?    2   Lang   Order language, not implemented, so left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pan Positions: &lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    &#039;PPAN&#039;&lt;br /&gt;
 4    12  Pan    Pan positions; empty positions left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
 0    2   Size   Size of pattern, including these bytes&lt;br /&gt;
 2    1   Len    Length of pattern, in rows. Max length is 64 rows.&lt;br /&gt;
 3    1   Chan   Number of channels in pattern, 1-32&lt;br /&gt;
 4    ?   Data   Pattern data&lt;br /&gt;
&lt;br /&gt;
This is similar to the previous two segments, except actual pattern data is stored here. Patterns are very similar to the S3M format, and consist of y rows of x channels. Each row contains a number of channels and ends with a byte of value 0. Each channel is between 2-6+ bytes long. A totally empty channel is represented by a single byte of value 0.&lt;br /&gt;
&lt;br /&gt;
Each channel starts with a flag byte, abcddddd, where a,b and c indicate whether there is a note and instrument, volume or special effect and effect magnitude in the following data, and dddd is the channel number (0-31, used since a given channel may or may not be present in a row.)&lt;br /&gt;
&lt;br /&gt;
The usual maximum length of a channel entry is 6 bytes (1 flag byte, 2 Note AND instrument bytes, 1 volume byte and two Effect and Effect magnitude bytes.) Thus Note&amp;amp;ins\Eff&amp;amp;Eff mag must always occur together.&lt;br /&gt;
&lt;br /&gt;
Like S3M, volume range is 0-64, as is special magnitude. However, special effects range from 0-255, like PSM New Format.&lt;br /&gt;
&lt;br /&gt;
=== Effects conversion ===&lt;br /&gt;
&lt;br /&gt;
 ###  Co  MOD  Description               Arguments&lt;br /&gt;
 ---  --  ---  -----------               ---------&lt;br /&gt;
 Volume Commands&lt;br /&gt;
   1  A1   EA  Fine Volume Slide Up      B xx xx=speed&lt;br /&gt;
   2  A2   A   Volume Slide Up           B xx xx=speed&lt;br /&gt;
   3  A3   EB  Fine Volume Slide Down    B xx xx=speed&lt;br /&gt;
   4  A4   A   Volume Slide Down         B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Portamento Commands&lt;br /&gt;
  10  B0   E1  Fine Porta Up             B xx xx=speed&lt;br /&gt;
  11  B1   1   Portamento Up             B xx xx=speed&lt;br /&gt;
  12  B2   E2  Fine Porta Down           B xx xx=speed&lt;br /&gt;
  13  B3   2   Portamento Down           B xx xx=speed&lt;br /&gt;
  14  B4   3   Tone Portamento           B xx xx=speed&lt;br /&gt;
  15  B5   E3  Set Glissando Control     B xx xx=0 - Off, 1 - On&lt;br /&gt;
  16  B6   5   Tone Port+Vol Slide Up    B xx xx=speed&lt;br /&gt;
  17  B7   5   Tone Port+Vol Slide Down  B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Vibrato Commands&lt;br /&gt;
  20  C0   4   Vibrato                   B xy x=speed, y=depth&lt;br /&gt;
  21  C1   E4  Set Vibrato Waveform      B x  x=Waveform&lt;br /&gt;
  21  C2   6   Vibrato+Vol Slide Up      B xx xx=speed&lt;br /&gt;
  22  C3   6   Vibrato+Vol Slide Down    B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Tremolo Commands&lt;br /&gt;
  30  D0   7   Tremolo                   B xy x=speed, y=depth&lt;br /&gt;
  31  D1   E7  Set Tremolo Control       B x  x=Waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample Commands&lt;br /&gt;
  40  E0   9   Sample Offset             3B Position for offset change (0-1,048,575)&lt;br /&gt;
  41  E1   E9  Retrig Note               B xx xx=tick to retrigger sample&lt;br /&gt;
  42  E2   EC  Note Cut                  B xx xx=tick to cut note&lt;br /&gt;
  43  E3   ED  Note Delay                B xx xx=ticks to delay note&lt;br /&gt;
 &lt;br /&gt;
 Pos. Change Commands&lt;br /&gt;
  50  F0   B   Position Jump             B xx xx=order position&lt;br /&gt;
  51  F1   D   Pattern Break             B xx Skip to line xx in next pattern&lt;br /&gt;
  52  F2   E6  Jump Loop                 B xx xx=number of loops  0 Set&lt;br /&gt;
  53  F3   EE  Pattern Delay             B xx xx=notes to delay pattern&lt;br /&gt;
 &lt;br /&gt;
 Speed Change Cmds&lt;br /&gt;
  60  G0   F   Set Regular Speed         B xx xx=speed&lt;br /&gt;
  61  G1   F   Set BPM                   B xx xx=BPM (32-255)&lt;br /&gt;
 &lt;br /&gt;
 Misc. Commands&lt;br /&gt;
  70  H0   0   Arpeggio                  B xy x=semitone #1, y=semitone #2&lt;br /&gt;
  71  H1   E5  Set Finetune              B xx xx=finetune&lt;br /&gt;
  72  H2       Set Balance               B xx xx=Balance (0-15)&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
 Sample segment&lt;br /&gt;
 0    4   ID     &#039;PSAM&#039; (Psm SAMple)&lt;br /&gt;
 4    ?  Data    Sample data&lt;br /&gt;
&lt;br /&gt;
 Sample header segment&lt;br /&gt;
 0    4   ID     &#039;PSAH&#039; (Psm SAmple Header)&lt;br /&gt;
 4    ?  Data    Sample headers&lt;br /&gt;
&lt;br /&gt;
 Sample header&lt;br /&gt;
 0    13  Name   Sample filename, terminated with a null.&lt;br /&gt;
 13   24  Desc   Sample description or comments.&lt;br /&gt;
 37   4   Offs   Location of raw sample data in file&lt;br /&gt;
 43   4   Mem    This is the physical offset in RAM/DRAM of the sample. (Often blank.)&lt;br /&gt;
 45   2   Num    Sample number, 1-255&lt;br /&gt;
 47   1   Type   Sample type: (In some games left blank; if this is the case then the&lt;br /&gt;
                 sample format is END, as used in most PSM New Format files)&lt;br /&gt;
                 Bit 0: 0 - Digital, 1 - Synthesized&lt;br /&gt;
                 Bit 2: 0 - 8-bit, 1 - 16-bit&lt;br /&gt;
                 Bit 3: 0 - Signed, 1 - Unsigned&lt;br /&gt;
                 Bit 4: 0 - Deltas, 1 - Raw&lt;br /&gt;
                 Bit 5: 0 - Loop normally, 1 - Bidirectional&lt;br /&gt;
                 Bit 6: 1 - Gravis patch (unsupported)&lt;br /&gt;
                 Bit 7: 0 - No loop, 1 - Loop sample&lt;br /&gt;
 48   4   Len    Sample length, in bytes.&lt;br /&gt;
 52   4   Rep st Sample repeat start; if sample loops, the loop starts here.&lt;br /&gt;
 56   4   Rep fn Sample repeat end, if sample loops, it ends here. If this is less than the sample&lt;br /&gt;
                 repeat start, the sample loops backwards.&lt;br /&gt;
 60   1   Tune   Fine tune; range 0-15, Tune 0-7 = 0-7; tune -1 - -8 = 8-15&lt;br /&gt;
 61   1   Vol    Sample volume, 0-64&lt;br /&gt;
 62   2   Freq   This is the frequency for the sample at a C of Octave 2.&lt;br /&gt;
                 Typical values are 8,000 hz to 8,448 hz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like in S3M, sample headers are stored separately from the raw sample data.&lt;br /&gt;
&lt;br /&gt;
A type of sample storage used often, like in the PSM New Format is &#039;Deltas&#039;, which converts a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte, often making them compress better using general-purpose file compression tools. Thus:&lt;br /&gt;
&lt;br /&gt;
 RAW:        64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: 11  64   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
This is done to make files more compressible, but doesn&#039;t seem to be used much.&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.shikadi.net/files/psm2scrm.zip psm2scrm.zip] - DOS program to convert .PSM songs into ScreamTracker .S3M format, suitable for playing in your favourite tracker/module player. Works only with PSM New Format and is not nearly as accurate as OpenMPT.&lt;br /&gt;
* [http://openmpt.org OpenMPT] 1.18 and newer can load all PSM and PSM16 files.&lt;br /&gt;
* [http://openmpt.org/legacy_software ModPlug Tracker] and OpenMPT 1.17 can play the files and save them as S3M. More complex songs don&#039;t load correctly though. Works only with new format.&lt;br /&gt;
* [http://kode54.foobar2000.org/ foo_dumb] is a plugin for various module formats for the Foobar2k media player. It supports both PSM16 and PSM and is similar to OpenMPT in playback quality.&lt;br /&gt;
* [http://ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/mxinfo/epictest.zip EPICTEST] is a demonstration of the Epic Megagames MASI. It contains CONVERT.EXE which can be used to convert modules to the new PSM format.&lt;br /&gt;
* [http://www.jazz2online.com/J2Ov2/downloads/info.php?levelID=5471#29435] JJ1MOD can convert S3M files to new PSM, though often with errors (Though these are usually only detectable with older programs such as game executables.) It is currently the only utility able to do this, and works only with New Format.&lt;br /&gt;
&lt;br /&gt;
= Notes =&lt;br /&gt;
&lt;br /&gt;
The New PSM format was reverse engineered by Levellord and tidied up by Levellass. It is possible there may be minor errors in the sample format information, especially since this is poorly documented.&lt;br /&gt;
Some format definitions have been updated and corrected by Johannes Schultz of the OpenMPT development team.&lt;br /&gt;
&lt;br /&gt;
The PSM16 format documentation was found on Wotsit and written up by Levellass (this appears to be an official document from the MASI developer). More info is needed.&lt;br /&gt;
&lt;br /&gt;
In all formats the following table shows how note bytes are converted into actual notes: (PSM new format has the widest range, 0-255)&lt;br /&gt;
&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;br /&gt;
           | C-0   0 | C-1  12 | C-2  24 | C-3  36 | C-4  48 |&lt;br /&gt;
           | C#0   1 | C#1  13 | C#2  25 | C#3  37 | C#4  49 |&lt;br /&gt;
           | D-0   2 | D-1  14 | D-2  26 | D-3  38 | D-4  50 |&lt;br /&gt;
           | D#0   3 | D#1  15 | D#2  27 | D#3  39 | D#4  51 |&lt;br /&gt;
           | E-0   4 | E-1  16 | E-2  28 | E-3  40 | E-4  52 |&lt;br /&gt;
           | F-0   5 | F-1  17 | F-2  29 | F-3  41 | F-4  53 |&lt;br /&gt;
           | F#0   6 | F#1  18 | F#2  30 | F#3  42 | F#4  54 |&lt;br /&gt;
           | G-0   7 | G-1  19 | G-2  31 | G-3  43 | G-4  55 |&lt;br /&gt;
           | G#0   8 | G#1  20 | G#2  32 | G#3  44 | G#4  56 |&lt;br /&gt;
           | A-0   9 | A-1  21 | A-2  33 | A-3  45 | A-4  57 |&lt;br /&gt;
           | A#0  10 | A#1  22 | A#2  34 | A#3  46 | A#4  58 |&lt;br /&gt;
           | B-0  11 | B-1  23 | B-2  35 | B-3  47 | B-4  59 |&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=6936</id>
		<title>ProTracker Studio Module</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=6936"/>
		<updated>2016-08-02T23:12:47Z</updated>

		<summary type="html">&lt;p&gt;Saga: Mention encryption, clarify channel volume, fix sample rate field&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 1-256 (PSM) / 1-32 (PSM16)&lt;br /&gt;
 | NumTracks = unlimited (PSM) / 1 (PSM16)&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Epic Pinball}}&lt;br /&gt;
   {{Game|Extreme Pinball}}&lt;br /&gt;
   {{Game|Jazz Jackrabbit}}&lt;br /&gt;
   {{Game|One Must Fall}}&lt;br /&gt;
   {{Game|Silverball}}&lt;br /&gt;
   {{Game|Sinaria}}&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;ProTracker Studio Module&#039;&#039;&#039; (PSM) file format is used for the music in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]].  The file format is named after ProTracker, an Amiga program, though this program was probably actually not used to write PSM files. One Must Fall&#039;s music was written in Multitracker, and the music for Jazz Jackrabbit, Epic Pinball and Extreme Pinball probably in Scream Tracker.&lt;br /&gt;
&lt;br /&gt;
There are two file types that use the extension .PSM; they are both used by Epic Megagames&#039; MASI sound system, but are used by different versions of the system. The two formats are:&lt;br /&gt;
&lt;br /&gt;
* PSM New Format: Used by Jazz Jackrabbit, Epic Pinball, Extreme Pinball, One Must Fall, Sinaria (in this game with slight differences, see below), newest PSM format&lt;br /&gt;
* PSM 16:         Used by Silverball, an older version of the format which is closer to ScreamTracker-style modules.&lt;br /&gt;
&lt;br /&gt;
The most common of the two PSM formats is the new format, and most programs that try to interpret PSM files will be expecting this. For example, ModPlug Player cannot open Silverball files as these are in the PSM 16 format.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM New Format =&lt;br /&gt;
&lt;br /&gt;
This format is used by [[:Category:Epic Megagames|Epic]] games in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]]. It is notable for consisting of a number of segments (chunks) and sub segments. It bears the 4-byte signature &#039;PSM &#039; at the file start.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Song segment&lt;br /&gt;
 Samples&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 12 bytes long:&lt;br /&gt;
&lt;br /&gt;
 File header:&lt;br /&gt;
 0   4  ID     &#039;PSM &#039;; indicates file is PSM format&lt;br /&gt;
 4   4  Size   Filesize - 12&lt;br /&gt;
 8   4  ID2    &#039;FILE&#039;; indicates start of file info&lt;br /&gt;
&lt;br /&gt;
After the header, some chunks follow in IFF-style. You should not expect chunks to come up in the same order as they are described here. A good way to handle chunks is to read the 4-Byte ID and the 4-Byte size field first, then evaluate the ID and decide what to do next based on this ID. Note that the size field does not include the ID and itself; it only holds the size of the chunk &#039;&#039;content&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Title segment ==&lt;br /&gt;
&lt;br /&gt;
This segment is optional, and one of the few segments that can be absent when playing PSM files in most programs. (Most programs expect all other segments to exist, even if they are not vital.)&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;TITL&#039;; indicates a title follows&lt;br /&gt;
 4   4  Size   Size of title as dword after this dword&lt;br /&gt;
 8   ?  Title  Song title&lt;br /&gt;
&lt;br /&gt;
== Song info segment ==&lt;br /&gt;
&lt;br /&gt;
This segment seems to indicate the beginning of the song data and is not really relevant when parsing.&lt;br /&gt;
&lt;br /&gt;
 12  4  ID     &#039;SDFT&#039;; indicates start of format info&lt;br /&gt;
 16  4  Size   Size of next header as dword, (8)&lt;br /&gt;
 20  8  Song   &#039;MAINSONG&#039;; indicates song type. No other song types are known.&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
Each pattern is stored in its own PBOD chunk. Note that there are two possible formats for this chunk; one is used in the &amp;quot;old&amp;quot; format (as used in Epic Pinball, Extreme Pinball, Jazz Jackrabbit, One Must Fall) and the other in the &amp;quot;new&amp;quot; format (as used in Sinaria)&lt;br /&gt;
&lt;br /&gt;
 Pattern segment:&lt;br /&gt;
 0   4  ID     &#039;PBOD&#039;; indicates a pattern follows (Pattern BODy)&lt;br /&gt;
 4   4  Size   Length of pattern data as dword, after this dword&lt;br /&gt;
 4   4  Size   Same value again.&lt;br /&gt;
&lt;br /&gt;
 Pattern:&lt;br /&gt;
 0 4/8  Number Pattern ID. See note below.&lt;br /&gt;
 4   2  Row n  Number of rows in ALL channels in pattern (64 usually, but can differ.) as word.&lt;br /&gt;
 6   ?  Data   Contains pattern data as a number of rows of interlaced channels (12341234...)&lt;br /&gt;
               &#039;&#039;Usual&#039;&#039; settings is 64 rows of 4 channels. Epic Pinball has shorter patterns for example, but they also include a &amp;quot;break to row&amp;quot; command at the end of the pattern.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; In the old format, this starts with a &#039;P&#039; and is followed by an integer number which is the pattern number, padded to 4 bytes with spaces. Caution: This number might or might not be zero-padded; In some files, the ID of the first pattern could be &#039;P0  &#039;, but there are also files where it is &#039;P00 &#039;!. In C/C++, you could use atoi() to parse this value. In the new format (Sinaria), This field is 8 bytes long instead of 4 bytes, and the first 4 bytes read &amp;quot;PATT&amp;quot;, so the first pattern could be for example &#039;PATT0   &#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Pattern row channel entry:&lt;br /&gt;
 ?   1  Fill   Convert this byte value into binary; (240 -&amp;gt; 11110000), the first four     &lt;br /&gt;
               values                          &lt;br /&gt;
 +1  1  chan   What channel this belongs to, 0-255, each filled only once per tick, this is &lt;br /&gt;
               what, by absence, identifies empty channels. It is possible that actual PSM implementations will support less channels and crash if a file contains too many channels.&lt;br /&gt;
 +2  1  Note   Pitch, $01 is C-1, etc... The octaves are aligned by 16, i.e. B-1 is $0C but the next note, C-2, is $10.&lt;br /&gt;
 +3  1  Ins    Instrument used, 0-31&lt;br /&gt;
 +4  1  Vol    Volume change to, 0-63 = 0-127; optional&lt;br /&gt;
 +5  1  Effect Effect to use, volume slide, Portamanto...&lt;br /&gt;
 +6  1  Eff Am Strength of effect, e.g amount of slide&lt;br /&gt;
&lt;br /&gt;
Each row consists of a word giving the size of the row (Including the word) followed by the channel data. A channel is only included if it has data in it, but a totally empty row is still included. So an &#039;empty&#039; row (Where none of the channels have data.) thus consists of just a word of value 2.&lt;br /&gt;
&lt;br /&gt;
Each channel entry consists of between 3-7 bytes. The first byte is a flag that shows what data follows. (The first four bits indicate whether there are bytes for the following four variables; Note ($80), Instrument ($40), Volume ($20), Effect AND Effect magnitude ($10). Thus 5 bytes are represented by a combination of 4 possibilities.) The next byte identifies the channel (Since each channel may or may not be present.) starting at 0 for channel 1. The remaining 5 bytes may or may not be present and contain data for Note, Instrument(Sample) used, Volume change for channel, Effect and Effect magnitude.&lt;br /&gt;
&lt;br /&gt;
There are several things to note about this; Effect and Effect magnitude MUST occur together. Sample numbers, like channels are numbered starting at 0, not 1. Magnitudes (For effect AND volume) are from 0-127, not 0-64 as in other formats.&lt;br /&gt;
&lt;br /&gt;
=== Effect conversion ===&lt;br /&gt;
&lt;br /&gt;
Note that this table is guaranteed to be correct; Most effects seem to be converted correctly, though. Note that these values are not correct for the PSM files that can be found in the game Sinaria. Leave out all divisions and it will be correct again.&lt;br /&gt;
&lt;br /&gt;
 PSM Command   Param length  S3M Command&lt;br /&gt;
 &lt;br /&gt;
  Volume commands&lt;br /&gt;
    1           1 Byte        DxF - fine volside up&lt;br /&gt;
    2           1 Byte        Dx0 - volslide up&lt;br /&gt;
    3           1 Byte        DFx - fine volslide down&lt;br /&gt;
    4           1 Byte        D0x - volslide down&lt;br /&gt;
 &lt;br /&gt;
 Portamento commands&lt;br /&gt;
    B           1 Byte        FFx - fine porta up (divide x by 4)&lt;br /&gt;
    C           1 Byte        Fxx - porta up (if x &amp;lt; 4, use FFx, else divide x by 4)&lt;br /&gt;
    D           1 Byte        EFx - fine porta down (divide x by 4)&lt;br /&gt;
    E           1 Byte        Exx - porta down (if x &amp;lt; 4, use EFx, else divide x by 4)&lt;br /&gt;
    F           1 Byte        Gxx - portamento (divide x by 4)&lt;br /&gt;
   10           1 Byte        S1x - glissando control&lt;br /&gt;
   11           1 Byte        Lx0 - tone porta + volslide up&lt;br /&gt;
   12           1 Byte        L0x - tone porta + volslide down&lt;br /&gt;
    &lt;br /&gt;
 Vibrato&lt;br /&gt;
   15           1 Byte        Hxy - vibrato&lt;br /&gt;
   16           1 Byte        S3x - vibrato waveform&lt;br /&gt;
   17           1 Byte        K0x - vibrato + volslide up&lt;br /&gt;
   18           1 Byte        Kx0 - vibrato + volslide down&lt;br /&gt;
   	&lt;br /&gt;
 Tremolo			&lt;br /&gt;
   1F           1 Byte        Rxy - tremolo&lt;br /&gt;
   20           1 Byte        S4x - tremolo waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample commands&lt;br /&gt;
   29           3 Bytes       Oxx - offset (only take the 2nd byte)&lt;br /&gt;
   2A           1 Byte        Q0x - retrigger&lt;br /&gt;
   2B           1 Byte        SCx - note cut&lt;br /&gt;
   2C           1 Byte        SDx - note delay&lt;br /&gt;
 &lt;br /&gt;
 Position change&lt;br /&gt;
   33           2 Bytes(?)    Bxx - position jump (divide by 2)&lt;br /&gt;
   34           1 Byte        Cxx - break to row (divide by 2)&lt;br /&gt;
   35           1 Byte        SBx - pattern loop&lt;br /&gt;
   36           1 Byte        SEx - pattern delay&lt;br /&gt;
  &lt;br /&gt;
 Speed change&lt;br /&gt;
   3D           1 Byte        Axx - set speed&lt;br /&gt;
   3E           1 Byte        Txx - set tempo&lt;br /&gt;
 &lt;br /&gt;
 Misc. commands&lt;br /&gt;
   47           1 Byte        Jxy - arpeggio&lt;br /&gt;
   48           1 Byte        S2x - set finetune&lt;br /&gt;
   49           1 Byte        S8x - set balance&lt;br /&gt;
&lt;br /&gt;
Effect interpretation is different in Sinaria&#039;s new format.&lt;br /&gt;
&lt;br /&gt;
== Song segment ==&lt;br /&gt;
&lt;br /&gt;
This segment contains most of the important data used to play the song. It contains several sub-segments, each of the same format as a normal segment, but contained in the song segment. Note that there might be more than one song segment and thus, more than one order list, default speed, default tempo, etc... For example, in Extreme Pinball, all the different jingles and mission songs are stored as separate SONG chunks. It is up to the developer to find a clever way of managing / playing several sub songs.&lt;br /&gt;
&lt;br /&gt;
 Segment structure:&lt;br /&gt;
 0   4  ID     &#039;SONG&#039; indicates start of song structure&lt;br /&gt;
 4   4  Size   Size of song structure, including all sub-segments&lt;br /&gt;
 8   9  Type   Type of song this is for; This is &#039;MAINSONG &#039; in almost all PSM files. Extreme Pinball has several SONG items with different types!&lt;br /&gt;
 17  1  Comp   Compression, for PSM = 1 (Uncompressed)&lt;br /&gt;
 18  1  Chan   Number of channels, usually, but not always, 4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Date sub-segment ===&lt;br /&gt;
&lt;br /&gt;
This dates the file and is used by some programs. It is usually the first sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DATE&#039; indicates date data&lt;br /&gt;
 4   4  Size   Size of date segment (6)&lt;br /&gt;
 8   6  Date   Date as text, YYMMDD&lt;br /&gt;
&lt;br /&gt;
This can also be used as a way to heuristically detect if the new version of the format is being used. Sinaria&#039;s song dates are: 800211, 940902, 940903, 940906, 940914, 941213&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Order sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Orders describe how patterns are arranged in the song. This allows the same pattern of instruments to be played more than once in a song (e.g. a chorus). without the pattern data having to be duplicated. There should be only one order. This section also contains basic song information. It usually follows the date sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;OPLH&#039; indicates start of pattern placement order&lt;br /&gt;
 4   4  Size   Size of order segment&lt;br /&gt;
 8   2  Cnt.   Number of following chunks&lt;br /&gt;
&lt;br /&gt;
Now, the following chunks may follow until the end of the &amp;quot;OPLH&amp;quot; chunk is reached. Every chunk is identified by the first byte:&lt;br /&gt;
* $00 (1 Byte): End (Nothing follows)&lt;br /&gt;
* $01 (5/9 Bytes): Order list item follows (e.g. &amp;quot;P0  &amp;quot;, &amp;quot;P12 &amp;quot; in old format or &amp;quot;PATT0   &amp;quot; in new format, see above) - join those to get the complete order list.&lt;br /&gt;
* $04 (3 Bytes): This 16-bit value indicates the &amp;quot;restart chunk&amp;quot;. If the end of the subsong is reached, it will jump back to this chunk. In many cases, this would be 4th chunk (no 3rd chunk, as the chunk index is starting at 0!), which is a panning index in most PSMs - So you would just go to the nearest order list item that&#039;s following this chunk. However, this can also point to a valid order list chunk.&lt;br /&gt;
* $07 (2 Bytes): Next byte is default speed for this subtune&lt;br /&gt;
* $08 (2 Bytes): Next byte is default tempo for this subtune&lt;br /&gt;
* $0C (7 Bytes): Sample map table(?): This chunk is always $0C $00 $FF $00 $00 $01 $00. The purpose is unknown.&lt;br /&gt;
* $0D (4 Bytes): Channel panning index. Next byte is channel number (Start at 0), then initial pan ($00 ... $FF) and a byte follow. The byte seems to tell what to do with the previous pan position (0 - use it, 2 - ignore it, make this channel surround, 4 - set to center).&lt;br /&gt;
* $0E (3 Bytes): Channel volume index. Next byte is channel number (Start at 0), then volume ($00 ... $FF). $FF in most cases. Some OMF 2097 tracks use a lower volume.&lt;br /&gt;
&lt;br /&gt;
=== Pattern list ===&lt;br /&gt;
&lt;br /&gt;
This is simply a list of all the patterns used in the file. You do not really need to parse this, it seems to be a purely informational chunk.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;PATT&#039; indicates start of pattern list&lt;br /&gt;
 4   4  Size   Size of pattern list after this&lt;br /&gt;
 8   4  Size   Same as above&lt;br /&gt;
 12  4x Pat    An ordered list &#039;P0  &#039;, &#039;P1  &#039;... for all patterns in the file, each entry 4 bytes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sample list sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Similar to the above, this is a list of all the samples used in the file. It is usually the last sub-segment in the song segment and you do not really need to parse this.&lt;br /&gt;
&lt;br /&gt;
  0  4   ID     &#039;DSAM&#039;; indicates start of sample list, used to say what samples are &#039;full&#039;&lt;br /&gt;
                Any samples not on this list will be ignored, even if they have data&lt;br /&gt;
  4  4   Size   Size of list after this&lt;br /&gt;
  8  4   Size   Same value as above&lt;br /&gt;
  12 15x Entry  Sample entries, one for each sample in the file, each entry 15 bytes&lt;br /&gt;
&lt;br /&gt;
 Sample entry:&lt;br /&gt;
 0   8  Format Sample format, padded with spaces (END, RAG2...) This is important to some programs&lt;br /&gt;
 8   4  ID     &#039;I0  &#039;, &#039;I1  &#039;... the sample ID (&#039;I&#039; means &#039;Instrument&#039;). Again, be sure to accept both &#039;I0  &#039; and &#039;I00 &#039;!&lt;br /&gt;
 12  2  Num    The sample number, 0,1,2... for the sample&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
Samples are the raw sound data that makes up the instruments on the song. The actual format depends on the sample format. Samples have information in their headers which allows data to be played at different pitches (Speeds.) and to loop from and to various points in the data. This is by far the largest part of the file, since the raw data takes up so much space.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DSMP&#039; indicates start of sample&lt;br /&gt;
 4   4  Size   Size of following sample as &#039;DSMP&#039; + dword from end of word&lt;br /&gt;
 8   9  Flags  If highest bit is set, then sample is looped&lt;br /&gt;
 9   8  Songn. Filename of the original module (without extension)&lt;br /&gt;
 17  4  INSx   Last digit of sample (Instrument) number, 0-9; with 31 instruments possible&lt;br /&gt;
               Only last digit is shown. E.g 1st, 11th, 21st and 31st sample is &#039;INS0&#039;&lt;br /&gt;
 21  33 Name   Defines the instrument name or file, usually a .st or line of text&lt;br /&gt;
 54  51 Header Sample parameters (Can also 58 bytes long, padded with nuls)&lt;br /&gt;
               Byte 1-6 are unknown (but apparently always $00 $00 $00 $00 $00 $FF)&lt;br /&gt;
               Bytes 7-8 is instrument number&lt;br /&gt;
               Bytes 9-12 are sample length&lt;br /&gt;
               Bytes 13-16 are loop start&lt;br /&gt;
               Bytes 17-20 are loop end (all $FF means at end of sample)&lt;br /&gt;
               Bytes 21-22 are unknown (second byte could be default pan, but seems to be unused)&lt;br /&gt;
               Byte 23 is default volume&lt;br /&gt;
               Bytes 24-27 are unknwon&lt;br /&gt;
               Bytes 28-31 is frequency (Sample rate)&lt;br /&gt;
               19 $00-bytes follow&lt;br /&gt;
 105 ?  Data   Music data in 8-bit mono format&lt;br /&gt;
&lt;br /&gt;
The sample header is slightly different in Sinaria&#039;s new format: INSx is 8 bytes long (like the PATT IDs), and the last 21 $00-bytes are just 16 bytes.&lt;br /&gt;
&lt;br /&gt;
The PSM new format, along with the PSM 16 format use delta-encoded samples, something to make the file smaller when zipped. &#039;Deltas&#039;, convert a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. It has the effect that if a single byte in the sample is changed, the entire sample will be degraded. This use of deltas varies slightly from that of the PSM 16. The &#039;start value&#039; of the string is assumed to be $80 (128) and the first byte will thus turn this into the first desired value, the second delta converts the first value to the second, and so on.) All deltas are signed, 1-byte values, but loop (Thus 10 - 20 = -10 can also be considered as 10 + 236 = 246). An example of this is as follows:&lt;br /&gt;
&lt;br /&gt;
 RAW:   (128) 64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: -64  0   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Encryption ==&lt;br /&gt;
&lt;br /&gt;
CONVERT.EXE can produce &amp;quot;encrypted&amp;quot; PSM files with the /K command line switch. The encryption scheme is simple: It adds 1 to the first byte, 2 to the second, 3 to the third, and so until, for the entire file. It does not appear like any game made use of this feature, though.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM 16 =&lt;br /&gt;
&lt;br /&gt;
This is the format used in [[Silverball]], early versions of Epic Pinball and possibly other games. The designation &#039;Protracker Studio 16 format&#039; was given to it by the only reliable source of information on this format, and may not be the official designation.&lt;br /&gt;
&lt;br /&gt;
The format bears many similarities to the S3M format; the file is set out roughly the same, patterns and samples are similar, indeed, near identical and the functionality is similar. It also shows many similarities to the ProTracker MOD format and retains vestiges of Amiga compatibility.&lt;br /&gt;
&lt;br /&gt;
This format can be identified by its signature &#039;PSMþ&#039;, though files may lack this and still function.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Order&lt;br /&gt;
 Pan segment&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Sample data&lt;br /&gt;
 Sample headers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
 0    4  Sig      Signature, &#039;PSMþ&#039;&lt;br /&gt;
 4    59 Title    Song title, padded with nulls. Unlike other formats, this must also be terminated&lt;br /&gt;
                  with a null byte. (It sometimes is not terminated, though.)&lt;br /&gt;
 62   1           This must be $1A to end the song name, like in S3M format.&lt;br /&gt;
 64   1  Type     Song type, First bit: 0 - Module (w/samp.), 1 - Song (w/o samples)&lt;br /&gt;
                  Second bit: 0 - 3 octave Protracker, 1 - 5 octave; remaining bits reserved.&lt;br /&gt;
 65   1  PSM v    PSM format version, $10 for this format (Hence the name PSM 16) = &#039;v1.00&#039;.&lt;br /&gt;
                  Sometimes, this is also $01, but there&#039;s no difference in the format itself.&lt;br /&gt;
 66   1  Patt v   Pattern version, 0 or 1. 0 means the pattern is stored in the module are in the 32&lt;br /&gt;
                  channel file format.  A 1 signifies the patterns as being stored as a 255&lt;br /&gt;
                  channel format. (I have not found any PSM16 modules that have this format.)&lt;br /&gt;
 67   1   Speed   Song speed&lt;br /&gt;
 68   1   BPM     Beats per minute, the default Amiga BPM value. (The only reason that the Amiga BPM&lt;br /&gt;
                  format is still followed here is that it allows more control over the final hz value.)&lt;br /&gt;
                  Range: 32 to 255.&lt;br /&gt;
 69   1   Vol     Master volume of song, 0-255&lt;br /&gt;
 70   2   Len     Song length, 0-255. The number of patterns to play in the song, in total.&lt;br /&gt;
 72   2   Ordlen  The number of orders actually stored at the order offset. It was hoped that the&lt;br /&gt;
                  PSM 16 format would allow multiple orders, so this would be the length of the first&lt;br /&gt;
                  order. This doesn&#039;t appea to ahve happened, and is usually the same as the previous value.&lt;br /&gt;
 74   2   Patnum  Number of patterns in the song. 1-255&lt;br /&gt;
 76   2   Sampnum Number of samples and &#039;sample structures&#039; in song, 1-255&lt;br /&gt;
 78   2   NCIS    Number of channels in song to PLAY. 1-32. &lt;br /&gt;
 80   2   NCP     Number of Channels to Process; describes the MAXIMUM number of channels to process.&lt;br /&gt;
                  As an example, when converting 669 files,  NCP = 9 because some track information &lt;br /&gt;
                  is in Channel 8, but the Number of Channels to Play was set to 8, (Channel numbers&lt;br /&gt;
                  to play from 0 to 7.) 1-32&lt;br /&gt;
 82   4   Ordoff  Location of order in header&lt;br /&gt;
 86   4   Panoff  Location of pan positions in header&lt;br /&gt;
 90   4   Patoff  Location of patterns in header&lt;br /&gt;
 94   4   Sampoff Location of sample headers in header&lt;br /&gt;
 98   4   Commoff Location of comments in header&lt;br /&gt;
 102  4   Patsiz  Total pattern size; the total size of all the patterns loaded from the pattern offset.&lt;br /&gt;
 106  40  Fillers 10 fillers, to be used for any possible expansions.&lt;br /&gt;
&lt;br /&gt;
It is important to notice that the offsets point to the first byte &#039;&#039;&#039;after&#039;&#039;&#039; the chunk ID, i.e. &amp;quot;Ordoff&amp;quot; points to the first byte after &amp;quot;PORD&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Order and Pan positions ==&lt;br /&gt;
&lt;br /&gt;
These are two separate segments, pointed to in the header. They may be anywhere, but usually follow the header sometimes after an amount of blank space. They are often padded with blank space. They are basically lists.&lt;br /&gt;
&lt;br /&gt;
Order: This segment is pointed to in the header, and sets the PSM 16 format apart. The PSM 16 format was designed to be much more like the MOD format, allowing game designers to set flags to switch from one set of patterns to another, in effect allowing one file to contain more than one song. (For example a boss flag might make the music switch from a clam patterns 1-4 to a racy and dangerous patterns 5-7.)&lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    Signature, not needed, &#039;PORD&#039;&lt;br /&gt;
 4    ?   Ords   Pattern numbers and order. There will be [Ordlen] bytes of patterns&lt;br /&gt;
 ?    2   Lang   Order language, not implemented, so left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pan Positions: &lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    &#039;PPAN&#039;&lt;br /&gt;
 4    12  Pan    Pan positions; empty positions left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
 0    2   Size   Size of pattern, including these bytes&lt;br /&gt;
 2    1   Len    Length of pattern, in rows. Max length is 64 rows.&lt;br /&gt;
 3    1   Chan   Number of channels in pattern, 1-32&lt;br /&gt;
 4    ?   Data   Pattern data&lt;br /&gt;
&lt;br /&gt;
This is similar to the previous two segments, except actual pattern data is stored here. Patterns are very similar to the S3M format, and consist of y rows of x channels. Each row contains a number of channels and ends with a byte of value 0. Each channel is between 2-6+ bytes long. A totally empty channel is represented by a single byte of value 0.&lt;br /&gt;
&lt;br /&gt;
Each channel starts with a flag byte, abcddddd, where a,b and c indicate whether there is a note and instrument, volume or special effect and effect magnitude in the following data, and dddd is the channel number (0-31, used since a given channel may or may not be present in a row.)&lt;br /&gt;
&lt;br /&gt;
The usual maximum length of a channel entry is 6 bytes (1 flag byte, 2 Note AND instrument bytes, 1 volume byte and two Effect and Effect magnitude bytes.) Thus Note&amp;amp;ins\Eff&amp;amp;Eff mag must always occur together.&lt;br /&gt;
&lt;br /&gt;
Like S3M, volume range is 0-64, as is special magnitude. However, special effects range from 0-255, like PSM New Format.&lt;br /&gt;
&lt;br /&gt;
=== Effects conversion ===&lt;br /&gt;
&lt;br /&gt;
 ###  Co  MOD  Description               Arguments&lt;br /&gt;
 ---  --  ---  -----------               ---------&lt;br /&gt;
 Volume Commands&lt;br /&gt;
   1  A1   EA  Fine Volume Slide Up      B xx xx=speed&lt;br /&gt;
   2  A2   A   Volume Slide Up           B xx xx=speed&lt;br /&gt;
   3  A3   EB  Fine Volume Slide Down    B xx xx=speed&lt;br /&gt;
   4  A4   A   Volume Slide Down         B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Portamento Commands&lt;br /&gt;
  10  B0   E1  Fine Porta Up             B xx xx=speed&lt;br /&gt;
  11  B1   1   Portamento Up             B xx xx=speed&lt;br /&gt;
  12  B2   E2  Fine Porta Down           B xx xx=speed&lt;br /&gt;
  13  B3   2   Portamento Down           B xx xx=speed&lt;br /&gt;
  14  B4   3   Tone Portamento           B xx xx=speed&lt;br /&gt;
  15  B5   E3  Set Glissando Control     B xx xx=0 - Off, 1 - On&lt;br /&gt;
  16  B6   5   Tone Port+Vol Slide Up    B xx xx=speed&lt;br /&gt;
  17  B7   5   Tone Port+Vol Slide Down  B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Vibrato Commands&lt;br /&gt;
  20  C0   4   Vibrato                   B xy x=speed, y=depth&lt;br /&gt;
  21  C1   E4  Set Vibrato Waveform      B x  x=Waveform&lt;br /&gt;
  21  C2   6   Vibrato+Vol Slide Up      B xx xx=speed&lt;br /&gt;
  22  C3   6   Vibrato+Vol Slide Down    B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Tremolo Commands&lt;br /&gt;
  30  D0   7   Tremolo                   B xy x=speed, y=depth&lt;br /&gt;
  31  D1   E7  Set Tremolo Control       B x  x=Waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample Commands&lt;br /&gt;
  40  E0   9   Sample Offset             3B Position for offset change (0-1,048,575)&lt;br /&gt;
  41  E1   E9  Retrig Note               B xx xx=tick to retrigger sample&lt;br /&gt;
  42  E2   EC  Note Cut                  B xx xx=tick to cut note&lt;br /&gt;
  43  E3   ED  Note Delay                B xx xx=ticks to delay note&lt;br /&gt;
 &lt;br /&gt;
 Pos. Change Commands&lt;br /&gt;
  50  F0   B   Position Jump             B xx xx=order position&lt;br /&gt;
  51  F1   D   Pattern Break             B xx Skip to line xx in next pattern&lt;br /&gt;
  52  F2   E6  Jump Loop                 B xx xx=number of loops  0 Set&lt;br /&gt;
  53  F3   EE  Pattern Delay             B xx xx=notes to delay pattern&lt;br /&gt;
 &lt;br /&gt;
 Speed Change Cmds&lt;br /&gt;
  60  G0   F   Set Regular Speed         B xx xx=speed&lt;br /&gt;
  61  G1   F   Set BPM                   B xx xx=BPM (32-255)&lt;br /&gt;
 &lt;br /&gt;
 Misc. Commands&lt;br /&gt;
  70  H0   0   Arpeggio                  B xy x=semitone #1, y=semitone #2&lt;br /&gt;
  71  H1   E5  Set Finetune              B xx xx=finetune&lt;br /&gt;
  72  H2       Set Balance               B xx xx=Balance (0-15)&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
 Sample segment&lt;br /&gt;
 0    4   ID     &#039;PSAM&#039; (Psm SAMple)&lt;br /&gt;
 4    ?  Data    Sample data&lt;br /&gt;
&lt;br /&gt;
 Sample header segment&lt;br /&gt;
 0    4   ID     &#039;PSAH&#039; (Psm SAmple Header)&lt;br /&gt;
 4    ?  Data    Sample headers&lt;br /&gt;
&lt;br /&gt;
 Sample header&lt;br /&gt;
 0    13  Name   Sample filename, terminated with a null.&lt;br /&gt;
 13   24  Desc   Sample description or comments.&lt;br /&gt;
 37   4   Offs   Location of raw sample data in file&lt;br /&gt;
 43   4   Mem    This is the physical offset in RAM/DRAM of the sample. (Often blank.)&lt;br /&gt;
 45   2   Num    Sample number, 1-255&lt;br /&gt;
 47   1   Type   Sample type: (In some games left blank; if this is the case then the&lt;br /&gt;
                 sample format is END, as used in most PSM New Format files)&lt;br /&gt;
                 Bit 0: 0 - Digital, 1 - Synthesized&lt;br /&gt;
                 Bit 2: 0 - 8-bit, 1 - 16-bit&lt;br /&gt;
                 Bit 3: 0 - Signed, 1 - Unsigned&lt;br /&gt;
                 Bit 4: 0 - Deltas, 1 - Raw&lt;br /&gt;
                 Bit 5: 0 - Loop normally, 1 - Bidirectional&lt;br /&gt;
                 Bit 6: 1 - Gravis patch (unsupported)&lt;br /&gt;
                 Bit 7: 0 - No loop, 1 - Loop sample&lt;br /&gt;
 48   4   Len    Sample length, in bytes.&lt;br /&gt;
 52   4   Rep st Sample repeat start; if sample loops, the loop starts here.&lt;br /&gt;
 56   4   Rep fn Sample repeat end, if sample loops, it ends here. If this is less than the sample&lt;br /&gt;
                 repeat start, the sample loops backwards.&lt;br /&gt;
 60   1   Tune   Fine tune; range 0-15, Tune 0-7 = 0-7; tune -1 - -8 = 8-15&lt;br /&gt;
 61   1   Vol    Sample volume, 0-64&lt;br /&gt;
 62   2   Freq   This is the frequency for the sample at a C of Octave 2.&lt;br /&gt;
                 Typical values are 8,000 hz to 8,448 hz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like in S3M, sample headers are stored separately from the raw sample data.&lt;br /&gt;
&lt;br /&gt;
A type of sample storage used often, like in the PSM New Format is &#039;Deltas&#039;, which converts a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte, often making them compress better using general-purpose file compression tools. Thus:&lt;br /&gt;
&lt;br /&gt;
 RAW:        64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: 11  64   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
This is done to make files more compressible, but doesn&#039;t seem to be used much.&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.shikadi.net/files/psm2scrm.zip psm2scrm.zip] - DOS program to convert .PSM songs into ScreamTracker .S3M format, suitable for playing in your favourite tracker/module player. Works only with PSM New Format and is not nearly as accurate as OpenMPT.&lt;br /&gt;
* [http://openmpt.org OpenMPT] 1.18 and newer can load all PSM and PSM16 files.&lt;br /&gt;
* [http://openmpt.org/legacy_software ModPlug Tracker] and OpenMPT 1.17 can play the files and save them as S3M. More complex songs don&#039;t load correctly though. Works only with new format.&lt;br /&gt;
* [http://kode54.foobar2000.org/ foo_dumb] is a plugin for various module formats for the Foobar2k media player. It supports both PSM16 and PSM and is similar to OpenMPT in playback quality.&lt;br /&gt;
* [http://ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/mxinfo/epictest.zip EPICTEST] is a demonstration of the Epic Megagames MASI. It contains CONVERT.EXE which can be used to convert modules to the new PSM format.&lt;br /&gt;
* [http://www.jazz2online.com/J2Ov2/downloads/info.php?levelID=5471#29435] JJ1MOD can convert S3M files to new PSM, though often with errors (Though these are usually only detectable with older programs such as game executables.) It is currently the only utility able to do this, and works only with New Format.&lt;br /&gt;
&lt;br /&gt;
= Notes =&lt;br /&gt;
&lt;br /&gt;
The New PSM format was reverse engineered by Levellord and tidied up by Levellass. It is possible there may be minor errors in the sample format information, especially since this is poorly documented.&lt;br /&gt;
Some format definitions have been updated and corrected by Johannes Schultz of the OpenMPT development team.&lt;br /&gt;
&lt;br /&gt;
The PSM16 format documentation was found on Wotsit and written up by Levellass (this appears to be an official document from the MASI developer). More info is needed.&lt;br /&gt;
&lt;br /&gt;
In all formats the following table shows how note bytes are converted into actual notes: (PSM new format has the widest range, 0-255)&lt;br /&gt;
&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;br /&gt;
           | C-0   0 | C-1  12 | C-2  24 | C-3  36 | C-4  48 |&lt;br /&gt;
           | C#0   1 | C#1  13 | C#2  25 | C#3  37 | C#4  49 |&lt;br /&gt;
           | D-0   2 | D-1  14 | D-2  26 | D-3  38 | D-4  50 |&lt;br /&gt;
           | D#0   3 | D#1  15 | D#2  27 | D#3  39 | D#4  51 |&lt;br /&gt;
           | E-0   4 | E-1  16 | E-2  28 | E-3  40 | E-4  52 |&lt;br /&gt;
           | F-0   5 | F-1  17 | F-2  29 | F-3  41 | F-4  53 |&lt;br /&gt;
           | F#0   6 | F#1  18 | F#2  30 | F#3  42 | F#4  54 |&lt;br /&gt;
           | G-0   7 | G-1  19 | G-2  31 | G-3  43 | G-4  55 |&lt;br /&gt;
           | G#0   8 | G#1  20 | G#2  32 | G#3  44 | G#4  56 |&lt;br /&gt;
           | A-0   9 | A-1  21 | A-2  33 | A-3  45 | A-4  57 |&lt;br /&gt;
           | A#0  10 | A#1  22 | A#2  34 | A#3  46 | A#4  58 |&lt;br /&gt;
           | B-0  11 | B-1  23 | B-2  35 | B-3  47 | B-4  59 |&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=6851</id>
		<title>ProTracker Studio Module</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=6851"/>
		<updated>2016-06-07T23:19:12Z</updated>

		<summary type="html">&lt;p&gt;Saga: Remove bogus info&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 1-256 (PSM) / 1-32 (PSM16)&lt;br /&gt;
 | NumTracks = unlimited (PSM) / 1 (PSM16)&lt;br /&gt;
 | Games = &lt;br /&gt;
   {{Game|Epic Pinball}}&lt;br /&gt;
   {{Game|Extreme Pinball}}&lt;br /&gt;
   {{Game|Jazz Jackrabbit}}&lt;br /&gt;
   {{Game|One Must Fall}}&lt;br /&gt;
   {{Game|Silverball}}&lt;br /&gt;
   {{Game|Sinaria}}&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;ProTracker Studio Module&#039;&#039;&#039; (PSM) file format is used for the music in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]].  The file format is named after ProTracker, an Amiga program, though this program was probably actually not used to write PSM files. One Must Fall&#039;s music was written in Multitracker, and the music for Jazz Jackrabbit, Epic Pinball and Extreme Pinball probably in Scream Tracker.&lt;br /&gt;
&lt;br /&gt;
There are two file types that use the extension .PSM; they are both used by Epic Megagames&#039; MASI sound system, but are used by different versions of the system. The two formats are:&lt;br /&gt;
&lt;br /&gt;
* PSM New Format: Used by Jazz Jackrabbit, Epic Pinball, Extreme Pinball, One Must Fall, Sinaria (in this game with slight differences, see below), newest PSM format&lt;br /&gt;
* PSM 16:         Used by Silverball, an older version of the format which is closer to ScreamTracker-style modules.&lt;br /&gt;
&lt;br /&gt;
The most common of the two PSM formats is the new format, and most programs that try to interpret PSM files will be expecting this. For example, ModPlug Player cannot open Silverball files as these are in the PSM 16 format.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM New Format =&lt;br /&gt;
&lt;br /&gt;
This format is used by [[:Category:Epic Megagames|Epic]] games in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]]. It is notable for consisting of a number of segments (chunks) and sub segments. It bears the 4-byte signature &#039;PSM &#039; at the file start.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Song segment&lt;br /&gt;
 Samples&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 12 bytes long:&lt;br /&gt;
&lt;br /&gt;
 File header:&lt;br /&gt;
 0   4  ID     &#039;PSM &#039;; indicates file is PSM format&lt;br /&gt;
 4   4  Size   Filesize - 12&lt;br /&gt;
 8   4  ID2    &#039;FILE&#039;; indicates start of file info&lt;br /&gt;
&lt;br /&gt;
After the header, some chunks follow in IFF-style. You should not expect chunks to come up in the same order as they are described here. A good way to handle chunks is to read the 4-Byte ID and the 4-Byte size field first, then evaluate the ID and decide what to do next based on this ID. Note that the size field does not include the ID and itself; it only holds the size of the chunk &#039;&#039;content&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Title segment ==&lt;br /&gt;
&lt;br /&gt;
This segment is optional, and one of the few segments that can be absent when playing PSM files in most programs. (Most programs expect all other segments to exist, even if they are not vital.)&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;TITL&#039;; indicates a title follows&lt;br /&gt;
 4   4  Size   Size of title as dword after this dword&lt;br /&gt;
 8   ?  Title  Song title&lt;br /&gt;
&lt;br /&gt;
== Song info segment ==&lt;br /&gt;
&lt;br /&gt;
This segment seems to indicate the beginning of the song data and is not really relevant when parsing.&lt;br /&gt;
&lt;br /&gt;
 12  4  ID     &#039;SDFT&#039;; indicates start of format info&lt;br /&gt;
 16  4  Size   Size of next header as dword, (8)&lt;br /&gt;
 20  8  Song   &#039;MAINSONG&#039;; indicates song type. No other song types are known.&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
Each pattern is stored in its own PBOD chunk. Note that there are two possible formats for this chunk; one is used in the &amp;quot;old&amp;quot; format (as used in Epic Pinball, Extreme Pinball, Jazz Jackrabbit, One Must Fall) and the other in the &amp;quot;new&amp;quot; format (as used in Sinaria)&lt;br /&gt;
&lt;br /&gt;
 Pattern segment:&lt;br /&gt;
 0   4  ID     &#039;PBOD&#039;; indicates a pattern follows (Pattern BODy)&lt;br /&gt;
 4   4  Size   Length of pattern data as dword, after this dword&lt;br /&gt;
 4   4  Size   Same value again.&lt;br /&gt;
&lt;br /&gt;
 Pattern:&lt;br /&gt;
 0 4/8  Number Pattern ID. See note below.&lt;br /&gt;
 4   2  Row n  Number of rows in ALL channels in pattern (64 usually, but can differ.) as word.&lt;br /&gt;
 6   ?  Data   Contains pattern data as a number of rows of interlaced channels (12341234...)&lt;br /&gt;
               &#039;&#039;Usual&#039;&#039; settings is 64 rows of 4 channels. Epic Pinball has shorter patterns for example, but they also include a &amp;quot;break to row&amp;quot; command at the end of the pattern.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; In the old format, this starts with a &#039;P&#039; and is followed by an integer number which is the pattern number, padded to 4 bytes with spaces. Caution: This number might or might not be zero-padded; In some files, the ID of the first pattern could be &#039;P0  &#039;, but there are also files where it is &#039;P00 &#039;!. In C/C++, you could use atoi() to parse this value. In the new format (Sinaria), This field is 8 bytes long instead of 4 bytes, and the first 4 bytes read &amp;quot;PATT&amp;quot;, so the first pattern could be for example &#039;PATT0   &#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Pattern row channel entry:&lt;br /&gt;
 ?   1  Fill   Convert this byte value into binary; (240 -&amp;gt; 11110000), the first four     &lt;br /&gt;
               values                          &lt;br /&gt;
 +1  1  chan   What channel this belongs to, 0-255, each filled only once per tick, this is &lt;br /&gt;
               what, by absence, identifies empty channels. It is possible that actual PSM implementations will support less channels and crash if a file contains too many channels.&lt;br /&gt;
 +2  1  Note   Pitch, $01 is C-1, etc... The octaves are aligned by 16, i.e. B-1 is $0C but the next note, C-2, is $10.&lt;br /&gt;
 +3  1  Ins    Instrument used, 0-31&lt;br /&gt;
 +4  1  Vol    Volume change to, 0-63 = 0-127; optional&lt;br /&gt;
 +5  1  Effect Effect to use, volume slide, Portamanto...&lt;br /&gt;
 +6  1  Eff Am Strength of effect, e.g amount of slide&lt;br /&gt;
&lt;br /&gt;
Each row consists of a word giving the size of the row (Including the word) followed by the channel data. A channel is only included if it has data in it, but a totally empty row is still included. So an &#039;empty&#039; row (Where none of the channels have data.) thus consists of just a word of value 2.&lt;br /&gt;
&lt;br /&gt;
Each channel entry consists of between 3-7 bytes. The first byte is a flag that shows what data follows. (The first four bits indicate whether there are bytes for the following four variables; Note ($80), Instrument ($40), Volume ($20), Effect AND Effect magnitude ($10). Thus 5 bytes are represented by a combination of 4 possibilities.) The next byte identifies the channel (Since each channel may or may not be present.) starting at 0 for channel 1. The remaining 5 bytes may or may not be present and contain data for Note, Instrument(Sample) used, Volume change for channel, Effect and Effect magnitude.&lt;br /&gt;
&lt;br /&gt;
There are several things to note about this; Effect and Effect magnitude MUST occur together. Sample numbers, like channels are numbered starting at 0, not 1. Magnitudes (For effect AND volume) are from 0-127, not 0-64 as in other formats.&lt;br /&gt;
&lt;br /&gt;
=== Effect conversion ===&lt;br /&gt;
&lt;br /&gt;
Note that this table is guaranteed to be correct; Most effects seem to be converted correctly, though. Note that these values are not correct for the PSM files that can be found in the game Sinaria. Leave out all divisions and it will be correct again.&lt;br /&gt;
&lt;br /&gt;
 PSM Command   Param length  S3M Command&lt;br /&gt;
 &lt;br /&gt;
  Volume commands&lt;br /&gt;
    1           1 Byte        DxF - fine volside up&lt;br /&gt;
    2           1 Byte        Dx0 - volslide up&lt;br /&gt;
    3           1 Byte        DFx - fine volslide down&lt;br /&gt;
    4           1 Byte        D0x - volslide down&lt;br /&gt;
 &lt;br /&gt;
 Portamento commands&lt;br /&gt;
    B           1 Byte        FFx - fine porta up (divide x by 4)&lt;br /&gt;
    C           1 Byte        Fxx - porta up (if x &amp;lt; 4, use FFx, else divide x by 4)&lt;br /&gt;
    D           1 Byte        EFx - fine porta down (divide x by 4)&lt;br /&gt;
    E           1 Byte        Exx - porta down (if x &amp;lt; 4, use EFx, else divide x by 4)&lt;br /&gt;
    F           1 Byte        Gxx - portamento (divide x by 4)&lt;br /&gt;
   10           1 Byte        S1x - glissando control&lt;br /&gt;
   11           1 Byte        Lx0 - tone porta + volslide up&lt;br /&gt;
   12           1 Byte        L0x - tone porta + volslide down&lt;br /&gt;
    &lt;br /&gt;
 Vibrato&lt;br /&gt;
   15           1 Byte        Hxy - vibrato&lt;br /&gt;
   16           1 Byte        S3x - vibrato waveform&lt;br /&gt;
   17           1 Byte        K0x - vibrato + volslide up&lt;br /&gt;
   18           1 Byte        Kx0 - vibrato + volslide down&lt;br /&gt;
   	&lt;br /&gt;
 Tremolo			&lt;br /&gt;
   1F           1 Byte        Rxy - tremolo&lt;br /&gt;
   20           1 Byte        S4x - tremolo waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample commands&lt;br /&gt;
   29           3 Bytes       Oxx - offset (only take the 2nd byte)&lt;br /&gt;
   2A           1 Byte        Q0x - retrigger&lt;br /&gt;
   2B           1 Byte        SCx - note cut&lt;br /&gt;
   2C           1 Byte        SDx - note delay&lt;br /&gt;
 &lt;br /&gt;
 Position change&lt;br /&gt;
   33           2 Bytes(?)    Bxx - position jump (divide by 2)&lt;br /&gt;
   34           1 Byte        Cxx - break to row (divide by 2)&lt;br /&gt;
   35           1 Byte        SBx - pattern loop&lt;br /&gt;
   36           1 Byte        SEx - pattern delay&lt;br /&gt;
  &lt;br /&gt;
 Speed change&lt;br /&gt;
   3D           1 Byte        Axx - set speed&lt;br /&gt;
   3E           1 Byte        Txx - set tempo&lt;br /&gt;
 &lt;br /&gt;
 Misc. commands&lt;br /&gt;
   47           1 Byte        Jxy - arpeggio&lt;br /&gt;
   48           1 Byte        S2x - set finetune&lt;br /&gt;
   49           1 Byte        S8x - set balance&lt;br /&gt;
&lt;br /&gt;
Effect interpretation is different in Sinaria&#039;s new format.&lt;br /&gt;
&lt;br /&gt;
== Song segment ==&lt;br /&gt;
&lt;br /&gt;
This segment contains most of the important data used to play the song. It contains several sub-segments, each of the same format as a normal segment, but contained in the song segment. Note that there might be more than one song segment and thus, more than one order list, default speed, default tempo, etc... For example, in Extreme Pinball, all the different jingles and mission songs are stored as separate SONG chunks. It is up to the developer to find a clever way of managing / playing several sub songs.&lt;br /&gt;
&lt;br /&gt;
 Segment structure:&lt;br /&gt;
 0   4  ID     &#039;SONG&#039; indicates start of song structure&lt;br /&gt;
 4   4  Size   Size of song structure, including all sub-segments&lt;br /&gt;
 8   9  Type   Type of song this is for; This is &#039;MAINSONG &#039; in almost all PSM files. Extreme Pinball has several SONG items with different types!&lt;br /&gt;
 17  1  Comp   Compression, for PSM = 1 (Uncompressed)&lt;br /&gt;
 18  1  Chan   Number of channels, usually, but not always, 4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Date sub-segment ===&lt;br /&gt;
&lt;br /&gt;
This dates the file and is used by some programs. It is usually the first sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DATE&#039; indicates date data&lt;br /&gt;
 4   4  Size   Size of date segment (6)&lt;br /&gt;
 8   6  Date   Date as text, YYMMDD&lt;br /&gt;
&lt;br /&gt;
This can also be used as a way to heuristically detect if the new version of the format is being used. Sinaria&#039;s song dates are: 800211, 940902, 940903, 940906, 940914, 941213&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Order sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Orders describe how patterns are arranged in the song. This allows the same pattern of instruments to be played more than once in a song (e.g. a chorus). without the pattern data having to be duplicated. There should be only one order. This section also contains basic song information. It usually follows the date sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;OPLH&#039; indicates start of pattern placement order&lt;br /&gt;
 4   4  Size   Size of order segment&lt;br /&gt;
 8   2  Cnt.   Number of following chunks&lt;br /&gt;
&lt;br /&gt;
Now, the following chunks may follow until the end of the &amp;quot;OPLH&amp;quot; chunk is reached. Every chunk is identified by the first byte:&lt;br /&gt;
* $00 (1 Byte): End (Nothing follows)&lt;br /&gt;
* $01 (5/9 Bytes): Order list item follows (e.g. &amp;quot;P0  &amp;quot;, &amp;quot;P12 &amp;quot; in old format or &amp;quot;PATT0   &amp;quot; in new format, see above) - join those to get the complete order list.&lt;br /&gt;
* $04 (3 Bytes): This 16-bit value indicates the &amp;quot;restart chunk&amp;quot;. If the end of the subsong is reached, it will jump back to this chunk. In many cases, this would be 4th chunk (no 3rd chunk, as the chunk index is starting at 0!), which is a panning index in most PSMs - So you would just go to the nearest order list item that&#039;s following this chunk. However, this can also point to a valid order list chunk.&lt;br /&gt;
* $07 (2 Bytes): Next byte is default speed for this subtune&lt;br /&gt;
* $08 (2 Bytes): Next byte is default tempo for this subtune&lt;br /&gt;
* $0C (7 Bytes): Sample map table(?): This chunk is always $0C $00 $FF $00 $00 $01 $00. The purpose is unknown.&lt;br /&gt;
* $0D (4 Bytes): Channel panning index. Next byte is channel number (Start at 0), then initial pan ($00 ... $FF) and a byte follow. The byte seems to tell what to do with the previous pan position (0 - use it, 2 - ignore it, make this channel surround, 4 - set to center).&lt;br /&gt;
* $0E (3 Bytes): Channel volume index. Next byte is channel number (Start at 0), then volume ($00 ... $FF). $FF in most (all?) cases.&lt;br /&gt;
&lt;br /&gt;
=== Pattern list ===&lt;br /&gt;
&lt;br /&gt;
This is simply a list of all the patterns used in the file. You do not really need to parse this, it seems to be a purely informational chunk.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;PATT&#039; indicates start of pattern list&lt;br /&gt;
 4   4  Size   Size of pattern list after this&lt;br /&gt;
 8   4  Size   Same as above&lt;br /&gt;
 12  4x Pat    An ordered list &#039;P0  &#039;, &#039;P1  &#039;... for all patterns in the file, each entry 4 bytes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sample list sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Similar to the above, this is a list of all the samples used in the file. It is usually the last sub-segment in the song segment and you do not really need to parse this.&lt;br /&gt;
&lt;br /&gt;
  0  4   ID     &#039;DSAM&#039;; indicates start of sample list, used to say what samples are &#039;full&#039;&lt;br /&gt;
                Any samples not on this list will be ignored, even if they have data&lt;br /&gt;
  4  4   Size   Size of list after this&lt;br /&gt;
  8  4   Size   Same value as above&lt;br /&gt;
  12 15x Entry  Sample entries, one for each sample in the file, each entry 15 bytes&lt;br /&gt;
&lt;br /&gt;
 Sample entry:&lt;br /&gt;
 0   8  Format Sample format, padded with spaces (END, RAG2...) This is important to some programs&lt;br /&gt;
 8   4  ID     &#039;I0  &#039;, &#039;I1  &#039;... the sample ID (&#039;I&#039; means &#039;Instrument&#039;). Again, be sure to accept both &#039;I0  &#039; and &#039;I00 &#039;!&lt;br /&gt;
 12  2  Num    The sample number, 0,1,2... for the sample&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
Samples are the raw sound data that makes up the instruments on the song. The actual format depends on the sample format. Samples have information in their headers which allows data to be played at different pitches (Speeds.) and to loop from and to various points in the data. This is by far the largest part of the file, since the raw data takes up so much space.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DSMP&#039; indicates start of sample&lt;br /&gt;
 4   4  Size   Size of following sample as &#039;DSMP&#039; + dword from end of word&lt;br /&gt;
 8   9  Flags  If highest bit is set, then sample is looped&lt;br /&gt;
 9   8  Songn. Filename of the original module (without extension)&lt;br /&gt;
 17  4  INSx   Last digit of sample (Instrument) number, 0-9; with 31 instruments possible&lt;br /&gt;
               Only last digit is shown. E.g 1st, 11th, 21st and 31st sample is &#039;INS0&#039;&lt;br /&gt;
 21  33 Name   Defines the instrument name or file, usually a .st or line of text&lt;br /&gt;
 54  51 Header Sample parameters (Can also 58 bytes long, padded with nuls)&lt;br /&gt;
               Byte 1-6 are unknown ($00 $00 $00 $00 $00 $FF)&lt;br /&gt;
               Bytes 7-8 is instrument number&lt;br /&gt;
               Bytes 9-12 are sample length&lt;br /&gt;
               Bytes 13-16 are loop start&lt;br /&gt;
               Bytes 17-20 are loop end (all $FF means at end of sample)&lt;br /&gt;
               Bytes 21-22 are unknown (second byte could be default pan, but seems to be unused)&lt;br /&gt;
               Byte 23 is default volume&lt;br /&gt;
               Bytes 24-27 are unknwon&lt;br /&gt;
               Bytes 28-29 is frequency (Sample rate)&lt;br /&gt;
               21 $00-bytes follow&lt;br /&gt;
 105 ?  Data   Music data in 8-bit mono format&lt;br /&gt;
&lt;br /&gt;
The sample header is slightly different in Sinaria&#039;s new format: INSx is 8 bytes long (like the PATT IDs), and the last 21 $00-bytes are just 16 bytes.&lt;br /&gt;
&lt;br /&gt;
The PSM new format, along with the PSM 16 format use delta-encoded samples, something to make the file smaller when zipped. &#039;Deltas&#039;, convert a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. It has the effect that if a single byte in the sample is changed, the entire sample will be degraded. This use of deltas varies slightly from that of the PSM 16. The &#039;start value&#039; of the string is assumed to be $80 (128) and the first byte will thus turn this into the first desired value, the second delta converts the first value to the second, and so on.) All deltas are signed, 1-byte values, but loop (Thus 10 - 20 = -10 can also be considered as 10 + 236 = 246). An example of this is as follows:&lt;br /&gt;
&lt;br /&gt;
 RAW:   (128) 64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: -64  0   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM 16 =&lt;br /&gt;
&lt;br /&gt;
This is the format used in [[Silverball]], early versions of Epic Pinball and possibly other games. The designation &#039;Protracker Studio 16 format&#039; was given to it by the only reliable source of information on this format, and may not be the official designation.&lt;br /&gt;
&lt;br /&gt;
The format bears many similarities to the S3M format; the file is set out roughly the same, patterns and samples are similar, indeed, near identical and the functionality is similar. It also shows many similarities to the ProTracker MOD format and retains vestiges of Amiga compatibility.&lt;br /&gt;
&lt;br /&gt;
This format can be identified by its signature &#039;PSMþ&#039;, though files may lack this and still function.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Order&lt;br /&gt;
 Pan segment&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Sample data&lt;br /&gt;
 Sample headers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
 0    4  Sig      Signature, &#039;PSMþ&#039;&lt;br /&gt;
 4    59 Title    Song title, padded with nulls. Unlike other formats, this must also be terminated&lt;br /&gt;
                  with a null byte. (It sometimes is not terminated, though.)&lt;br /&gt;
 62   1           This must be $1A to end the song name, like in S3M format.&lt;br /&gt;
 64   1  Type     Song type, First bit: 0 - Module (w/samp.), 1 - Song (w/o samples)&lt;br /&gt;
                  Second bit: 0 - 3 octave Protracker, 1 - 5 octave; remaining bits reserved.&lt;br /&gt;
 65   1  PSM v    PSM format version, $10 for this format (Hence the name PSM 16) = &#039;v1.00&#039;.&lt;br /&gt;
                  Sometimes, this is also $01, but there&#039;s no difference in the format itself.&lt;br /&gt;
 66   1  Patt v   Pattern version, 0 or 1. 0 means the pattern is stored in the module are in the 32&lt;br /&gt;
                  channel file format.  A 1 signifies the patterns as being stored as a 255&lt;br /&gt;
                  channel format. (I have not found any PSM16 modules that have this format.)&lt;br /&gt;
 67   1   Speed   Song speed&lt;br /&gt;
 68   1   BPM     Beats per minute, the default Amiga BPM value. (The only reason that the Amiga BPM&lt;br /&gt;
                  format is still followed here is that it allows more control over the final hz value.)&lt;br /&gt;
                  Range: 32 to 255.&lt;br /&gt;
 69   1   Vol     Master volume of song, 0-255&lt;br /&gt;
 70   2   Len     Song length, 0-255. The number of patterns to play in the song, in total.&lt;br /&gt;
 72   2   Ordlen  The number of orders actually stored at the order offset. It was hoped that the&lt;br /&gt;
                  PSM 16 format would allow multiple orders, so this would be the length of the first&lt;br /&gt;
                  order. This doesn&#039;t appea to ahve happened, and is usually the same as the previous value.&lt;br /&gt;
 74   2   Patnum  Number of patterns in the song. 1-255&lt;br /&gt;
 76   2   Sampnum Number of samples and &#039;sample structures&#039; in song, 1-255&lt;br /&gt;
 78   2   NCIS    Number of channels in song to PLAY. 1-32. &lt;br /&gt;
 80   2   NCP     Number of Channels to Process; describes the MAXIMUM number of channels to process.&lt;br /&gt;
                  As an example, when converting 669 files,  NCP = 9 because some track information &lt;br /&gt;
                  is in Channel 8, but the Number of Channels to Play was set to 8, (Channel numbers&lt;br /&gt;
                  to play from 0 to 7.) 1-32&lt;br /&gt;
 82   4   Ordoff  Location of order in header&lt;br /&gt;
 86   4   Panoff  Location of pan positions in header&lt;br /&gt;
 90   4   Patoff  Location of patterns in header&lt;br /&gt;
 94   4   Sampoff Location of sample headers in header&lt;br /&gt;
 98   4   Commoff Location of comments in header&lt;br /&gt;
 102  4   Patsiz  Total pattern size; the total size of all the patterns loaded from the pattern offset.&lt;br /&gt;
 106  40  Fillers 10 fillers, to be used for any possible expansions.&lt;br /&gt;
&lt;br /&gt;
It is important to notice that the offsets point to the first byte &#039;&#039;&#039;after&#039;&#039;&#039; the chunk ID, i.e. &amp;quot;Ordoff&amp;quot; points to the first byte after &amp;quot;PORD&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Order and Pan positions ==&lt;br /&gt;
&lt;br /&gt;
These are two separate segments, pointed to in the header. They may be anywhere, but usually follow the header sometimes after an amount of blank space. They are often padded with blank space. They are basically lists.&lt;br /&gt;
&lt;br /&gt;
Order: This segment is pointed to in the header, and sets the PSM 16 format apart. The PSM 16 format was designed to be much more like the MOD format, allowing game designers to set flags to switch from one set of patterns to another, in effect allowing one file to contain more than one song. (For example a boss flag might make the music switch from a clam patterns 1-4 to a racy and dangerous patterns 5-7.)&lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    Signature, not needed, &#039;PORD&#039;&lt;br /&gt;
 4    ?   Ords   Pattern numbers and order. There will be [Ordlen] bytes of patterns&lt;br /&gt;
 ?    2   Lang   Order language, not implemented, so left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pan Positions: &lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    &#039;PPAN&#039;&lt;br /&gt;
 4    12  Pan    Pan positions; empty positions left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
 0    2   Size   Size of pattern, including these bytes&lt;br /&gt;
 2    1   Len    Length of pattern, in rows. Max length is 64 rows.&lt;br /&gt;
 3    1   Chan   Number of channels in pattern, 1-32&lt;br /&gt;
 4    ?   Data   Pattern data&lt;br /&gt;
&lt;br /&gt;
This is similar to the previous two segments, except actual pattern data is stored here. Patterns are very similar to the S3M format, and consist of y rows of x channels. Each row contains a number of channels and ends with a byte of value 0. Each channel is between 2-6+ bytes long. A totally empty channel is represented by a single byte of value 0.&lt;br /&gt;
&lt;br /&gt;
Each channel starts with a flag byte, abcddddd, where a,b and c indicate whether there is a note and instrument, volume or special effect and effect magnitude in the following data, and dddd is the channel number (0-31, used since a given channel may or may not be present in a row.)&lt;br /&gt;
&lt;br /&gt;
The usual maximum length of a channel entry is 6 bytes (1 flag byte, 2 Note AND instrument bytes, 1 volume byte and two Effect and Effect magnitude bytes.) Thus Note&amp;amp;ins\Eff&amp;amp;Eff mag must always occur together.&lt;br /&gt;
&lt;br /&gt;
Like S3M, volume range is 0-64, as is special magnitude. However, special effects range from 0-255, like PSM New Format.&lt;br /&gt;
&lt;br /&gt;
=== Effects conversion ===&lt;br /&gt;
&lt;br /&gt;
 ###  Co  MOD  Description               Arguments&lt;br /&gt;
 ---  --  ---  -----------               ---------&lt;br /&gt;
 Volume Commands&lt;br /&gt;
   1  A1   EA  Fine Volume Slide Up      B xx xx=speed&lt;br /&gt;
   2  A2   A   Volume Slide Up           B xx xx=speed&lt;br /&gt;
   3  A3   EB  Fine Volume Slide Down    B xx xx=speed&lt;br /&gt;
   4  A4   A   Volume Slide Down         B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Portamento Commands&lt;br /&gt;
  10  B0   E1  Fine Porta Up             B xx xx=speed&lt;br /&gt;
  11  B1   1   Portamento Up             B xx xx=speed&lt;br /&gt;
  12  B2   E2  Fine Porta Down           B xx xx=speed&lt;br /&gt;
  13  B3   2   Portamento Down           B xx xx=speed&lt;br /&gt;
  14  B4   3   Tone Portamento           B xx xx=speed&lt;br /&gt;
  15  B5   E3  Set Glissando Control     B xx xx=0 - Off, 1 - On&lt;br /&gt;
  16  B6   5   Tone Port+Vol Slide Up    B xx xx=speed&lt;br /&gt;
  17  B7   5   Tone Port+Vol Slide Down  B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Vibrato Commands&lt;br /&gt;
  20  C0   4   Vibrato                   B xy x=speed, y=depth&lt;br /&gt;
  21  C1   E4  Set Vibrato Waveform      B x  x=Waveform&lt;br /&gt;
  21  C2   6   Vibrato+Vol Slide Up      B xx xx=speed&lt;br /&gt;
  22  C3   6   Vibrato+Vol Slide Down    B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Tremolo Commands&lt;br /&gt;
  30  D0   7   Tremolo                   B xy x=speed, y=depth&lt;br /&gt;
  31  D1   E7  Set Tremolo Control       B x  x=Waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample Commands&lt;br /&gt;
  40  E0   9   Sample Offset             3B Position for offset change (0-1,048,575)&lt;br /&gt;
  41  E1   E9  Retrig Note               B xx xx=tick to retrigger sample&lt;br /&gt;
  42  E2   EC  Note Cut                  B xx xx=tick to cut note&lt;br /&gt;
  43  E3   ED  Note Delay                B xx xx=ticks to delay note&lt;br /&gt;
 &lt;br /&gt;
 Pos. Change Commands&lt;br /&gt;
  50  F0   B   Position Jump             B xx xx=order position&lt;br /&gt;
  51  F1   D   Pattern Break             B xx Skip to line xx in next pattern&lt;br /&gt;
  52  F2   E6  Jump Loop                 B xx xx=number of loops  0 Set&lt;br /&gt;
  53  F3   EE  Pattern Delay             B xx xx=notes to delay pattern&lt;br /&gt;
 &lt;br /&gt;
 Speed Change Cmds&lt;br /&gt;
  60  G0   F   Set Regular Speed         B xx xx=speed&lt;br /&gt;
  61  G1   F   Set BPM                   B xx xx=BPM (32-255)&lt;br /&gt;
 &lt;br /&gt;
 Misc. Commands&lt;br /&gt;
  70  H0   0   Arpeggio                  B xy x=semitone #1, y=semitone #2&lt;br /&gt;
  71  H1   E5  Set Finetune              B xx xx=finetune&lt;br /&gt;
  72  H2       Set Balance               B xx xx=Balance (0-15)&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
 Sample segment&lt;br /&gt;
 0    4   ID     &#039;PSAM&#039; (Psm SAMple)&lt;br /&gt;
 4    ?  Data    Sample data&lt;br /&gt;
&lt;br /&gt;
 Sample header segment&lt;br /&gt;
 0    4   ID     &#039;PSAH&#039; (Psm SAmple Header)&lt;br /&gt;
 4    ?  Data    Sample headers&lt;br /&gt;
&lt;br /&gt;
 Sample header&lt;br /&gt;
 0    13  Name   Sample filename, terminated with a null.&lt;br /&gt;
 13   24  Desc   Sample description or comments.&lt;br /&gt;
 37   4   Offs   Location of raw sample data in file&lt;br /&gt;
 43   4   Mem    This is the physical offset in RAM/DRAM of the sample. (Often blank.)&lt;br /&gt;
 45   2   Num    Sample number, 1-255&lt;br /&gt;
 47   1   Type   Sample type: (In some games left blank; if this is the case then the&lt;br /&gt;
                 sample format is END, as used in most PSM New Format files)&lt;br /&gt;
                 Bit 0: 0 - Digital, 1 - Synthesized&lt;br /&gt;
                 Bit 2: 0 - 8-bit, 1 - 16-bit&lt;br /&gt;
                 Bit 3: 0 - Signed, 1 - Unsigned&lt;br /&gt;
                 Bit 4: 0 - Deltas, 1 - Raw&lt;br /&gt;
                 Bit 5: 0 - Loop normally, 1 - Bidirectional&lt;br /&gt;
                 Bit 6: 1 - Gravis patch (unsupported)&lt;br /&gt;
                 Bit 7: 0 - No loop, 1 - Loop sample&lt;br /&gt;
 48   4   Len    Sample length, in bytes.&lt;br /&gt;
 52   4   Rep st Sample repeat start; if sample loops, the loop starts here.&lt;br /&gt;
 56   4   Rep fn Sample repeat end, if sample loops, it ends here. If this is less than the sample&lt;br /&gt;
                 repeat start, the sample loops backwards.&lt;br /&gt;
 60   1   Tune   Fine tune; range 0-15, Tune 0-7 = 0-7; tune -1 - -8 = 8-15&lt;br /&gt;
 61   1   Vol    Sample volume, 0-64&lt;br /&gt;
 62   2   Freq   This is the frequency for the sample at a C of Octave 2.&lt;br /&gt;
                 Typical values are 8,000 hz to 8,448 hz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like in S3M, sample headers are stored separately from the raw sample data.&lt;br /&gt;
&lt;br /&gt;
A type of sample storage used often, like in the PSM New Format is &#039;Deltas&#039;, which converts a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte, often making them compress better using general-purpose file compression tools. Thus:&lt;br /&gt;
&lt;br /&gt;
 RAW:        64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: 11  64   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
This is done to make files more compressible, but doesn&#039;t seem to be used much.&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.shikadi.net/files/psm2scrm.zip psm2scrm.zip] - DOS program to convert .PSM songs into ScreamTracker .S3M format, suitable for playing in your favourite tracker/module player. Works only with PSM New Format and is not nearly as accurate as OpenMPT.&lt;br /&gt;
* [http://openmpt.org OpenMPT] 1.18 and newer can load all PSM and PSM16 files.&lt;br /&gt;
* [http://openmpt.org/legacy_software ModPlug Tracker] and OpenMPT 1.17 can play the files and save them as S3M. More complex songs don&#039;t load correctly though. Works only with new format.&lt;br /&gt;
* [http://kode54.foobar2000.org/ foo_dumb] is a plugin for various module formats for the Foobar2k media player. It supports both PSM16 and PSM and is similar to OpenMPT in playback quality.&lt;br /&gt;
* [http://ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/mxinfo/epictest.zip EPICTEST] is a demonstration of the Epic Megagames MASI. It contains CONVERT.EXE which can be used to convert modules to the new PSM format.&lt;br /&gt;
* [http://www.jazz2online.com/J2Ov2/downloads/info.php?levelID=5471#29435] JJ1MOD can convert S3M files to new PSM, though often with errors (Though these are usually only detectable with older programs such as game executables.) It is currently the only utility able to do this, and works only with New Format.&lt;br /&gt;
&lt;br /&gt;
= Notes =&lt;br /&gt;
&lt;br /&gt;
The New PSM format was reverse engineered by Levellord and tidied up by Levellass. It is possible there may be minor errors in the sample format information, especially since this is poorly documented.&lt;br /&gt;
Some format definitions have been updated and corrected by Johannes Schultz of the OpenMPT development team.&lt;br /&gt;
&lt;br /&gt;
The PSM16 format documentation was found on Wotsit and written up by Levellass (this appears to be an official document from the MASI developer). More info is needed.&lt;br /&gt;
&lt;br /&gt;
In all formats the following table shows how note bytes are converted into actual notes: (PSM new format has the widest range, 0-255)&lt;br /&gt;
&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;br /&gt;
           | C-0   0 | C-1  12 | C-2  24 | C-3  36 | C-4  48 |&lt;br /&gt;
           | C#0   1 | C#1  13 | C#2  25 | C#3  37 | C#4  49 |&lt;br /&gt;
           | D-0   2 | D-1  14 | D-2  26 | D-3  38 | D-4  50 |&lt;br /&gt;
           | D#0   3 | D#1  15 | D#2  27 | D#3  39 | D#4  51 |&lt;br /&gt;
           | E-0   4 | E-1  16 | E-2  28 | E-3  40 | E-4  52 |&lt;br /&gt;
           | F-0   5 | F-1  17 | F-2  29 | F-3  41 | F-4  53 |&lt;br /&gt;
           | F#0   6 | F#1  18 | F#2  30 | F#3  42 | F#4  54 |&lt;br /&gt;
           | G-0   7 | G-1  19 | G-2  31 | G-3  43 | G-4  55 |&lt;br /&gt;
           | G#0   8 | G#1  20 | G#2  32 | G#3  44 | G#4  56 |&lt;br /&gt;
           | A-0   9 | A-1  21 | A-2  33 | A-3  45 | A-4  57 |&lt;br /&gt;
           | A#0  10 | A#1  22 | A#2  34 | A#3  46 | A#4  58 |&lt;br /&gt;
           | B-0  11 | B-1  23 | B-2  35 | B-3  47 | B-4  59 |&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=6210</id>
		<title>ProTracker Studio Module</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=6210"/>
		<updated>2015-08-10T14:11:30Z</updated>

		<summary type="html">&lt;p&gt;Saga: Actually PSM16 looks a lot like S3M internally, not MOD.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 1-256 (PSM) / 1-32 (PSM16)&lt;br /&gt;
 | NumTracks = unlimited (PSM) / 1 (PSM16)&lt;br /&gt;
 | Game1 = Epic Pinball&lt;br /&gt;
 | Game2 = Extreme Pinball&lt;br /&gt;
 | Game3 = Jazz Jackrabbit&lt;br /&gt;
 | Game4 = One Must Fall&lt;br /&gt;
 | Game5 = Silverball&lt;br /&gt;
 | Game6 = Sinaria&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;ProTracker Studio Module&#039;&#039;&#039; (PSM) file format is used for the music in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]].  The file format is named after ProTracker, an Amiga program, though this program was probably actually not used to write PSM files. One Must Fall&#039;s music was written in Multitracker, and the music for Jazz Jackrabbit, Epic Pinball and Extreme Pinball probably in Scream Tracker.&lt;br /&gt;
&lt;br /&gt;
There are two file types that use the extension .PSM; they are both used by Epic Megagames&#039; MASI sound system, but are used by different versions of the system. The two formats are:&lt;br /&gt;
&lt;br /&gt;
* PSM New Format: Used by Jazz Jackrabbit, Epic Pinball, Extreme Pinball, One Must Fall, Sinaria (in this game with slight differences, see below), newest PSM format&lt;br /&gt;
* PSM 16:         Used by Silverball, an older version of the format which is closer to ScreamTracker-style modules.&lt;br /&gt;
&lt;br /&gt;
The most common of the two PSM formats is the new format, and most programs that try to interpret PSM files will be expecting this. For example, ModPlug Player cannot open Silverball files as these are in the PSM 16 format.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM New Format =&lt;br /&gt;
&lt;br /&gt;
This format is used by [[:Category:Epic Megagames|Epic]] games in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]]. It is notable for consisting of a number of segments (chunks) and sub segments. It bears the 4-byte signature &#039;PSM &#039; at the file start.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Song segment&lt;br /&gt;
 Samples&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 12 bytes long:&lt;br /&gt;
&lt;br /&gt;
 File header:&lt;br /&gt;
 0   4  ID     &#039;PSM &#039;; indicates file is PSM format&lt;br /&gt;
 4   4  Size   Filesize - 12&lt;br /&gt;
 8   4  ID2    &#039;FILE&#039;; indicates start of file info&lt;br /&gt;
&lt;br /&gt;
After the header, some chunks follow in IFF-style. You should not expect chunks to come up in the same order as they are described here. A good way to handle chunks is to read the 4-Byte ID and the 4-Byte size field first, then evaluate the ID and decide what to do next based on this ID. Note that the size field does not include the ID and itself; it only holds the size of the chunk &#039;&#039;content&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Title segment ==&lt;br /&gt;
&lt;br /&gt;
This segment is optional, and one of the few segments that can be absent when playing PSM files in most programs. (Most programs expect all other segments to exist, even if they are not vital.)&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;TITL&#039;; indicates a title follows&lt;br /&gt;
 4   4  Size   Size of title as dword after this dword&lt;br /&gt;
 8   ?  Title  Song title&lt;br /&gt;
&lt;br /&gt;
== Song info segment ==&lt;br /&gt;
&lt;br /&gt;
This segment seems to indicate the beginning of the song data and is not really relevant when parsing.&lt;br /&gt;
&lt;br /&gt;
 12  4  ID     &#039;SDFT&#039;; indicates start of format info&lt;br /&gt;
 16  4  Size   Size of next header as dword, (8)&lt;br /&gt;
 20  8  Song   &#039;MAINSONG&#039;; indicates song type. No other song types are known.&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
Each pattern is stored in its own PBOD chunk. Note that there are two possible formats for this chunk; one is used in the &amp;quot;old&amp;quot; format (as used in Epic Pinball, Extreme Pinball, Jazz Jackrabbit, One Must Fall) and the other in the &amp;quot;new&amp;quot; format (as used in Sinaria)&lt;br /&gt;
&lt;br /&gt;
 Pattern segment:&lt;br /&gt;
 0   4  ID     &#039;PBOD&#039;; indicates a pattern follows (Pattern BODy)&lt;br /&gt;
 4   4  Size   Length of pattern data as dword, after this dword&lt;br /&gt;
 4   4  Size   Same value again.&lt;br /&gt;
&lt;br /&gt;
 Pattern:&lt;br /&gt;
 0 4/8  Number Pattern ID. See note below.&lt;br /&gt;
 4   2  Row n  Number of rows in ALL channels in pattern (64 usually, but can differ.) as word.&lt;br /&gt;
 6   ?  Data   Contains pattern data as a number of rows of interlaced channels (12341234...)&lt;br /&gt;
               &#039;&#039;Usual&#039;&#039; settings is 64 rows of 4 channels. Epic Pinball has shorter patterns for example, but they also include a &amp;quot;break to row&amp;quot; command at the end of the pattern.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; In the old format, this starts with a &#039;P&#039; and is followed by an integer number which is the pattern number, padded to 4 bytes with spaces. Caution: This number might or might not be zero-padded; In some files, the ID of the first pattern could be &#039;P0  &#039;, but there are also files where it is &#039;P00 &#039;!. In C/C++, you could use atoi() to parse this value. In the new format (Sinaria), This field is 8 bytes long instead of 4 bytes, and the first 4 bytes read &amp;quot;PATT&amp;quot;, so the first pattern could be for example &#039;PATT0   &#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Pattern row channel entry:&lt;br /&gt;
 ?   1  Fill   Convert this byte value into binary; (240 -&amp;gt; 11110000), the first four     &lt;br /&gt;
               values                          &lt;br /&gt;
 +1  1  chan   What channel this belongs to, 0-255, each filled only once per tick, this is &lt;br /&gt;
               what, by absence, identifies empty channels. It is possible that actual PSM implementations will support less channels and crash if a file contains too many channels.&lt;br /&gt;
 +2  1  Note   Pitch, $01 is C-1, etc... The octaves are aligned by 16, i.e. B-1 is $0C but the next note, C-2, is $10.&lt;br /&gt;
 +3  1  Ins    Instrument used, 0-31&lt;br /&gt;
 +4  1  Vol    Volume change to, 0-63 = 0-127; optional&lt;br /&gt;
 +5  1  Effect Effect to use, volume slide, Portamanto...&lt;br /&gt;
 +6  1  Eff Am Strength of effect, e.g amount of slide&lt;br /&gt;
&lt;br /&gt;
Each row consists of a word giving the size of the row (Including the word) followed by the channel data. A channel is only included if it has data in it, but a totally empty row is still included. So an &#039;empty&#039; row (Where none of the channels have data.) thus consists of just a word of value 2.&lt;br /&gt;
&lt;br /&gt;
Each channel entry consists of between 3-7 bytes. The first byte is a flag that shows what data follows. (The first four bits indicate whether there are bytes for the following four variables; Note ($80), Instrument ($40), Volume ($20), Effect AND Effect magnitude ($10). Thus 5 bytes are represented by a combination of 4 possibilities.) The next byte identifies the channel (Since each channel may or may not be present.) starting at 0 for channel 1. The remaining 5 bytes may or may not be present and contain data for Note, Instrument(Sample) used, Volume change for channel, Effect and Effect magnitude.&lt;br /&gt;
&lt;br /&gt;
There are several things to note about this; Effect and Effect magnitude MUST occur together. Sample numbers, like channels are numbered starting at 0, not 1. Magnitudes (For effect AND volume) are from 0-127, not 0-64 as in other formats.&lt;br /&gt;
&lt;br /&gt;
=== Effect conversion ===&lt;br /&gt;
&lt;br /&gt;
Note that this table is guaranteed to be correct; Most effects seem to be converted correctly, though. Note that these values are not correct for the PSM files that can be found in the game Sinaria. Leave out all divisions and it will be correct again.&lt;br /&gt;
&lt;br /&gt;
 PSM Command   Param length  S3M Command&lt;br /&gt;
 &lt;br /&gt;
  Volume commands&lt;br /&gt;
    1           1 Byte        DxF - fine volside up&lt;br /&gt;
    2           1 Byte        Dx0 - volslide up&lt;br /&gt;
    3           1 Byte        DFx - fine volslide down&lt;br /&gt;
    4           1 Byte        D0x - volslide down&lt;br /&gt;
 &lt;br /&gt;
 Portamento commands&lt;br /&gt;
    B           1 Byte        FFx - fine porta up (divide x by 4)&lt;br /&gt;
    C           1 Byte        Fxx - porta up (if x &amp;lt; 4, use FFx, else divide x by 4)&lt;br /&gt;
    D           1 Byte        EFx - fine porta down (divide x by 4)&lt;br /&gt;
    E           1 Byte        Exx - porta down (if x &amp;lt; 4, use EFx, else divide x by 4)&lt;br /&gt;
    F           1 Byte        Gxx - portamento (divide x by 4)&lt;br /&gt;
   10           1 Byte        S1x - glissando control&lt;br /&gt;
   11           1 Byte        Lx0 - tone porta + volslide up&lt;br /&gt;
   12           1 Byte        L0x - tone porta + volslide down&lt;br /&gt;
    &lt;br /&gt;
 Vibrato&lt;br /&gt;
   15           1 Byte        Hxy - vibrato&lt;br /&gt;
   16           1 Byte        S3x - vibrato waveform&lt;br /&gt;
   17           1 Byte        K0x - vibrato + volslide up&lt;br /&gt;
   18           1 Byte        Kx0 - vibrato + volslide down&lt;br /&gt;
   	&lt;br /&gt;
 Tremolo			&lt;br /&gt;
   1F           1 Byte        Rxy - tremolo&lt;br /&gt;
   20           1 Byte        S4x - tremolo waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample commands&lt;br /&gt;
   29           3 Bytes       Oxx - offset (only take the 2nd byte)&lt;br /&gt;
   2A           1 Byte        Q0x - retrigger&lt;br /&gt;
   2B           1 Byte        SCx - note cut&lt;br /&gt;
   2C           1 Byte        SDx - note delay&lt;br /&gt;
 &lt;br /&gt;
 Position change&lt;br /&gt;
   33           2 Bytes(?)    Bxx - position jump (divide by 2)&lt;br /&gt;
   34           1 Byte        Cxx - break to row (divide by 2)&lt;br /&gt;
   35           1 Byte        SBx - pattern loop&lt;br /&gt;
   36           1 Byte        SEx - pattern delay&lt;br /&gt;
  &lt;br /&gt;
 Speed change&lt;br /&gt;
   3D           1 Byte        Axx - set speed&lt;br /&gt;
   3E           1 Byte        Txx - set tempo&lt;br /&gt;
 &lt;br /&gt;
 Misc. commands&lt;br /&gt;
   47           1 Byte        Jxy - arpeggio&lt;br /&gt;
   48           1 Byte        S2x - set finetune&lt;br /&gt;
   49           1 Byte        S8x - set balance&lt;br /&gt;
&lt;br /&gt;
Effect interpretation is different in Sinaria&#039;s new format.&lt;br /&gt;
&lt;br /&gt;
== Song segment ==&lt;br /&gt;
&lt;br /&gt;
This segment contains most of the important data used to play the song. It contains several sub-segments, each of the same format as a normal segment, but contained in the song segment. Note that there might be more than one song segment and thus, more than one order list, default speed, default tempo, etc... For example, in Extreme Pinball, all the different jingles and mission songs are stored as separate SONG chunks. It is up to the developer to find a clever way of managing / playing several sub songs.&lt;br /&gt;
&lt;br /&gt;
 Segment structure:&lt;br /&gt;
 0   4  ID     &#039;SONG&#039; indicates start of song structure&lt;br /&gt;
 4   4  Size   Size of song structure, including all sub-segments&lt;br /&gt;
 8   9  Type   Type of song this is for; This is &#039;MAINSONG &#039; in almost all PSM files. Extreme Pinball has several SONG items with different types!&lt;br /&gt;
 17  1  Comp   Compression, for PSM = 1 (Uncompressed)&lt;br /&gt;
 18  1  Chan   Number of channels, usually, but not always, 4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Date sub-segment ===&lt;br /&gt;
&lt;br /&gt;
This dates the file and is used by some programs. It is usually the first sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DATE&#039; indicates date data&lt;br /&gt;
 4   4  Size   Size of date segment (6)&lt;br /&gt;
 8   6  Date   Date as text, YYMMDD&lt;br /&gt;
&lt;br /&gt;
This can also be used as a way to heuristically detect if the new version of the format is being used. Sinaria&#039;s song dates are: 800211, 940902, 940903, 940906, 940914, 941213&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Order sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Orders describe how patterns are arranged in the song. This allows the same pattern of instruments to be played more than once in a song (e.g. a chorus). without the pattern data having to be duplicated. There should be only one order. This section also contains basic song information. It usually follows the date sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;OPLH&#039; indicates start of pattern placement order&lt;br /&gt;
 4   4  Size   Size of order segment&lt;br /&gt;
 8   2  Cnt.   Number of following chunks&lt;br /&gt;
&lt;br /&gt;
Now, the following chunks may follow until the end of the &amp;quot;OPLH&amp;quot; chunk is reached. Every chunk is identified by the first byte:&lt;br /&gt;
* $00 (1 Byte): End (Nothing follows)&lt;br /&gt;
* $01 (5/9 Bytes): Order list item follows (e.g. &amp;quot;P0  &amp;quot;, &amp;quot;P12 &amp;quot; in old format or &amp;quot;PATT0   &amp;quot; in new format, see above) - join those to get the complete order list.&lt;br /&gt;
* $04 (3 Bytes): This 16-bit value indicates the &amp;quot;restart chunk&amp;quot;. If the end of the subsong is reached, it will jump back to this chunk. In many cases, this would be 4th chunk (no 3rd chunk, as the chunk index is starting at 0!), which is a panning index in most PSMs - So you would just go to the nearest order list item that&#039;s following this chunk. However, this can also point to a valid order list chunk.&lt;br /&gt;
* $07 (2 Bytes): Next byte is default speed for this subtune&lt;br /&gt;
* $08 (2 Bytes): Next byte is default tempo for this subtune&lt;br /&gt;
* $0C (7 Bytes): Sample map table(?): This chunk is always $0C $00 $FF $00 $00 $01 $00. The purpose is unknown.&lt;br /&gt;
* $0D (4 Bytes): Channel panning index. Next byte is channel number (Start at 0), then initial pan ($00 ... $FF) and a byte follow. The byte seems to tell what to do with the previous pan position (0 - use it, 2 - ignore it, make this channel surround, 4 - set to center).&lt;br /&gt;
* $0E (3 Bytes): Channel volume index. Next byte is channel number (Start at 0), then volume ($00 ... $FF). $FF in most (all?) cases.&lt;br /&gt;
&lt;br /&gt;
=== Pattern list ===&lt;br /&gt;
&lt;br /&gt;
This is simply a list of all the patterns used in the file. You do not really need to parse this, it seems to be a purely informational chunk.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;PATT&#039; indicates start of pattern list&lt;br /&gt;
 4   4  Size   Size of pattern list after this&lt;br /&gt;
 8   4  Size   Same as above&lt;br /&gt;
 12  4x Pat    An ordered list &#039;P0  &#039;, &#039;P1  &#039;... for all patterns in the file, each entry 4 bytes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sample list sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Similar to the above, this is a list of all the samples used in the file. It is usually the last sub-segment in the song segment and you do not really need to parse this.&lt;br /&gt;
&lt;br /&gt;
  0  4   ID     &#039;DSAM&#039;; indicates start of sample list, used to say what samples are &#039;full&#039;&lt;br /&gt;
                Any samples not on this list will be ignored, even if they have data&lt;br /&gt;
  4  4   Size   Size of list after this&lt;br /&gt;
  8  4   Size   Same value as above&lt;br /&gt;
  12 15x Entry  Sample entries, one for each sample in the file, each entry 15 bytes&lt;br /&gt;
&lt;br /&gt;
 Sample entry:&lt;br /&gt;
 0   8  Format Sample format, padded with spaces (END, RAG2...) This is important to some programs&lt;br /&gt;
 8   4  ID     &#039;I0  &#039;, &#039;I1  &#039;... the sample ID (&#039;I&#039; means &#039;Instrument&#039;). Again, be sure to accept both &#039;I0  &#039; and &#039;I00 &#039;!&lt;br /&gt;
 12  2  Num    The sample number, 0,1,2... for the sample&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
Samples are the raw sound data that makes up the instruments on the song. The actual format depends on the sample format. Samples have information in their headers which allows data to be played at different pitches (Speeds.) and to loop from and to various points in the data. This is by far the largest part of the file, since the raw data takes up so much space.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DSMP&#039; indicates start of sample&lt;br /&gt;
 4   4  Size   Size of following sample as &#039;DSMP&#039; + dword from end of word&lt;br /&gt;
 8   9  Flags  If highest bit is set, then sample is looped&lt;br /&gt;
 9   8  Songn. Filename of the original module (without extension)&lt;br /&gt;
 17  4  INSx   Last digit of sample (Instrument) number, 0-9; with 31 instruments possible&lt;br /&gt;
               Only last digit is shown. E.g 1st, 11th, 21st and 31st sample is &#039;INS0&#039;&lt;br /&gt;
 21  33 Name   Defines the instrument name or file, usually a .st or line of text&lt;br /&gt;
 54  51 Header Sample parameters (Can also 58 bytes long, padded with nuls)&lt;br /&gt;
               Byte 1-6 are unknown ($00 $00 $00 $00 $00 $FF)&lt;br /&gt;
               Bytes 7-8 is instrument number&lt;br /&gt;
               Bytes 9-12 are sample length&lt;br /&gt;
               Bytes 13-16 are loop start&lt;br /&gt;
               Bytes 17-20 are loop end (all $FF means at end of sample)&lt;br /&gt;
               Bytes 21-22 are unknown (second byte could be default pan, but seems to be unused)&lt;br /&gt;
               Byte 23 is default volume&lt;br /&gt;
               Bytes 24-27 are unknwon&lt;br /&gt;
               Bytes 28-29 is frequency (Sample rate)&lt;br /&gt;
               21 $00-bytes follow&lt;br /&gt;
 105 ?  Data   Music data in 8-bit mono format&lt;br /&gt;
&lt;br /&gt;
The sample header is slightly different in Sinaria&#039;s new format: INSx is 8 bytes long (like the PATT IDs), and the last 21 $00-bytes are just 16 bytes.&lt;br /&gt;
&lt;br /&gt;
The PSM new format, along with the PSM 16 format use delta-encoded samples, something to make the file smaller when zipped. &#039;Deltas&#039;, convert a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. It has the effect that if a single byte in the sample is changed, the entire sample will be degraded. This use of deltas varies slightly from that of the PSM 16. The &#039;start value&#039; of the string is assumed to be $80 (128) and the first byte will thus turn this into the first desired value, the second delta converts the first value to the second, and so on.) All deltas are signed, 1-byte values, but loop (Thus 10 - 20 = -10 can also be considered as 10 + 236 = 246). An example of this is as follows:&lt;br /&gt;
&lt;br /&gt;
 RAW:   (128) 64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: -64  0   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM 16 =&lt;br /&gt;
&lt;br /&gt;
This is the format used in [[Silverball]], early versions of Epic Pinball and possibly other games. The designation &#039;Protracker Studio 16 format&#039; was given to it by the only reliable source of information on this format, and may not be the official designation.&lt;br /&gt;
&lt;br /&gt;
The format bears many similarities to the S3M format; the file is set out roughly the same, patterns and samples are similar, indeed, near identical and the functionality is similar. It also shows many similarities to the ProTracker MOD format and retains vestiges of Amiga compatibility.&lt;br /&gt;
&lt;br /&gt;
This format can be identified by its signature &#039;PSMþ&#039;, though files may lack this and still function.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Order&lt;br /&gt;
 Pan segment&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Sample data&lt;br /&gt;
 Sample headers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
 0    4  Sig      Signature, &#039;PSMþ&#039;&lt;br /&gt;
 4    59 Title    Song title, padded with nulls. Unlike other formats, this must also be terminated&lt;br /&gt;
                  with a null byte. (It sometimes is not terminated, though.)&lt;br /&gt;
 62   1           This must be $1A to end the song name, like in S3M format.&lt;br /&gt;
 64   1  Type     Song type, First bit: 0 - Module (w/samp.), 1 - Song (w/o samples)&lt;br /&gt;
                  Second bit: 0 - 3 octave Protracker, 1 - 5 octave; remaining bits reserved.&lt;br /&gt;
 65   1  PSM v    PSM format version, $10 for this format (Hence the name PSM 16) = &#039;v1.00&#039;.&lt;br /&gt;
                  Sometimes, this is also $01, but there&#039;s no difference in the format itself.&lt;br /&gt;
 66   1  Patt v   Pattern version, 0 or 1. 0 means the pattern is stored in the module are in the 32&lt;br /&gt;
                  channel file format.  A 1 signifies the patterns as being stored as a 255&lt;br /&gt;
                  channel format. (I have not found any PSM16 modules that have this format.)&lt;br /&gt;
 67   1   Speed   Song speed&lt;br /&gt;
 68   1   BPM     Beats per minute, the default Amiga BPM value. (The only reason that the Amiga BPM&lt;br /&gt;
                  format is still followed here is that it allows more control over the final hz value.)&lt;br /&gt;
                  Range: 32 to 255.&lt;br /&gt;
 69   1   Vol     Master volume of song, 0-255&lt;br /&gt;
 70   2   Len     Song length, 0-255. The number of patterns to play in the song, in total.&lt;br /&gt;
 72   2   Ordlen  The number of orders actually stored at the order offset. It was hoped that the&lt;br /&gt;
                  PSM 16 format would allow multiple orders, so this would be the length of the first&lt;br /&gt;
                  order. This doesn&#039;t appea to ahve happened, and is usually the same as the previous value.&lt;br /&gt;
 74   2   Patnum  Number of patterns in the song. 1-255&lt;br /&gt;
 76   2   Sampnum Number of samples and &#039;sample structures&#039; in song, 1-255&lt;br /&gt;
 78   2   NCIS    Number of channels in song to PLAY. 1-32. &lt;br /&gt;
 80   2   NCP     Number of Channels to Process; describes the MAXIMUM number of channels to process.&lt;br /&gt;
                  As an example, when converting 669 files,  NCP = 9 because some track information &lt;br /&gt;
                  is in Channel 8, but the Number of Channels to Play was set to 8, (Channel numbers&lt;br /&gt;
                  to play from 0 to 7.) 1-32&lt;br /&gt;
 82   4   Ordoff  Location of order in header&lt;br /&gt;
 86   4   Panoff  Location of pan positions in header&lt;br /&gt;
 90   4   Patoff  Location of patterns in header&lt;br /&gt;
 94   4   Sampoff Location of sample headers in header&lt;br /&gt;
 98   4   Commoff Location of comments in header&lt;br /&gt;
 102  4   Patsiz  Total pattern size; the total size of all the patterns loaded from the pattern offset.&lt;br /&gt;
 106  40  Fillers 10 fillers, to be used for any possible expansions.&lt;br /&gt;
&lt;br /&gt;
It is important to notice that the offsets point to the first byte &#039;&#039;&#039;after&#039;&#039;&#039; the chunk ID, i.e. &amp;quot;Ordoff&amp;quot; points to the first byte after &amp;quot;PORD&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Order and Pan positions ==&lt;br /&gt;
&lt;br /&gt;
These are two separate segments, pointed to in the header. They may be anywhere, but usually follow the header sometimes after an amount of blank space. They are often padded with blank space. They are basically lists.&lt;br /&gt;
&lt;br /&gt;
Order: This segment is pointed to in the header, and sets the PSM 16 format apart. The PSM 16 format was designed to be much more like the MOD format, allowing game designers to set flags to switch from one set of patterns to another, in effect allowing one file to contain more than one song. (For example a boss flag might make the music switch from a clam patterns 1-4 to a racy and dangerous patterns 5-7.)&lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    Signature, not needed, &#039;PORD&#039;&lt;br /&gt;
 4    ?   Ords   Pattern numbers and order. There will be [Ordlen] bytes of patterns&lt;br /&gt;
 ?    2   Lang   Order language, not implemented, so left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pan Positions: &lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    &#039;PPAN&#039;&lt;br /&gt;
 4    12  Pan    Pan positions; empty positions left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
 0    2   Size   Size of pattern, including these bytes&lt;br /&gt;
 2    1   Len    Length of pattern, in rows. Max length is 64 rows.&lt;br /&gt;
 3    1   Chan   Number of channels in pattern, 1-32&lt;br /&gt;
 4    ?   Data   Pattern data&lt;br /&gt;
&lt;br /&gt;
This is similar to the previous two segments, except actual pattern data is stored here. Patterns are very similar to the S3M format, and consist of y rows of x channels. Each row contains a number of channels and ends with a byte of value 0. Each channel is between 2-6+ bytes long. A totally empty channel is represented by a single byte of value 0.&lt;br /&gt;
&lt;br /&gt;
Each channel starts with a flag byte, abcddddd, where a,b and c indicate whether there is a note and instrument, volume or special effect and effect magnitude in the following data, and dddd is the channel number (0-31, used since a given channel may or may not be present in a row.)&lt;br /&gt;
&lt;br /&gt;
The usual maximum length of a channel entry is 6 bytes (1 flag byte, 2 Note AND instrument bytes, 1 volume byte and two Effect and Effect magnitude bytes.) Thus Note&amp;amp;ins\Eff&amp;amp;Eff mag must always occur together.&lt;br /&gt;
&lt;br /&gt;
Like S3M, volume range is 0-64, as is special magnitude. However, special effects range from 0-255, like PSM New Format.&lt;br /&gt;
&lt;br /&gt;
=== Effects conversion ===&lt;br /&gt;
&lt;br /&gt;
 ###  Co  MOD  Description               Arguments&lt;br /&gt;
 ---  --  ---  -----------               ---------&lt;br /&gt;
 Volume Commands&lt;br /&gt;
   1  A1   EA  Fine Volume Slide Up      B xx xx=speed&lt;br /&gt;
   2  A2   A   Volume Slide Up           B xx xx=speed&lt;br /&gt;
   3  A3   EB  Fine Volume Slide Down    B xx xx=speed&lt;br /&gt;
   4  A4   A   Volume Slide Down         B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Portamento Commands&lt;br /&gt;
  10  B0   E1  Fine Porta Up             B xx xx=speed&lt;br /&gt;
  11  B1   1   Portamento Up             B xx xx=speed&lt;br /&gt;
  12  B2   E2  Fine Porta Down           B xx xx=speed&lt;br /&gt;
  13  B3   2   Portamento Down           B xx xx=speed&lt;br /&gt;
  14  B4   3   Tone Portamento           B xx xx=speed&lt;br /&gt;
  15  B5   E3  Set Glissando Control     B xx xx=0 - Off, 1 - On&lt;br /&gt;
  16  B6   5   Tone Port+Vol Slide Up    B xx xx=speed&lt;br /&gt;
  17  B7   5   Tone Port+Vol Slide Down  B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Vibrato Commands&lt;br /&gt;
  20  C0   4   Vibrato                   B xy x=speed, y=depth&lt;br /&gt;
  21  C1   E4  Set Vibrato Waveform      B x  x=Waveform&lt;br /&gt;
  21  C2   6   Vibrato+Vol Slide Up      B xx xx=speed&lt;br /&gt;
  22  C3   6   Vibrato+Vol Slide Down    B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Tremolo Commands&lt;br /&gt;
  30  D0   7   Tremolo                   B xy x=speed, y=depth&lt;br /&gt;
  31  D1   E7  Set Tremolo Control       B x  x=Waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample Commands&lt;br /&gt;
  40  E0   9   Sample Offset             3B Position for offset change (0-1,048,575)&lt;br /&gt;
  41  E1   E9  Retrig Note               B xx xx=tick to retrigger sample&lt;br /&gt;
  42  E2   EC  Note Cut                  B xx xx=tick to cut note&lt;br /&gt;
  43  E3   ED  Note Delay                B xx xx=ticks to delay note&lt;br /&gt;
 &lt;br /&gt;
 Pos. Change Commands&lt;br /&gt;
  50  F0   B   Position Jump             B xx xx=order position&lt;br /&gt;
  51  F1   D   Pattern Break             B xx Skip to line xx in next pattern&lt;br /&gt;
  52  F2   E6  Jump Loop                 B xx xx=number of loops  0 Set&lt;br /&gt;
  53  F3   EE  Pattern Delay             B xx xx=notes to delay pattern&lt;br /&gt;
 &lt;br /&gt;
 Speed Change Cmds&lt;br /&gt;
  60  G0   F   Set Regular Speed         B xx xx=speed&lt;br /&gt;
  61  G1   F   Set BPM                   B xx xx=BPM (32-255)&lt;br /&gt;
 &lt;br /&gt;
 Misc. Commands&lt;br /&gt;
  70  H0   0   Arpeggio                  B xy x=semitone #1, y=semitone #2&lt;br /&gt;
  71  H1   E5  Set Finetune              B xx xx=finetune&lt;br /&gt;
  72  H2       Set Balance               B xx xx=Balance (0-15)&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
 Sample segment&lt;br /&gt;
 0    4   ID     &#039;PSAM&#039; (Psm SAMple)&lt;br /&gt;
 4    ?  Data    Sample data&lt;br /&gt;
&lt;br /&gt;
 Sample header segment&lt;br /&gt;
 0    4   ID     &#039;PSAH&#039; (Psm SAmple Header)&lt;br /&gt;
 4    ?  Data    Sample headers&lt;br /&gt;
&lt;br /&gt;
 Sample header&lt;br /&gt;
 0    13  Name   Sample filename, terminated with a null.&lt;br /&gt;
 13   24  Desc   Sample description or comments.&lt;br /&gt;
 37   4   Offs   Location of raw sample data in file&lt;br /&gt;
 43   4   Mem    This is the physical offset in RAM/DRAM of the sample. (Often blank.)&lt;br /&gt;
 45   2   Num    Sample number, 1-255&lt;br /&gt;
 47   1   Type   Sample type: (In some games left blank; if this is the case then the&lt;br /&gt;
                 sample format is END, as used in most PSM New Format files)&lt;br /&gt;
                 Bit 0: 0 - Digital, 1 - Synthesized&lt;br /&gt;
                 Bit 2: 0 - 8-bit, 1 - 16-bit&lt;br /&gt;
                 Bit 3: 0 - Signed, 1 - Unsigned&lt;br /&gt;
                 Bit 4: 0 - Deltas, 1 - Raw&lt;br /&gt;
                 Bit 5: 0 - Loop normally, 1 - Bidirectional&lt;br /&gt;
                 Bit 6: 1 - Gravis patch (unsupported)&lt;br /&gt;
                 Bit 7: 0 - No loop, 1 - Loop sample&lt;br /&gt;
 48   4   Len    Sample length, in bytes.&lt;br /&gt;
 52   4   Rep st Sample repeat start; if sample loops, the loop starts here.&lt;br /&gt;
 56   4   Rep fn Sample repeat end, if sample loops, it ends here. If this is less than the sample&lt;br /&gt;
                 repeat start, the sample loops backwards.&lt;br /&gt;
 60   1   Tune   Fine tune; range 0-15, Tune 0-7 = 0-7; tune -1 - -8 = 8-15&lt;br /&gt;
 61   1   Vol    Sample volume, 0-64&lt;br /&gt;
 62   2   Freq   This is the frequency for the sample at a C of Octave 2.&lt;br /&gt;
                 Typical values are 8,000 hz to 8,448 hz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like S3M, sample headers are stored separately from the raw sample data. Unlike S3M, the number of sample headers doesn&#039;t have to be 31, but rather is the number of samples in the header. Sample headers are usually stored at then end of the file, after the raw sample data.&lt;br /&gt;
&lt;br /&gt;
A type of sample compression used often, like in the PSM New Format is &#039;Deltas&#039;, which converts a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. Thus:&lt;br /&gt;
&lt;br /&gt;
 RAW:        64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: 11  64   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
This is done to make files more compressible, but doesn&#039;t seem to be used much.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.shikadi.net/files/psm2scrm.zip psm2scrm.zip] - DOS program to convert .PSM songs into ScreamTracker .S3M format, suitable for playing in your favourite tracker/module player. Works only with PSM New Format and is not nearly as accurate as OpenMPT.&lt;br /&gt;
* [http://openmpt.org OpenMPT] 1.18 and newer can load all PSM and PSM16 files.&lt;br /&gt;
* [http://openmpt.org/legacy_software ModPlug Tracker] and OpenMPT 1.17 can play the files and save them as S3M. More complex songs don&#039;t load correctly though. Works only with new format.&lt;br /&gt;
* [http://kode54.foobar2000.org/ foo_dumb] is a plugin for various module formats for the Foobar2k media player. It supports both PSM16 and PSM and is similar to OpenMPT in playback quality.&lt;br /&gt;
* [http://ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/mxinfo/epictest.zip EPICTEST] is a demonstration of the Epic Megagames MASI. It contains CONVERT.EXE which can be used to convert modules to the new PSM format.&lt;br /&gt;
* [http://www.jazz2online.com/J2Ov2/downloads/info.php?levelID=5471#29435] JJ1MOD can convert S3M files to new PSM, though often with errors (Though these are usually only detectable with older programs such as game executables.) It is currently the only utility able to do this, and works only with New Format.&lt;br /&gt;
&lt;br /&gt;
= Notes =&lt;br /&gt;
&lt;br /&gt;
The New PSM format was reverse engineered by Levellord and tidied up by Levellass. It is possible there may be minor errors in the sample format information, especially since this is poorly documented.&lt;br /&gt;
Some format definitions have been updated and corrected by Johannes Schultz of the OpenMPT development team.&lt;br /&gt;
&lt;br /&gt;
The PSM16 format documentation was found on Wotsit and written up by Levellass (this appears to be an official document from the MASI developer). More info is needed.&lt;br /&gt;
&lt;br /&gt;
In all formats the following table shows how note bytes are converted into actual notes: (PSM new format has the widest range, 0-255)&lt;br /&gt;
&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;br /&gt;
           | C-0   0 | C-1  12 | C-2  24 | C-3  36 | C-4  48 |&lt;br /&gt;
           | C#0   1 | C#1  13 | C#2  25 | C#3  37 | C#4  49 |&lt;br /&gt;
           | D-0   2 | D-1  14 | D-2  26 | D-3  38 | D-4  50 |&lt;br /&gt;
           | D#0   3 | D#1  15 | D#2  27 | D#3  39 | D#4  51 |&lt;br /&gt;
           | E-0   4 | E-1  16 | E-2  28 | E-3  40 | E-4  52 |&lt;br /&gt;
           | F-0   5 | F-1  17 | F-2  29 | F-3  41 | F-4  53 |&lt;br /&gt;
           | F#0   6 | F#1  18 | F#2  30 | F#3  42 | F#4  54 |&lt;br /&gt;
           | G-0   7 | G-1  19 | G-2  31 | G-3  43 | G-4  55 |&lt;br /&gt;
           | G#0   8 | G#1  20 | G#2  32 | G#3  44 | G#4  56 |&lt;br /&gt;
           | A-0   9 | A-1  21 | A-2  33 | A-3  45 | A-4  57 |&lt;br /&gt;
           | A#0  10 | A#1  22 | A#2  34 | A#3  46 | A#4  58 |&lt;br /&gt;
           | B-0  11 | B-1  23 | B-2  35 | B-3  47 | B-4  59 |&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=5265</id>
		<title>ProTracker Studio Module</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=5265"/>
		<updated>2014-07-13T14:31:50Z</updated>

		<summary type="html">&lt;p&gt;Saga: New PSM format has subsongs. Change some other information to make more sense&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 1-256 (PSM) / 1-32 (PSM16)&lt;br /&gt;
 | NumTracks = unlimited (PSM) / 1 (PSM16)&lt;br /&gt;
 | Game1 = Epic Pinball&lt;br /&gt;
 | Game2 = Extreme Pinball&lt;br /&gt;
 | Game3 = Jazz Jackrabbit&lt;br /&gt;
 | Game4 = One Must Fall&lt;br /&gt;
 | Game5 = Silverball&lt;br /&gt;
 | Game6 = Sinaria&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;ProTracker Studio Module&#039;&#039;&#039; (PSM) file format is used for the music in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]].  The file format is named after ProTracker, an Amiga program, though this program was probably actually not used to write PSM files. One Must Fall&#039;s music was written in Multitracker, and the music for Jazz Jackrabbit, Epic Pinball and Extreme Pinball probably in Scream Tracker.&lt;br /&gt;
&lt;br /&gt;
There are two file types that use the extension .PSM; they are both used by Epic Megagames&#039; MASI sound system, but are used by different versions of the system. The two formats are:&lt;br /&gt;
&lt;br /&gt;
* PSM New Format: Used by Jazz Jackrabbit, Epic Pinball, Extreme Pinball, One Must Fall, Sinaria (in this game with slight differences, see below), newest PSM format&lt;br /&gt;
* PSM 16:         Used by Silverball, an older version of the format which is closer to ProTracker-style modules.&lt;br /&gt;
&lt;br /&gt;
The most common of the two PSM formats is the new format, and most programs that try to interpret PSM files will be expecting this. For example, ModPlug Player cannot open Silverball files as these are in the PSM 16 format.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM New Format =&lt;br /&gt;
&lt;br /&gt;
This format is used by [[:Category:Epic Megagames|Epic]] games in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]]. It is notable for consisting of a number of segments (chunks) and sub segments. It bears the 4-byte signature &#039;PSM &#039; at the file start.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Song segment&lt;br /&gt;
 Samples&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 12 bytes long:&lt;br /&gt;
&lt;br /&gt;
 File header:&lt;br /&gt;
 0   4  ID     &#039;PSM &#039;; indicates file is PSM format&lt;br /&gt;
 4   4  Size   Filesize - 12&lt;br /&gt;
 8   4  ID2    &#039;FILE&#039;; indicates start of file info&lt;br /&gt;
&lt;br /&gt;
After the header, some chunks follow in IFF-style. You should not expect chunks to come up in the same order as they are described here. A good way to handle chunks is to read the 4-Byte ID and the 4-Byte size field first, then evaluate the ID and decide what to do next based on this ID. Note that the size field does not include the ID and itself; it only holds the size of the chunk &#039;&#039;content&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Title segment ==&lt;br /&gt;
&lt;br /&gt;
This segment is optional, and one of the few segments that can be absent when playing PSM files in most programs. (Most programs expect all other segments to exist, even if they are not vital.)&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;TITL&#039;; indicates a title follows&lt;br /&gt;
 4   4  Size   Size of title as dword after this dword&lt;br /&gt;
 8   ?  Title  Song title&lt;br /&gt;
&lt;br /&gt;
== Song info segment ==&lt;br /&gt;
&lt;br /&gt;
This segment seems to indicate the beginning of the song data and is not really relevant when parsing.&lt;br /&gt;
&lt;br /&gt;
 12  4  ID     &#039;SDFT&#039;; indicates start of format info&lt;br /&gt;
 16  4  Size   Size of next header as dword, (8)&lt;br /&gt;
 20  8  Song   &#039;MAINSONG&#039;; indicates song type. No other song types are known.&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
Each pattern is stored in its own PBOD chunk. Note that there are two possible formats for this chunk; one is used in the &amp;quot;old&amp;quot; format (as used in Epic Pinball, Extreme Pinball, Jazz Jackrabbit, One Must Fall) and the other in the &amp;quot;new&amp;quot; format (as used in Sinaria)&lt;br /&gt;
&lt;br /&gt;
 Pattern segment:&lt;br /&gt;
 0   4  ID     &#039;PBOD&#039;; indicates a pattern follows (Pattern BODy)&lt;br /&gt;
 4   4  Size   Length of pattern data as dword, after this dword&lt;br /&gt;
 4   4  Size   Same value again.&lt;br /&gt;
&lt;br /&gt;
 Pattern:&lt;br /&gt;
 0 4/8  Number Pattern ID. See note below.&lt;br /&gt;
 4   2  Row n  Number of rows in ALL channels in pattern (64 usually, but can differ.) as word.&lt;br /&gt;
 6   ?  Data   Contains pattern data as a number of rows of interlaced channels (12341234...)&lt;br /&gt;
               &#039;&#039;Usual&#039;&#039; settings is 64 rows of 4 channels. Epic Pinball has shorter patterns for example, but they also include a &amp;quot;break to row&amp;quot; command at the end of the pattern.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; In the old format, this starts with a &#039;P&#039; and is followed by an integer number which is the pattern number, padded to 4 bytes with spaces. Caution: This number might or might not be zero-padded; In some files, the ID of the first pattern could be &#039;P0  &#039;, but there are also files where it is &#039;P00 &#039;!. In C/C++, you could use atoi() to parse this value. In the new format (Sinaria), This field is 8 bytes long instead of 4 bytes, and the first 4 bytes read &amp;quot;PATT&amp;quot;, so the first pattern could be for example &#039;PATT0   &#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Pattern row channel entry:&lt;br /&gt;
 ?   1  Fill   Convert this byte value into binary; (240 -&amp;gt; 11110000), the first four     &lt;br /&gt;
               values                          &lt;br /&gt;
 +1  1  chan   What channel this belongs to, 0-255, each filled only once per tick, this is &lt;br /&gt;
               what, by absence, identifies empty channels. It is possible that actual PSM implementations will support less channels and crash if a file contains too many channels.&lt;br /&gt;
 +2  1  Note   Pitch, $01 is C-1, etc... The octaves are aligned by 16, i.e. B-1 is $0C but the next note, C-2, is $10.&lt;br /&gt;
 +3  1  Ins    Instrument used, 0-31&lt;br /&gt;
 +4  1  Vol    Volume change to, 0-63 = 0-127; optional&lt;br /&gt;
 +5  1  Effect Effect to use, volume slide, Portamanto...&lt;br /&gt;
 +6  1  Eff Am Strength of effect, e.g amount of slide&lt;br /&gt;
&lt;br /&gt;
Each row consists of a word giving the size of the row (Including the word) followed by the channel data. A channel is only included if it has data in it, but a totally empty row is still included. So an &#039;empty&#039; row (Where none of the channels have data.) thus consists of just a word of value 2.&lt;br /&gt;
&lt;br /&gt;
Each channel entry consists of between 3-7 bytes. The first byte is a flag that shows what data follows. (The first four bits indicate whether there are bytes for the following four variables; Note ($80), Instrument ($40), Volume ($20), Effect AND Effect magnitude ($10). Thus 5 bytes are represented by a combination of 4 possibilities.) The next byte identifies the channel (Since each channel may or may not be present.) starting at 0 for channel 1. The remaining 5 bytes may or may not be present and contain data for Note, Instrument(Sample) used, Volume change for channel, Effect and Effect magnitude.&lt;br /&gt;
&lt;br /&gt;
There are several things to note about this; Effect and Effect magnitude MUST occur together. Sample numbers, like channels are numbered starting at 0, not 1. Magnitudes (For effect AND volume) are from 0-127, not 0-64 as in other formats.&lt;br /&gt;
&lt;br /&gt;
=== Effect conversion ===&lt;br /&gt;
&lt;br /&gt;
Note that this table is guaranteed to be correct; Most effects seem to be converted correctly, though. Note that these values are not correct for the PSM files that can be found in the game Sinaria. Leave out all divisions and it will be correct again.&lt;br /&gt;
&lt;br /&gt;
 PSM Command   Param length  S3M Command&lt;br /&gt;
 &lt;br /&gt;
  Volume commands&lt;br /&gt;
    1           1 Byte        DxF - fine volside up&lt;br /&gt;
    2           1 Byte        Dx0 - volslide up&lt;br /&gt;
    3           1 Byte        DFx - fine volslide down&lt;br /&gt;
    4           1 Byte        D0x - volslide down&lt;br /&gt;
 &lt;br /&gt;
 Portamento commands&lt;br /&gt;
    B           1 Byte        FFx - fine porta up (divide x by 4)&lt;br /&gt;
    C           1 Byte        Fxx - porta up (if x &amp;lt; 4, use FFx, else divide x by 4)&lt;br /&gt;
    D           1 Byte        EFx - fine porta down (divide x by 4)&lt;br /&gt;
    E           1 Byte        Exx - porta down (if x &amp;lt; 4, use EFx, else divide x by 4)&lt;br /&gt;
    F           1 Byte        Gxx - portamento (divide x by 4)&lt;br /&gt;
   10           1 Byte        S1x - glissando control&lt;br /&gt;
   11           1 Byte        Lx0 - tone porta + volslide up&lt;br /&gt;
   12           1 Byte        L0x - tone porta + volslide down&lt;br /&gt;
    &lt;br /&gt;
 Vibrato&lt;br /&gt;
   15           1 Byte        Hxy - vibrato&lt;br /&gt;
   16           1 Byte        S3x - vibrato waveform&lt;br /&gt;
   17           1 Byte        K0x - vibrato + volslide up&lt;br /&gt;
   18           1 Byte        Kx0 - vibrato + volslide down&lt;br /&gt;
   	&lt;br /&gt;
 Tremolo			&lt;br /&gt;
   1F           1 Byte        Rxy - tremolo&lt;br /&gt;
   20           1 Byte        S4x - tremolo waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample commands&lt;br /&gt;
   29           3 Bytes       Oxx - offset (only take the 2nd byte)&lt;br /&gt;
   2A           1 Byte        Q0x - retrigger&lt;br /&gt;
   2B           1 Byte        SCx - note cut&lt;br /&gt;
   2C           1 Byte        SDx - note delay&lt;br /&gt;
 &lt;br /&gt;
 Position change&lt;br /&gt;
   33           2 Bytes(?)    Bxx - position jump (divide by 2)&lt;br /&gt;
   34           1 Byte        Cxx - break to row (divide by 2)&lt;br /&gt;
   35           1 Byte        SBx - pattern loop&lt;br /&gt;
   36           1 Byte        SEx - pattern delay&lt;br /&gt;
  &lt;br /&gt;
 Speed change&lt;br /&gt;
   3D           1 Byte        Axx - set speed&lt;br /&gt;
   3E           1 Byte        Txx - set tempo&lt;br /&gt;
 &lt;br /&gt;
 Misc. commands&lt;br /&gt;
   47           1 Byte        Jxy - arpeggio&lt;br /&gt;
   48           1 Byte        S2x - set finetune&lt;br /&gt;
   49           1 Byte        S8x - set balance&lt;br /&gt;
&lt;br /&gt;
Effect interpretation is different in Sinaria&#039;s new format.&lt;br /&gt;
&lt;br /&gt;
== Song segment ==&lt;br /&gt;
&lt;br /&gt;
This segment contains most of the important data used to play the song. It contains several sub-segments, each of the same format as a normal segment, but contained in the song segment. Note that there might be more than one song segment and thus, more than one order list, default speed, default tempo, etc... For example, in Extreme Pinball, all the different jingles and mission songs are stored as separate SONG chunks. It is up to the developer to find a clever way of managing / playing several sub songs.&lt;br /&gt;
&lt;br /&gt;
 Segment structure:&lt;br /&gt;
 0   4  ID     &#039;SONG&#039; indicates start of song structure&lt;br /&gt;
 4   4  Size   Size of song structure, including all sub-segments&lt;br /&gt;
 8   9  Type   Type of song this is for; This is &#039;MAINSONG &#039; in almost all PSM files. Extreme Pinball has several SONG items with different types!&lt;br /&gt;
 17  1  Comp   Compression, for PSM = 1 (Uncompressed)&lt;br /&gt;
 18  1  Chan   Number of channels, usually, but not always, 4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Date sub-segment ===&lt;br /&gt;
&lt;br /&gt;
This dates the file and is used by some programs. It is usually the first sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DATE&#039; indicates date data&lt;br /&gt;
 4   4  Size   Size of date segment (6)&lt;br /&gt;
 8   6  Date   Date as text, YYMMDD&lt;br /&gt;
&lt;br /&gt;
This can also be used as a way to heuristically detect if the new version of the format is being used. Sinaria&#039;s song dates are: 800211, 940902, 940903, 940906, 940914, 941213&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Order sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Orders describe how patterns are arranged in the song. This allows the same pattern of instruments to be played more than once in a song (e.g. a chorus). without the pattern data having to be duplicated. There should be only one order. This section also contains basic song information. It usually follows the date sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;OPLH&#039; indicates start of pattern placement order&lt;br /&gt;
 4   4  Size   Size of order segment&lt;br /&gt;
 8   2  Cnt.   Number of following chunks&lt;br /&gt;
&lt;br /&gt;
Now, the following chunks may follow until the end of the &amp;quot;OPLH&amp;quot; chunk is reached. Every chunk is identified by the first byte:&lt;br /&gt;
* $00 (1 Byte): End (Nothing follows)&lt;br /&gt;
* $01 (5/9 Bytes): Order list item follows (e.g. &amp;quot;P0  &amp;quot;, &amp;quot;P12 &amp;quot; in old format or &amp;quot;PATT0   &amp;quot; in new format, see above) - join those to get the complete order list.&lt;br /&gt;
* $04 (3 Bytes): This 16-bit value indicates the &amp;quot;restart chunk&amp;quot;. If the end of the subsong is reached, it will jump back to this chunk. In many cases, this would be 4th chunk (no 3rd chunk, as the chunk index is starting at 0!), which is a panning index in most PSMs - So you would just go to the nearest order list item that&#039;s following this chunk. However, this can also point to a valid order list chunk.&lt;br /&gt;
* $07 (2 Bytes): Next byte is default speed for this subtune&lt;br /&gt;
* $08 (2 Bytes): Next byte is default tempo for this subtune&lt;br /&gt;
* $0C (7 Bytes): Sample map table(?): This chunk is always $0C $00 $FF $00 $00 $01 $00. The purpose is unknown.&lt;br /&gt;
* $0D (4 Bytes): Channel panning index. Next byte is channel number (Start at 0), then initial pan ($00 ... $FF) and a byte follow. The byte seems to tell what to do with the previous pan position (0 - use it, 2 - ignore it, make this channel surround, 4 - set to center).&lt;br /&gt;
* $0E (3 Bytes): Channel volume index. Next byte is channel number (Start at 0), then volume ($00 ... $FF). $FF in most (all?) cases.&lt;br /&gt;
&lt;br /&gt;
=== Pattern list ===&lt;br /&gt;
&lt;br /&gt;
This is simply a list of all the patterns used in the file. You do not really need to parse this, it seems to be a purely informational chunk.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;PATT&#039; indicates start of pattern list&lt;br /&gt;
 4   4  Size   Size of pattern list after this&lt;br /&gt;
 8   4  Size   Same as above&lt;br /&gt;
 12  4x Pat    An ordered list &#039;P0  &#039;, &#039;P1  &#039;... for all patterns in the file, each entry 4 bytes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sample list sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Similar to the above, this is a list of all the samples used in the file. It is usually the last sub-segment in the song segment and you do not really need to parse this.&lt;br /&gt;
&lt;br /&gt;
  0  4   ID     &#039;DSAM&#039;; indicates start of sample list, used to say what samples are &#039;full&#039;&lt;br /&gt;
                Any samples not on this list will be ignored, even if they have data&lt;br /&gt;
  4  4   Size   Size of list after this&lt;br /&gt;
  8  4   Size   Same value as above&lt;br /&gt;
  12 15x Entry  Sample entries, one for each sample in the file, each entry 15 bytes&lt;br /&gt;
&lt;br /&gt;
 Sample entry:&lt;br /&gt;
 0   8  Format Sample format, padded with spaces (END, RAG2...) This is important to some programs&lt;br /&gt;
 8   4  ID     &#039;I0  &#039;, &#039;I1  &#039;... the sample ID (&#039;I&#039; means &#039;Instrument&#039;). Again, be sure to accept both &#039;I0  &#039; and &#039;I00 &#039;!&lt;br /&gt;
 12  2  Num    The sample number, 0,1,2... for the sample&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
Samples are the raw sound data that makes up the instruments on the song. The actual format depends on the sample format. Samples have information in their headers which allows data to be played at different pitches (Speeds.) and to loop from and to various points in the data. This is by far the largest part of the file, since the raw data takes up so much space.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DSMP&#039; indicates start of sample&lt;br /&gt;
 4   4  Size   Size of following sample as &#039;DSMP&#039; + dword from end of word&lt;br /&gt;
 8   9  Flags  If highest bit is set, then sample is looped&lt;br /&gt;
 9   8  Songn. Filename of the original module (without extension)&lt;br /&gt;
 17  4  INSx   Last digit of sample (Instrument) number, 0-9; with 31 instruments possible&lt;br /&gt;
               Only last digit is shown. E.g 1st, 11th, 21st and 31st sample is &#039;INS0&#039;&lt;br /&gt;
 21  33 Name   Defines the instrument name or file, usually a .st or line of text&lt;br /&gt;
 54  51 Header Sample parameters (Can also 58 bytes long, padded with nuls)&lt;br /&gt;
               Byte 1-6 are unknown ($00 $00 $00 $00 $00 $FF)&lt;br /&gt;
               Bytes 7-8 is instrument number&lt;br /&gt;
               Bytes 9-12 are sample length&lt;br /&gt;
               Bytes 13-16 are loop start&lt;br /&gt;
               Bytes 17-20 are loop end (all $FF means at end of sample)&lt;br /&gt;
               Bytes 21-22 are unknown (second byte could be default pan, but seems to be unused)&lt;br /&gt;
               Byte 23 is default volume&lt;br /&gt;
               Bytes 24-27 are unknwon&lt;br /&gt;
               Bytes 28-29 is frequency (Sample rate)&lt;br /&gt;
               21 $00-bytes follow&lt;br /&gt;
 105 ?  Data   Music data in 8-bit mono format&lt;br /&gt;
&lt;br /&gt;
The sample header is slightly different in Sinaria&#039;s new format: INSx is 8 bytes long (like the PATT IDs), and the last 21 $00-bytes are just 16 bytes.&lt;br /&gt;
&lt;br /&gt;
The PSM new format, along with the PSM 16 format use delta-encoded samples, something to make the file smaller when zipped. &#039;Deltas&#039;, convert a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. It has the effect that if a single byte in the sample is changed, the entire sample will be degraded. This use of deltas varies slightly from that of the PSM 16. The &#039;start value&#039; of the string is assumed to be $80 (128) and the first byte will thus turn this into the first desired value, the second delta converts the first value to the second, and so on.) All deltas are signed, 1-byte values, but loop (Thus 10 - 20 = -10 can also be considered as 10 + 236 = 246). An example of this is as follows:&lt;br /&gt;
&lt;br /&gt;
 RAW:   (128) 64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: -64  0   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM 16 =&lt;br /&gt;
&lt;br /&gt;
This is the format used in [[Silverball]], early versions of Epic Pinball and possibly other games. The designation &#039;Protracker Studio 16 format&#039; was given to it by the only reliable source of information on this format, and may not be the official designation.&lt;br /&gt;
&lt;br /&gt;
The format bears many similarities to the S3M format; the file is set out roughly the same, patterns and samples are similar, indeed, near identical and the functionality is similar. It also shows many similarities to the ProTracker MOD format and retains vestiges of Amiga compatibility.&lt;br /&gt;
&lt;br /&gt;
This format can be identified by its signature &#039;PSMþ&#039;, though files may lack this and still function.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Order&lt;br /&gt;
 Pan segment&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Sample data&lt;br /&gt;
 Sample headers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
 0    4  Sig      Signature, &#039;PSMþ&#039;&lt;br /&gt;
 4    59 Title    Song title, padded with nulls. Unlike other formats, this must also be terminated&lt;br /&gt;
                  with a null byte. (It sometimes is not terminated, though.)&lt;br /&gt;
 62   1           This must be $1A to end the song name, like in S3M format.&lt;br /&gt;
 64   1  Type     Song type, First bit: 0 - Module (w/samp.), 1 - Song (w/o samples)&lt;br /&gt;
                  Second bit: 0 - 3 octave Protracker, 1 - 5 octave; remaining bits reserved.&lt;br /&gt;
 65   1  PSM v    PSM format version, $10 for this format (Hence the name PSM 16) = &#039;v1.00&#039;.&lt;br /&gt;
                  Sometimes, this is also $01, but there&#039;s no difference in the format itself.&lt;br /&gt;
 66   1  Patt v   Pattern version, 0 or 1. 0 means the pattern is stored in the module are in the 32&lt;br /&gt;
                  channel file format.  A 1 signifies the patterns as being stored as a 255&lt;br /&gt;
                  channel format. (I have not found any PSM16 modules that have this format.)&lt;br /&gt;
 67   1   Speed   Song speed&lt;br /&gt;
 68   1   BPM     Beats per minute, the default Amiga BPM value. (The only reason that the Amiga BPM&lt;br /&gt;
                  format is still followed here is that it allows more control over the final hz value.)&lt;br /&gt;
                  Range: 32 to 255.&lt;br /&gt;
 69   1   Vol     Master volume of song, 0-255&lt;br /&gt;
 70   2   Len     Song length, 0-255. The number of patterns to play in the song, in total.&lt;br /&gt;
 72   2   Ordlen  The number of orders actually stored at the order offset. It was hoped that the&lt;br /&gt;
                  PSM 16 format would allow multiple orders, so this would be the length of the first&lt;br /&gt;
                  order. This doesn&#039;t appea to ahve happened, and is usually the same as the previous value.&lt;br /&gt;
 74   2   Patnum  Number of patterns in the song. 1-255&lt;br /&gt;
 76   2   Sampnum Number of samples and &#039;sample structures&#039; in song, 1-255&lt;br /&gt;
 78   2   NCIS    Number of channels in song to PLAY. 1-32. &lt;br /&gt;
 80   2   NCP     Number of Channels to Process; describes the MAXIMUM number of channels to process.&lt;br /&gt;
                  As an example, when converting 669 files,  NCP = 9 because some track information &lt;br /&gt;
                  is in Channel 8, but the Number of Channels to Play was set to 8, (Channel numbers&lt;br /&gt;
                  to play from 0 to 7.) 1-32&lt;br /&gt;
 82   4   Ordoff  Location of order in header&lt;br /&gt;
 86   4   Panoff  Location of pan positions in header&lt;br /&gt;
 90   4   Patoff  Location of patterns in header&lt;br /&gt;
 94   4   Sampoff Location of sample headers in header&lt;br /&gt;
 98   4   Commoff Location of comments in header&lt;br /&gt;
 102  4   Patsiz  Total pattern size; the total size of all the patterns loaded from the pattern offset.&lt;br /&gt;
 106  40  Fillers 10 fillers, to be used for any possible expansions.&lt;br /&gt;
&lt;br /&gt;
It is important to notice that the offsets point to the first byte &#039;&#039;&#039;after&#039;&#039;&#039; the chunk ID, i.e. &amp;quot;Ordoff&amp;quot; points to the first byte after &amp;quot;PORD&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Order and Pan positions ==&lt;br /&gt;
&lt;br /&gt;
These are two separate segments, pointed to in the header. They may be anywhere, but usually follow the header sometimes after an amount of blank space. They are often padded with blank space. They are basically lists.&lt;br /&gt;
&lt;br /&gt;
Order: This segment is pointed to in the header, and sets the PSM 16 format apart. The PSM 16 format was designed to be much more like the MOD format, allowing game designers to set flags to switch from one set of patterns to another, in effect allowing one file to contain more than one song. (For example a boss flag might make the music switch from a clam patterns 1-4 to a racy and dangerous patterns 5-7.)&lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    Signature, not needed, &#039;PORD&#039;&lt;br /&gt;
 4    ?   Ords   Pattern numbers and order. There will be [Ordlen] bytes of patterns&lt;br /&gt;
 ?    2   Lang   Order language, not implemented, so left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pan Positions: &lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    &#039;PPAN&#039;&lt;br /&gt;
 4    12  Pan    Pan positions; empty positions left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
 0    2   Size   Size of pattern, including these bytes&lt;br /&gt;
 2    1   Len    Length of pattern, in rows. Max length is 64 rows.&lt;br /&gt;
 3    1   Chan   Number of channels in pattern, 1-32&lt;br /&gt;
 4    ?   Data   Pattern data&lt;br /&gt;
&lt;br /&gt;
This is similar to the previous two segments, except actual pattern data is stored here. Patterns are very similar to the S3M format, and consist of y rows of x channels. Each row contains a number of channels and ends with a byte of value 0. Each channel is between 2-6+ bytes long. A totally empty channel is represented by a single byte of value 0.&lt;br /&gt;
&lt;br /&gt;
Each channel starts with a flag byte, abcddddd, where a,b and c indicate whether there is a note and instrument, volume or special effect and effect magnitude in the following data, and dddd is the channel number (0-31, used since a given channel may or may not be present in a row.)&lt;br /&gt;
&lt;br /&gt;
The usual maximum length of a channel entry is 6 bytes (1 flag byte, 2 Note AND instrument bytes, 1 volume byte and two Effect and Effect magnitude bytes.) Thus Note&amp;amp;ins\Eff&amp;amp;Eff mag must always occur together.&lt;br /&gt;
&lt;br /&gt;
Like S3M, volume range is 0-64, as is special magnitude. However, special effects range from 0-255, like PSM New Format.&lt;br /&gt;
&lt;br /&gt;
=== Effects conversion ===&lt;br /&gt;
&lt;br /&gt;
 ###  Co  MOD  Description               Arguments&lt;br /&gt;
 ---  --  ---  -----------               ---------&lt;br /&gt;
 Volume Commands&lt;br /&gt;
   1  A1   EA  Fine Volume Slide Up      B xx xx=speed&lt;br /&gt;
   2  A2   A   Volume Slide Up           B xx xx=speed&lt;br /&gt;
   3  A3   EB  Fine Volume Slide Down    B xx xx=speed&lt;br /&gt;
   4  A4   A   Volume Slide Down         B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Portamento Commands&lt;br /&gt;
  10  B0   E1  Fine Porta Up             B xx xx=speed&lt;br /&gt;
  11  B1   1   Portamento Up             B xx xx=speed&lt;br /&gt;
  12  B2   E2  Fine Porta Down           B xx xx=speed&lt;br /&gt;
  13  B3   2   Portamento Down           B xx xx=speed&lt;br /&gt;
  14  B4   3   Tone Portamento           B xx xx=speed&lt;br /&gt;
  15  B5   E3  Set Glissando Control     B xx xx=0 - Off, 1 - On&lt;br /&gt;
  16  B6   5   Tone Port+Vol Slide Up    B xx xx=speed&lt;br /&gt;
  17  B7   5   Tone Port+Vol Slide Down  B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Vibrato Commands&lt;br /&gt;
  20  C0   4   Vibrato                   B xy x=speed, y=depth&lt;br /&gt;
  21  C1   E4  Set Vibrato Waveform      B x  x=Waveform&lt;br /&gt;
  21  C2   6   Vibrato+Vol Slide Up      B xx xx=speed&lt;br /&gt;
  22  C3   6   Vibrato+Vol Slide Down    B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Tremolo Commands&lt;br /&gt;
  30  D0   7   Tremolo                   B xy x=speed, y=depth&lt;br /&gt;
  31  D1   E7  Set Tremolo Control       B x  x=Waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample Commands&lt;br /&gt;
  40  E0   9   Sample Offset             3B Position for offset change (0-1,048,575)&lt;br /&gt;
  41  E1   E9  Retrig Note               B xx xx=tick to retrigger sample&lt;br /&gt;
  42  E2   EC  Note Cut                  B xx xx=tick to cut note&lt;br /&gt;
  43  E3   ED  Note Delay                B xx xx=ticks to delay note&lt;br /&gt;
 &lt;br /&gt;
 Pos. Change Commands&lt;br /&gt;
  50  F0   B   Position Jump             B xx xx=order position&lt;br /&gt;
  51  F1   D   Pattern Break             B xx Skip to line xx in next pattern&lt;br /&gt;
  52  F2   E6  Jump Loop                 B xx xx=number of loops  0 Set&lt;br /&gt;
  53  F3   EE  Pattern Delay             B xx xx=notes to delay pattern&lt;br /&gt;
 &lt;br /&gt;
 Speed Change Cmds&lt;br /&gt;
  60  G0   F   Set Regular Speed         B xx xx=speed&lt;br /&gt;
  61  G1   F   Set BPM                   B xx xx=BPM (32-255)&lt;br /&gt;
 &lt;br /&gt;
 Misc. Commands&lt;br /&gt;
  70  H0   0   Arpeggio                  B xy x=semitone #1, y=semitone #2&lt;br /&gt;
  71  H1   E5  Set Finetune              B xx xx=finetune&lt;br /&gt;
  72  H2       Set Balance               B xx xx=Balance (0-15)&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
 Sample segment&lt;br /&gt;
 0    4   ID     &#039;PSAM&#039; (Psm SAMple)&lt;br /&gt;
 4    ?  Data    Sample data&lt;br /&gt;
&lt;br /&gt;
 Sample header segment&lt;br /&gt;
 0    4   ID     &#039;PSAH&#039; (Psm SAmple Header)&lt;br /&gt;
 4    ?  Data    Sample headers&lt;br /&gt;
&lt;br /&gt;
 Sample header&lt;br /&gt;
 0    13  Name   Sample filename, terminated with a null.&lt;br /&gt;
 13   24  Desc   Sample description or comments.&lt;br /&gt;
 37   4   Offs   Location of raw sample data in file&lt;br /&gt;
 43   4   Mem    This is the physical offset in RAM/DRAM of the sample. (Often blank.)&lt;br /&gt;
 45   2   Num    Sample number, 1-255&lt;br /&gt;
 47   1   Type   Sample type: (In some games left blank; if this is the case then the&lt;br /&gt;
                 sample format is END, as used in most PSM New Format files)&lt;br /&gt;
                 Bit 0: 0 - Digital, 1 - Synthesized&lt;br /&gt;
                 Bit 2: 0 - 8-bit, 1 - 16-bit&lt;br /&gt;
                 Bit 3: 0 - Signed, 1 - Unsigned&lt;br /&gt;
                 Bit 4: 0 - Deltas, 1 - Raw&lt;br /&gt;
                 Bit 5: 0 - Loop normally, 1 - Bidirectional&lt;br /&gt;
                 Bit 6: 1 - Gravis patch (unsupported)&lt;br /&gt;
                 Bit 7: 0 - No loop, 1 - Loop sample&lt;br /&gt;
 48   4   Len    Sample length, in bytes.&lt;br /&gt;
 52   4   Rep st Sample repeat start; if sample loops, the loop starts here.&lt;br /&gt;
 56   4   Rep fn Sample repeat end, if sample loops, it ends here. If this is less than the sample&lt;br /&gt;
                 repeat start, the sample loops backwards.&lt;br /&gt;
 60   1   Tune   Fine tune; range 0-15, Tune 0-7 = 0-7; tune -1 - -8 = 8-15&lt;br /&gt;
 61   1   Vol    Sample volume, 0-64&lt;br /&gt;
 62   2   Freq   This is the frequency for the sample at a C of Octave 2.&lt;br /&gt;
                 Typical values are 8,000 hz to 8,448 hz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like S3M, sample headers are stored separately from the raw sample data. Unlike S3M, the number of sample headers doesn&#039;t have to be 31, but rather is the number of samples in the header. Sample headers are usually stored at then end of the file, after the raw sample data.&lt;br /&gt;
&lt;br /&gt;
A type of sample compression used often, like in the PSM New Format is &#039;Deltas&#039;, which converts a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. Thus:&lt;br /&gt;
&lt;br /&gt;
 RAW:        64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: 11  64   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
This is done to make files more compressible, but doesn&#039;t seem to be used much.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
&lt;br /&gt;
It is unknown which of the two PSM formats the following utilities support, unless stated otherwise.&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.shikadi.net/files/psm2scrm.zip psm2scrm.zip] - DOS program to convert .PSM songs into ScreamTracker .S3M format, suitable for playing in your favourite tracker/module player. Works only with PSM New Format and is not nearly as accurate as OpenMPT.&lt;br /&gt;
* [http://openmpt.org OpenMPT] 1.18 and newer can load all PSM and PSM16 files.&lt;br /&gt;
* [http://openmpt.org/legacy_software ModPlug Tracker] and OpenMPT 1.17 can play the files and save them as S3M. More complex songs don&#039;t load correctly though. Works only with new format.&lt;br /&gt;
* [http://kode54.foobar2000.org/ foo_dumb] is a plugin for various module formats for the Foobar2k media player. It supports both PSM16 and PSM and is similar to OpenMPT in playback quality.&lt;br /&gt;
* [http://ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/mxinfo/epictest.zip EPICTEST] is a demonstration of the Epic Megagames MASI. It contains CONVERT.EXE which can be used to convert modules to the PSM format.&lt;br /&gt;
* [http://www.jazz2online.com/J2Ov2/downloads/info.php?levelID=5471#29435] JJ1MOD can convert S3M files to PSM, though often with errors (Though these are usually only detectable with older programs such as game executables.) It is currently the only utility able to do this, and works only with New Format.&lt;br /&gt;
&lt;br /&gt;
= Notes =&lt;br /&gt;
&lt;br /&gt;
The New PSM format was reverse engineered by Levellord and tidied up by Levellass. It is possible there may be minor errors in the sample format information, especially since this is poorly documented.&lt;br /&gt;
Some format definitions have been updated and corrected by Johannes Schultz of the OpenMPT development team.&lt;br /&gt;
&lt;br /&gt;
The PSM16 format documentation was found on Wotsit and written up by Levellass (this appears to be an official document from the MASI developer). More info is needed.&lt;br /&gt;
&lt;br /&gt;
In all formats the following table shows how note bytes are converted into actual notes: (PSM new format has the widest range, 0-255)&lt;br /&gt;
&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;br /&gt;
           | C-0   0 | C-1  12 | C-2  24 | C-3  36 | C-4  48 |&lt;br /&gt;
           | C#0   1 | C#1  13 | C#2  25 | C#3  37 | C#4  49 |&lt;br /&gt;
           | D-0   2 | D-1  14 | D-2  26 | D-3  38 | D-4  50 |&lt;br /&gt;
           | D#0   3 | D#1  15 | D#2  27 | D#3  39 | D#4  51 |&lt;br /&gt;
           | E-0   4 | E-1  16 | E-2  28 | E-3  40 | E-4  52 |&lt;br /&gt;
           | F-0   5 | F-1  17 | F-2  29 | F-3  41 | F-4  53 |&lt;br /&gt;
           | F#0   6 | F#1  18 | F#2  30 | F#3  42 | F#4  54 |&lt;br /&gt;
           | G-0   7 | G-1  19 | G-2  31 | G-3  43 | G-4  55 |&lt;br /&gt;
           | G#0   8 | G#1  20 | G#2  32 | G#3  44 | G#4  56 |&lt;br /&gt;
           | A-0   9 | A-1  21 | A-2  33 | A-3  45 | A-4  57 |&lt;br /&gt;
           | A#0  10 | A#1  22 | A#2  34 | A#3  46 | A#4  58 |&lt;br /&gt;
           | B-0  11 | B-1  23 | B-2  35 | B-3  47 | B-4  59 |&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=4451</id>
		<title>ProTracker Studio Module</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=4451"/>
		<updated>2012-11-03T16:36:09Z</updated>

		<summary type="html">&lt;p&gt;Saga: Channel count was wrong&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Music Infobox&lt;br /&gt;
 | Type = Tracked&lt;br /&gt;
 | Instruments = PCM&lt;br /&gt;
 | NumChannels = 1-256 (PSM) 1-32 (PSM16)&lt;br /&gt;
 | NumTracks = 1&lt;br /&gt;
 | Game1 = Epic Pinball&lt;br /&gt;
 | Game2 = Extreme Pinball&lt;br /&gt;
 | Game3 = Jazz Jackrabbit&lt;br /&gt;
 | Game4 = One Must Fall&lt;br /&gt;
 | Game5 = Silverball&lt;br /&gt;
 | Game6 = Sinaria&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;ProTracker Studio Module&#039;&#039;&#039; (PSM) file format is used for the music in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]].  The file format is named after ProTracker, an Amiga program, though this program was probably actually not used to write PSM files. One Must Fall&#039;s music was written in Multitracker, and the music for Jazz Jackrabbit, Epic Pinball and Extreme Pinball probably in Scream Tracker.&lt;br /&gt;
&lt;br /&gt;
There are currently two file types that use the extension .PSM; they seem to be related to a certain extent, though how is currently unknown. The two formats are:&lt;br /&gt;
&lt;br /&gt;
* PSM New Format: Used by Jazz Jackrabbit, Epic Pinball, Extreme Pinball, One Must Fall, Sinaria (in this game with slight differences, see below), newest PSM format&lt;br /&gt;
* PSM 16:         Used by Silverball, an older version of the format which is closer to ProTracker-style modules.&lt;br /&gt;
&lt;br /&gt;
The most common of the two PSM formats is the new format, and most programs that try to run PSM files will be expecting this. For example, ModPlug Player cannot open Silverball files as these are in the PSM 16 format.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM New Format =&lt;br /&gt;
&lt;br /&gt;
This format is used by [[:Category:Epic Megagames|Epic]] games in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]]. It is notable for consisting of a number of segments (chunks) and sub segments. It bears the 4-byte signature &#039;PSM &#039; at the file start.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Song segment&lt;br /&gt;
 Samples&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 12 bytes long:&lt;br /&gt;
&lt;br /&gt;
 File header:&lt;br /&gt;
 0   4  ID     &#039;PSM &#039;; indicates file is PSM format&lt;br /&gt;
 4   4  Size   Filesize - 12&lt;br /&gt;
 8   4  ID2    &#039;FILE&#039;; indicates start of file info&lt;br /&gt;
&lt;br /&gt;
After the header, some chunks follow in IFF-style. You should not expect chunks to come up in the same order as they are described here. A good way to handle chunks is to read the 4-Byte ID and the 4-Byte size field first, then evaluate the ID and decide what to do next based on this ID. Note that the size field does not include the ID and itself; it only holds the size of the chunk &#039;&#039;content&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Title segment ==&lt;br /&gt;
&lt;br /&gt;
This segment is optional, and one of the few segments that can be absent when playing PSM files in most programs. (Most programs expect all other segments to exist, even if they are not vital.) Most PSM songs have no title.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;TITL&#039;; indicates a title follows&lt;br /&gt;
 4   4  Size   Size of title as dword after this dword&lt;br /&gt;
 8   ?  Title  Song title&lt;br /&gt;
&lt;br /&gt;
== Song info segment ==&lt;br /&gt;
&lt;br /&gt;
This segment seems to indicate the beginning of the song data and is not really relevant when parsing.&lt;br /&gt;
&lt;br /&gt;
 12  4  ID     &#039;SDFT&#039;; indicates start of format info&lt;br /&gt;
 16  4  Size   Size of next header as dword, (8)&lt;br /&gt;
 20  8  Song   &#039;MAINSONG&#039;; indicates song type. No other song types are known.&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
Each pattern is stored in its own PBOD chunk. Note that there are two possible formats for this chunk; one is used in the &amp;quot;old&amp;quot; format (as used in Epic Pinball, Extreme Pinball, Jazz Jackrabbit, One Must Fall) and the other in the &amp;quot;new&amp;quot; format (as used in Sinaria)&lt;br /&gt;
&lt;br /&gt;
 Pattern segment:&lt;br /&gt;
 0   4  ID     &#039;PBOD&#039;; indicates a pattern follows (Pattern BODy)&lt;br /&gt;
 4   4  Size   Length of pattern data as dword, after this dword&lt;br /&gt;
 4   4  Size   Same value again.&lt;br /&gt;
&lt;br /&gt;
 Pattern:&lt;br /&gt;
 0 4/8  Number Pattern ID. See note below.&lt;br /&gt;
 4   2  Row n  Number of rows in ALL channels in pattern (64 usually, but can differ.) as word.&lt;br /&gt;
 6   ?  Data   Contains pattern data as a number of rows of interlaced channels (12341234...)&lt;br /&gt;
               &#039;&#039;Usual&#039;&#039; settings is 64 rows of 4 channels. Epic Pinball has shorter patterns for example, but they also include a &amp;quot;break to row&amp;quot; command at the end of the pattern.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; In the old format, this starts with a &#039;P&#039; and is followed by an integer number which is the pattern number, padded to 4 bytes with spaces. Caution: This number might or might not be zero-padded; In some files, the ID of the first pattern could be &#039;P0  &#039;, but there are also files where it is &#039;P00 &#039;!. In C/C++, you could use atoi() to parse this value. In the new format (Sinaria), This field is 8 bytes long instead of 4 bytes, and the first 4 bytes read &amp;quot;PATT&amp;quot;, so the first pattern could be for example &#039;PATT0   &#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Pattern row channel entry:&lt;br /&gt;
 ?   1  Fill   Convert this byte value into binary; (240 -&amp;gt; 11110000), the first four     &lt;br /&gt;
               values                          &lt;br /&gt;
 +1  1  chan   What channel this belongs to, 0-255, each filled only once per tick, this is &lt;br /&gt;
               what, by absence, identifies empty channels. It is possible that actual PSM implementations will support less channels and crash if a file contains too many channels.&lt;br /&gt;
 +2  1  Note   Pitch, $01 is C-1, etc... The octaves are aligned by 16, i.e. B-1 is $0C but the next note, C-2, is $10.&lt;br /&gt;
 +3  1  Ins    Instrument used, 0-31&lt;br /&gt;
 +4  1  Vol    Volume change to, 0-63 = 0-127; optional&lt;br /&gt;
 +5  1  Effect Effect to use, volume slide, Portamanto...&lt;br /&gt;
 +6  1  Eff Am Strength of effect, e.g amount of slide&lt;br /&gt;
&lt;br /&gt;
Each row consists of a word giving the size of the row (Including the word) followed by the channel data. A channel is only included if it has data in it, but a totally empty row is still included. So an &#039;empty&#039; row (Where none of the channels have data.) thus consists of just a word of value 2.&lt;br /&gt;
&lt;br /&gt;
Each channel entry consists of between 3-7 bytes. The first byte is a flag that shows what data follows. (The first four bits indicate whether there are bytes for the following four variables; Note ($80), Instrument ($40), Volume ($20), Effect AND Effect magnitude ($10). Thus 5 bytes are represented by a combination of 4 possibilities.) The next byte identifies the channel (Since each channel may or may not be present.) starting at 0 for channel 1. The remaining 5 bytes may or may not be present and contain data for Note, Instrument(Sample) used, Volume change for channel, Effect and Effect magnitude.&lt;br /&gt;
&lt;br /&gt;
There are several things to note about this; Effect and Effect magnitude MUST occur together. Sample numbers, like channels are numbered starting at 0, not 1. Magnitudes (For effect AND volume) are from 0-127, not 0-64 as in other formats.&lt;br /&gt;
&lt;br /&gt;
=== Effect conversion ===&lt;br /&gt;
&lt;br /&gt;
Note that this table is guaranteed to be correct; Most effects seem to be converted correctly, though. Note that these values are not correct for the PSM files that can be found in the game Sinaria. Leave out all divisions and it will be correct again.&lt;br /&gt;
&lt;br /&gt;
 PSM Command   Param length  S3M Command&lt;br /&gt;
 &lt;br /&gt;
  Volume commands&lt;br /&gt;
    1           1 Byte        DxF - fine volside up&lt;br /&gt;
    2           1 Byte        Dx0 - volslide up&lt;br /&gt;
    3           1 Byte        DFx - fine volslide down&lt;br /&gt;
    4           1 Byte        D0x - volslide down&lt;br /&gt;
 &lt;br /&gt;
 Portamento commands&lt;br /&gt;
    B           1 Byte        FFx - fine porta up (divide x by 4)&lt;br /&gt;
    C           1 Byte        Fxx - porta up (if x &amp;lt; 4, use FFx, else divide x by 4)&lt;br /&gt;
    D           1 Byte        EFx - fine porta down (divide x by 4)&lt;br /&gt;
    E           1 Byte        Exx - porta down (if x &amp;lt; 4, use EFx, else divide x by 4)&lt;br /&gt;
    F           1 Byte        Gxx - portamento (divide x by 4)&lt;br /&gt;
   10           1 Byte        S1x - glissando control&lt;br /&gt;
   11           1 Byte        Lx0 - tone porta + volslide up&lt;br /&gt;
   12           1 Byte        L0x - tone porta + volslide down&lt;br /&gt;
    &lt;br /&gt;
 Vibrato&lt;br /&gt;
   15           1 Byte        Hxy - vibrato&lt;br /&gt;
   16           1 Byte        S3x - vibrato waveform&lt;br /&gt;
   17           1 Byte        K0x - vibrato + volslide up&lt;br /&gt;
   18           1 Byte        Kx0 - vibrato + volslide down&lt;br /&gt;
   	&lt;br /&gt;
 Tremolo			&lt;br /&gt;
   1F           1 Byte        Rxy - tremolo&lt;br /&gt;
   20           1 Byte        S4x - tremolo waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample commands&lt;br /&gt;
   29           3 Bytes       Oxx - offset (only take the 2nd byte)&lt;br /&gt;
   2A           1 Byte        Q0x - retrigger&lt;br /&gt;
   2B           1 Byte        SCx - note cut&lt;br /&gt;
   2C           1 Byte        SDx - note delay&lt;br /&gt;
 &lt;br /&gt;
 Position change&lt;br /&gt;
   33           2 Bytes(?)    Bxx - position jump (divide by 2)&lt;br /&gt;
   34           1 Byte        Cxx - break to row (divide by 2)&lt;br /&gt;
   35           1 Byte        SBx - pattern loop&lt;br /&gt;
   36           1 Byte        SEx - pattern delay&lt;br /&gt;
  &lt;br /&gt;
 Speed change&lt;br /&gt;
   3D           1 Byte        Axx - set speed&lt;br /&gt;
   3E           1 Byte        Txx - set tempo&lt;br /&gt;
 &lt;br /&gt;
 Misc. commands&lt;br /&gt;
   47           1 Byte        Jxy - arpeggio&lt;br /&gt;
   48           1 Byte        S2x - set finetune&lt;br /&gt;
   49           1 Byte        S8x - set balance&lt;br /&gt;
&lt;br /&gt;
Effect interpretation is different in Sinaria&#039;s new format.&lt;br /&gt;
&lt;br /&gt;
== Song segment ==&lt;br /&gt;
&lt;br /&gt;
This segment contains most of the important data used to play the song, as well as a lot of unimportant data that is no longer used. It contains several sub-segments, each of the same format as a normal segment, but contained in the song segment. Note that there might be more than one song segment and thus, more than one order list, default speed, default tempo, etc...&lt;br /&gt;
&lt;br /&gt;
 Segment structure:&lt;br /&gt;
 0   4  ID     &#039;SONG&#039; indicates start of song structure&lt;br /&gt;
 4   4  Size   Size of song structure, including all sub-segments&lt;br /&gt;
 8   9  Type   Type of song this is for; This is &#039;MAINSONG &#039; in almost all PSM files. Extreme Pinball has several SONG items with different types!&lt;br /&gt;
 17  1  Comp   Compression, for PSM = 1 (Uncompressed)&lt;br /&gt;
 18  1  Chan   Number of channels, usually, but not always, 4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Date sub-segment ===&lt;br /&gt;
&lt;br /&gt;
This dates the file and is used by some programs. It is usually the first sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DATE&#039; indicates date data&lt;br /&gt;
 4   4  Size   Size of date segment (6)&lt;br /&gt;
 8   6  Date   Date as text, YYMMDD&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Order sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Orders are how patterns are arranged in the song. This allows the same pattern of instruments to be played more than once in a song (E.g. a chorus.) without the pattern having to be repeated. There is usually only one order. This section also contains basic song information. It usually follows the date sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;OPLH&#039; indicates start of pattern placement order&lt;br /&gt;
 4   4  Size   Size of order segment&lt;br /&gt;
 8   2  Cnt.   Number of following chunks&lt;br /&gt;
&lt;br /&gt;
Now, the following chunks may follow until the end of the &amp;quot;OPLH&amp;quot; chunk is reached. Every chunk is identified by the first byte:&lt;br /&gt;
* $00 (1 Byte): End (Nothing follows)&lt;br /&gt;
* $01 (5/9 Bytes): Order list item follows (e.g. &amp;quot;P0  &amp;quot;, &amp;quot;P12 &amp;quot; in old format or &amp;quot;PATT0   &amp;quot; in new format, see above) - join those to get the complete order list.&lt;br /&gt;
* $04 (3 Bytes): This 16-bit value indicates the &amp;quot;restart chunk&amp;quot;. If the end of the subsong is reached, it will jump back to this chunk. In many cases, this would be 4th chunk (no 3rd chunk, as the chunk index is starting at 0!), which is a panning index in most PSMs - So you would just go to the nearest order list item that&#039;s following this chunk. However, this can also point to a valid order list chunk.&lt;br /&gt;
* $07 (2 Bytes): Next byte is default speed for this subtune&lt;br /&gt;
* $08 (2 Bytes): Next byte is default tempo for this subtune&lt;br /&gt;
* $0C (7 Bytes): Sample map table(?): This chunk is always $0C $00 $FF $00 $00 $01 $00.&lt;br /&gt;
* $0D (4 Bytes): Channel panning index. Next byte is channel number (Start at 0), then initial pan ($00 ... $FF) and a byte follow. The byte seems to tell what to do with the previous pan position (0 - use it, 2 - ignore it, make this channel surround, 4 - set to center).&lt;br /&gt;
* $0E (3 Bytes): Channel volume index. Next byte is channel number (Start at 0), then volume ($00 ... $FF). $FF in most (all?) cases.&lt;br /&gt;
&lt;br /&gt;
=== Pattern list ===&lt;br /&gt;
&lt;br /&gt;
This is simply a list of all the patterns used in the file. You do not really need to parse this, it seems to be a purely informational chunk.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;PATT&#039; indicates start of pattern list&lt;br /&gt;
 4   4  Size   Size of pattern list after this&lt;br /&gt;
 8   4  Size   Same as above&lt;br /&gt;
 12  4x Pat    An ordered list &#039;P0  &#039;, &#039;P1  &#039;... for all patterns in the file, each entry 4 bytes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sample list sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Similar to the above, this is a list of all the samples used in the file. It is usually the last sub-segment in the song segment and you do not really need to parse this.&lt;br /&gt;
&lt;br /&gt;
  0  4   ID     &#039;DSAM&#039;; indicates start of sample list, used to say what samples are &#039;full&#039;&lt;br /&gt;
                Any samples not on this list will be ignored, even if they have data&lt;br /&gt;
  4  4   Size   Size of list after this&lt;br /&gt;
  8  4   Size   Same value as above&lt;br /&gt;
  12 15x Entry  Sample entries, one for each sample in the file, each entry 15 bytes&lt;br /&gt;
&lt;br /&gt;
 Sample entry:&lt;br /&gt;
 0   8  Format Sample format, padded with spaces (END, RAG2...) This is important to some programs&lt;br /&gt;
 8   4  ID     &#039;I0  &#039;, &#039;I1  &#039;... the sample ID (&#039;I&#039; means &#039;Instrument&#039;). Again, be sure to accept both &#039;I0  &#039; and &#039;I00 &#039;!&lt;br /&gt;
 12  2  Num    The sample number, 0,1,2... for the sample&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
Samples are the raw sound data that makes up the instruments on the song. The actual format depends on the sample format. Samples have information in their headers which allows data to be played at different pitches (Speeds.) and to loop from and to various points in the data. This is by far the largest part of the file, since the raw data takes up so much space.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DSMP&#039; indicates start of sample&lt;br /&gt;
 4   4  Size   Size of following sample as &#039;DSMP&#039; + dword from end of word&lt;br /&gt;
 8   9  Flags  If highest bit is set, then sample is looped&lt;br /&gt;
 9   8  Songn. Filename of the original module (without extension)&lt;br /&gt;
 17  4  INSx   Last digit of sample (Instrument) number, 0-9; with 31 instruments possible&lt;br /&gt;
               Only last digit is shown. E.g 1st, 11th, 21st and 31st sample is &#039;INS0&#039;&lt;br /&gt;
 21  33 Name   Defines the instrument name or file, usually a .st or line of text&lt;br /&gt;
 54  51 Header Sample parameters (Can also 58 bytes long, padded with nuls)&lt;br /&gt;
               Byte 1-6 are unknown ($00 $00 $00 $00 $00 $FF)&lt;br /&gt;
               Bytes 7-8 is instrument number&lt;br /&gt;
               Bytes 9-12 are sample length&lt;br /&gt;
               Bytes 13-16 are loop start&lt;br /&gt;
               Bytes 17-20 are loop end (all $FF means at end of sample)&lt;br /&gt;
               Bytes 21-22 are unknown (second byte could be default pan, but seems to be unused)&lt;br /&gt;
               Byte 23 is default volume&lt;br /&gt;
               Bytes 24-27 are unknwon&lt;br /&gt;
               Bytes 28-29 is frequency (Sample rate)&lt;br /&gt;
               21 $00-bytes follow&lt;br /&gt;
 105 ?  Data   Music data in 8-bit mono format&lt;br /&gt;
&lt;br /&gt;
The sample header is slightly different in Sinaria&#039;s new format: INSx is 8 bytes long (like the PATT IDs), and the last 21 $00-bytes are just 16 bytes.&lt;br /&gt;
&lt;br /&gt;
The PSM new format, along with the PSM 16 format use delta-encoded samples, something to make the file smaller when zipped. &#039;Deltas&#039;, convert a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. It has the effect that if a single byte in the sample is changed, the entire sample will be degraded. This use of deltas varies slightly from that of the PSM 16. The &#039;start value&#039; of the string is assumed to be $80 (128) and the first byte will thus turn this into the first desired value, the second delta converts the first value to the second, and so on.) All deltas are signed, 1-byte values, but loop (Thus 10 - 20 = -10 can also be considered as 10 + 236 = 246). An example of this is as follows:&lt;br /&gt;
&lt;br /&gt;
 RAW:   (128) 64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: -64  0   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM 16 =&lt;br /&gt;
&lt;br /&gt;
This is the format used in [[Silverball]], early versions of Epic Pinball and possibly other games. The designation &#039;Protracker Studio 16 format&#039; was given to it by the only reliable source of information on this format, and may not be the official designation.&lt;br /&gt;
&lt;br /&gt;
The format bears many similarities to the S3M format; the file is set out roughly the same, patterns and samples are similar, indeed, near identical and the functionality is similar. It also shows many similarities to the ProTracker MOD format and retains vestiges of Amiga compatibility.&lt;br /&gt;
&lt;br /&gt;
This format can be identified by its signature &#039;PSMþ&#039;, though files may lack this and still function.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Order&lt;br /&gt;
 Pan segment&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Sample data&lt;br /&gt;
 Sample headers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
 0    4  Sig      Signature, &#039;PSMþ&#039;&lt;br /&gt;
 4    59 Title    Song title, padded with nulls. Unlike other formats, this must also be terminated&lt;br /&gt;
                  with a null byte. (It sometimes is not terminated, though.)&lt;br /&gt;
 62   1           This must be $1A to end the song name, like in S3M format.&lt;br /&gt;
 64   1  Type     Song type, First bit: 0 - Module (w/samp.), 1 - Song (w/o samples)&lt;br /&gt;
                  Second bit: 0 - 3 octave Protracker, 1 - 5 octave; remaining bits reserved.&lt;br /&gt;
 65   1  PSM v    PSM format version, $10 for this format (Hence the name PSM 16) = &#039;v1.00&#039;.&lt;br /&gt;
                  Sometimes, this is also $01, but there&#039;s no difference in the format itself.&lt;br /&gt;
 66   1  Patt v   Pattern version, 0 or 1. 0 means the pattern is stored in the module are in the 32&lt;br /&gt;
                  channel file format.  A 1 signifies the patterns as being stored as a 255&lt;br /&gt;
                  channel format. (I have not found any PSM16 modules that have this format.)&lt;br /&gt;
 67   1   Speed   Song speed&lt;br /&gt;
 68   1   BPM     Beats per minute, the default Amiga BPM value. (The only reason that the Amiga BPM&lt;br /&gt;
                  format is still followed here is that it allows more control over the final hz value.)&lt;br /&gt;
                  Range: 32 to 255.&lt;br /&gt;
 69   1   Vol     Master volume of song, 0-255&lt;br /&gt;
 70   2   Len     Song length, 0-255. The number of patterns to play in the song, in total.&lt;br /&gt;
 72   2   Ordlen  The number of orders actually stored at the order offset. It was hoped that the&lt;br /&gt;
                  PSM 16 format would allow multiple orders, so this would be the length of the first&lt;br /&gt;
                  order. This doesn&#039;t appea to ahve happened, and is usually the same as the previous value.&lt;br /&gt;
 74   2   Patnum  Number of patterns in the song. 1-255&lt;br /&gt;
 76   2   Sampnum Number of samples and &#039;sample structures&#039; in song, 1-255&lt;br /&gt;
 78   2   NCIS    Number of channels in song to PLAY. 1-32. &lt;br /&gt;
 80   2   NCP     Number of Channels to Process; describes the MAXIMUM number of channels to process.&lt;br /&gt;
                  As an example, when converting 669 files,  NCP = 9 because some track information &lt;br /&gt;
                  is in Channel 8, but the Number of Channels to Play was set to 8, (Channel numbers&lt;br /&gt;
                  to play from 0 to 7.) 1-32&lt;br /&gt;
 82   4   Ordoff  Location of order in header&lt;br /&gt;
 86   4   Panoff  Location of pan positions in header&lt;br /&gt;
 90   4   Patoff  Location of patterns in header&lt;br /&gt;
 94   4   Sampoff Location of sample headers in header&lt;br /&gt;
 98   4   Commoff Location of comments in header&lt;br /&gt;
 102  4   Patsiz  Total pattern size; the total size of all the patterns loaded from the pattern offset.&lt;br /&gt;
 106  40  Fillers 10 fillers, to be used for any possible expansions.&lt;br /&gt;
&lt;br /&gt;
It is important to notice that the offsets point to the first byte &#039;&#039;&#039;after&#039;&#039;&#039; the chunk ID, i.e. &amp;quot;Ordoff&amp;quot; points to the first byte after &amp;quot;PORD&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Order and Pan positions ==&lt;br /&gt;
&lt;br /&gt;
These are two separate segments, pointed to in the header. They may be anywhere, but usually follow the header sometimes after an amount of blank space. They are often padded with blank space. They are basically lists.&lt;br /&gt;
&lt;br /&gt;
Order: This segment is pointed to in the header, and sets the PSM 16 format apart. The PSM 16 format was designed to be much more like the MOD format, allowing game designers to set flags to switch from one set of patterns to another, in effect allowing one file to contain more than one song. (For example a boss flag might make the music switch from a clam patterns 1-4 to a racy and dangerous patterns 5-7.)&lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    Signature, not needed, &#039;PORD&#039;&lt;br /&gt;
 4    ?   Ords   Pattern numbers and order. There will be [Ordlen] bytes of patterns&lt;br /&gt;
 ?    2   Lang   Order language, not implemented, so left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pan Positions: &lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    &#039;PPAN&#039;&lt;br /&gt;
 4    12  Pan    Pan positions; empty positions left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
 0    2   Size   Size of pattern, including these bytes&lt;br /&gt;
 2    1   Len    Length of pattern, in rows. Max length is 64 rows.&lt;br /&gt;
 3    1   Chan   Number of channels in pattern, 1-32&lt;br /&gt;
 4    ?   Data   Pattern data&lt;br /&gt;
&lt;br /&gt;
This is similar to the previous two segments, except actual pattern data is stored here. Patterns are very similar to the S3M format, and consist of y rows of x channels. Each row contains a number of channels and ends with a byte of value 0. Each channel is between 2-6+ bytes long. A totally empty channel is represented by a single byte of value 0.&lt;br /&gt;
&lt;br /&gt;
Each channel starts with a flag byte, abcddddd, where a,b and c indicate whether there is a note and instrument, volume or special effect and effect magnitude in the following data, and dddd is the channel number (0-31, used since a given channel may or may not be present in a row.)&lt;br /&gt;
&lt;br /&gt;
The usual maximum length of a channel entry is 6 bytes (1 flag byte, 2 Note AND instrument bytes, 1 volume byte and two Effect and Effect magnitude bytes.) Thus Note&amp;amp;ins\Eff&amp;amp;Eff mag must always occur together.&lt;br /&gt;
&lt;br /&gt;
Like S3M, volume range is 0-64, as is special magnitude. However, special effects range from 0-255, like PSM New Format.&lt;br /&gt;
&lt;br /&gt;
=== Effects conversion ===&lt;br /&gt;
&lt;br /&gt;
 ###  Co  MOD  Description               Arguments&lt;br /&gt;
 ---  --  ---  -----------               ---------&lt;br /&gt;
 Volume Commands&lt;br /&gt;
   1  A1   EA  Fine Volume Slide Up      B xx xx=speed&lt;br /&gt;
   2  A2   A   Volume Slide Up           B xx xx=speed&lt;br /&gt;
   3  A3   EB  Fine Volume Slide Down    B xx xx=speed&lt;br /&gt;
   4  A4   A   Volume Slide Down         B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Portamento Commands&lt;br /&gt;
  10  B0   E1  Fine Porta Up             B xx xx=speed&lt;br /&gt;
  11  B1   1   Portamento Up             B xx xx=speed&lt;br /&gt;
  12  B2   E2  Fine Porta Down           B xx xx=speed&lt;br /&gt;
  13  B3   2   Portamento Down           B xx xx=speed&lt;br /&gt;
  14  B4   3   Tone Portamento           B xx xx=speed&lt;br /&gt;
  15  B5   E3  Set Glissando Control     B xx xx=0 - Off, 1 - On&lt;br /&gt;
  16  B6   5   Tone Port+Vol Slide Up    B xx xx=speed&lt;br /&gt;
  17  B7   5   Tone Port+Vol Slide Down  B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Vibrato Commands&lt;br /&gt;
  20  C0   4   Vibrato                   B xy x=speed, y=depth&lt;br /&gt;
  21  C1   E4  Set Vibrato Waveform      B x  x=Waveform&lt;br /&gt;
  21  C2   6   Vibrato+Vol Slide Up      B xx xx=speed&lt;br /&gt;
  22  C3   6   Vibrato+Vol Slide Down    B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Tremolo Commands&lt;br /&gt;
  30  D0   7   Tremolo                   B xy x=speed, y=depth&lt;br /&gt;
  31  D1   E7  Set Tremolo Control       B x  x=Waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample Commands&lt;br /&gt;
  40  E0   9   Sample Offset             3B Position for offset change (0-1,048,575)&lt;br /&gt;
  41  E1   E9  Retrig Note               B xx xx=tick to retrigger sample&lt;br /&gt;
  42  E2   EC  Note Cut                  B xx xx=tick to cut note&lt;br /&gt;
  43  E3   ED  Note Delay                B xx xx=ticks to delay note&lt;br /&gt;
 &lt;br /&gt;
 Pos. Change Commands&lt;br /&gt;
  50  F0   B   Position Jump             B xx xx=order position&lt;br /&gt;
  51  F1   D   Pattern Break             B xx Skip to line xx in next pattern&lt;br /&gt;
  52  F2   E6  Jump Loop                 B xx xx=number of loops  0 Set&lt;br /&gt;
  53  F3   EE  Pattern Delay             B xx xx=notes to delay pattern&lt;br /&gt;
 &lt;br /&gt;
 Speed Change Cmds&lt;br /&gt;
  60  G0   F   Set Regular Speed         B xx xx=speed&lt;br /&gt;
  61  G1   F   Set BPM                   B xx xx=BPM (32-255)&lt;br /&gt;
 &lt;br /&gt;
 Misc. Commands&lt;br /&gt;
  70  H0   0   Arpeggio                  B xy x=semitone #1, y=semitone #2&lt;br /&gt;
  71  H1   E5  Set Finetune              B xx xx=finetune&lt;br /&gt;
  72  H2       Set Balance               B xx xx=Balance (0-15)&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
 Sample segment&lt;br /&gt;
 0    4   ID     &#039;PSAM&#039; (Psm SAMple)&lt;br /&gt;
 4    ?  Data    Sample data&lt;br /&gt;
&lt;br /&gt;
 Sample header segment&lt;br /&gt;
 0    4   ID     &#039;PSAH&#039; (Psm SAmple Header)&lt;br /&gt;
 4    ?  Data    Sample headers&lt;br /&gt;
&lt;br /&gt;
 Sample header&lt;br /&gt;
 0    13  Name   Sample filename, terminated with a null.&lt;br /&gt;
 13   24  Desc   Sample description or comments.&lt;br /&gt;
 37   4   Offs   Location of raw sample data in file&lt;br /&gt;
 43   4   Mem    This is the physical offset in RAM/DRAM of the sample. (Often blank.)&lt;br /&gt;
 45   2   Num    Sample number, 1-255&lt;br /&gt;
 47   1   Type   Sample type: (In some games left blank; if this is the case then the&lt;br /&gt;
                 sample format is END, as used in most PSM New Format files)&lt;br /&gt;
                 Bit 0: 0 - Digital, 1 - Synthesized&lt;br /&gt;
                 Bit 2: 0 - 8-bit, 1 - 16-bit&lt;br /&gt;
                 Bit 3: 0 - Signed, 1 - Unsigned&lt;br /&gt;
                 Bit 4: 0 - Deltas, 1 - Raw&lt;br /&gt;
                 Bit 5: 0 - Loop normally, 1 - Bidirectional&lt;br /&gt;
                 Bit 6: 1 - Gravis patch (unsupported)&lt;br /&gt;
                 Bit 7: 0 - No loop, 1 - Loop sample&lt;br /&gt;
 48   4   Len    Sample length, in bytes.&lt;br /&gt;
 52   4   Rep st Sample repeat start; if sample loops, the loop starts here.&lt;br /&gt;
 56   4   Rep fn Sample repeat end, if sample loops, it ends here. If this is less than the sample&lt;br /&gt;
                 repeat start, the sample loops backwards.&lt;br /&gt;
 60   1   Tune   Fine tune; range 0-15, Tune 0-7 = 0-7; tune -1 - -8 = 8-15&lt;br /&gt;
 61   1   Vol    Sample volume, 0-64&lt;br /&gt;
 62   2   Freq   This is the frequency for the sample at a C of Octave 2.&lt;br /&gt;
                 Typical values are 8,000 hz to 8,448 hz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like S3M, sample headers are stored separately from the raw sample data. Unlike S3M, the number of sample headers doesn&#039;t have to be 31, but rather is the number of samples in the header. Sample headers are usually stored at then end of the file, after the raw sample data.&lt;br /&gt;
&lt;br /&gt;
A type of sample compression used often, like in the PSM New Format is &#039;Deltas&#039;, which converts a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. Thus:&lt;br /&gt;
&lt;br /&gt;
 RAW:        64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: 11  64   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
This is done to make files more compressible, but doesn&#039;t seem to be used much.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
&lt;br /&gt;
It is unknown which of the two PSM formats the following utilities support, unless stated otherwise.&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.shikadi.net/files/psm2scrm.zip psm2scrm.zip] - DOS program to convert .PSM songs into ScreamTracker .S3M format, suitable for playing in your favourite tracker/module player. Works only with PSM New Format and is not nearly as accurate as OpenMPT.&lt;br /&gt;
* [http://openmpt.org/legacy_software ModPlug Tracker] and OpenMPT 1.17 can play the files and save them as S3M. More complex songs don&#039;t load correctly though. Works only with new format.&lt;br /&gt;
* [http://openmpt.org OpenMPT] 1.18 and newer can load all PSM and PSM16 files.&lt;br /&gt;
* [http://kode54.foobar2000.org/ foo_dumb] is a plugin for various module formats for the Foobar2k media player. It supports both PSM16 and PSM and is similar to OpenMPT in playback quality.&lt;br /&gt;
* [http://ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/mxinfo/epictest.zip EPICTEST] is a demonstration of the Epic Megagames MASI. It contains CONVERT.EXE which can be used to convert modules to the PSM format.&lt;br /&gt;
* [http://www.jazz2online.com/J2Ov2/downloads/info.php?levelID=5471#29435] JJ1MOD can convert S3M files to PSM, though often with errors (Though these are usually only detectable with older programs such as game executables.) It is currently the only utility able to do this, and works only with New Format.&lt;br /&gt;
&lt;br /&gt;
= Notes =&lt;br /&gt;
&lt;br /&gt;
The New PSM format was reverse engineered by Levellord and tidied up by Levellass. It is possible there may be minor errors in the sample format information, especially since this is poorly documented.&lt;br /&gt;
Some format definitions have been updated and corrected by Johannes Schultz of the OpenMPT development team.&lt;br /&gt;
&lt;br /&gt;
The PSM16 format was reverse engineered by Wotsit and written up by Levellass. More info is needed.&lt;br /&gt;
&lt;br /&gt;
In all formats the following table shows how note bytes are converted into actual notes: (PSM new format has the widest range, 0-255)&lt;br /&gt;
&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;br /&gt;
           | C-0   0 | C-1  12 | C-2  24 | C-3  36 | C-4  48 |&lt;br /&gt;
           | C#0   1 | C#1  13 | C#2  25 | C#3  37 | C#4  49 |&lt;br /&gt;
           | D-0   2 | D-1  14 | D-2  26 | D-3  38 | D-4  50 |&lt;br /&gt;
           | D#0   3 | D#1  15 | D#2  27 | D#3  39 | D#4  51 |&lt;br /&gt;
           | E-0   4 | E-1  16 | E-2  28 | E-3  40 | E-4  52 |&lt;br /&gt;
           | F-0   5 | F-1  17 | F-2  29 | F-3  41 | F-4  53 |&lt;br /&gt;
           | F#0   6 | F#1  18 | F#2  30 | F#3  42 | F#4  54 |&lt;br /&gt;
           | G-0   7 | G-1  19 | G-2  31 | G-3  43 | G-4  55 |&lt;br /&gt;
           | G#0   8 | G#1  20 | G#2  32 | G#3  44 | G#4  56 |&lt;br /&gt;
           | A-0   9 | A-1  21 | A-2  33 | A-3  45 | A-4  57 |&lt;br /&gt;
           | A#0  10 | A#1  22 | A#2  34 | A#3  46 | A#4  58 |&lt;br /&gt;
           | B-0  11 | B-1  23 | B-2  35 | B-3  47 | B-4  59 |&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=4019</id>
		<title>ProTracker Studio Module</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=4019"/>
		<updated>2012-04-24T16:10:57Z</updated>

		<summary type="html">&lt;p&gt;Saga: Removed irrelevant information, added clarifications&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;&#039;ProTracker Studio Module&#039;&#039;&#039; (PSM) file format is used for the music in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]].  The file format is named after ProTracker, an Amiga program, though this program was probably actually not used to write PSM files. One Must Fall&#039;s music was written in Multitracker, and the music for Jazz Jackrabbit, Epic Pinball and Extreme Pinball probably in Scream Tracker.&lt;br /&gt;
&lt;br /&gt;
There are currently two file types that use the extension .PSM; they seem to be related to a certain extent, though how is currently unknown. The two formats are:&lt;br /&gt;
&lt;br /&gt;
* PSM New Format: Used by Jazz Jackrabbit, Epic Pinball, Extreme Pinball, One Must Fall, Sinaria (in this game with slight differences, see below), newest PSM format&lt;br /&gt;
* PSM 16:         Used by Silverball, an older version of the format which is closer to ProTracker-style modules.&lt;br /&gt;
&lt;br /&gt;
The most common of the two PSM formats is the new format, and most programs that try to run PSM files will be expecting this. For example, ModPlug Player cannot open Silverball files as these are in the PSM 16 format.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM New Format =&lt;br /&gt;
&lt;br /&gt;
This format is used by [[:Category:Epic Megagames|Epic]] games in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]]. It is notable for consisting of a number of segments (chunks) and sub segments. It bears the 4-byte signature &#039;PSM &#039; at the file start.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Song segment&lt;br /&gt;
 Samples&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 12 bytes long:&lt;br /&gt;
&lt;br /&gt;
 File header:&lt;br /&gt;
 0   4  ID     &#039;PSM &#039;; indicates file is PSM format&lt;br /&gt;
 4   4  Size   Filesize - 12&lt;br /&gt;
 8   4  ID2    &#039;FILE&#039;; indicates start of file info&lt;br /&gt;
&lt;br /&gt;
After the header, some chunks follow in IFF-style. You should not expect chunks to come up in the same order as they are described here. A good way to handle chunks is to read the 4-Byte ID and the 4-Byte size field first, then evaluate the ID and decide what to do next based on this ID. Note that the size field does not include the ID and itself; it only holds the size of the chunk &#039;&#039;content&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Title segment ==&lt;br /&gt;
&lt;br /&gt;
This segment is optional, and one of the few segments that can be absent when playing PSM files in most programs. (Most programs expect all other segments to exist, even if they are not vital.) Most PSM songs have no title.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;TITL&#039;; indicates a title follows&lt;br /&gt;
 4   4  Size   Size of title as dword after this dword&lt;br /&gt;
 8   ?  Title  Song title&lt;br /&gt;
&lt;br /&gt;
== Song info segment ==&lt;br /&gt;
&lt;br /&gt;
This segment seems to indicate the beginning of the song data and is not really relevant when parsing.&lt;br /&gt;
&lt;br /&gt;
 12  4  ID     &#039;SDFT&#039;; indicates start of format info&lt;br /&gt;
 16  4  Size   Size of next header as dword, (8)&lt;br /&gt;
 20  8  Song   &#039;MAINSONG&#039;; indicates song type. No other song types are known.&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
Each pattern is stored in its own PBOD chunk. Note that there are two possible formats for this chunk; one is used in the &amp;quot;old&amp;quot; format (as used in Epic Pinball, Extreme Pinball, Jazz Jackrabbit, One Must Fall) and the other in the &amp;quot;new&amp;quot; format (as used in Sinaria)&lt;br /&gt;
&lt;br /&gt;
 Pattern segment:&lt;br /&gt;
 0   4  ID     &#039;PBOD&#039;; indicates a pattern follows (Pattern BODy)&lt;br /&gt;
 4   4  Size   Length of pattern data as dword, after this dword&lt;br /&gt;
 4   4  Size   Same value again.&lt;br /&gt;
&lt;br /&gt;
 Pattern:&lt;br /&gt;
 0 4/8  Number Pattern ID. See note below.&lt;br /&gt;
 4   2  Row n  Number of rows in ALL channels in pattern (64 usually, but can differ.) as word.&lt;br /&gt;
 6   ?  Data   Contains pattern data as a number of rows of interlaced channels (12341234...)&lt;br /&gt;
               &#039;&#039;Usual&#039;&#039; settings is 64 rows of 4 channels. Epic Pinball has shorter patterns for example, but they also include a &amp;quot;break to row&amp;quot; command at the end of the pattern.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; In the old format, this starts with a &#039;P&#039; and is followed by an integer number which is the pattern number, padded to 4 bytes with spaces. Caution: This number might or might not be zero-padded; In some files, the ID of the first pattern could be &#039;P0  &#039;, but there are also files where it is &#039;P00 &#039;!. In C/C++, you could use atoi() to parse this value. In the new format (Sinaria), This field is 8 bytes long instead of 4 bytes, and the first 4 bytes read &amp;quot;PATT&amp;quot;, so the first pattern could be for example &#039;PATT0   &#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Pattern row channel entry:&lt;br /&gt;
 ?   1  Fill   Convert this byte value into binary; (240 -&amp;gt; 11110000), the first four     &lt;br /&gt;
               values                          &lt;br /&gt;
 +1  1  chan   What channel this belongs to, 0-3, each filled only once per tick, this is &lt;br /&gt;
               what, by absence, identifies empty channels.                               &lt;br /&gt;
 +2  1  Note   Pitch, $01 is C-1, etc... The octaves are aligned by 16, i.e. B-1 is $0C but the next note, C-2, is $10.&lt;br /&gt;
 +3  1  Ins    Instrument used, 0-31&lt;br /&gt;
 +4  1  Vol    Volume change to, 0-63 = 0-127; optional&lt;br /&gt;
 +5  1  Effect Effect to use, volume slide, Portamanto...&lt;br /&gt;
 +6  1  Eff Am Strength of effect, e.g amount of slide&lt;br /&gt;
&lt;br /&gt;
Each row consists of a word giving the size of the row (Including the word) followed by the channel data. A channel is only included if it has data in it, but a totally empty row is still included. So an &#039;empty&#039; row (Where none of the channels have data.) thus consists of just a word of value 2.&lt;br /&gt;
&lt;br /&gt;
Each channel entry consists of between 3-7 bytes. The first byte is a flag that shows what data follows. (The first four bits indicate whether there are bytes for the following four variables; Note ($80), Instrument ($40), Volume ($20), Effect AND Effect magnitude ($10). Thus 5 bytes are represented by a combination of 4 possibilities.) The next byte identifies the channel (Since each channel may or may not be present.) starting at 0 for channel 1. The remaining 5 bytes may or may not be present and contain data for Note, Instrument(Sample) used, Volume change for channel, Effect and Effect magnitude.&lt;br /&gt;
&lt;br /&gt;
There are several things to note about this; Effect and Effect magnitude MUST occur together. Sample numbers, like channels are numbered starting at 0, not 1. Magnitudes (For effect AND volume) are from 0-127, not 0-64 as in other formats.&lt;br /&gt;
&lt;br /&gt;
=== Effect conversion ===&lt;br /&gt;
&lt;br /&gt;
Note that this table is guaranteed to be correct; Most effects seem to be converted correctly, though. Note that these values are not correct for the PSM files that can be found in the game Sinaria. Leave out all divisions and it will be correct again.&lt;br /&gt;
&lt;br /&gt;
 PSM Command   Param length  S3M Command&lt;br /&gt;
 &lt;br /&gt;
  Volume commands&lt;br /&gt;
    1           1 Byte        DxF - fine volside up&lt;br /&gt;
    2           1 Byte        Dx0 - volslide up&lt;br /&gt;
    3           1 Byte        DFx - fine volslide down&lt;br /&gt;
    4           1 Byte        D0x - volslide down&lt;br /&gt;
 &lt;br /&gt;
 Portamento commands&lt;br /&gt;
    B           1 Byte        FFx - fine porta up (divide x by 4)&lt;br /&gt;
    C           1 Byte        Fxx - porta up (if x &amp;lt; 4, use FFx, else divide x by 4)&lt;br /&gt;
    D           1 Byte        EFx - fine porta down (divide x by 4)&lt;br /&gt;
    E           1 Byte        Exx - porta down (if x &amp;lt; 4, use EFx, else divide x by 4)&lt;br /&gt;
    F           1 Byte        Gxx - portamento (divide x by 4)&lt;br /&gt;
   10           1 Byte        S1x - glissando control&lt;br /&gt;
   11           1 Byte        Lx0 - tone porta + volslide up&lt;br /&gt;
   12           1 Byte        L0x - tone porta + volslide down&lt;br /&gt;
    &lt;br /&gt;
 Vibrato&lt;br /&gt;
   15           1 Byte        Hxy - vibrato&lt;br /&gt;
   16           1 Byte        S3x - vibrato waveform&lt;br /&gt;
   17           1 Byte        K0x - vibrato + volslide up&lt;br /&gt;
   18           1 Byte        Kx0 - vibrato + volslide down&lt;br /&gt;
   	&lt;br /&gt;
 Tremolo			&lt;br /&gt;
   1F           1 Byte        Rxy - tremolo&lt;br /&gt;
   20           1 Byte        S4x - tremolo waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample commands&lt;br /&gt;
   29           3 Bytes       Oxx - offset (only take the 2nd byte)&lt;br /&gt;
   2A           1 Byte        Q0x - retrigger&lt;br /&gt;
   2B           1 Byte        SCx - note cut&lt;br /&gt;
   2C           1 Byte        SDx - note delay&lt;br /&gt;
 &lt;br /&gt;
 Position change&lt;br /&gt;
   33           2 Bytes(?)    Bxx - position jump (divide by 2)&lt;br /&gt;
   34           1 Byte        Cxx - break to row (divide by 2)&lt;br /&gt;
   35           1 Byte        SBx - pattern loop&lt;br /&gt;
   36           1 Byte        SEx - pattern delay&lt;br /&gt;
  &lt;br /&gt;
 Speed change&lt;br /&gt;
   3D           1 Byte        Axx - set speed&lt;br /&gt;
   3E           1 Byte        Txx - set tempo&lt;br /&gt;
 &lt;br /&gt;
 Misc. commands&lt;br /&gt;
   47           1 Byte        Jxy - arpeggio&lt;br /&gt;
   48           1 Byte        S2x - set finetune&lt;br /&gt;
   49           1 Byte        S8x - set balance&lt;br /&gt;
&lt;br /&gt;
Effect interpretation is different in Sinaria&#039;s new format.&lt;br /&gt;
&lt;br /&gt;
== Song segment ==&lt;br /&gt;
&lt;br /&gt;
This segment contains most of the important data used to play the song, as well as a lot of unimportant data that is no longer used. It contains several sub-segments, each of the same format as a normal segment, but contained in the song segment. Note that there might be more than one song segment and thus, more than one order list, default speed, default tempo, etc...&lt;br /&gt;
&lt;br /&gt;
 Segment structure:&lt;br /&gt;
 0   4  ID     &#039;SONG&#039; indicates start of song structure&lt;br /&gt;
 4   4  Size   Size of song structure, including all sub-segments&lt;br /&gt;
 8   9  Type   Type of song this is for; This is &#039;MAINSONG &#039; in almost all PSM files. Extreme Pinball has several SONG items with different types!&lt;br /&gt;
 17  1  Comp   Compression, for PSM = 1 (Uncompressed)&lt;br /&gt;
 18  1  Chan   Number of channels, usually, but not always, 4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Date sub-segment ===&lt;br /&gt;
&lt;br /&gt;
This dates the file and is used by some programs. It is usually the first sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DATE&#039; indicates date data&lt;br /&gt;
 4   4  Size   Size of date segment (6)&lt;br /&gt;
 8   6  Date   Date as text, YYMMDD&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Order sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Orders are how patterns are arranged in the song. This allows the same pattern of instruments to be played more than once in a song (E.g. a chorus.) without the pattern having to be repeated. There is usually only one order. This section also contains basic song information. It usually follows the date sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;OPLH&#039; indicates start of pattern placement order&lt;br /&gt;
 4   4  Size   Size of order segment&lt;br /&gt;
 8   2  Cnt.   Number of following chunks&lt;br /&gt;
&lt;br /&gt;
Now, the following chunks may follow until the end of the &amp;quot;OPLH&amp;quot; chunk is reached. Every chunk is identified by the first byte:&lt;br /&gt;
* $00 (1 Byte): End (Nothing follows)&lt;br /&gt;
* $01 (5/9 Bytes): Order list item follows (e.g. &amp;quot;P0  &amp;quot;, &amp;quot;P12 &amp;quot; in old format or &amp;quot;PATT0   &amp;quot; in new format, see above) - join those to get the complete order list.&lt;br /&gt;
* $04 (3 Bytes): This 16-bit value indicates the &amp;quot;restart chunk&amp;quot;. If the end of the subsong is reached, it will jump back to this chunk. In many cases, this would be 4th chunk (no 3rd chunk, as the chunk index is starting at 0!), which is a panning index in most PSMs - So you would just go to the nearest order list item that&#039;s following this chunk. However, this can also point to a valid order list chunk.&lt;br /&gt;
* $07 (2 Bytes): Next byte is default speed for this subtune&lt;br /&gt;
* $08 (2 Bytes): Next byte is default tempo for this subtune&lt;br /&gt;
* $0C (7 Bytes): Sample map table(?): This chunk is always $0C $00 $FF $00 $00 $01 $00.&lt;br /&gt;
* $0D (4 Bytes): Channel panning index. Next byte is channel number (Start at 0), then initial pan ($00 ... $FF) and a byte follow. The byte seems to tell what to do with the previous pan position (0 - use it, 2 - ignore it, make this channel surround, 4 - set to center).&lt;br /&gt;
* $0E (3 Bytes): Channel volume index. Next byte is channel number (Start at 0), then volume ($00 ... $FF). $FF in most (all?) cases.&lt;br /&gt;
&lt;br /&gt;
=== Pattern list ===&lt;br /&gt;
&lt;br /&gt;
This is simply a list of all the patterns used in the file. You do not really need to parse this, it seems to be a purely informational chunk.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;PATT&#039; indicates start of pattern list&lt;br /&gt;
 4   4  Size   Size of pattern list after this&lt;br /&gt;
 8   4  Size   Same as above&lt;br /&gt;
 12  4x Pat    An ordered list &#039;P0  &#039;, &#039;P1  &#039;... for all patterns in the file, each entry 4 bytes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sample list sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Similar to the above, this is a list of all the samples used in the file. It is usually the last sub-segment in the song segment and you do not really need to parse this.&lt;br /&gt;
&lt;br /&gt;
  0  4   ID     &#039;DSAM&#039;; indicates start of sample list, used to say what samples are &#039;full&#039;&lt;br /&gt;
                Any samples not on this list will be ignored, even if they have data&lt;br /&gt;
  4  4   Size   Size of list after this&lt;br /&gt;
  8  4   Size   Same value as above&lt;br /&gt;
  12 15x Entry  Sample entries, one for each sample in the file, each entry 15 bytes&lt;br /&gt;
&lt;br /&gt;
 Sample entry:&lt;br /&gt;
 0   8  Format Sample format, padded with spaces (END, RAG2...) This is important to some programs&lt;br /&gt;
 8   4  ID     &#039;I0  &#039;, &#039;I1  &#039;... the sample ID (&#039;I&#039; means &#039;Instrument&#039;). Again, be sure to accept both &#039;I0  &#039; and &#039;I00 &#039;!&lt;br /&gt;
 12  2  Num    The sample number, 0,1,2... for the sample&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
Samples are the raw sound data that makes up the instruments on the song. The actual format depends on the sample format. Samples have information in their headers which allows data to be played at different pitches (Speeds.) and to loop from and to various points in the data. This is by far the largest part of the file, since the raw data takes up so much space.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DSMP&#039; indicates start of sample&lt;br /&gt;
 4   4  Size   Size of following sample as &#039;DSMP&#039; + dword from end of word&lt;br /&gt;
 8   9  Flags  If highest bit is set, then sample is looped&lt;br /&gt;
 9   8  Songn. Filename of the original module (without extension)&lt;br /&gt;
 17  4  INSx   Last digit of sample (Instrument) number, 0-9; with 31 instruments possible&lt;br /&gt;
               Only last digit is shown. E.g 1st, 11th, 21st and 31st sample is &#039;INS0&#039;&lt;br /&gt;
 21  33 Name   Defines the instrument name or file, usually a .st or line of text&lt;br /&gt;
 54  51 Header Sample parameters (Can also 58 bytes long, padded with nuls)&lt;br /&gt;
               Byte 1-6 are unknown ($00 $00 $00 $00 $00 $FF)&lt;br /&gt;
               Bytes 7-8 is instrument number&lt;br /&gt;
               Bytes 9-12 are sample length&lt;br /&gt;
               Bytes 13-16 are loop start&lt;br /&gt;
               Bytes 17-20 are loop end (all $FF means at end of sample)&lt;br /&gt;
               Bytes 21-22 are unknown (second byte could be default pan, but seems to be unused)&lt;br /&gt;
               Byte 23 is default volume&lt;br /&gt;
               Bytes 24-27 are unknwon&lt;br /&gt;
               Bytes 28-29 is frequency (Sample rate)&lt;br /&gt;
               21 $00-bytes follow&lt;br /&gt;
 105 ?  Data   Music data in 8-bit mono format&lt;br /&gt;
&lt;br /&gt;
The sample header is slightly different in Sinaria&#039;s new format: INSx is 8 bytes long (like the PATT IDs), and the last 21 $00-bytes are just 16 bytes.&lt;br /&gt;
&lt;br /&gt;
The PSM new format, along with the PSM 16 format use delta-encoded samples, something to make the file smaller when zipped. &#039;Deltas&#039;, convert a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. It has the effect that if a single byte in the sample is changed, the entire sample will be degraded. This use of deltas varies slightly from that of the PSM 16. The &#039;start value&#039; of the string is assumed to be $80 (128) and the first byte will thus turn this into the first desired value, the second delta converts the first value to the second, and so on.) All deltas are signed, 1-byte values, but loop (Thus 10 - 20 = -10 can also be considered as 10 + 236 = 246). An example of this is as follows:&lt;br /&gt;
&lt;br /&gt;
 RAW:   (128) 64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: -64  0   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM 16 =&lt;br /&gt;
&lt;br /&gt;
This is the format used in [[Silverball]], early versions of Epic Pinball and possibly other games. The designation &#039;Protracker Studio 16 format&#039; was given to it by the only reliable source of information on this format, and may not be the official designation.&lt;br /&gt;
&lt;br /&gt;
The format bears many similarities to the S3M format; the file is set out roughly the same, patterns and samples are similar, indeed, near identical and the functionality is similar. It also shows many similarities to the ProTracker MOD format and retains vestiges of Amiga compatibility.&lt;br /&gt;
&lt;br /&gt;
This format can be identified by its signature &#039;PSMþ&#039;, though files may lack this and still function.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Order&lt;br /&gt;
 Pan segment&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Sample data&lt;br /&gt;
 Sample headers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
 0    4  Sig      Signature, &#039;PSMþ&#039;&lt;br /&gt;
 4    59 Title    Song title, padded with nulls. Unlike other formats, this must also be terminated&lt;br /&gt;
                  with a null byte. (It sometimes is not terminated, though.)&lt;br /&gt;
 62   1           This must be $1A to end the song name, like in S3M format.&lt;br /&gt;
 64   1  Type     Song type, First bit: 0 - Module (w/samp.), 1 - Song (w/o samples)&lt;br /&gt;
                  Second bit: 0 - 3 octave Protracker, 1 - 5 octave; remaining bits reserved.&lt;br /&gt;
 65   1  PSM v    PSM format version, $10 for this format (Hence the name PSM 16) = &#039;v1.00&#039;.&lt;br /&gt;
                  Sometimes, this is also $01, but there&#039;s no difference in the format itself.&lt;br /&gt;
 66   1  Patt v   Pattern version, 0 or 1. 0 means the pattern is stored in the module are in the 32&lt;br /&gt;
                  channel file format.  A 1 signifies the patterns as being stored as a 255&lt;br /&gt;
                  channel format. (I have not found any PSM16 modules that have this format.)&lt;br /&gt;
 67   1   Speed   Song speed&lt;br /&gt;
 68   1   BPM     Beats per minute, the default Amiga BPM value. (The only reason that the Amiga BPM&lt;br /&gt;
                  format is still followed here is that it allows more control over the final hz value.)&lt;br /&gt;
                  Range: 32 to 255.&lt;br /&gt;
 69   1   Vol     Master volume of song, 0-255&lt;br /&gt;
 70   2   Len     Song length, 0-255. The number of patterns to play in the song, in total.&lt;br /&gt;
 72   2   Ordlen  The number of orders actually stored at the order offset. It was hoped that the&lt;br /&gt;
                  PSM 16 format would allow multiple orders, so this would be the length of the first&lt;br /&gt;
                  order. This doesn&#039;t appea to ahve happened, and is usually the same as the previous value.&lt;br /&gt;
 74   2   Patnum  Number of patterns in the song. 1-255&lt;br /&gt;
 76   2   Sampnum Number of samples and &#039;sample structures&#039; in song, 1-255&lt;br /&gt;
 78   2   NCIS    Number of channels in song to PLAY. 1-32. &lt;br /&gt;
 80   2   NCP     Number of Channels to Process; describes the MAXIMUM number of channels to process.&lt;br /&gt;
                  As an example, when converting 669 files,  NCP = 9 because some track information &lt;br /&gt;
                  is in Channel 8, but the Number of Channels to Play was set to 8, (Channel numbers&lt;br /&gt;
                  to play from 0 to 7.) 1-32&lt;br /&gt;
 82   4   Ordoff  Location of order in header&lt;br /&gt;
 86   4   Panoff  Location of pan positions in header&lt;br /&gt;
 90   4   Patoff  Location of patterns in header&lt;br /&gt;
 94   4   Sampoff Location of sample headers in header&lt;br /&gt;
 98   4   Commoff Location of comments in header&lt;br /&gt;
 102  4   Patsiz  Total pattern size; the total size of all the patterns loaded from the pattern offset.&lt;br /&gt;
 106  40  Fillers 10 fillers, to be used for any possible expansions.&lt;br /&gt;
&lt;br /&gt;
It is important to notice that the offsets point to the first byte &#039;&#039;&#039;after&#039;&#039;&#039; the chunk ID, i.e. &amp;quot;Ordoff&amp;quot; points to the first byte after &amp;quot;PORD&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Order and Pan positions ==&lt;br /&gt;
&lt;br /&gt;
These are two separate segments, pointed to in the header. They may be anywhere, but usually follow the header sometimes after an amount of blank space. They are often padded with blank space. They are basically lists.&lt;br /&gt;
&lt;br /&gt;
Order: This segment is pointed to in the header, and sets the PSM 16 format apart. The PSM 16 format was designed to be much more like the MOD format, allowing game designers to set flags to switch from one set of patterns to another, in effect allowing one file to contain more than one song. (For example a boss flag might make the music switch from a clam patterns 1-4 to a racy and dangerous patterns 5-7.)&lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    Signature, not needed, &#039;PORD&#039;&lt;br /&gt;
 4    ?   Ords   Pattern numbers and order. There will be [Ordlen] bytes of patterns&lt;br /&gt;
 ?    2   Lang   Order language, not implemented, so left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pan Positions: &lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    &#039;PPAN&#039;&lt;br /&gt;
 4    12  Pan    Pan positions; empty positions left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
 0    2   Size   Size of pattern, including these bytes&lt;br /&gt;
 2    1   Len    Length of pattern, in rows. Max length is 64 rows.&lt;br /&gt;
 3    1   Chan   Number of channels in pattern, 1-31&lt;br /&gt;
 4    ?   Data   Pattern data&lt;br /&gt;
&lt;br /&gt;
This is similar to the previous two segments, except actual pattern data is stored here. Patterns are very similar to the S3M format, and consist of y rows of x channels. Each row contains a number of channels and ends with a byte of value 0. Each channel is between 2-6+ bytes long. A totally empty channel is represented by a single byte of value 0.&lt;br /&gt;
&lt;br /&gt;
Each channel starts with a flag byte, abcddddd, where a,b and c indicate whether there is a note and instrument, volume or special effect and effect magnitude in the following data, and dddd is the channel number (0-31, used since a given channel may or may not be present in a row.)&lt;br /&gt;
&lt;br /&gt;
The usual maximum length of a channel entry is 6 bytes (1 flag byte, 2 Note AND instrument bytes, 1 volume byte and two Effect and Effect magnitude bytes.) Thus Note&amp;amp;ins\Eff&amp;amp;Eff mag must always occur together.&lt;br /&gt;
&lt;br /&gt;
Like S3M, volume range is 0-64, as is special magnitude. However, special effects range from 0-255, like PSM New Format.&lt;br /&gt;
&lt;br /&gt;
=== Effects conversion ===&lt;br /&gt;
&lt;br /&gt;
 ###  Co  MOD  Description               Arguments&lt;br /&gt;
 ---  --  ---  -----------               ---------&lt;br /&gt;
 Volume Commands&lt;br /&gt;
   1  A1   EA  Fine Volume Slide Up      B xx xx=speed&lt;br /&gt;
   2  A2   A   Volume Slide Up           B xx xx=speed&lt;br /&gt;
   3  A3   EB  Fine Volume Slide Down    B xx xx=speed&lt;br /&gt;
   4  A4   A   Volume Slide Down         B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Portamento Commands&lt;br /&gt;
  10  B0   E1  Fine Porta Up             B xx xx=speed&lt;br /&gt;
  11  B1   1   Portamento Up             B xx xx=speed&lt;br /&gt;
  12  B2   E2  Fine Porta Down           B xx xx=speed&lt;br /&gt;
  13  B3   2   Portamento Down           B xx xx=speed&lt;br /&gt;
  14  B4   3   Tone Portamento           B xx xx=speed&lt;br /&gt;
  15  B5   E3  Set Glissando Control     B xx xx=0 - Off, 1 - On&lt;br /&gt;
  16  B6   5   Tone Port+Vol Slide Up    B xx xx=speed&lt;br /&gt;
  17  B7   5   Tone Port+Vol Slide Down  B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Vibrato Commands&lt;br /&gt;
  20  C0   4   Vibrato                   B xy x=speed, y=depth&lt;br /&gt;
  21  C1   E4  Set Vibrato Waveform      B x  x=Waveform&lt;br /&gt;
  21  C2   6   Vibrato+Vol Slide Up      B xx xx=speed&lt;br /&gt;
  22  C3   6   Vibrato+Vol Slide Down    B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Tremolo Commands&lt;br /&gt;
  30  D0   7   Tremolo                   B xy x=speed, y=depth&lt;br /&gt;
  31  D1   E7  Set Tremolo Control       B x  x=Waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample Commands&lt;br /&gt;
  40  E0   9   Sample Offset             3B Position for offset change (0-1,048,575)&lt;br /&gt;
  41  E1   E9  Retrig Note               B xx xx=tick to retrigger sample&lt;br /&gt;
  42  E2   EC  Note Cut                  B xx xx=tick to cut note&lt;br /&gt;
  43  E3   ED  Note Delay                B xx xx=ticks to delay note&lt;br /&gt;
 &lt;br /&gt;
 Pos. Change Commands&lt;br /&gt;
  50  F0   B   Position Jump             B xx xx=order position&lt;br /&gt;
  51  F1   D   Pattern Break             B xx Skip to line xx in next pattern&lt;br /&gt;
  52  F2   E6  Jump Loop                 B xx xx=number of loops  0 Set&lt;br /&gt;
  53  F3   EE  Pattern Delay             B xx xx=notes to delay pattern&lt;br /&gt;
 &lt;br /&gt;
 Speed Change Cmds&lt;br /&gt;
  60  G0   F   Set Regular Speed         B xx xx=speed&lt;br /&gt;
  61  G1   F   Set BPM                   B xx xx=BPM (32-255)&lt;br /&gt;
 &lt;br /&gt;
 Misc. Commands&lt;br /&gt;
  70  H0   0   Arpeggio                  B xy x=semitone #1, y=semitone #2&lt;br /&gt;
  71  H1   E5  Set Finetune              B xx xx=finetune&lt;br /&gt;
  72  H2       Set Balance               B xx xx=Balance (0-15)&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
 Sample segment&lt;br /&gt;
 0    4   ID     &#039;PSAM&#039; (Psm SAMple)&lt;br /&gt;
 4    ?  Data    Sample data&lt;br /&gt;
&lt;br /&gt;
 Sample header segment&lt;br /&gt;
 0    4   ID     &#039;PSAH&#039; (Psm SAmple Header)&lt;br /&gt;
 4    ?  Data    Sample headers&lt;br /&gt;
&lt;br /&gt;
 Sample header&lt;br /&gt;
 0    13  Name   Sample filename, terminated with a null.&lt;br /&gt;
 13   24  Desc   Sample description or comments.&lt;br /&gt;
 37   4   Offs   Location of raw sample data in file&lt;br /&gt;
 43   4   Mem    This is the physical offset in RAM/DRAM of the sample. (Often blank.)&lt;br /&gt;
 45   2   Num    Sample number, 1-255&lt;br /&gt;
 47   1   Type   Sample type: (In some games left blank; if this is the case then the&lt;br /&gt;
                 sample format is END, as used in most PSM New Format files)&lt;br /&gt;
                 Bit 0: 0 - Digital, 1 - Synthesized&lt;br /&gt;
                 Bit 2: 0 - 8-bit, 1 - 16-bit&lt;br /&gt;
                 Bit 3: 0 - Signed, 1 - Unsigned&lt;br /&gt;
                 Bit 4: 0 - Deltas, 1 - Raw&lt;br /&gt;
                 Bit 5: 0 - Loop normally, 1 - Bidirectional&lt;br /&gt;
                 Bit 6: 1 - Gravis patch (unsupported)&lt;br /&gt;
                 Bit 7: 0 - No loop, 1 - Loop sample&lt;br /&gt;
 48   4   Len    Sample length, in bytes.&lt;br /&gt;
 52   4   Rep st Sample repeat start; if sample loops, the loop starts here.&lt;br /&gt;
 56   4   Rep fn Sample repeat end, if sample loops, it ends here. If this is less than the sample&lt;br /&gt;
                 repeat start, the sample loops backwards.&lt;br /&gt;
 60   1   Tune   Fine tune; range 0-15, Tune 0-7 = 0-7; tune -1 - -8 = 8-15&lt;br /&gt;
 61   1   Vol    Sample volume, 0-64&lt;br /&gt;
 62   2   Freq   This is the frequency for the sample at a C of Octave 2.&lt;br /&gt;
                 Typical values are 8,000 hz to 8,448 hz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like S3M, sample headers are stored separately from the raw sample data. Unlike S3M, the number of sample headers doesn&#039;t have to be 31, but rather is the number of samples in the header. Sample headers are usually stored at then end of the file, after the raw sample data.&lt;br /&gt;
&lt;br /&gt;
A type of sample compression used often, like in the PSM New Format is &#039;Deltas&#039;, which converts a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. Thus:&lt;br /&gt;
&lt;br /&gt;
 RAW:        64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: 11  64   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
This is done to make files more compressible, but doesn&#039;t seem to be used much.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
&lt;br /&gt;
It is unknown which of the two PSM formats the following utilities support, unless stated otherwise.&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.shikadi.net/files/psm2scrm.zip psm2scrm.zip] - DOS program to convert .PSM songs into ScreamTracker .S3M format, suitable for playing in your favourite tracker/module player. Works only with PSM New Format and is not nearly as accurate as OpenMPT.&lt;br /&gt;
* [http://openmpt.org/legacy_software ModPlug Tracker] and OpenMPT 1.17 can play the files and save them as S3M. More complex songs don&#039;t load correctly though. Works only with new format.&lt;br /&gt;
* [http://openmpt.org OpenMPT] 1.18 and newer can load all PSM and PSM16 files.&lt;br /&gt;
* [http://kode54.foobar2000.org/ foo_dumb] is a plugin for various module formats for the Foobar2k media player. It supports both PSM16 and PSM and is similar to OpenMPT in playback quality.&lt;br /&gt;
* [http://ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/mxinfo/epictest.zip EPICTEST] is a demonstration of the Epic Megagames MASI. It contains CONVERT.EXE which can be used to convert modules to the PSM format.&lt;br /&gt;
* [http://www.jazz2online.com/J2Ov2/downloads/info.php?levelID=5471#29435] JJ1MOD can convert S3M files to PSM, though often with errors (Though these are usually only detectable with older programs such as game executables.) It is currently the only utility able to do this, and works only with New Format.&lt;br /&gt;
&lt;br /&gt;
= Notes =&lt;br /&gt;
&lt;br /&gt;
The New PSM format was reverse engineered by Levellord and tidied up by Levellass. It is possible there may be minor errors in the sample format information, especially since this is poorly documented.&lt;br /&gt;
Some format definitions have been updated and corrected by Johannes Schultz of the OpenMPT development team.&lt;br /&gt;
&lt;br /&gt;
The PSM16 format was reverse engineered by Wotsit and written up by Levellass. More info is needed.&lt;br /&gt;
&lt;br /&gt;
In all formats the following table shows how note bytes are converted into actual notes: (PSM new format has the widest range, 0-255)&lt;br /&gt;
&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;br /&gt;
           | C-0   0 | C-1  12 | C-2  24 | C-3  36 | C-4  48 |&lt;br /&gt;
           | C#0   1 | C#1  13 | C#2  25 | C#3  37 | C#4  49 |&lt;br /&gt;
           | D-0   2 | D-1  14 | D-2  26 | D-3  38 | D-4  50 |&lt;br /&gt;
           | D#0   3 | D#1  15 | D#2  27 | D#3  39 | D#4  51 |&lt;br /&gt;
           | E-0   4 | E-1  16 | E-2  28 | E-3  40 | E-4  52 |&lt;br /&gt;
           | F-0   5 | F-1  17 | F-2  29 | F-3  41 | F-4  53 |&lt;br /&gt;
           | F#0   6 | F#1  18 | F#2  30 | F#3  42 | F#4  54 |&lt;br /&gt;
           | G-0   7 | G-1  19 | G-2  31 | G-3  43 | G-4  55 |&lt;br /&gt;
           | G#0   8 | G#1  20 | G#2  32 | G#3  44 | G#4  56 |&lt;br /&gt;
           | A-0   9 | A-1  21 | A-2  33 | A-3  45 | A-4  57 |&lt;br /&gt;
           | A#0  10 | A#1  22 | A#2  34 | A#3  46 | A#4  58 |&lt;br /&gt;
           | B-0  11 | B-1  23 | B-2  35 | B-3  47 | B-4  59 |&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;br /&gt;
&lt;br /&gt;
[[Category:Music Files]]&lt;br /&gt;
[[Category:Jazz Jackrabbit]]&lt;br /&gt;
[[Category:File Formats]]&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=3652</id>
		<title>ProTracker Studio Module</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=ProTracker_Studio_Module&amp;diff=3652"/>
		<updated>2011-09-11T15:48:23Z</updated>

		<summary type="html">&lt;p&gt;Saga: Format&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;&#039;ProTracker Studio Module&#039;&#039;&#039; (PSM) file format is used for the music in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]].  The file format is named after ProTracker, an Amiga program, though this program was probably actually not used to write PSM files. One Must Fall&#039;s music was written in Multitracker, and the music for Jazz Jackrabbit, Epic Pinball and Extreme Pinball probably in Scream Tracker.&lt;br /&gt;
&lt;br /&gt;
There are currently two file types that use the extension .PSM; they seem to be related to a certain extent, though how is currently unknown. The two formats are:&lt;br /&gt;
&lt;br /&gt;
 PSM New Format: Used by Jazz Jackrabbit, Epic Pinball, Extreme Pinball, One Must Fall, Sinaria (in this game with slight differences, see below), newest PSM format&lt;br /&gt;
 PSM 16:         Used by Silverball, an older version of the format which is closer to ProTracker-style modules.&lt;br /&gt;
&lt;br /&gt;
The most common of the two PSM formats is the new format, and most programs that try to run PSM files will be expecting this. For example, ModPlug Player cannot open Silverball files as these are in the PSM 16 format.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM New Format =&lt;br /&gt;
&lt;br /&gt;
This format is used by [[:Category:Epic Megagames|Epic]] games in [[Jazz Jackrabbit]], [[Epic Pinball]], [[Extreme Pinball]], [[Silverball]], [[Sinaria]] and [[One Must Fall]]. It is notable for consisting of a number of segments (chunks) and sub segments. It bears the 4-byte signature &#039;PSM &#039; at the file start.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Song segment&lt;br /&gt;
 Samples&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
The file header is 12 bytes long:&lt;br /&gt;
&lt;br /&gt;
 File header:&lt;br /&gt;
 0   4  ID     &#039;PSM &#039;; indicates file is PSM format&lt;br /&gt;
 4   4  Size   Filesize - 12&lt;br /&gt;
 8   4  ID2    &#039;FILE&#039;; indicates start of file info&lt;br /&gt;
&lt;br /&gt;
After the header, some chunks follow in IFF-style. You should not expect chunks to come up in the same order as they are described here. A good way to handle chunks is to read the 4-Byte ID and the 4-Byte size field first, then evaluate the ID and decide what to do next based on this ID. Note that the size field does not include the ID and itself; it only holds the size of the chunk &#039;&#039;content&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Title segment ==&lt;br /&gt;
&lt;br /&gt;
This segment is optional, and one of the few segments that can be absent when playing PSM files in most programs. (Most programs expect all other segments to exist, even if they are not vital.) Most PSM songs have no title.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;TITL&#039;; indicates a title follows&lt;br /&gt;
 4   4  Size   Size of title as dword after this dword&lt;br /&gt;
 8   ?  Title  Song title&lt;br /&gt;
&lt;br /&gt;
== Song info segment ==&lt;br /&gt;
&lt;br /&gt;
This segment seems to indicate the beginning of the song data and is not really relevant when parsing.&lt;br /&gt;
&lt;br /&gt;
 12  4  ID     &#039;SDFT&#039;; indicates start of format info&lt;br /&gt;
 16  4  Size   Size of next header as dword, (8)&lt;br /&gt;
 20  8  Song   &#039;MAINSONG&#039;; indicates song type. No other song types are known.&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
Each pattern is stored in its own PBOD chunk. Note that there are two possible formats for this chunk; one is used in the &amp;quot;old&amp;quot; format (as used in Epic Pinball, Extreme Pinball, Jazz Jackrabbit, One Must Fall) and the other in the &amp;quot;new&amp;quot; format (as used in Sinaria)&lt;br /&gt;
&lt;br /&gt;
 Pattern segment:&lt;br /&gt;
 0   4  ID     &#039;PBOD&#039;; indicates a pattern follows (Pattern BODy)&lt;br /&gt;
 4   4  Size   Length of pattern data as dword, after this dword&lt;br /&gt;
 4   4  Size   Same value again.&lt;br /&gt;
&lt;br /&gt;
 Pattern:&lt;br /&gt;
 0 4/8  Number Pattern ID. See note below.&lt;br /&gt;
 4   2  Row n  Number of rows in ALL channels in pattern (64 usually, but can differ.) as word.&lt;br /&gt;
 6   ?  Data   Contains pattern data as a number of rows of interlaced channels (12341234...)&lt;br /&gt;
               &#039;&#039;Usual&#039;&#039; settings is 64 rows of 4 channels. Epic Pinball has shorter patterns for example, but they also include a &amp;quot;break to row&amp;quot; command at the end of the pattern.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; In the old format, this starts with a &#039;P&#039; and is followed by an integer number which is the pattern number, padded to 4 bytes with spaces. Caution: This number might or might not be zero-padded; In some files, the ID of the first pattern could be &#039;P0  &#039;, but there are also files where it is &#039;P00 &#039;!. In C/C++, you could use atoi() to parse this value. In the new format (Sinaria), This field is 8 bytes long instead of 4 bytes, and the first 4 bytes read &amp;quot;PATT&amp;quot;, so the first pattern could be for example &#039;PATT0   &#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Pattern row channel entry:&lt;br /&gt;
 ?   1  Fill   Convert this byte value into binary; (240 -&amp;gt; 11110000), the first four     &lt;br /&gt;
               values                          &lt;br /&gt;
 +1  1  chan   What channel this belongs to, 0-3, each filled only once per tick, this is &lt;br /&gt;
               what, by absence, identifies empty channels.                               &lt;br /&gt;
 +2  1  Note   Pitch, $01 is C-1, etc... The octaves are aligned by 16, i.e. B-1 is $0C but the next note, C-2, is $10.&lt;br /&gt;
 +3  1  Ins    Instrument used, 0-31&lt;br /&gt;
 +4  1  Vol    Volume change to, 0-63 = 0-127; optional&lt;br /&gt;
 +5  1  Effect Effect to use, volume slide, Portamanto...&lt;br /&gt;
 +6  1  Eff Am Strength of effect, e.g amount of slide&lt;br /&gt;
&lt;br /&gt;
Each row consists of a word giving the size of the row (Including the word) followed by the channel data. A channel is only included if it has data in it, but a totally empty row is still included. So an &#039;empty&#039; row (Where none of the channels have data.) thus consists of just a word of value 2.&lt;br /&gt;
&lt;br /&gt;
Each channel entry consists of between 3-7 bytes. The first byte is a flag that shows what data follows. (The first four bits indicate whether there are bytes for the following four variables; Note ($80), Instrument ($40), Volume ($20), Effect AND Effect magnitude ($10). Thus 5 bytes are represented by a combination of 4 possibilities.) The next byte identifies the channel (Since each channel may or may not be present.) starting at 0 for channel 1. The remaining 5 bytes may or may not be present and contain data for Note, Instrument(Sample) used, Volume change for channel, Effect and Effect magnitude.&lt;br /&gt;
&lt;br /&gt;
There are several things to note about this; Effect and Effect magnitude MUST occur together. Sample numbers, like channels are numbered starting at 0, not 1. Magnitudes (For effect AND volume) are from 0-127, not 0-63 as in other formats.&lt;br /&gt;
&lt;br /&gt;
=== Effect conversion ===&lt;br /&gt;
&lt;br /&gt;
Note that this table is guaranteed to be correct; Most effects seem to be converted correctly, though. Note that these values are not correct for the PSM files that can be found in the game Sinaria. Leave out all divisions and it will be correct again.&lt;br /&gt;
&lt;br /&gt;
 PSM Command   Param length  S3M Command&lt;br /&gt;
 &lt;br /&gt;
  Volume commands&lt;br /&gt;
    1           1 Byte        DxF - fine volside up&lt;br /&gt;
    2           1 Byte        Dx0 - volslide up&lt;br /&gt;
    3           1 Byte        DFx - fine volslide down&lt;br /&gt;
    4           1 Byte        D0x - volslide down&lt;br /&gt;
 &lt;br /&gt;
 Portamento commands&lt;br /&gt;
    B           1 Byte        FFx - fine porta up (divide x by 4)&lt;br /&gt;
    C           1 Byte        Fxx - porta up (if x &amp;lt; 4, use FFx, else divide x by 4)&lt;br /&gt;
    D           1 Byte        EFx - fine porta down (divide x by 4)&lt;br /&gt;
    E           1 Byte        Exx - porta down (if x &amp;lt; 4, use EFx, else divide x by 4)&lt;br /&gt;
    F           1 Byte        Gxx - portamento (divide x by 4)&lt;br /&gt;
   10           1 Byte        S1x - glissando control&lt;br /&gt;
   11           1 Byte        Lx0 - tone porta + volslide up&lt;br /&gt;
   12           1 Byte        L0x - tone porta + volslide down&lt;br /&gt;
    &lt;br /&gt;
 Vibrato&lt;br /&gt;
   15           1 Byte        Hxy - vibrato&lt;br /&gt;
   16           1 Byte        S3x - vibrato waveform&lt;br /&gt;
   17           1 Byte        K0x - vibrato + volslide up&lt;br /&gt;
   18           1 Byte        Kx0 - vibrato + volslide down&lt;br /&gt;
   	&lt;br /&gt;
 Tremolo			&lt;br /&gt;
   1F           1 Byte        Rxy - tremolo&lt;br /&gt;
   20           1 Byte        S4x - tremolo waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample commands&lt;br /&gt;
   29           3 Bytes       Oxx - offset (only take the 2nd byte)&lt;br /&gt;
   2A           1 Byte        Q0x - retrigger&lt;br /&gt;
   2B           1 Byte        SCx - note cut&lt;br /&gt;
   2C           1 Byte        SDx - note delay&lt;br /&gt;
 &lt;br /&gt;
 Position change&lt;br /&gt;
   33           2 Bytes(?)    Bxx - position jump (divide by 2)&lt;br /&gt;
   34           1 Byte        Cxx - break to row (divide by 2)&lt;br /&gt;
   35           1 Byte        SBx - pattern loop&lt;br /&gt;
   36           1 Byte        SEx - pattern delay&lt;br /&gt;
  &lt;br /&gt;
 Speed change&lt;br /&gt;
   3D           1 Byte        Axx - set speed&lt;br /&gt;
   3E           1 Byte        Txx - set tempo&lt;br /&gt;
 &lt;br /&gt;
 Misc. commands&lt;br /&gt;
   47           1 Byte        Jxy - arpeggio&lt;br /&gt;
   48           1 Byte        S2x - set finetune&lt;br /&gt;
   49           1 Byte        S8x - set balance&lt;br /&gt;
&lt;br /&gt;
Effect interpretation is different in Sinaria&#039;s new format.&lt;br /&gt;
&lt;br /&gt;
== Song segment ==&lt;br /&gt;
&lt;br /&gt;
This segment contains most of the important data used to play the song, as well as a lot of unimportant data that is no longer used. It contains several sub-segments, each of the same format as a normal segment, but contained in the song segment. Note that there might be more than one song segment and thus, more than one order list, default speed, default tempo, etc...&lt;br /&gt;
&lt;br /&gt;
 Segment structure:&lt;br /&gt;
 0   4  ID     &#039;SONG&#039; indicates start of song structure&lt;br /&gt;
 4   4  Size   Size of song structure, including all sub-segments&lt;br /&gt;
 8   9  Type   Type of song this is for; This is &#039;MAINSONG &#039; in almost all PSM files. Extreme Pinball has several SONG items with different types!&lt;br /&gt;
 17  1  Comp   Compression, for PSM = 1 (Uncompressed)&lt;br /&gt;
 18  1  Chan   Number of channels, usually, but not always, 4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Date sub-segment ===&lt;br /&gt;
&lt;br /&gt;
This dates the file and is used by some programs. It is usually the first sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DATE&#039; indicates date data&lt;br /&gt;
 4   4  Size   Size of date segment (6)&lt;br /&gt;
 8   6  Date   Date as text, YYMMDD&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Order sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Orders are how patterns are arranged in the song. This allows the same pattern of instruments to be played more than once in a song (E.g. a chorus.) without the pattern having to be repeated. There is usually only one order. This section also contains basic song information. It usually follows the date sub-segment.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;OPLH&#039; indicates start of pattern placement order&lt;br /&gt;
 4   4  Size   Size of order segment&lt;br /&gt;
 8   2  Cnt.   Number of following chunks&lt;br /&gt;
&lt;br /&gt;
Now, the following chunks may follow until the end of the &amp;quot;OPLH&amp;quot; chunk is reached. Every chunk is identified by the first byte:&lt;br /&gt;
* $00 (1 Byte): End (Nothing follows)&lt;br /&gt;
* $01 (5/9 Bytes): Order list item follows (e.g. &amp;quot;P0  &amp;quot;, &amp;quot;P12 &amp;quot; in old format or &amp;quot;PATT0   &amp;quot; in new format, see above) - join those to get the complete order list.&lt;br /&gt;
* $04 (3 Bytes): This 16-bit value indicates the &amp;quot;restart chunk&amp;quot;. If the end of the subsong is reached, it will jump back to this chunk. In many cases, this would be 4th chunk (no 3rd chunk, as the chunk index is starting at 0!), which is a panning index in most PSMs - So you would just go to the nearest order list item that&#039;s following this chunk. However, this can also point to a valid order list chunk.&lt;br /&gt;
* $07 (2 Bytes): Next byte is default speed for this subtune&lt;br /&gt;
* $08 (2 Bytes): Next byte is default tempo for this subtune&lt;br /&gt;
* $0C (7 Bytes): Sample map table(?): This chunk is always $0C $00 $FF $00 $00 $01 $00.&lt;br /&gt;
* $0D (4 Bytes): Channel panning index. Next byte is channel number (Start at 0), then initial pan ($00 ... $FF) and a byte follow. The byte seems to tell what to do with the previous pan position (0 - use it, 2 - ignore it, make this channel surround, 4 - set to center).&lt;br /&gt;
* $0E (3 Bytes): Channel volume index. Next byte is channel number (Start at 0), then volume ($00 ... $FF). $FF in most (all?) cases.&lt;br /&gt;
&lt;br /&gt;
=== Pattern list ===&lt;br /&gt;
&lt;br /&gt;
This is simply a list of all the patterns used in the file. You do not really need to parse this, it seems to be a purely informational chunk.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;PATT&#039; indicates start of pattern list&lt;br /&gt;
 4   4  Size   Size of pattern list after this&lt;br /&gt;
 8   4  Size   Same as above&lt;br /&gt;
 12  4x Pat    An ordered list &#039;P0  &#039;, &#039;P1  &#039;... for all patterns in the file, each entry 4 bytes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sample list sub-segment ===&lt;br /&gt;
&lt;br /&gt;
Similar to the above, this is a list of all the samples used in the file. It is usually the last sub-segment in the song segment and you do not really need to parse this.&lt;br /&gt;
&lt;br /&gt;
  0  4   ID     &#039;DSAM&#039;; indicates start of sample list, used to say what samples are &#039;full&#039;&lt;br /&gt;
                Any samples not on this list will be ignored, even if they have data&lt;br /&gt;
  4  4   Size   Size of list after this&lt;br /&gt;
  8  4   Size   Same value as above&lt;br /&gt;
  12 15x Entry  Sample entries, one for each sample in the file, each entry 15 bytes&lt;br /&gt;
&lt;br /&gt;
 Sample entry:&lt;br /&gt;
 0   8  Format Sample format, padded with spaces (END, RAG2...) This is important to some programs&lt;br /&gt;
 8   4  ID     &#039;I0  &#039;, &#039;I1  &#039;... the sample ID (&#039;I&#039; means &#039;Instrument&#039;). Again, be sure to accept both &#039;I0  &#039; and &#039;I00 &#039;!&lt;br /&gt;
 12  2  Num    The sample number, 0,1,2... for the sample&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
Samples are the raw sound data that makes up the instruments on the song. The actual format depends on the sample format. For example, XM2 is identical to wave format data, but signed, END is &#039;delta&#039; format and RAG2 may be plain wave data. Samples have information in their headers which allows data to be played at different pitches (Speeds.) and to loop from and to various points in the data. This is by far the largest part of the file, since the raw data takes up so much space.&lt;br /&gt;
&lt;br /&gt;
There are several sample formats, which can be used by other modules than PSM. The following is the format of the &#039;END&#039; sample. The XM2 format sample has a header that is 7 bytes longer (Padded with nulls at the end.) and is labeled &#039;Ix  &#039; instead of &#039;INSx&#039; Most sample formats are poorly known.&lt;br /&gt;
&lt;br /&gt;
 0   4  ID     &#039;DSMP&#039; indicates start of sample&lt;br /&gt;
 4   4  Size   Size of following sample as &#039;DSMP&#039; + dword from end of word&lt;br /&gt;
 8   9  Flags  If highest bit is set, then sample is looped&lt;br /&gt;
 9   8  Songn. This seems to be a song name or something&lt;br /&gt;
 17  4  INSx   Last digit of sample (Instrument) number, 0-9; with 31 instruments possible&lt;br /&gt;
               Only last digit is shown. E.g 1st, 11th, 21st and 31st sample is &#039;INS0&#039;&lt;br /&gt;
 21  33 Name   Defines the instrument name or file, usually a .st or line of text&lt;br /&gt;
 54  51 Header Sample parameters (Can also 58 bytes long, padded with nuls)&lt;br /&gt;
               Byte 1-6 are unknown ($00 $00 $00 $00 $00 $FF)&lt;br /&gt;
               Bytes 7-8 is instrument number&lt;br /&gt;
               Bytes 9-12 are sample length&lt;br /&gt;
               Bytes 13-16 are loop start&lt;br /&gt;
               Bytes 17-20 are loop end (all $FF means at end of sample)&lt;br /&gt;
               Bytes 21-22 are unknown&lt;br /&gt;
               Byte 23 is default volume&lt;br /&gt;
               Bytes 24-27 are unknwon&lt;br /&gt;
               Bytes 28-29 is frequency (Sample rate)&lt;br /&gt;
               21 $00-bytes follow&lt;br /&gt;
 105 ?  Data   Music data in 8-bit mono format&lt;br /&gt;
&lt;br /&gt;
The sample header is slightly different in Sinaria&#039;s new format: INSx is 8 bytes long (like the PATT IDs), and the last 21 $00-bytes are just 16 bytes.&lt;br /&gt;
&lt;br /&gt;
The PSM new format, along with the PSM 16 format use a form of &#039;compression&#039; (Actually something to make the file smaller when zipped.) is &#039;Deltas&#039;, which converts a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. It is used in END format samples and has the effect that if a single byte is changed, the entire sample will be degraded. This use of deltas varies slightly from that of the PSM 16. The &#039;start value&#039; of the string is assumed to be $80 (128) and the first byte will thus turn this into the first desired value, the second delta converts the first value to the second, and so on.) All deltas are signed, 1-byte values, but loop (Thus 10 - 20 = -10 can also be considered as 10 + 236 = 246). An example of this is as follows:&lt;br /&gt;
&lt;br /&gt;
 RAW:   (128) 64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: -64  0   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= PSM 16 =&lt;br /&gt;
&lt;br /&gt;
This is the format used in [[Silverball]] and possibly other games. The designation &#039;Protracker Studio 16 format&#039; was given to it by the only reliable source of information on this format, and may not be the official designation. Earlier versions of this format may also exist, but if so, they have not been identified as yet.&lt;br /&gt;
&lt;br /&gt;
The format bears many similarities to the S3M format; the file is set out roughly the same, patterns and samples are similar, indeed, near identical and the functionality is similar. It also shows many similarities to the PSM Old format and retains vestiges of Amiga compatibility.&lt;br /&gt;
&lt;br /&gt;
This format can be identified by its signature &#039;PSMþ&#039;, though files may lack this and still function.&lt;br /&gt;
&lt;br /&gt;
 File structure:&lt;br /&gt;
 Header&lt;br /&gt;
 Order&lt;br /&gt;
 Pan segment&lt;br /&gt;
 Pattern segment&lt;br /&gt;
 Sample data&lt;br /&gt;
 Sample headers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
&lt;br /&gt;
 0    4  Sig      Signature, &#039;PSMþ&#039;&lt;br /&gt;
 4    59 Title    Song title, padded with nulls. Unlike other formats, this must also be terminated&lt;br /&gt;
                  with a null byte. (It sometimes is not terminated, though.)&lt;br /&gt;
 62   1           This must be $1A to end the song name, like in S3M format.&lt;br /&gt;
 64   1  Type     Song type, First bit: 0 - Module (w/samp.), 1 - Song (w/o samples)&lt;br /&gt;
                  Second bit: 0 - 3 octave Protracker, 1 - 5 octave; remaining bits reserved.&lt;br /&gt;
 65   1  PSM v    PSM format version, $10 for this format (Hence the name PSM 16) = &#039;v1.00&#039;.&lt;br /&gt;
                  Sometimes, this is also $01, but there&#039;s no difference in the format itself.&lt;br /&gt;
 66   1  Patt v   Pattern version, 0 or 1. 0 means the pattern is stored in the module are in the 32&lt;br /&gt;
                  channel file format.  A 1 signifies the patterns as being stored as a 255&lt;br /&gt;
                  channel format. (I have not found any PSM16 modules that have this format.)&lt;br /&gt;
 67   1   Speed   Song speed&lt;br /&gt;
 68   1   BPM     Beats per minute, the default Amiga BPM value. (The only reason that the Amiga BPM&lt;br /&gt;
                  format is still followed here is that it allows more control over the final hz value.)&lt;br /&gt;
                  Range: 32 to 255.&lt;br /&gt;
 69   1   Vol     Master volume of song, 0-255&lt;br /&gt;
 70   2   Len     Song length, 0-255. The number of patterns to play in the song, in total.&lt;br /&gt;
 72   2   Ordlen  The number of orders actually stored at the order offset. It was hoped that the&lt;br /&gt;
                  PSM 16 format would allow multiple orders, so this would be the length of the first&lt;br /&gt;
                  order. This doesn&#039;t appea to ahve happened, and is usually the same as the previous value.&lt;br /&gt;
 74   2   Patnum  Number of patterns in the song. 1-255&lt;br /&gt;
 76   2   Sampnum Number of samples and &#039;sample structures&#039; in song, 1-255&lt;br /&gt;
 78   2   NCIS    Number of channels in song to PLAY. 1-32. &lt;br /&gt;
 80   2   NCP     Number of Channels to Process; describes the MAXIMUM number of channels to process.&lt;br /&gt;
                  As an example, when converting 669 files,  NCP = 9 because some track information &lt;br /&gt;
                  is in Channel 8, but the Number of Channels to Play was set to 8, (Channel numbers&lt;br /&gt;
                  to play from 0 to 7.) 1-32&lt;br /&gt;
 82   4   Ordoff  Location of order in header&lt;br /&gt;
 86   4   Panoff  Location of pan positions in header&lt;br /&gt;
 90   4   Patoff  Location of patterns in header&lt;br /&gt;
 94   4   Sampoff Location of sample headers in header&lt;br /&gt;
 98   4   Commoff Location of comments in header&lt;br /&gt;
 102  4   Patsiz  Total pattern size; the total size of all the patterns loaded from the pattern offset.&lt;br /&gt;
 106  40  Fillers 10 fillers, to be used for any possible expansions.&lt;br /&gt;
&lt;br /&gt;
It is important to notice that the offsets point to the first byte &#039;&#039;&#039;after&#039;&#039;&#039; the chunk ID, i.e. &amp;quot;Ordoff&amp;quot; points to the first byte after &amp;quot;PORD&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Order and Pan positions ==&lt;br /&gt;
&lt;br /&gt;
These are two separate segments, pointed to in the header. They may be anywhere, but usually follow the header sometimes after an amount of blank space. They are often padded with blank space. They are basically lists.&lt;br /&gt;
&lt;br /&gt;
Order: This segment is pointed to in the header, and sets the PSM 16 format apart. The PSM 16 format was designed to be much more like the MOD format, allowing game designers to set flags to switch from one set of patterns to another, in effect allowing one file to contain more than one song. (For example a boss flag might make the music switch from a clam patterns 1-4 to a racy and dangerous patterns 5-7.)&lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    Signature, not needed, &#039;PORD&#039;&lt;br /&gt;
 4    ?   Ords   Pattern numbers and order. There will be [Ordlen] bytes of patterns&lt;br /&gt;
 ?    2   Lang   Order language, not implemented, so left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pan Positions: &lt;br /&gt;
&lt;br /&gt;
 0    4   Sig    &#039;PPAN&#039;&lt;br /&gt;
 4    12  Pan    Pan positions; empty positions left blank.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Patterns ==&lt;br /&gt;
&lt;br /&gt;
 0    2   Size   Size of pattern, including these bytes&lt;br /&gt;
 2    1   Len    Length of pattern, in rows. Max length is 64 rows.&lt;br /&gt;
 3    1   Chan   Number of channels in pattern, 1-31&lt;br /&gt;
 4    ?   Data   Pattern data&lt;br /&gt;
&lt;br /&gt;
This is similar to the previous two segments, except actual pattern data is stored here. Patterns are very similar to the S3M format, and consist of y rows of x channels. Each row contains a number of channels and ends with a byte of value 0. Each channel is between 2-6+ bytes long. A totally empty channel is represented by a single byte of value 0.&lt;br /&gt;
&lt;br /&gt;
Each channel starts with a flag byte, abcddddd, where a,b and c indicate whether there is a note and instrument, volume or special effect and effect magnitude in the following data, and dddd is the channel number (0-31, used since a given channel may or may not be present in a row.)&lt;br /&gt;
&lt;br /&gt;
The usual maximum length of a channel entry is 6 bytes (1 flag byte, 2 Note AND instrument bytes, 1 volume byte and two Effect and Effect magnitude bytes.) Thus Note&amp;amp;ins\Eff&amp;amp;Eff mag must always occur together.&lt;br /&gt;
&lt;br /&gt;
Like S3M, volume range is 0-64, as is special magnitude. However, special effects range from 0-255, like PSM New Format.&lt;br /&gt;
&lt;br /&gt;
=== Effects conversion ===&lt;br /&gt;
&lt;br /&gt;
 ###  Co  MOD  Description               Arguments&lt;br /&gt;
 ---  --  ---  -----------               ---------&lt;br /&gt;
 Volume Commands&lt;br /&gt;
   1  A1   EA  Fine Volume Slide Up      B xx xx=speed&lt;br /&gt;
   2  A2   A   Volume Slide Up           B xx xx=speed&lt;br /&gt;
   3  A3   EB  Fine Volume Slide Down    B xx xx=speed&lt;br /&gt;
   4  A4   A   Volume Slide Down         B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Portamento Commands&lt;br /&gt;
  10  B0   E1  Fine Porta Up             B xx xx=speed&lt;br /&gt;
  11  B1   1   Portamento Up             B xx xx=speed&lt;br /&gt;
  12  B2   E2  Fine Porta Down           B xx xx=speed&lt;br /&gt;
  13  B3   2   Portamento Down           B xx xx=speed&lt;br /&gt;
  14  B4   3   Tone Portamento           B xx xx=speed&lt;br /&gt;
  15  B5   E3  Set Glissando Control     B xx xx=0 - Off, 1 - On&lt;br /&gt;
  16  B6   5   Tone Port+Vol Slide Up    B xx xx=speed&lt;br /&gt;
  17  B7   5   Tone Port+Vol Slide Down  B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Vibrato Commands&lt;br /&gt;
  20  C0   4   Vibrato                   B xy x=speed, y=depth&lt;br /&gt;
  21  C1   E4  Set Vibrato Waveform      B x  x=Waveform&lt;br /&gt;
  21  C2   6   Vibrato+Vol Slide Up      B xx xx=speed&lt;br /&gt;
  22  C3   6   Vibrato+Vol Slide Down    B xx xx=speed&lt;br /&gt;
 &lt;br /&gt;
 Tremolo Commands&lt;br /&gt;
  30  D0   7   Tremolo                   B xy x=speed, y=depth&lt;br /&gt;
  31  D1   E7  Set Tremolo Control       B x  x=Waveform&lt;br /&gt;
 &lt;br /&gt;
 Sample Commands&lt;br /&gt;
  40  E0   9   Sample Offset             3B Position for offset change (0-1,048,575)&lt;br /&gt;
  41  E1   E9  Retrig Note               B xx xx=tick to retrigger sample&lt;br /&gt;
  42  E2   EC  Note Cut                  B xx xx=tick to cut note&lt;br /&gt;
  43  E3   ED  Note Delay                B xx xx=ticks to delay note&lt;br /&gt;
 &lt;br /&gt;
 Pos. Change Commands&lt;br /&gt;
  50  F0   B   Position Jump             B xx xx=order position&lt;br /&gt;
  51  F1   D   Pattern Break             B xx Skip to line xx in next pattern&lt;br /&gt;
  52  F2   E6  Jump Loop                 B xx xx=number of loops  0 Set&lt;br /&gt;
  53  F3   EE  Pattern Delay             B xx xx=notes to delay pattern&lt;br /&gt;
 &lt;br /&gt;
 Speed Change Cmds&lt;br /&gt;
  60  G0   F   Set Regular Speed         B xx xx=speed&lt;br /&gt;
  61  G1   F   Set BPM                   B xx xx=BPM (32-255)&lt;br /&gt;
 &lt;br /&gt;
 Misc. Commands&lt;br /&gt;
  70  H0   0   Arpeggio                  B xy x=semitone #1, y=semitone #2&lt;br /&gt;
  71  H1   E5  Set Finetune              B xx xx=finetune&lt;br /&gt;
  72  H2       Set Balance               B xx xx=Balance (0-15)&lt;br /&gt;
&lt;br /&gt;
== Samples ==&lt;br /&gt;
&lt;br /&gt;
 Sample segment&lt;br /&gt;
 0    4   ID     &#039;PSAM&#039; (Psm SAMple)&lt;br /&gt;
 4    ?  Data    Sample data&lt;br /&gt;
&lt;br /&gt;
 Sample header segment&lt;br /&gt;
 0    4   ID     &#039;PSAH&#039; (Psm SAmple Header)&lt;br /&gt;
 4    ?  Data    Sample headers&lt;br /&gt;
&lt;br /&gt;
 Sample header&lt;br /&gt;
 0    13  Name   Sample filename, terminated with a null.&lt;br /&gt;
 13   24  Desc   Sample description or comments.&lt;br /&gt;
 37   4   Offs   Location of raw sample data in file&lt;br /&gt;
 43   4   Mem    This is the physical offset in RAM/DRAM of the sample. (Often blank.)&lt;br /&gt;
 45   2   Num    Sample number, 1-255&lt;br /&gt;
 47   1   Type   Sample type: (In some games left blank; if this is the case then the&lt;br /&gt;
                 sample format is END, as used in most PSM New Format files)&lt;br /&gt;
                 Bit 0: 0 - Digital, 1 - Synthesized&lt;br /&gt;
                 Bit 2: 0 - 8-bit, 1 - 16-bit&lt;br /&gt;
                 Bit 3: 0 - Signed, 1 - Unsigned&lt;br /&gt;
                 Bit 4: 0 - Deltas, 1 - Raw&lt;br /&gt;
                 Bit 5: 0 - Loop normally, 1 - Bidirectional&lt;br /&gt;
                 Bit 6: 1 - Gravis patch (unsupported)&lt;br /&gt;
                 Bit 7: 0 - No loop, 1 - Loop sample&lt;br /&gt;
 48   4   Len    Sample length, in bytes.&lt;br /&gt;
 52   4   Rep st Sample repeat start; if sample loops, the loop starts here.&lt;br /&gt;
 56   4   Rep fn Sample repeat end, if sample loops, it ends here. If this is less than the sample&lt;br /&gt;
                 repeat start, the sample loops backwards.&lt;br /&gt;
 60   1   Tune   Fine tune; range 0-15, Tune 0-7 = 0-7; tune -1 - -8 = 8-15&lt;br /&gt;
 61   1   Vol    Sample volume, 0-64&lt;br /&gt;
 62   2   Freq   This is the frequency for the sample at a C of Octave 2.&lt;br /&gt;
                 Typical values are 8,000 hz to 8,448 hz.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like S3M, sample headers are stored separately from the raw sample data. Unlike S3M, the number of sample headers doesn&#039;t have to be 31, but rather is the number of samples in the header. Sample headers are usually stored at then end of the file, after the raw sample data.&lt;br /&gt;
&lt;br /&gt;
A type of sample compression used often, like in the PSM New Format is &#039;Deltas&#039;, which converts a string of bytes into another by storing the DIFFERENCE between a byte and the previous byte. Thus:&lt;br /&gt;
&lt;br /&gt;
 RAW:        64  66  67  68  69  70  71  73  75  77  76&lt;br /&gt;
 DELTAS: 11  64   2   1   1   1   1   1   2   2   2  -1&lt;br /&gt;
&lt;br /&gt;
This is done to make files more compressible, but doesn&#039;t seem to be used much.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Utilities =&lt;br /&gt;
&lt;br /&gt;
It is unknown which of the three PSM formats the following utilities support, unless stated otherwise.&lt;br /&gt;
&lt;br /&gt;
* Download [http://www.shikadi.net/files/psm2scrm.zip psm2scrm.zip] - DOS program to convert .PSM songs into ScreamTracker .S3M format, suitable for playing in your favourite tracker/module player. Works only with PSM New Format and is not nearly as accurate as OpenMPT.&lt;br /&gt;
* [http://www.modplug.com ModPlug Tracker] and OpenMPT 1.17 can play the files and save them as S3M. More complex songs don&#039;t load correctly though. Works only with new format.&lt;br /&gt;
* [http://openmpt.org OpenMPT] 1.18 and newer can load all PSM and PSM16 files.&lt;br /&gt;
* [http://kode54.foobar2000.org/ foo_dumb] is a plugin for various module formats for the Foobar2k media player. It supports both PSM16 and PSM and is similar to OpenMPT in playback quality.&lt;br /&gt;
* [http://ftp.lanet.lv/ftp/mirror/x2ftp/msdos/programming/mxinfo/epictest.zip EPICTEST] is a demonstration of the Epic Megagames MASI. It contains CONVERT.EXE which can be used to convert modules to the PSM format.&lt;br /&gt;
* [http://www.jazz2online.com/J2Ov2/downloads/info.php?levelID=5471#29435] JJ1MOD can convert S3M files to PSM, though often with errors (Though these are usually only detectable with older programs such as game executables.) It is currently the only utility able to do this, and works only with New Format.&lt;br /&gt;
&lt;br /&gt;
= Notes =&lt;br /&gt;
&lt;br /&gt;
The New PSM format was reverse engineered by Levellord and tidied up by Levellass. It is possible there may be minor errors in the sample format information, especially since this is poorly documented.&lt;br /&gt;
Some format definitions have been updated and corrected by Johannes Schultz of the OpenMPT development team.&lt;br /&gt;
&lt;br /&gt;
The Silverball PSM format was reverse engineered by Wotsit and written up by Levellass. More info is needed.&lt;br /&gt;
&lt;br /&gt;
The Old PSM format was obtained from [http://www.silent-dreams.de/handbook.html#ProTracker%20song&amp;amp;module%20format ProTracker song &amp;amp; module format] &lt;br /&gt;
&lt;br /&gt;
In all formats the following table shows how note bytes are converted into actual notes: (PSM new format has the widest range, 0-255)&lt;br /&gt;
&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;br /&gt;
           | C-0   0 | C-1  12 | C-2  24 | C-3  36 | C-4  48 |&lt;br /&gt;
           | C#0   1 | C#1  13 | C#2  25 | C#3  37 | C#4  49 |&lt;br /&gt;
           | D-0   2 | D-1  14 | D-2  26 | D-3  38 | D-4  50 |&lt;br /&gt;
           | D#0   3 | D#1  15 | D#2  27 | D#3  39 | D#4  51 |&lt;br /&gt;
           | E-0   4 | E-1  16 | E-2  28 | E-3  40 | E-4  52 |&lt;br /&gt;
           | F-0   5 | F-1  17 | F-2  29 | F-3  41 | F-4  53 |&lt;br /&gt;
           | F#0   6 | F#1  18 | F#2  30 | F#3  42 | F#4  54 |&lt;br /&gt;
           | G-0   7 | G-1  19 | G-2  31 | G-3  43 | G-4  55 |&lt;br /&gt;
           | G#0   8 | G#1  20 | G#2  32 | G#3  44 | G#4  56 |&lt;br /&gt;
           | A-0   9 | A-1  21 | A-2  33 | A-3  45 | A-4  57 |&lt;br /&gt;
           | A#0  10 | A#1  22 | A#2  34 | A#3  46 | A#4  58 |&lt;br /&gt;
           | B-0  11 | B-1  23 | B-2  35 | B-3  47 | B-4  59 |&lt;br /&gt;
           +---------+---------+---------+---------+---------+&lt;br /&gt;
&lt;br /&gt;
It should be noted that all PSM formats are severely limited compared to other module formats, most applications limited them to four channels, the note range is limited and the range of effects is severely curtailed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Music Files]]&lt;br /&gt;
[[Category:Jazz Jackrabbit]]&lt;br /&gt;
[[Category:File Formats]]&lt;/div&gt;</summary>
		<author><name>Saga</name></author>
	</entry>
</feed>