VOGONS


First post, by PalMusicFan

User metadata
Rank Newbie
Rank
Newbie

There are always some audible "clicks" at the start of certain notes when playing OPL2/3 music tracks. Please read this issue for details: https://github.com/adplug/adplug/issues/54

I did a test in the OPL2/3 emulator core of woodyopl and found why these "clicks" exist. The following is my summary:

Please look at the function of

enable_operator(Bitu regbase, op_type* op_pt, Bit32u act_type)

The phase reset is here:

op_pt->tcount = wavestart[wave_sel[wselbase]]*FIXEDPT;

I added a new state of act_type, OP_ACT_NORESET.

In woodyopl.h:

#define OP_ACT_NORESET 0x03

In woodyopl.cpp:

if (act_type != OP_ACT_NORESET) { op_pt->tcount = wavestart[wave_sel[wselbase]]*FIXEDPT; }

In the case ARC_KON_BNUM of adlib_write(Bitu idx, Bit8u val), all the enable operator actions of regular 0xb0-0xb8 should use OP_ACT_NORESET instead of OP_ACT_NORMAL.

The act_type OP_ACT_NORESET should be there for all the melody channels, not percussions, since the sound of kick drum may be a bit strange without a phase reset.

After the modification above, I got phase continuous waves. Yes, some "clicks" was removed, but there appeared new "clicks"! What was up?

After checking the waveforms, I knew what the problem was.
If there is phase reset for every key on event, a note always start at the beginning of its wave form, which is always at the zero point. But now, without phase reset, it is not necessarily. So, if the state of the enevlope amplifier suddenly changes greatly, a “click” could also appear though the phase of the original wave is still continous.

We know the A of envelope could be 15 to 0. Higher value comes with faster attack. 15 means immediately. This could cause the sudden change of the output.

So I made a limitation, the A of 15 should be changed to a lower value such as 13.

At case ARC_ATTR_DECR and case ARC_ATTR_DECR+0x10:

if ((val>>4) >=15) { adlibreg[idx] = 208 | (val&15); } //1101 is 13, 11010000 is 208.

OK, It worked! Note that the envlope amp is not necessarily start at level 0. The start point was affected by the previous amp level. The attack of 13 is very short, so I think changing 15 to 13 does not cause any noticeable change in voice.

The performance is pretty good although certain voices in certain tracks sound a bit different. The most obvious difference I found appears at certain kick drum voices in the melody channels. I have no idea how to identify such kind of voices form normal melody voices.

Reply 1 of 8, by Tiido

User metadata
Rank l33t
Rank
l33t

Phase reset should have been given its own activation bits like key on bits for each operator. When I was making my OPN2 emulator I accidentally had the phase not reset on new notes and things were really cool. No clicks and nice dynamic sound, no two notes were the same haha. This would have been cool to have as real feature on the chips...
One thing that is possible in emulation is to lowpass filter the phase output, so that sudden changes such as what produces the clicks will get smoothed out. The filter will need to take account the phase increment, otherwise you're gonna destroy higher freq sounds but overall I think the idea should work nicely.

T-04YBSC, a new YMF71x based sound card & Official VOGONS thread about it
Newly made 4MB 60ns 30pin SIMMs ~
mida sa loed ? nagunii aru ei saa 😜

Reply 2 of 8, by PalMusicFan

User metadata
Rank Newbie
Rank
Newbie
Tiido wrote:

One thing that is possible in emulation is to lowpass filter the phase output, so that sudden changes such as what produces the clicks will get smoothed out. The filter will need to take account the phase increment, otherwise you're gonna destroy higher freq sounds but overall I think the idea should work nicely.

Sorry, this seems to be a bit more than my knowledge reserve. Is that the de-click function of some commerial audio repairing tools? Thanks.

Reply 3 of 8, by Tiido

User metadata
Rank l33t
Rank
l33t

Stuff in commercial audio tools is some voodoo since it works in entire audio range not a single sawtooth generator output (that's what the phase generator is). Phase generator output goes into sine and power table, ADSR is applied and final output is produced for the operator. Some of that final output can go back into the phase generator to modulate it, which is the key to the entire synthesis method.

T-04YBSC, a new YMF71x based sound card & Official VOGONS thread about it
Newly made 4MB 60ns 30pin SIMMs ~
mida sa loed ? nagunii aru ei saa 😜

Reply 5 of 8, by bakemono

User metadata
Rank Oldbie
Rank
Oldbie

We know the A of envelope could be 15 to 0. Higher value comes with faster attack. 15 means immediately. This could cause the sudden change of the output.

Does it happen instantaneously on the real chip? Or still takes some measurable time?

I was coding a mod player and had problems with popping on certain mods where a looped sample would stop abruptly. I did try a simple low-pass filter with averaging consecutive samples together which helped a little bit. But later I solved the problem entirely by interpolating the volume level over a number of samples. So when it drops from 64 to 0 for instance, I keep playing the loop and drop the volume by 1 each sample until it reaches 0. So it goes silent very quickly (64 samples = ~1.5 milliseconds) but not instantly so no more pop.

again another retro game on itch: https://90soft90.itch.io/shmup-salad

Reply 6 of 8, by PalMusicFan

User metadata
Rank Newbie
Rank
Newbie
bakemono wrote:

Does it happen instantaneously on the real chip? Or still takes some measurable time?

I was coding a mod player and had problems with popping on certain mods where a looped sample would stop abruptly. I did try a simple low-pass filter with averaging consecutive samples together which helped a little bit. But later I solved the problem entirely by interpolating the volume level over a number of samples. So when it drops from 64 to 0 for instance, I keep playing the loop and drop the volume by 1 each sample until it reaches 0. So it goes silent very quickly (64 samples = ~1.5 milliseconds) but not instantly so no more pop.

Sorry, I don't have a real OPL 2/3 chip at hand.
Moreover, I think maybe there is no way to test it since I have no idea how to make a note with a non-zero start (there is always a phase reset).
Maybe we could take a look at NukedOPL core, since it is based on chip scanning.

Yes! That's right!
Actually, I have tested a similar solution: use another group of channel, making notes alternately together with the original channles, to give each note more release time .
However, I found some notes with audible longer A time. We know, each channel works as a monophonic synthesizer. I found that the start point of the envelope of the new note is affected by the previous envelope level. So simply changing the working mode to polyphonic is not OK.

Reply 7 of 8, by SirNickity

User metadata
Rank Oldbie
Rank
Oldbie

A key-tracking lowpass filter would work, but you might still have some anomaly, limited to the frequency band of the waveform. If you're already implementing a temporal solution, why not watch for a zero-crossing instead?

Reply 8 of 8, by cyclone3d

User metadata
Rank l33t++
Rank
l33t++

I'm rezzing this thread for a question about the possibility of eliminating the clicks in games that support Adlib when using a dual OPL2 card such as the SB Pro 1 or PAS 8-bit.

Would it be possible to send every other note to separate OPL2 chips? Would this help at all?

Yamaha modified setupds and drivers
Yamaha XG repository
YMF7x4 Guide
Aopen AW744L II SB-LINK