aaronsgiles / ymfm

BSD-licensed Yamaha FM sound cores (OPM, OPN, OPL, and others)
BSD 3-Clause "New" or "Revised" License
265 stars 41 forks source link

YM2151 LFO can't be turned off #11

Closed LeonardoDemartino closed 3 years ago

LeonardoDemartino commented 3 years ago

I discovered that even if you set the LFO speed to 0 (disable LFO), you actually get a very slow LFO on ym2151. Which means that notes will begin to detune after a while.

Doesn't happen on other emulators: https://deflemask.com/ym2151_lfo_bug.vgm

Check this .wav: https://deflemask.com/ym2151_lfo_bug.wav (If you scroll around the detuning will be obvious)

aaronsgiles commented 3 years ago

So actually, this is a bit subtler than you suspected. An LFO value of 0 does not really disable the LFO. According to the YM2151 application manual (see excerpt below), an LFO speed of 0 is 0.0008Hz, or a period of ~20.8minutes. What you're hearing is totally what I would expect, unless something else is causing the LFO to be reset.

Which does seem to be the case. The YM2151 test register is known to reset the LFO when bit 1 is set. I had implemented that, but only as an instantaneous effect when the register was written. Your VGM writes to the test register and sets the 1 bit once at the start, but clearly expects that bit to be "sticky", so that it should disable the LFO until it is cleared. Implementing this gets rid of the LFO.

lfo