YM2413 producing buggy output - is that even possible?

Page 2/2
1 |

By Bengalack

Hero (568)

Bengalack's picture

15-01-2022, 21:35

Thanks. Yes, agree --so many years! --"What is it that I'm not seing?"-kind of.

Bengalack wrote:

If understand you correctly, I can just use a hex editor, and swap that 0x10 with a 0x20, and test? If so, I thought of that and tested that, but the cymbal is still there.

When I say, "it is still there", I should mention what I used:
* Just the hex-editor
* Using vgmplay to start off a 9-channel tune which *also* was recorded from MoonBlaster
* Using vgmplay once again to trigger the cymbal

What I don't know:
* Does the first MoonBlaster mess up totally so that the newly modified vgm-file goes wrong anyway? (...hard to believe)
* I do not know how vgmplay prepares the 2413, but I assume it resets it by setting all registers to zero at startup.

By Grauw

Ascended (10560)

Grauw's picture

15-01-2022, 21:50

It would be helpful to see a VGM capture with vgm_rec from before you play 0002.VGM until after you play 2413BUG.VGM for the second time. If you can record that, then we should have a complete reproduction test case that can also be easily analyzed…

VGMPlay initializes the YM2413 by resetting all registers to zero at startup, and on exit it disables the rhythm and on all channels switches to instrument 0 with max RR, sets volume to 0, and does key-off.

By Bengalack

Hero (568)

Bengalack's picture

15-01-2022, 21:52

Grauw wrote:

It would be helpful to see a VGM capture with vgm_rec from before you play 0002.VGM until after you play 2413BUG.VGM for the second time. If you can record that, then we should have a complete reproduction test case that can also be easily analyzed….

Sure, I'll do that shortly. I can also mention that I've started to look for other files to run first instead of the 0002, so I grabbed another 9-channel here: World Clear https://vgmrips.net/packs/pack/super-pang-mitchell and the cymbal didn't trigger...

By Bengalack

Hero (568)

Bengalack's picture

15-01-2022, 22:03

By Grauw

Ascended (10560)

Grauw's picture

15-01-2022, 22:57

Thanks very helpful. Still trying to figure it out, but in the mean while;

Bengalack wrote:

The fix is to cling to the fact that the artifact did not occur if you make sure the volume for the rhythm-instruments that you are not using, is set to 0xF (=lowest, silent). We can call it "JIT" - Just In Time Smile

Note that volume 15 is not completely muted, just very soft. So it doesn’t completely address it.

Replace 513600 by 5136FF, 513742 by 5137FF, and 513824 by 5138FF, and you can still hear it, quietly.

By Grauw

Ascended (10560)

Grauw's picture

16-01-2022, 02:37

Ok, this took forever to figure out, but I think I’ve got it. I added some debug output to the VGMPlay PC YM2413 emulator to try and figure out what’s going on.

The drums we hear are TOM and HH corresponding to slot 14 and 15, which are also the modulators of channels 8 & 9. Before we set register 0EH to 20H, the debug output tells me the envelope generator for these slots is stuck in the sustain state at max amplitude (0) with rate 0. Due to this, once rhythm is enabled, the instrument patches change, the envelope generator plays out and you hear the tail end of the tom and hi-hat.

Resetting all registers to 0 does nothing to clear this internal state of the envelope generator.

So ok, why are these stuck in the sustain state? Somehow, despite the key-off VGMPlay MSX sends on exit, the modulators have not released. Now I notice VGMPlay MSX does not set the modulator RR to 0FH, so maybe if the RR happens to be 0 that could be the cause? However even if I add a command to the VGM to set the RR to 0FH, the issue still persists.

Now comes the punch line: It seems that during key off the modulator release rate is completely ignored, and is instead hardcoded to 0. Due to this, the envelope generator of the modulator stays completely static. This is documented by wouterv and also emulated by all emulation cores, e.g. here is the relevant line for the Nuked.OPLL core.

What use is it to have RR for the modulator then you ask? Well it has some use in percussive EG mode, but yes it is rather useless this way. Very strange, and I don’t really see the reason why this restriction would exist, but it is the way it is.

Anyway, how to force the channel 8 & 9 modulator’s envelope generators to fully reset, then? So that we can safely enable rhythm mode without the possibility of stray drum sounds? Good question, I’ll think about that tomorrow, since it’s pretty late now :).

By Bengalack

Hero (568)

Bengalack's picture

16-01-2022, 11:17

Woow. This is some serious deep digging. Great work. You say it took a while, but I think it was quite fast, as this is rather deep into hw. I've seen the documentation for drums and references to RR and percussive mode in reg 00 and 01, but I found that latter stuff hard to follow as my music/audio compentence is limited. I read it like, "In drum mode, you shouldn't have to care about this".

Grauw wrote:

Anyway, how to force the channel 8 & 9 modulator’s envelope generators to fully reset, then? So that we can safely enable rhythm mode without the possibility of stray drum sounds?

I was afraid we were facing something like this, but I've been telling myself that the engineers of the chip would of course make sure that a reset is a full reset. I also wiped the thought, as I told myself, "this would be common knowledge, if it was that bad" oO

By Grauw

Ascended (10560)

Grauw's picture

16-01-2022, 19:23

Grauw wrote:

Anyway, how to force the channel 8 & 9 modulator’s envelope generators to fully reset, then? So that we can safely enable rhythm mode without the possibility of stray drum sounds? Good question, I’ll think about that tomorrow, since it’s pretty late now Smile.

The “nicest” way I can think of to reset the modulator envelope generator, is by playing a custom instrument for a short while with the following settings:

Mod EG-Type: 0 (percussive) - engage RR after SL is reached
Mod AR, DR, SL, RR: F, F, F, F - attack & decay 15 makes it go to SL as quick as possible
Car AR, DR, SL, RR: 0, F, F, F - attack 0 keeps it silent

In my (limited) test, if I hold key-on for 10 ms the modulator EG will be reset and I don’t hear the TOM and HH anymore when enabling the drums later. Would be nice if there was a more elegant way though, I’m not a fan of the 10 ms wait.

Page 2/2
1 |