View on GitHub

smf-to-ym2151log-rust

smf-to-ym2151log-rust

YM2151 Tone Definitions

This directory contains tone/voice definitions for the YM2151 FM synthesizer chip.

File Naming Convention

Tone files should be named according to the MIDI program number they represent:

JSON Format

Each tone file contains a JSON object with an events array. Each event represents a YM2151 register write:

{
  "events": [
    {
      "time": 0,
      "addr": "0x20",
      "data": "0xC7"
    },
    ...
  ]
}

Event Fields

Register Addressing for Channel 0

Tone definitions should be written as if configuring channel 0. The converter will automatically adjust the addresses for other channels.

Channel-Specific Registers (0x20-0x3F)

Operator-Specific Registers (0x40-0xFF)

Operators are numbered 0-3, with slots calculated as channel + (operator * 8).

For channel 0:

Common operator registers:

Example: Operator 0, Channel 0

{
  "time": 0,
  "addr": "0x40",  // DT1/MUL for operator 0, channel 0
  "data": "0x01"
}

When this tone is applied to channel 3, the converter automatically adjusts it to:

{
  "time": <current_time>,
  "addr": "0x43",  // DT1/MUL for operator 0, channel 3
  "data": "0x01"
}

Registers NOT to Include

Do not include the following in tone definitions, as they are set dynamically during playback:

Usage

When a MIDI file contains a Program Change event (e.g., Program Change to 42), the converter will:

  1. Look for tones/042.json in the current directory
  2. If found, load and apply the tone to the channel
  3. If not found, use the built-in default tone

Creating Custom Tones

To create a custom tone:

  1. Use the example 000.json as a template
  2. Modify register values according to the YM2151 datasheet
  3. Save as {program:03}.json (e.g., 042.json for program 42)
  4. Test with a MIDI file that uses the corresponding program number

Built-in Default Tone

If a tone file is not found, the converter uses a simple built-in tone with: