VOGONS


Nuked OPL3 emulator

Topic actions

First post, by nukeykt

User metadata
Rank Member
Rank
Member

Nuked OPL3 emulator

Features:
-Very accurate. IMHO it is most accurate emulator at this time.
-Easy to integrate to any C/C++ project.
-Integrated linear resampler, though i recommend to use better resampler since linear produces some artefacts.

My emulator already present in these projects:
-Doom source ports: ZDoom, GZDoom, Chocolate Doom(dev builds), Crispy Doom, 3DGE(2.1.0 test builds)
-Windows OPL3 user mode drivers.
-Adlib Tracker II SDL(ported to pascal)
-AdPlug

Comparison with real YMF262:
https://www.youtube.com/watch?v=6qXMIm4eSCc

Code:
https://github.com/chocolate-doom/chocolate-d … ster/opl/opl3.c
https://github.com/chocolate-doom/chocolate-d … ster/opl/opl3.h

Last edited by nukeykt on 2016-09-18, 14:02. Edited 11 times in total.

Reply 2 of 33, by MaliceX

User metadata
Rank Newbie
Rank
Newbie

This is good. Not only the codebase is smaller, it doesn't use floating point (save for the OPLRATE preprocessor define) arithmetic at all, and the upper registers sound louder/clearer.

Do you mind if I add this to the forked driver as a possible alternative emulator core?

Reply 3 of 33, by MaliceX

User metadata
Rank Newbie
Rank
Newbie

By the way, it looks like there is a bug with how key ons should be treated with operators whose output levels have reached silence on the envelope. On real chips (YMF724F-V, CMI8738, ESS ESFM, FM801), AdlibEmu/DOSBOX core, and Jarek's MAME core, key-ons for channels where Key Off has not been received do not reset the silent operator's EG.

With your core, Key Ons on voices will reset the envelopes of operators that have reached silent level, but has not been set to OFF state. Do not assume operators reaching silence means the operator EG is OFF as this is only determined after a key-off command. This is necessary for some game music (eg: Tyrian, Rusty, Mad Paradox) where songs have pitch sweeps on percussive patches.

Reply 4 of 33, by Jepael

User metadata
Rank Oldbie
Rank
Oldbie

There is definitely potential, but somewhat off from the details provided by the submarine forum.

For instance the waveforms are a bit off. When output is said to be zero, it is really attenuated so that PCM output is zero, not logsin[0] which is 12 in PCM.
And the square wave should be +/- max output, so the attenuation should be 0 with either +/- sign, not index/4 with +/- sign.

I also don't get the EG reset. At any point the key-on goes from 0 to 1, EG will start the attack phase, but from whatever previous volume, which is not zero if the sound was decaying/releasing.
Same with release, at any point the key-on goes from 1 to 0, the EG will start the release phase, even if it did not fully attack/release. I think. I have not verified this.

Reply 5 of 33, by MaliceX

User metadata
Rank Newbie
Rank
Newbie
Jepael wrote:

I also don't get the EG reset. At any point the key-on goes from 0 to 1, EG will start the attack phase, but from whatever previous volume, which is not zero if the sound was decaying/releasing.
Same with release, at any point the key-on goes from 1 to 0, the EG will start the release phase, even if it did not fully attack/release. I think. I have not verified this.

This is actually correct behaviour what you're describing. It exhibits features which benefit mono-legato voice playback support (which I'm using to support in my MIDI driver fork). This is also very common with other FM chips, to continue from previous voices on next key on, following from their current position on a channel's assigned envelope.

http://djtbmx.jamesoz.com/junk/opl3vgmlog-egbug.zip

The bug I'm describing however, is where this fails. I've attached a zip which contains the following files:

opl3test-egbug - Two drum notes both with falling pitch being demonstrated via Fnum+keyons without a key off
opl3test-egbug2 - A fast-attack marimba patch playing a single sustained chord for a few bars, with fnum+keyons for software-driven vibrato

Each of the above tests come with the following:

  • vgm file = playable (via in_vgm/VGMPlay/foo_gep) register log of YMF262 commands being received. (these are just two MIDI notes being played, whose notes/patches have a software pitch envelope attached to them to attain that 'falling' pitch sound)
  • txt file = text-readable representation of the above file (used vgm2txt)
  • cmi8738output wav = output of the above, using my CMI8738. The long silence is intentional since these are long-held notes, to let the driver spam f-num data to the chip as observed in their txt.
  • khokh2001output wav = output of the above, using khokh2001's emulated core. Note the intermittent attacks that follow, suggesting reset envelopes on key on without a key off between.

