Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:Standard MIDI File

From ReverseEngineering.wiki
Format
Magic MThd at 0 (RIFF....RMID wrapper for .rmi)
Extensions .mid, .midi, .rmi, .kar
Endianness big
On this wiki Facts · Code · Notes · Topics

The Standard MIDI File (.mid, .midi, .rmi): a chunk file with an MThd header (format 0, 1 or 2, track count, time division) followed by MTrk track chunks of delta-time-prefixed MIDI and meta events; also stored inside a RIFF RMID wrapper. Used for music in DOS, Windows and console games, and the target of converters from Format:Doom MUS and Format:XMIDI.

Overview

A Standard MIDI File is a sequence of chunks: a 4-character type and a 32-bit big-endian length. The first chunk is MThd; the rest are MTrk (other chunk types must be skipped). Many games ship plain SMFs (as .mid files or as lumps inside archives) and play them through the Windows MIDI mapper, a General MIDI or MT-32 device, or a software synthesizer. Others convert from a private format at load time (Format:Doom MUS, Format:XMIDI).

Header chunk

See Fact:Standard MIDI File/struct/MThd header chunk: length 6, format 0/1/2, number of track chunks, division. A division with bit 15 clear is ticks per quarter note (PPQN); with bit 15 set it is SMPTE (frames per second as a negative byte, then ticks per frame). Unverified: the SMPTE branch is from the specification; ScummVM's parser only reads the value as PPQN.

Track events

See Fact:Standard MIDI File/behavior/Track event stream: each event is a variable-length delta time, then a status byte (or running status), then data. Meta events start with 0xFF, a type byte, a variable-length length and data; 0xFF 0x2F 0x00 ends the track and 0xFF 0x51 with three data bytes sets the tempo in microseconds per quarter note (default 500000 = 120 BPM).

RIFF RMID wrapper

.rmi files are RIFF "RMID" containing a "data" chunk whose payload is a complete SMF (Unverified: general knowledge of the RIFF-MIDI layout, so the SMF starts 20 bytes in). ScummVM's loader accepts a leading "RIFF" by skipping 8 bytes and expecting MThd directly (midiparser_smf.cpp lines 133-141), which handles only RIFF wrappers laid out that way.

Formats 0, 1, 2

Format 0 = one track; format 1 = several simultaneous tracks sharing one timeline (track 0 usually holds tempo); format 2 = independent single-track sequences. ScummVM treats format 1 as one track with several subtracks and rejects a type above 2 (lines 143-152, 170-195).

Code & repositories

ScummVM (GPL-3.0-or-later) audio/midiparser_smf.cpp; the chocolate-doom mus2mid.c writes a format-0 SMF with division 0x46 (70).

  • https://github.com/scummvm/scummvm @ 3f4203f8833f12615b0df5fa27f19d3c30d3e5d8 · license: GPL-3.0-or-later (declared by the contributor; GitHub's detector did not recognize COPYING)
    ScummVM: audio/midiparser_smf.cpp, audio/midiparser_xmidi.cpp and audio/decoders/voc.cpp parse SMF, XMIDI and Creative VOC data of many DOS and Amiga adventure games.
    Tested on: source read, not run: read only, source files at the pinned commit · checked 2026-10-19
  • https://github.com/chocolate-doom/chocolate-doom @ e6f632a4397023b6b17cc312525a16b2aacd64d6 · license: GPL-2.0-or-later (declared by the contributor; GitHub's detector did not recognize a license file)
    Chocolate Doom: src/mus2mid.c converts Doom MUS lumps to a type-0 Standard MIDI File.
    Tested on: source read, not run: read only, mus2mid.c at the pinned commit · checked 2026-10-19