The YM2612
The Yamaha YM2612 (OPN2) is a six-channel FM synthesiser: each channel has four operators (sine oscillators with envelopes) combined in one of eight algorithms. Channels 1 to 3 are written
through port 0 (the 01 command) and channels 4 to 6 through port 1 (the 02 command); each write sets register rr to value vv. The registers are:
| Registers | Port | What they set |
|---|---|---|
| 22 | 0 | LFO enable and rate |
| 24 to 27 | 0 | The timers and the channel 3 mode |
| 28 | 0 | Key on and off, for all six channels |
| 2A | 0 | The DAC sample (see below) |
| 2B | 0 | Bit 7 turns the DAC on: channel 6 then plays the sample and not FM |
| 30 to 3F | both | Detune and multiple of each operator |
| 40 to 4F | both | Total level (volume) of each operator |
| 50 to 5F, 60 to 6F, 70 to 7F, 80 to 8F, 90 to 9F | both | Envelope: attack rate and rate scaling, decay rate and LFO, sustain rate, sustain level and release rate, SSG-EG |
| A0 to AF | both | The pitch of each channel: frequency number and block (octave) |
| B0 to BF | both | Algorithm and feedback; output to left, right or both, and the LFO depth |
The Commands tab describes every write in words (“Reg 0x28 …”), with the register meanings that the VGM viewer uses.
The SN76489
The Texas Instruments SN76489 (the Mega Drive’s PSG is inside the video chip) has three square-wave tone channels and one noise channel, each with a 4-bit attenuation. The 03 command writes one byte: a byte with bit 7 set latches a register (tone 0, 1 or 2 frequency, noise control, or the attenuation of one of the four channels) and gives its low four bits; a byte with bit 7 clear gives the high six bits of the frequency latched. The tone frequency is the clock divided by 32 times the 10-bit number.
Clocks
Both chips run from the console’s master clock: 53,693,175 Hz on NTSC and 53,203,424 Hz on PAL. The YM2612 gets one seventh of it and the PSG one fifteenth.
| Region | Frames | YM2612 | SN76489 |
|---|---|---|---|
| NTSC | 60 a second | 7,670,453 Hz | 3,579,545 Hz |
| PAL | 50 a second | 7,600,489 Hz | 3,546,895 Hz |
Gens and Game_Music_Emu take a master clock of 53,700,300 Hz (NTSC) for both; that is 0.013 % higher in pitch than the figure above.
How the explorer plays them
The explorer uses the YM2612 and SN76489 models of the VGM viewer without change (the YM2612 is the Gens model, with the clock above; the PSG is the libvgm one). For each frame it writes the commands of the frame to the models and renders 735 samples (NTSC) or 882 (PAL) at 44,100 Hz; the two chips are added into one stereo signal. The options bar can mute each chip as a whole.
Checked against Game_Music_Emu
Game_Music_Emu’s Gym_Emu (built here with its Gens YM2612 core) and the explorer play the same files. Measured on half a minute of real files and on built sample files, the pitch
agrees (the sample tones of 440 Hz come out as 440 and 439 Hz) and the levels (RMS) of the explorer relative to Game_Music_Emu are:
| Sound | Explorer ÷ Game_Music_Emu |
|---|---|
| FM (real files and a built tone) | 0.96 to 0.97 |
| PSG tone | 1.46 |
| DAC square wave | 0.69 |
The factors come from Game_Music_Emu’s source. In Gym_Emu.cpp the FM gain fm_gain is 3.0, the PSG volume is 0.135 × 3.0 = 0.405 and the DAC volume is 0.125 / 256 × 3.0 per step. Dual_Resampler::mix_samples adds the PSG and DAC (read from the band-limited buffer as accum >> 14, which is twice the volume as a fraction of 16-bit full scale) to the FM, which it doubles.
- PSG.
Sms_Apu::volumemultiplies by 0.85 / (4 oscillators × 64 × 2), and a full-volume square has an amplitude of ±64. One full-volume channel reaches 64 × 0.405 × 0.85 / 512 × 2 = 0.0861 of full scale. The explorer’s SN76489 (libvgm’s, volume table 0.25, halved) reaches 0.125. The ratio is 0.125 / 0.0861 = 1.45; measured, 1.46. - DAC. Game_Music_Emu gives each DAC step 3/1024 of full scale (0.125 / 256 × 3.0 × 2). The explorer’s YM2612 (libvgm’s DAC scale) gives 1/512 = 2/1024. The ratio is 2/3 = 0.667; measured, 0.69 (the band limiting of the buffer accounts for the rest).
- FM. Both use the Gens YM2612 core; the 0.96 comes from the output scale of the VGM viewer’s port against Game_Music_Emu’s resampler gain (3.0 × 0.5, doubled again in the mix) and is not derived to the last digit.
The explorer keeps the VGM viewer’s levels, which the VGM viewer shares with libvgm.
Divergence from the specification
- The chips’ register behaviour has no published “GYM” specification: the models are the chips’ own, as the VGM viewer has them (checked against libvgm there).
- The relative level of FM, PSG and DAC differs from Game_Music_Emu’s, as in the table above. Both are valid choices; a real console’s mix depends on the board and the analogue stage.
- The clocks are the console’s master clock divided; Gens and Game_Music_Emu use a master clock of 53,700,300 Hz.
Sources
- Game_Music_Emu,
gme/Gym_Emu.cppandYm2612_GENS.cpp: the clocks, the gains, the register writes as the player makes them. - Gens,
src/gens/util/sound/gym.c: the clocks the log is played at (CLOCK_NTSC / 7and/ 15). - The VGM viewer’s YM2612 and SN76489 models and register descriptions, and the sources they list there (the YM2612 data sheet, libvgm).