O4S - The Opl4 Stream

Introduction

Above: Go Figure intro. Use openMSX on a track to see how busy the chip is.
This article explains how the Go Figure game is able to replay OPL4 music extremely effectively on the Z80 and the MSX platform. 

It started out as a PoC (and still is as the python code painfully reflects) where I wanted to see how far I could push the optimizations. All the tracks in Go Figure spend less than 5000 Z80 (MSX) cycles per frame (ignoring the setup frame, frame 0, which is a special case).

The game uses 9 FM channels from the first FM-unit, 9 FM channels from the second FM unit, and 24 channels from the WAVE unit (ie. all channels as described in the manual).

Go Figure uses the awesome MoonSound Studio beta, MS2 (subscription here), for music creation, but any OPL4 composing software can be used.

The method is based on recording the raw YMF278B commands sent to the chip at one point, which in turn is re-sent to the chip in the game at runtime.

We use the VGM-format as an intermediate format. It exports both the streaming data and the wave-samples, "sample kit". 

The pipeline

  • Compose music using MS2
  • In openMSX, record audio as vgm-format.
  • A custom python tool outputs an o4s stream file and the sample kit.
  • Include the stream and the sample kit in the game binary.

Core components in this solution

Handcraft and file sizes

When it comes to minimizing the size of the sample kit, quite a lot can be done by the composer by hand.

A skilled composer can also help the out on the replay framerate by avoiding placing large amounts of effects on one single line in the tracker. This would be of help to any replayer, so this topic not discussed futher here.

Any drawbacks using a raw data method

  • The most obvious is file size. Sample kit size aside, a music clip of around 1.5 minute in Go Figure ends up between 35 kB and 86 kB.
  • You might encounter complexities tied to looping if you want to implement this (which is not covered here).
  • Dynamic channel specific volume control is hard to do. The data has a certain volume baked in. The only efficient way to adjust volume is by using the mix control registers (wave registers F8 and F9) which are global and affects all channels at once. Nice for global fades though.

Example music clip

I reckon we can use an OPL4 music file that is public already for this. Thinking in regress by legendary Italian scene composer dandan is using both FM and WAVE. Here recorded as a vgm-file.
  • regress MFM file length: 12262 bytes.
  • regress MWK sample kit file length: 2315 bytes.
  • vgm file - length: 1274651 bytes (includes a large 640kB sample kit).
  • O4S file - length: 110778 bytes.
  • O4S peak: 2430 cycles measured with profiler.


O4S - Introduction  |  O4S - The format  |  O4S - The replayer  |  O4S - The encoder

Comments