15

By "AdLib sound card" I mean AdLib Music Synthesizer Card released in 1987.

Wikipedia says that AdLib uses frequency modulation synthesis to produce sound, but does it use MIDI communication protocol or some another way?

It's entirely possible that the FM synthesis uses MIDI under the hood to control the FM synthesis chip. The other option would be a specific driver control library which would be linked into the software.

-- From the question on the sound.stackexchange.com

11
  • 1
    This type of device is (was?) well supported in Linux. So the driver details captured in that code-base would tell you pretty much everything.
    – user12
    Feb 26, 2019 at 17:58
  • 4
    Or, if you can find a copy of the "AdLib Music Synthesizer Card Programmer's Manual". My feelings are that MIDI was not used under the hood, as programming this thing was very much a low-level thing, where a handful of specific operators gave you access to oscillators, mixers, etc. (The control was such that you didn't have to use FM if you didn't want to -- there was an additive mode.)
    – user12
    Feb 26, 2019 at 18:06
  • @jdv Yes, I'm sure that MIDI wasn't used, because it's very easy to find YouTube videos entitled like "AdLib vs. MIDI". One: youtube.com/watch?v=He_mlHj7tOU, another: youtube.com/watch?v=v9snl7f5oms
    – john c. j.
    Feb 26, 2019 at 18:14
  • Sound cards based on Yamaha's OPL2 / OPL3 FM synthesis chips had a predefined set of patch definitions corresponding to the 128 standard General Midi instruments. The MIDI driver software simply loaded the appropriate data into the chip as required. Computer games typically defined their own set of "non-standard" sounds, but still used MIDI to play the music. MIDI is a very compact data format and there would have been little value in trying to "invent a better wheel" to do the same task.
    – alephzero
    Feb 26, 2019 at 18:25
  • 2
    @alephzero that wheel was re-invented and for decent reasons. CMF (Creative), IMF (Apogee), LAA (LucasArts), and DMX MUS (Doom/Heretic/Hexen/others) are formats used by various games and music players to encapsulate OPL2/3 data in non-MIDI format. Many other games used a similar concept of encoding raw OPL register/value/timing data in their music files, only they didn't reuse their code enough times or get popular enough to become a "recognized file format"
    – hobbs
    Feb 26, 2019 at 21:34

2 Answers 2

22

As documented by Jeffrey S. Lee, the AdLib simply provides raw programmatic access to its OPL2:

The sound card is programmed by sending data to its internal registers via its two I/O ports: ...

The sound card possesses an array of two hundred forty-four registers; to write to a particular register, send the register number (01-F5) to the address port, and the desired value to the data port.

After writing to the register port, you must wait twelve cycles before sending the data; after writing the data, eighty-four cycles must elapse before any other sound card operation may be performed.

So, no MIDI, no other high-level format. The card produces nine channels of sound, each of which is the product of two sine-derived functions; you can instead configure it as six of those channels plus five percussion channels.

It supports automatic application of ADSR but otherwise it is a simple modal device. Set the current instrument set, their frequencies and volume envelopes, then they'll play continuously until you tell the card otherwise.

So, unlike MIDI or other formats like it, there's no inherent sequencing or timing of notes — the card has no autonomy in proceeding through music. It just makes the noises you've currently assigned to it.

(and as to implementation of that expensive-sounding audio generation, see this reverse engineering; summary: it's all log tables)

3
  • This is correct so far as it goes, but it's only half the story. To produce some "interesting" sounds you need to change the values on the OPL registers under real time control. MIDI has always been used for that purpose, since it is a very compact representation of "music notation". The OPL chip is the "musical instrument," and MIDI is the "performer" on the instrument.
    – alephzero
    Feb 26, 2019 at 18:40
  • 8
    @alephzero the question is "Which communication protocol is used in AdLib sound card?"; if you chose to use MIDI, that decision would live entirely in your code over on the CPU and the communication protocol you'd use with the AdLib sound card would still just be setting registers as and when you feel like it. So this is half the story as to how you'd write an AdLib music player, but the entire story as to the functioning of the AdLib card.
    – Tommy
    Feb 26, 2019 at 19:50
  • @CodyGray the only omission was the original author's name, which is now corrected. Fragile vanity makes me observe that, even before editing, a link to the original was provided and the text was explicitly demarcated as a quote.
    – Tommy
    Feb 27, 2019 at 3:43
15

As another answer has said, the OPL2/3 chip on the AdLib is driven by directly writing the registers that control the pitch, volume, and tone of each channel. But how does a game (or other music player) know what values to send when? There are a few different approaches.

  1. Raw data. The IMF format used by Apogee and early Id titles is a typical example of this. The file is a sequence of instructions, where every instruction consists of which register to write, what value to write, and how long to wait before processing the next instruction. This is easy to integrate into a game engine, and uses pretty much the minimal possible amount of CPU on playback. The DRO format used by DOSBox's OPL capture is a slightly more advanced version of this concept that produces smaller file sizes, and there's at least one game in existence that stores its music files on disk as DRO (I know because I wrote the music playback code for it).

  2. Raw data with separate instrument definitions. A simple way to save space (and simplify composer tools) is to define an instrument by directly dumping the OPL register values needed to create a given sound, and store the instruments separately from the note data. Then on playback you need commands to set the instrument for a given channel (which loads a bunch of registers from the instrument data), play a note at a given pitch and volume (loads the pitch, volume, and keyon registers), and stop a note (clears the keyon register). The ROL format used by AdLib themselves is an example of this method.

  3. MIDI. If you have instrument definitions for each of the 127 General MIDI instruments (you could get these from AdLib, or someone else, or make your own), then you can play MIDI files by parsing the MIDI events and doing a little bit of conversion between the value ranges used by MIDI and the value ranges used by AdLib. The Windows 3 - 9x MIDI Mapper driver did this, as did several standalone DOS MIDI players and DOS games.

  4. CMF (Creative Music Format) was a very popular format for AdLib music, which is almost MIDI, except that the headers are different (it isn't recognized as a MIDI file), and each file contains its own set of instrument definitions (like option #2) instead of using a standardized set of General MIDI patches. Program numbers in the MIDI data correspond to the built-in instruments rather than GM instruments. The "SBFMDRV" music driver provided by Creative Labs supports playback of CMF, and a number of games make use of it.

  5. Anything else. Since the programming interface to the OPL chip is so simple and low-level, other things are possible that I don't have time to write about. Procedurally generated music, using AdLib for sound effects rather than music by tweaking the register values in real time, AdLib S3M modules, etc., etc.

2
  • Option 2 is very similar to what you typically do for SID music (c64 et al) :) (except that "instruments" there also change registers while a note is being played...) Feb 27, 2019 at 7:10
  • 1
    @FelixPalmen yeah that's a cool thing about the OPL — since it has builtin support for ADSR envelopes, and operator mixing provides a basic way to change other parameters with time, you can get away without updating registers mid-note for everything other than pitchbend and crescendo/decrescendo and still have a decent sound.
    – hobbs
    Feb 27, 2019 at 17:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .