Tuesday, February 24, 2015

Digital OPL2 and OPL3 Recording

The Yamaha YM-3812 OPL2 chip, used on the Ad Lib Music Feature Card and the early Sound Blasters and their clones, is fairly unique among computer and video game music chips because the output of the chip is still digital.  That output is intended to be fed into a YM-3014 DAC, then sent to the pre-amplifier (for line output to powered speakers) and amplifier (for amplified output to passive speakers and headphones).  This makes it possible to capture digital audio from the card.  Its successors, the YMF-262 OPL3 and its Yamaha descendants (YMF-278 OPL4, YMF-289B OPL3-L, YMF-7xx DS-1, CT-1747) also output digital data which is fed through a Yamaha DAC.  There have been several devices which can output some form of the digitized sound generated by an OPL2 or OPL3 chip.

Adlib Digi-Snap

The original PC compatible implementation of the OPL2 chip, the Ad Lib MSC, was not designed to provide the user with digital output.  However, the OPL2 and the DAC were discrete components, so by removing the DAC the data from the OPL2 could be captured.  This is what the Digi-Snap device does.  It requires the DAC, an 8-pin chip, to be removed and a small ribbon cable soldered or socketed in its place.  The other end of that ribbon cable connects to a parallel port in a second computer.  The digital data from the OPL2 chip can be read off the parallel port using a special program.  You can piggyback the DAC chip on top of the cable going out of the computer to retain the ability to hear the sound you are trying to record.

The YM-3812 OPL2 chip outputs a 16-bit serial monaural digital signal at a sample rate of 49,716Hz.  This odd sample rate is based on the input clock, 3,579,545Hz (a.k.a. the NTSC color burst frequency).  Essentially this signal is divided by 72 to get the sample rate.

The Digi-Snap requires an Enhanced Parallel Port (EPP) set to I/O 278 and IRQ5, MS-DOS in the recording PC.  The software requires 32MB of RAM (which should indicate the speed of the PC you should be using, a Pentium) and will record nine minutes of sound before overwriting the oldest data.  The resulting data is in a raw, signed 16-bit data format.  You will need to tell any playback software like Audacity the bit depth (16-bit signed), sampling rate (49,716) and number of channels (one/mono) to be used.  Audacity can easily convert RAW files to WAV files without any loss in quality, since both are uncompressed formats.

While I cannot recall ever seeing a true Ad Lib card with a socketed DAC, many Sound Blaster 1.0, 1.5, 2.0 and Pro 1.0s have socketed OPL2 and DAC chips.  Whatever differences there may be in their analog outputs, for the Digi-Snap's purpose, they will sound exactly the same (unless a game detects a Sound Blaster and uses its digitized audio output capabilities).

The sole limitation to the Digi-Snap is that it only works on OPL2 chips.  In theory it could be adapted to the YMF-262 OPL3 chip and its DAC, the YAC-512.  However, the YAC-512 is surface mounted instead of a through-hole chip like the YM-3014.  This makes it much more difficult to solder wires to it.  Also, the YMF-262 in its OPL3 mode acts like two OPL2 chips, so the amount of data that would be stored would be cut in half.  Finally, there are enough differences between the two DAC chips that the design may have to be changed.

There is no reason why the Digi-Snap could not be used with a Sound Blaster Pro 1.0 or a Pro Audio Spectrum.  Both have two OPL2 chips and two DACs and function completely independently in stereo mode.  You would need a second Digi-Snap board and a third PC to use them.  Essentially, each PC would record one of the OPL2 chip's outputs and you could recombine them in your audio editing program.  Synchronization may be an issue, however.

The instructions for building the Digi-Snap and the software for it can be found here.

Sound Blaster AWE32

The AWE32 was the first device that provided official support for obtaining digital output from an OPL chip.  The early AWE32s have a CT-1747 bus interface chip.  This chip contains a YMF-262 core.  An YMF-262 or CT-1747 OPL3 has a 14,318,180Hz master clock and divides this by 288 to obtain the same sample rate, 49,716Hz, as the OPL2.

The Sound Blaster AWE32 and Sound Blaster 32 cards which have a YMF-262, YMF-289 or a CT-1978 do not support OPL through their SPDIF connectors.  Instead they have discrete DAC chips that only go to the analog outputs.

