hello_ymfm_wasm

What is FM Tone Generation?

Before going deeper into YM2612 details, these Yamaha pages are a good starting point for the general idea of FM tone generation.

About YM2612

The YM2612 is a sound chip developed by Yamaha. It was used in Sega’s Mega Drive / Genesis video game console.

This chip has:

YM2612 Chip Information

http://www.chipdir.nl/pinusr/ym2612.txt


    +--()--+
GND | 1  24| 0M(CLK)
 D0 | 2  23| Vcc
 D1 | 3  22| A.Vcc
 D2 | 4  21| MOL
 D3 | 5  20| MOR
 D4 | 6  19| A.GND
 D5 | 7  18| A1
 D6 | 8  17| A0
 D7 | 9  16| /RD
  ? |10  15| /WR
/IC |11  14| /CS
GND |12  13| /IRQ
    +------+

Pin summary

FM sound design

Before going deeper into PCM / DAC, it is helpful to first look at how YM2612 makes FM tones.

The main idea is:

You can try these interactive pages first:

FM sound chip control

A0 and A1 choose which control port is being accessed. They switch between address/data access and port 0/port 1 access.

How chip.write() maps to YM2612 pins

void ym2612::write(uint32_t offset, uint8_t data) is a simplified interface.

The mapping is:

Example:

chip.write(0, 0x30);
chip.write(1, 0x01);

This means:

  1. Select register 0x30 on address port 0.
  2. Write 0x01 to that register on data port 0.

In other words, software is not changing the sound by magic. It is sending YM2612-specific control values through these chip pins and writing them into YM2612 registers.

PCM / DAC on YM2612

The YM2612 is mainly known as a 6-channel FM chip, but it also has a simple DAC playback path.

When DAC playback is enabled, channel 6 can be used for PCM-style sample playback instead of normal FM output.

This is not a separate large PCM engine like later chips. It is a simpler DAC path where software keeps writing sample bytes to the chip.

In practice, this is important for:

In this repository, the current PCM-related browser support is mainly handled through the VGM playback path. That path reads VGM DAC/stream commands and forwards the sample bytes to YM2612 DAC register writes.

Questions

Q: Why are there two types of ground, GND and A.GND?

A: The chip has both digital and analog sections. The analog section is used for audio output, so A.Vcc and A.GND are used for the audio output circuitry behind MOL and MOR.

Q: Why do we need /CS?

A: /CS tells the YM2612 that the current bus access is for this chip. Without it, multiple chips on the same bus could respond at the same time.

Q: Why do we need /IRQ?

A: /IRQ is mainly used to notify the CPU when an internal timer event occurs.

Q: Why do we need /RD and /WR?

A: /RD and /WR are control signals, not data lines. The actual data is carried on D0-D7.

Q: What are D0-D7 for?

A: D0-D7 are 8-bit data pins. They carry digital data between the CPU and the YM2612.

Q: What is /IC for?

A: /IC is the reset signal. It initializes the chip and clears its registers.

References