Friday, January 5, 2018

OPL2/3 Frequency - The 1Hz-ish Difference

The nature of FM Synthesis sound is based on sine waves.  Sine waves create sound by oscillating at a certain frequency and amplitude.  So a sine wave oscillating at a frequency of 440Hz (the pitch) would sound like an A note (A4) hit above the middle C (C4) on the 4th octave of a full 88-key keyboard.  But a sine wave in and of itself is not very interesting musically, so FM synthesis modulates two or more sine waves to create a much more complex sound.  The sine wave's frequency is programmed into the FM Synthesis chip and the modulation of the two frequency, combined with other methods to shape the waveform such as ASDR envelopes, make a sound more complex and realistic than the Programmable Sound Generators that were used in computer and video game music before FM Synthesis became popular in computer music.




The only widely supported PC compatible standard for FM Synthesis is based on the YM3812 OPL2 chip found in the original Adlib Music Synthesis Card.  This chip can support up to 18 sine waves oscillators  combined into 9 two-operator channels or 6 two-operator channels with 5 percussion instruments using the remaining oscillators.  (Two oscillators combine to form one operator.)  Each oscillator has its pitch frequency programmed independently through a pair of registers in the chip.  The frequency is derived from a 3-bit Block Number selecting the octave and a 10-bit Frequency Number selecting the frequency within the octave.  The standard eight octaves of an 88-key keyboard are available using this method.

The YM3812 works off a master frequency of 3.579MHz.  This frequency is fed into the chip.  This frequency is divided by 72 to obtain the base frequency of 49,716Hz.  The base frequency is used to determine the pitch frequency of the sine wave oscillators, as divided by the Block and Frequency Numbers.  The base frequency also functions as the sampling frequency, all output from the YM3812 is digital and sampled at 16-bits.

The pitch frequency of each oscillator is calculated by the following formula :

F-Num = Music Frequency (in Hz) * 2^(20-Block) /49716Hz

F-Num is the 10-bit Frequency Number and Block is the 3-bit Block Number.  In order to obtain a frequency of 440Hz, we need a Block Number of 4 and a Frequency Number of 580 (all values are in decimal for the formula, but you program the chip in hexadecimal).

Original Base and Sample Frequency Chips

YM2413 OPLL
YM3526 OPL
Y8950
YM3812 OPL2
YMF262 OPL3

The OPL, OPLL, OPL2 and Y8950 all use an input frequency of 3.579MHz and the OPL3 uses a 14.318MHz frequency input and divides it by 288.  (Arcade games may have used different frequencies).  The end result is that all of these chips use a pitch frequency and a sampling frequency of 49,716Hz.

CT-1747

CT-1747 is a slightly odd chip.  It was once believed that it was fed the 33.8688MHz signal from a board with an EMU8000, but the EMU has been determined to feed it a 14.318180MHz signal.  When output through analog outputs, the base frequency and the sampling frequency are the same.  Many of the 2nd generation Sound Blaster 16s use this chip solely in analog output mode and have 14.318MHz crystals on When output through digital outputs as on most of AWE32s, the sampling frequency is 44,100Hz.  This is achieved by dividing 33.8688MHz/768.

Modified Base and 44,100 Resampled Chips

YMF278 OPL4
YMF289 OPL3-L
YMF701 OPL-SA
YMF704 OPL4-ML
YMF711 OPL3-SA2
YMF715 OPL3-SA3
YMF718 OPL3-SA2C
YMF719 OPL3-SA3C
YMF721 OPL4-ML2
YMF741 OPL3-SA3L

All the above only use a 33.8688MHz signal for their timing.  These chips divide that signal by 684 to achieve a base frequency of 49,516Hz base frequency.  Their sampling frequency is 44,100Hz as with the digital output of a CT-1747.

Now here is where the 1Hz issue comes into play.  As shown above, a Frequency Number of 580 in an OPL2 or OPL3 will get you a 440Hz sine wave.  But with a 49,516 base frequency, the formula changes somewhat :

F-Num = Music Frequency (in Hz) * 2^(20-Block) /49516Hz or 580 = Music Frequency * 65536/49516 or 438.22Hz.  582 is a better value to use because it gets you 439.73Hz.

As a result of a change in the base frequency, all sine waves will be almost 2Hz off from what they were intended.  It should be noted that the YMF278 and YMF289 hail from 1993-1994, years in which we saw a decline in the use of OPL as the standard which defined PC-compatible computer game music.  Even the additional features of OPL3 over OPL2 were infrequently tapped.  While it is quite possible to distinguish a 440Hz sine wave from a 438.22Hz sine wave, it is much more difficult to distinguish the differences in Hz in typical FM Synthesis musical playback.  Essentially unless you have pitch-perfect hearing, you will probably never notice it unless you have some more information such as the identity of the chip which is playing back the music.

On some 3rd generation Sound Blaster 16s and most of the Sound Blaster 32s, you could have either a CT1978 CQM chip or a YMF289 chip.  (1st Gens have YMF262s, 2nd Gens have YMF262s or CT1747, 3rd Gens have YMF289 or discrete CT1978 and 4th Gens have integrated CT1978s).  It is not really known how they deal with the base frequency.  Some PCBs with a CT1978 chip have a 14.318MHz crystal and presumably those have a 49,176Hz frequency.  Those that do not usually have a 46,61512MHz crystal and must derive the clock in some way close to that frequency like the YMF289.

The OPL3-SAx series were essentially all-in-one chips that supported all the standard features of a sound card, including Sound Blaster Pro and Windows Sound System compatibility.  They require a 24,576MHz clock signal in addition to the 33.8688MHz signal but do not use it for OPL FM Synthesis.

Unknown Base and 48,000Hz Resampled Chips

YMF724 DS-1
YMF738
YMF734 DS-1B
YMF740 DS-1S
YMF744 DS-1L
YMF754 DS-1E

These are Yamaha's PCI-based sound card chips.  All the above use a single 24,576MHz signal for their timing.  Their sampling frequency is 48,000Hz, which is achieved by dividing 24,576MHz by 512.  It has been confirmed that their base frequency is identical to the YMF289 and they suffer from the difference in frequency.  How the base frequency is derived is unknown, but the easiest way to generate this would be to divide the 24,576MHz signal by 496, giving a frequency of 49,549Hz.  Alternatively, the YMF-7x4 chips may multiply the 24,576MHz signal by 1.378125 somehow to obtain a 33,8688MHz signal for the a YMF289 core.  It has been theorized that the EMU8000 did something similar to provide a 14.318MHz signal to the CT-1747.

As demonstrated in the wikipedia article on the YMF262, 44,100Hz resampling can give rise to artifacts.  In the YMF262 vs YMF289 comparison recording, if you listen carefully, you can hear "ringing" in the first several notes on the YMF289 which are not present on the YMF262.  The PCI chipsets are still something of a mystery when it comes resampling artifacts.  Does resampling at 48,000Hz as opposed to 44,100Hz reduce or eliminate the sampling artifacts?  No one has recorded the music piece in the YMF262 article.  That recording would help solve these mysteries, and I do not have a PCI card with a YMF chip to contribute recordings to the cause.

In addition to the various Yamaha chip datasheets, most of my information came from the contributors to these pair of VOGONS posts :

http://www.vogons.org/viewtopic.php?f=46&t=38201
http://www.vogons.org/viewtopic.php?f=46&t=48700

You can hear samples of sine waves and music at 440Hz and "439Hz" in the more recent topic.  Can you hear a difference in the music?  Personally I really cannot through headphones, and not for a lack of trying.

No comments: