Hi; in the spirit of some the other excellent primers on various old-chip topics that I've seen posted here recently I thought I would try to provide an introduction FM synthesis in the Yamaha sense, in case anybody else is eyeing up the topic for the first time.
I am very strongly indebted to the following resources in my comprehension of this topic (though any errors below are almost certainly my own):
If you're looking to make life easy for yourself, the latter offers reference cycle-perfect implementations of both the OPLL and OPN2, amongst others, via GitHub. I have not read them because they are GPL licensed and I'm working on an MIT-licensed emulator, so there's a whole can of worms there that I'd rather avoid, not wanting to rip anyone off.
This article discusses in broad strokes the sort of sound generation used by Yamaha in its various OPx chips — primarily based the OPL line that was in the AdLib, the MSX, the Master System and elsewhere, but the same principles apply to the OPN line that was in the Mega Drive and Neo Geo, the OPM from various arcade games and Japanese home computers, and others.
The most basic elements of an OPL FM synthesiser are:
The OPL chips calculate output in terms of attenuation, which is a logarithmic scale. They treat all attenuation numbers as implicitly negative, and use base 2 for logarithms.
So an attenuation of 0 means maximum output because 20 = 1.
An attenuation of 1 means half as much output as level 0 because 2-1 = 0.5.
An attenation of 2 means half as much output as level 1 and a quarter as much as level 0 because 2-2 = 0.25.
This means that:
The overview version of envelope generators is that the programmer provides:
All channels have a 'key on' input. Taking only the simplest case: when a channel is off, it will be resting at the maximum available attenuation. When it recieves a 'key on', it will ramp attenuation down from there according to the attack rate. When it gets to attenuation 0 it will apply the decay rate to move away from 0 until it hits the sutain level.
If the generator is supposed to hold the sustain level, it will stay at the sustain level until 'key on' is next disabled. At that point it will ramp up attenuation according to the release rate until it once again reaches the maximum.
If the generator is not supposed to hold the sustain level, it'll switch straight from decay to release.
There are various types of waveform available, increasing as you get to later OPL chips, but the original big hitter is the sine wave.
The programmer provides to the phase generator two paramaters: a block number, or octave, and what Yamaha calls the 'f-number', which is the wave's period. The two parts act essentially as if they were a single floating point number — at each tick the period is added to the current phase, after being scaled by 2octave. From a musician's point of view, the period is always the same for a particular note, and the octave is then selected separately.
Phase itself is essentially a sawtooth function. On the original OPL that is always used as an input to generate a sine wave. From the OPL2 onwards other waves are also available, specifically a half sine (i.e. the positive part only, silence for the second half of the period), rectified sine (the positive part repeated twice per cycle) or quarter sine (just the first ramp from 0 to 1, repeated twice, providing harmonics a lot like a sawtooth). The OPL3 goes even further, adding some extra sine options plus a square wave and a logarithmic sawtooth.
An operator is, primarily, just a phase generator plus an envelope generator. They also may apply an additional attenuation and possibly other tweaks as discussed below. Were the output of an OPL to be directly sourced from operators, it would primarily be simple sine-like harmonics.
In addition to per-operator phase there is a global low-frequency oscillator that provides both tremolo and vibrato. If an operator is opted in for either, it will take the relevant value and use it to modify either the period in the phase generator or the total output attenuation over time.
On an OPL1 or 2 each channel consists of two operators. On an OPL3 it may also consist of four. In either case the basic FM synthesis operation is the same:
The output of one operator is used to modulate the current phase of another. The former is known as the modulator, the latter as the carrier.
In two-operator frequency modulation mode, the output of the carrier, after modulation, is the audio output. That's all there is to it, you just FM synthesised!
In four-operator mode there are some more complicated options involving routing outputs between operators.
As an aside: modulating phase is mathematically very closely related to modifying frequency. So 'frequency modulation' isn't technically a misnomer even though it's phase, not frequency, that is modulated.
FM synthesis does a great job relative to its hardware requirements at reproducing melodic instruments but isn't especially useful for harsh percussion noises like drums. Yamaha provides separate drum noises for this purpose. The programmer has to forfeit three channels of regular FM synthesis, freeing up six operators for five rhythm instruments.
A global random level generator is implemented for this mode; it's a standard LFSR just like the noise generator on simple chips like the AY-3-8910 or SN76489, so it provides a one-bit semi-random output.
The OPL can then generate:
The programmer has some input as to pitch because the operators are those that are otherwise used for melodic output, but the drums have fixed-setting envelope generators.
For solid detail on the sine and exponential tables the real hardware uses, see this decapulation by Matthew Gambrell and Olli Niemitalo. Olli's blog entry on the same topic also contains a lot of interesting material in its comments, and carbon14's forum posts on OPL3 investigation are also very helpful.