FM Synthesis information

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
FM Synthesis information
by on (#1768)
I've been interested in writing emulation code for the VRC7 sound circuitry, and I'm running into a major roadblock: I can't make head or tail of *any* of Yamaha's FM chip documentation.

I have successfully written emulation code for various programmable sound generators including the 2A03 sound subsystem, the GameBoy sound subsystem, and the SN76496. All of these (as well as various other early sound chips like the AY-3-8910 and Pokey) seem to function in a roughly similar manner: the system clock is used to count down (or up) a programmable timer, and when the timer underflows (or overflows), it then clocks a logic circuit like a duty cycle generator or XOR-feedback register that creates the sound waveforms. Of course, some chips like the 2A03 incorporate additional timers that can be used to automatically update certain sound parameters at certain times, but the basic principle is similar for all of these chips. (I'd like to thank Matt Conte for assisting me with the basic principles of digital sound synthesis. Brad Taylor's documentation and Kevin Horton's technical know-how was also most helpful in obtaining a basic understanding of these circuits.)

The Yamaha YM-series FM chips *seem* wildly different. I'm not convinced they truly are. According to Vortexion's sound page: "The chips all operate in the digital domain, using adders, multipliers and look-up tables to achieve the sine wave modulation." So it seems plausible to me that the YM-series chips may simply be more complicated PSGs with more and more varied waveforms, wavetable ROMs, and timers than the old ones.

Unfortunately, the datasheets on these chips are completely incomprehensible to me. They're filled with terms both technical and musical that might as well be Greek to me. Very little documentation is provided as to what these terms mean; the sheets seem to be geared towards someone with a double major in music and advanced calculus. Nth-order Bessel functions? Detune? Key on/off? I don't know what any of this means. Has anyone written a simple explanation of how any of these chips *actually work* on a low hardware level? Something similar to Brad Taylor's NES 2A03 documentation or Kevin Horton's VRCVI info. Can anyone provide me with any help on this subject? I'm completely lost.

- Josh

by on (#1771)
The basic method behind FM synthesis is y = A sin(2πcft + I sin(2πmft)) where, for a musical sound, f controls the fundamental frequency, c and m are small integers that determine the character of the sound, A controls the amplitude, and I controls the intensity of modulation. As for the terms:
  • "Detune" means two oscillators are placed out of small integer ratios. I'd guess that in the context of the YM chips, it means setting c an m to an irrational ratio to produce a non-harmonic result, imparting a metallic or percussive character to the tone.
  • "Key on" and "key off" respectively mean starting and stopping a note.
  • "Bessel functions" are just a way to predict the output bandwidth of an FM signal. The chip doesn't actually use them.
Wikipedia may help more.

by on (#2179)
Yamaha's FM chips use phase accumulating oscillators, similar to the Commodore SID chip. This is why they specify frequency in the registers rather than period. (as with divide by n counters)

Some of them use an exponential lookup table to convert between musical intervals ("cents") and actual frequencies; however the cheaper ones such as the YM2413 use direct frequency settings in the registers. There's a mantissa (9 bit in YM2413) and an exponent (3 bit in YM2413) which can be converted into a 16 bit value by multiplying the mantissa by 2^exponent.

YM2413 outputs a new sample for each channel every 72 cycles, so the sample rate for a 3.58MHz clock is 3.58MHz/72.

Each 'operator' consists of an oscillator and a combined envelope generator/amplifier. Both are implemented digitally; the oscillators work by stepping through a sine wave lookup table at a rate determined by the frequency setting (see articles on phase-accumulating oscillators) and the envelope generators/amplifiers work by multiplying the output of the lookup table by an amplitude setting, which is incremented and decremented over time according to attack, decay and release rates.

'FM' synthesis (actually phase modulation in this case) is achieved by adding the output of one operator (i.e. one oscillator and envelope generator combination) to the phase accumulating oscillator of another operator. This means that the rate at which the second phase accumulating oscillator steps through the sine wave lookup table is modified by the output of another sine wave oscillator.