First post, by PalMusicFan
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.