CT-1978 is Creative Lab's clone/improvement that uses Creative Quadrature Modulation Synthesis (CQM) instead of Yamaha Frequency Modulation (FM) Synthesis of the OPL line to approximate the OPL2 and OPL3.  CQM usually is pretty close to the original, but common opinion is that it can sound harsher compared to FM synthesis.  If a card is marked as an AWE32 or SB32 and either has a CT-1978 or does not have a CT-1747 or YMF chip, then it will have CQM.  CQM was integrated into larger chips on Creative's later cards.

Unlike the Sound Blaster 16s with the CT-1747 bus interface chip, the AWE32s, including the "value" cards without SIMM sockets, have a 2-pin Sony/Phillips Digital Interface Feature (SPDIF) header.  SPDIF signals come in three main varieties.  First is the signal that the AWE32 and CD-ROM drives with a 2-pin digital out header and Sound Blaster Live! cards with a digital output mini-jack have, a +5v TTL signal.  Second is an optical signal, which converts a +5v TTL signal into digitized optical signal through the use of a TOSLINK transmitter.  The TOSLINK transmitters are those black, boxy SPDIF ports.  The signal is turned back into a +5v TTL signal by a TOSLINK receiver.  Third are coaxial SPDIF connectors, they use RCA connectors but use a 1v Peak to Peak signal.

There are two ways to make the SPDIF connector on an AWE32 useful.  First, you can connect the 2-pin header from an AWE32 to a 2-pin header on a sound card with a CD/SPDIF digital in.  Most Sound Blaster Live! and Audigy cards have this header on their boards or have it on their feature connectors.  The second is to use an I/O bracket with an optical connector on it.  You may need to fiddle with the wiring a bit, just remember that the O pin on the AWE32 is the digital output signal and the I pin is the ground.

In the YMF-289B OPL3-L and YMF-278 OPL4, these chips are fed by a 33,868,800Hz clock.  In this case, instead of a single divider like the OPL2 and OPL3, two different dividers are used.  One divider, for the waveform/phase/envelope/timer, uses a 684 divider to get a very close approximation of the 49.716Hz signal.  This ensures that the same data can be used for an OPL3 or OPL3-L chip and the user can expect it to sound the same.  Any differences in frequencies between the two chips would produce negligible error. The output sample rate uses a 768 divider to obtain a 44,100Hz output rate.  In a sense, this may lead to a coarser output, but human ears cannot tell the difference between a sample played back at 44,1000Hz and 49,716Hz.  The benefit to Yamaha and the companies that produced sound cards meant that one less clock crystal was needed.

Sound Blaster AWE64 Gold

The AWE64 Gold uses the same 2-pin header as an AWE32 for its SPDIF output, but this connector will connect to a standard coaxial I/O bracket.  It uses 1v Peak to Peak signaling, making it slightly more convenient than the AWE32.  However, the AWE64 Gold also provides the digitized audio from the Sound Blaster, but this is limited to Windows and may only work when the Windows drivers are invoked, something no DOS program would do.

Non-Gold AWE64s often have solder pads for the header, but they would only provide a +5v TTL signal and would not include the digitized Sound Blaster audio.  All AWE64s use CQM.

Yamaha YMF-7x4 Cards

Yamaha supplied low cost YMF-71x chips for OEMs to use for cheap ISA sound cards.  These chips included everything an ISA sound card typically needed, including a true OPL3 core, Sound Blaster Pro 2.0 and Windows Sound System compatibility, a gameport and and a UART compatible MPU-401 interface. Later, the Yamaha WF-192 Waveforce was among the first PCI sound cards, and it used the Yamaha YMF-724 chip.  This chip replaced WSS compatibility with a cut-down XG MIDI synthesizer core.  The The YMF-744 was a similar PCI chip that supported 4-channel analog audio output for surround sound and DirectSound 3D.   As these cards are based off a YMF-289 core and use the same 33,868,800Hz clock and they would output to the same sample rate.

