• Welcome to Touhou Wiki!
  • Registering is temporarily disabled. Check in our Discord server to request an account and for assistance of any kind.

Technical Information/BGM

From Touhou Wiki
Jump to navigation Jump to search

Windows games

All main Windows Touhou games by Team Shanghai Alice store their music as lossless, raw PCM data, as used in wave files. This is the sole reason these games take up comparatively much space when compared to their content, as the BGM often accounts for up to 90% of a game's size.

However, this allows for very easy access of the BGM data, since it can just be directly streamed from the drive to any audio engine, without any decoding.

As for the fighting games, Twilight Frontier was using wave files in Immaterial and Missing Power, but switched to Ogg Vorbis after that.

Position data

All Touhou BGMs, aside from a few special cases, are meant to loop infinitely. Since looping instructions are not part of the WAVE format spec, everyone stores them in a different way. The instructions themselves are simply positions in the wave data marking the beginning and end of a loop (or, beginning and length).

Here's a brief description of how each game stores its loop data:

TH06, Kioh Gyoku

  • wave files in bgm/*.wav
  • loops in 紅魔郷MD.dat/*.pos
    <start sample>.4b <end sample>.4b

TH07 and above (Team Shanghai Alice games)


  • wave files and loop data in th075bgm.dat/*.wav (Brightmoon archive)
  • loop data is saved with special RIFF chunks at the end of each wave file
    • Format: <RIFF header>.40b <wave data size>.4b <wave data>.<wave data size>b <junk>.16b <start sample>.4b <junk>.40b <loop section length>.4b

TH10.5 and above (Twilight Frontier games)

  • ogg files in th<xxx>b.dat/*.ogg, loops in th<xxx>b.dat/*.sfl; loops are stored inside Soundforge metadata, some tracks don't have loops
    • Format: <junk>.28b <start sample>.4b <junk>.40b <length in samples>.4b

All wave files are 44100 Hz 16 bit stereo, except the alternate spirit world themes in Ten Desires, which are 22050 Hz. When dealing with sample-based loop data (th06/Twilight Frontier games), multiply the sample values by 4 and, in case of IaMP, add the size of the wave header (0x2C = 44 bytes) when calculating byte offsets.

MIDI loops

For the MIDI files of TH06-TH08 (and the TH09 demo), the looping rules are specified with MIDI controller events inside the MIDI files. #cc02 (Breath Controller in the MIDI standard) defines the start, and #cc04 (Foot Controller in the MIDI standard) defines the end of the looping section.