OPL Emulation "clicks"

Developer's Forum, for discussion of bugs, code, and other developmental aspects of DOSBox.

OPL Emulation "clicks"

Postby thecoreyburton » 2017-11-06 @ 00:05

I've noticed both in DOSBox and when using WoodyOPL in adplug, there are audible clicks at the start of certain notes. Originally, I posted this as an adplug issue, because I wasn't sure where the problem was or what the best way to fix it was. Malvineous provided some good insight and directed me here, to see if it could be tackled on the OPL emulation level.

Here is an example file, demonstrating the issue (it's the menu song from Wolfenstein 3D, played back using WoodyOPL at 49716hz using adplug).

If you playback the clip, at roughly 2.85 seconds there are three bass notes (before the melody repeats). On the first of these bass notes, right at the start, one such "click" is present. If you amplify the clip, the problem becomes visually apparent, with a large jump being present when the clip starts to play the next note. There are several instances of the "clicks" throughout the clip and they all exhibit the same behavior.

I'm not sure the best way to tackle this and as far as I can tell, this isn't something that was present on the hardware itself.
Posts: 1
Joined: 2017-11-05 @ 23:50

Re: OPL Emulation "clicks"

Postby NewRisingSun » 2017-11-13 @ 06:38

The real chips click just as much. Real hardware usually low-pass filters the chip's output somewhat, making it less noticeable, but it's there. If you turn off a note, you are supposed to let the turned-off note play through its "release" phase. Reuse the channel too early, and you are cutting off the release phase, resulting in a click, because you're literally cutting off the waveform. This is true for any sound chip.

In the case of OPL2, an additional problem is that when a channel that has not sounded out is reused too soon, the chip will start the envelope not at zero amplitude but at the current amplitude, effectively cutting the attack phase short, adding further to the clickiness.

The proper way to prevent this is to make the code that assigns new note-ons to channels reuse channels as late as possible. Since the IMF format is just a register log, the bad channel assignment happened during creation of the IMF file. Correcting this would require reinterpreting the IMF data by reassigning note channels. Compare Commander Keen5's intro song --- original and with channels reassigned in the manner that I described. For certain instruments, not retriggering notes at all during legato play and just retuning the still-playing note may also be an option that has the advantage of not using up another channel.
Posts: 844
Joined: 2005-9-02 @ 02:26

Re: OPL Emulation "clicks"

Postby Jepael » 2017-11-14 @ 18:45

Yes, reusing the channel too soon before envelope has dropped to silence is kind of the issue.

Even when simply turning a slowly decaying note off and while it still decaying just turn same note/instrument on again (without touching any other sound parameters or frequency), the phase generator gets reset, causing the step and waveform starts at zero phase again.

So that's kind of not a bug but a feature of the chip doing exactly what is commanded to do under software control.
Posts: 1195
Joined: 2005-6-15 @ 19:28
Location: Finland

Return to DOSBox Development

Who is online

Users browsing this forum: No registered users and 2 guests