Gods Sample Music Format

From ModdingWiki
Jump to navigation Jump to search
Gods Sample Music Format
Format typeSound
HardwarePCM
Number of sounds11
Sampling rateN/A
Channel count1
Bits per sample8
Compressed?Yes
Tags?None
Games

When Gods is configured for a Sound Blaster, the intro plays digitised title music from PDEMOSB4.SB (together with FM music from PGODMUS2.MUS, see Gods Music Format). The file is compressed with PKWARE DCL Compression and is 227502 bytes when decompressed.

The file is not a single recording. It holds eleven sampled sounds plus a short script that plays them as a tune, much like a simple tracker module. It is played by PPLAYER.BIN, and the playback rates are stored in that file, not in PDEMOSB4.SB.

File format

All values are little-endian.

Header

Data type Name Description
UINT8 seqCount Number of sequences (1)
UINT8 padding
UINT16LE sampleTableOffset Offset of the sample table (0x1DC)
SEQUENCE[seqCount] sequences See below

Each SEQUENCE is 4 bytes:

Data type Name Description
UINT16LE scriptOffset Offset of the sequence's script
UINT8 startFM 0xFF = also start the FM music
INT8 pitchBias Pitch adjustment for all notes (-4 in the shipped file)

Sample table

Eleven entries of 6 bytes:

Data type Name Description
UINT16LE offset Offset within the paragraph below
UINT16LE paragraph Sample starts at file offset paragraph * 16 + offset
UINT16LE length Length in bytes

The samples are 8-bit unsigned mono PCM. The header, script and table take the first 0x21E bytes; the samples fill the rest of the file.

Script

The script is a list of one-byte commands, some followed by one argument byte:

Command Argument Meaning
00 n Set repeat count R
01 – Rest for one step
02 n Set step length S
03 – Jump to the start of the current sequence
04 n Call sequence n
05 – Return; at the top level, stop
07 n Select sample n
20-FF – Play the selected sample at pitch command - 0x20

A step lasts (S + 1) * (R + 1) ticks, at 50 ticks per second. Starting a new note stops the previous one, so samples never overlap.

The playback rate in Hz is the UINT16LE at byte offset 0x2992 + (command - 0x20) in the decompressed PPLAYER.BIN. (The offset is in bytes, not words, so neighbouring entries overlap.) The rate is then multiplied by (256 + pitchBias) / 256. For example the first note plays at 10548 × 252 / 256 = 10383 Hz.

The shipped script plays 64 notes over 153.6 seconds.

Source code

From re-gods, the open-source HTML5 port:

Credits

This file format was reverse engineered by VorticonCmdr. If you find this information helpful in a project you're working on, please give credit where credit is due. (A link back to this wiki would be nice too!)