digital-sound-antiques / emu2149

A YM2149 (aka PSG) emulator written in C.
MIT License
29 stars 10 forks source link

Bug with the envelope generator #2

Closed ValleyBell closed 3 years ago

ValleyBell commented 3 years ago

There seems to be a bug with the envelope generator that causes the channel to go "full volume" when it is not supposed to be.

It occours in the Level 1 music of Jim Power in Mutant Planet (Atari ST), on the first channel: VGM + MP3 The MP3 has EMU2149 on the left speaker and the MAME AY8910 sound core on the right speaker. The bug can be heard at 00:16.26 in the VGM / 00:02.68 in the MP3.

The command sequence that appears to trigger the bug, is:

Channel state before:
0x00002CB1: A0 07 0C    AY8910:     Enable: Channel AB-, Noise -BC, Port II
0x00002CCE: A0 0B 00    AY8910:     Envelope Freq. Fine: 0x00
0x00002CD1: A0 0D 08    AY8910:     Envelope Shape: 0x08
0x00002CD5: A0 00 DD    AY8910:     Chn A Freq. Fine: 0xDD
0x00002CD9: A0 01 01    AY8910:     Chn A Freq. Coarse: 0x1
0x00002CDD: A0 08 1E    AY8910:     Chn A Volume 93%, Envelope Mode: 8

commands that seem to trigger the bug:
0x00002CF8: 71          Wait:    2 sample(s) (   0.05 ms)   (total  717236 (00:16.26))
0x00002CF9: A0 0B FF    AY8910:     Envelope Freq. Fine: 0xFF
0x00002CFC: A0 0C FF    AY8910:     Envelope Freq. Coarse: 0xFF
0x00002CFF: A0 0D 08    AY8910:     Envelope Shape: 0x08

I also tried to do a minimal example that shows the same bug: SSG-test.vgm.gz This is based on how the bug occours in the game "Dragon Half" (NEC PC-9801).

Thanks go to GTheGuardian from vgmrips for noticing the issue.

ghost commented 3 years ago

Might want to add in that similar issue is also present in the Atari ST version of After Burner and is an even more egregious example of this bug. (Example VGM / MP3; Volume Warning on EMU2149 recording / HW Reference)

okaxaki commented 3 years ago

Thank you for detailed bug reports. I will investigate the problem and will fix it.

okaxaki commented 3 years ago

Hi, Folks,

I have fixed the bug and released 1.30. Thank you very much again for your reports!

Some details

There were two problems behind this bug.

The first problem was that the envelope frequency 0 was handled incorrectly. The frequency 0 should have been the same as 1 but it haven't. I fixed this with the patch at c48ec00 and the patch fixes the incorrect noise sound of SSG-test.vgm and After Burner music.

The second problem was that the envelope counter was not latched immediately after R#11 and R#12 access. The patch for this problem is 31ee5a4. This fixes "full volume" tones in Jim Power in Mutant Planet.

ValleyBell commented 3 years ago

I updated emu2149 in libvgm and I can confirm that the bug is fixed now.

Thanks!