The YMF724F-V matches the behaviour of the CMI8738 recording, as do Jarek's MAME and DOSBOX ADLIBEMU cores. If anyone with a real SB16 could play the .vgm log through VGMPlay via OPL passthrough, you can check if this happens with your hardware too (however I am confident this will result in confirming my findings anyway)

Reply 6 of 33, by MaliceX

User metadata
Rank Newbie
Rank
Newbie

OK. Fixed the retrigger bug.
opl->OPs[op].key was never used, so I used it to indicate key on/off, where on = 1, off = 0

Here's the fixed .cpp attached.

EDIT: Not sure if it's a bug, but it seems like voices that are meant to be silent, you can still hear them at a very faint volume. Is this intentional?

Attachments

  • Filename
    opl3.cpp
    File size
    29.02 KiB
    Downloads
    179 downloads
    File comment
    Fixed EG_OFF / EG_RELEASE state where key off was not received, causing unwanted retriggers on next key on commands.
    File license
    Fair use/fair dealing exception

Reply 7 of 33, by Jepael

User metadata
Rank Oldbie
Rank
Oldbie
MaliceX wrote:

EDIT: Not sure if it's a bug, but it seems like voices that are meant to be silent, you can still hear them at a very faint volume. Is this intentional?

Silent, in what situation? Regarding midi data or OPL emulation side? If a sound is in release phase, and the release rate is larger than 0 so that it will actually release, the sound level will go below audible levels. In fact the output will be either 0 or -1 depending on waveform sign being positive or negative.

Reply 8 of 33, by jwt27

User metadata
Rank Oldbie
Rank
Oldbie

Maximum value for the attenuation register is 0x3F or -47.25dB. That is very quiet but not silent.

WANTED - Manuals/drivers for:

  • Tecmar Graphics Master
  • Paradise Autoswitch EGA 350 (EGA1A)

Reply 9 of 33, by MaliceX

User metadata
Rank Newbie
Rank
Newbie
jwt27 wrote:

Maximum value for the attenuation register is 0x3F or -47.25dB. That is very quiet but not silent.

Yup. Confirmed this behaviour with my YMF724 card. Thanks.

Reply 12 of 33, by chipko

User metadata
Rank Newbie
Rank
Newbie

Hi to everyone, I read you for a while, you're good.
Unfortunately my knowledge is barely enough to follow you and to understand you, even if you are very clear.
I was wondering if the above oplemu created by khokh2001 (this is the same person of Chocolate Doom?) Could be installed or used on dosbox.
If so how do you do it?
I hope my question is not too stupid.
Thanks in advance.

Reply 14 of 33, by chipko

User metadata
Rank Newbie
Rank
Newbie

Ok, thank you. I had been deceived by the similarity of the letters.
Anyway I would like to know if it was possible to install the khokh2001's oplemu in dosbox. Is it better than version already present?

Reply 15 of 33, by MaliceX

User metadata
Rank Newbie
Rank
Newbie

khokh2001's core is all integer arithmetic, however it still has a few minor bugs in the emulation output (particularly for more complex/highly modulated waveforms). The core used in DOSBox is still more accurate, as far as comparing to genuine Yamaha OPL3 output goes. 😀

Reply 16 of 33, by chipko

User metadata
Rank Newbie
Rank
Newbie
MaliceX wrote:

khokh2001's core is all integer arithmetic, however it still has a few minor bugs in the emulation output (particularly for more complex/highly modulated waveforms). The core used in DOSBox is still more accurate, as far as comparing to genuine Yamaha OPL3 output goes. 😀

Thank you for answering me.

Reply 19 of 33, by Stretch

User metadata
Rank Member
Rank
Member

Does Nuked OPL3 emu have a rockbox port? Would it be faster than dosbox or MAME OPL on portable audio players?

PC1: Win98SE - Via Apollo Pro Mobo - Pentium II 233 - 256 MB - Voodoo 3 1000 - Acoustic Edge PSC706
PC2: Win98SE - ASRock 775i65G R3.0 - Celeron 2.2 GHz - 2048 MB - Geforce FX5700 - Audigy 2 ZS