Skip to content
This repository was archived by the owner on Apr 24, 2023. It is now read-only.

Background

datajake1999 edited this page Jun 25, 2019 · 25 revisions

What is MIDI?

Unlike formats such as WAV and MP3, which contain recorded audio, MIDI is a set of instructions such as which instrument to use and which note to play. It is like sheet music for a computer. As a result, the same MIDI file played with a different setup will sound completely different.

Most modern MIDI synthesizers use libraries of samples called sound fonts to generate sound. OPL3EMU on the other hand, generates all sound from scratch by emulating the Yamaha OPL3 FM synthesis chip.

What is FM synthesis?

FM synthesis is frequency modulation synthesis. Basicly, the frequency of a waveform is modulated by the frequency of another waveform to generate sound. The YMF262 was one such type of synthesizer. It was found in pc sound cards such as the sound blaster 16.

How are MIDI and the OPL3 related?

The OPL3 doesn't support MIDI on its own, so software will have to convert MIDI commands into OPL3 commands. Many programs can do this, but the most notable ones are the Apogee sound system, DMX from Doom, and Windows 9x's sound blaster 16 driver. This project accurately emulates All of these.

What can this driver do?

Since most modern computers don't have an OPL3 chip, emulation is required. By default, the Nuked OPL3 emulator is used. This is the most accurate OPL3 emulator. As a result, this emulator core uses the most CPU. If your system can't handle the Nuked emulator that well, or if you just want to try a different core, you can switch to the DOSBox, MAME, Java, or Opal OPL3 emulators. These emulators aren't quite as accurate as Nuked, but they use less CPU.

The driver can also write to a hardware chip, provided that you install inpout32.dll (inpoutx64.dll for 64-bit applications). If you want to get hardware OPL3 on a modern system, try getting a PCI or PCI express sound card with the CMI8738 chipset. If you have a CMI8738 card, the OPL3 synth can be found at the base I/O address of your card + 0x50. In my case, my CMI8738 is at address E000, so the OPL3 synth is at E050.

The driver can send the commands to a parallel port as well. If you have a PCI or PCI express parallel port card, you should send the commands to the base I/O address of that card. For example, my PCI express parallel port is at address D010, so I would configure the driver to send the commands to that address.

If your hardware is up and running properly, you can silence the emulation if you only want to hear the output of your hardware.

The driver can also write the audio output of the emulator to a WAV file, as well as the OPL3 commands to a VGM file.

Notes about audio

The OPL3 uses an unusual sample rate of 49716 HZ. By default, the emulation uses this sample rate to get the most accurate output. The OPL3 emulators can run at a different sample rate, but this can lead to artifacts in the emulator output. However, there is a high quality resampler that you can enable that internally runs the OPL3 emulation at 49716 HZ, then resamples the emulator output to the desired sample rate.

By default, the driver uses a buffer size of 100 MS and a chunk size of 10 MS. This should b ideal for most systems. However, you can get choppy audio on some systems. If you are getting choppy audio, try increasing the buffer and chunk sizes.

You can apply a few basic effects to the audio. These are stereo swap, mono mixdown, surround sound, a bit crusher that has various dithering modes, a limiter that limits the maximum amplitude allowed in the final output, reverb, and some biquad filters.

You can also set a number of MS to wait before shutting down the synth. This is useful if you want to let a note fully release before the MIDI application closes the driver.

System requirements

This driver runs on Windows 2000 or newer. The driver supports X86, X64, and IA64 platforms. However, I don't have any IA64 machines to verify that the driver works properly, but if someone has an IA64 machine, they can install the driver to test it.

If you are on Windows vista or later, you can install a MIDI Selector tool along with the driver. This is because MIDI Mapper was removed from the Control Panel in Windows Vista. In windows 8, Midi Mapper was removed completely. As a result, MIDI Selector will only select the default MIDI device used by Windows Media Player if you are on Windows 8 or later.

More Information

This project is based on the Windows OPL3 drivers found at This Vogons thread

The Apogee, Doom and Windows OPL3 synths use the same version of fmopl3lib, which I added a lot of features to. The Extended Doom OPL3 synth simply uses a version of Nuked OPL3 which has the ability to do full stereo panning and a different sample output method which allows emulation of multiple OPL3 chips. I was unable to port my additional features to the extended version of fmopl3lib.

The Windows OPL3 synth has built in patches. The Doom OPL3 synth requires a genmidi.op2 file in C:\OPLSynth. The Apogee OPL3 synth has built in patches, but you can copy a custom patch as apogee.tmb in C:\OPLSynth.

I have included many OPL patches in this project. I got them from various sources on the internet.

The only modification I made to synthlib was adding a midi_close function, which calls my fm_close function of fmopl3lib. I added this to close the resampler, WAV files, VGM files, and hardware access.

The original hardware playback and VGM logging code was from another fork of an older version of the Windows OPL3 synth

The code for the HQ resampler was from the foo_midi project