Some YMF-7x4 cards have a coaxial or optical digital output.  The digital output can be used for anything generated by the chip, including OPL2 and OPL3 music.  It can also be used for Dolby Digital AC-3 passthrough.  The digital SPDIF output has a fixed sample rate of 48,000Hz and the only clock crystal on these cards is 24,576,000Hz.  However, it appears from the YMF-724 datasheet that the OPL3 core is still using the 44,100Hz sampling frequency because there is a digital phase locked loop in the chip that converts the 24,576,000Hz master clock to 33,868,800Hz.  This would square with the claim that the OPL3 core in these chips is register compatible with the YMF-289B.  While it is beyond question that the OPL sample rate has been converted from 44,100 to 48,000 when output via the SPDIF connector, it is unknown whether the same is true for the analog output but it probably is when mixed with samples from other sources.

Samples

All other consumer PCI sound cards of the late 1990s, most of them adhering to the AC'97 specifications, also sample all input at 48,000Hz. Unfortunately, the Sound Blaster Live! and Audigy cards have a poor reputation when it comes to their resampling.  But is it deserved?  I have an Sound Blaster AWE32 CT2760 and a Sound Blaster Live! CT4760.  On one PC, I played Wolfenstein 3D and DOOM with the AWE32.  I ran a 2-pin cable from the AWE32's SPDIF out to the CD Digital Input on the Sound Blaster Live!, which was installed in a second PC.  The second PC recorded the digital input through an old version of Audacity (1.2.6) running on Windows 98SE.  Here are the results :

DOOM Episode 1, Mission 1 :



Wolfenstein 3D Episode 1, Mission 1 :



Conclusion

There is no such thing as a perfect digital recording from an OPL2 or OPL3 chip.  The 49,716Hz frequency is odd and except for the Digi-Snap device, is not something you are going to record digitally.  Even so, nothing but an OPL chip is likely to output at that frequency.  The typical ideal will be a 44,100 frequency, but most recording devices will resample this to 48,000Hz.  (DOSBox supports the 49,716 frequency to improve the OPL emulation, but your system will resample it).  Ultimately, all audio is analog, and the methods discussed in my previous post,  about capturing the data writes to the OPL chips should, if nothing else, make your file sizes smaller.

4 comments:

  1. All my tests with Pentium1-3 Systems show, that a CT4170 is the best card overall.

    ReplyDelete
  2. Hi,

    I'm trying like you to record my favorites opl2/opl3 tunes digitally.
    My setup is composed by one CT3910 (AWE32 Value 512kb+spdif pins) and one CT4620 (SBLive! 1st gen). I'm using the KX Drivers for the CT4620 and the SPDIF Input Status show me a 44098 Hz signal. http://i.imgur.com/KPqpGr3.jpg
    However i've some difficulty to get the best volume level for recording. In some games, the volume is really low and if i'm applying some normalization, the sound seemed to be distorted.
    Actually my vol settins are set 216/255 for all and bass/treble at 127/255 in SB16SET for AWE32. Recording volume on SBLive is set @ 0dB.
    Wich is the best, put some amp on recording or put the awe32 to the max ?
    Thanks

    ReplyDelete
  3. DjLc,

    I am not sure that the mixer settings will do anything at all to help you. The SB16SET manipulates the analog mixer chip found in the SB 16s, 32s, AWE32s and AWE64s. It should have no effect on the digital stream from the S/PDIF connector.

    I would recommend turning up the volume settings in whatever program that is outputting the music you want to record.

    What program are you using to normalize? I use Audacity and have never heard distortion. (I don't believe I normalized the recordings on this page.)

    ReplyDelete
  4. Thanks for your reply !

    You're right about SB16SET, it does nothing on SPDIF output. Don't if there a way to adjust the digital output throug software, i'll check with various ingame mixers.
    I'm using an old version of Soundforge (v6 by Sonic Foundry bought by Sony now, because i'm used to this software and it's the last version compatible with XP).
    I meant "distortion" because in some game, while the volume (ingame) is set to the max, the volume output is REALLY low (signal is recorded between -30 -25dB). When i'm applying normalization on that low signal i get many "digital" artifacts/noise. I'll make some test with the recording volume.
    I'll make a post on Vogons with more details and samples.

    ReplyDelete