vgmrips / vgmplay-legacy

VGM file command-line player and Winamp plugin.
http://vgmrips.net
224 stars 54 forks source link

ym2151.c clipping #32

Closed vampirefrog closed 5 years ago

vampirefrog commented 6 years ago

Hello. When using the following voice with the ym2151 core:

{
/* AR D1R D2R  RR  D1L TL KS MUL DT1 DT2 AME */
   31,  0,  0, 15, 0,  0, 0,  1,  0,  0,  0,
   31,  0,  0, 15, 0,  0, 0,  1,  0,  0,  0,
   31,  0,  0, 15, 0,  0, 0,  1,  0,  0,  0,
   31,  0,  0, 15, 0,  0, 0,  1,  0,  0,  0,
/* CON FL OP */
   7,  0, 15
}

which is the loudest sine wave I could get, you get clipping. Try values 1,3,7 and 15 for OP (operator mask). This is due to the code:

    if (chanout[chan] > +16384)         chanout[chan] = +16384;
    else if (chanout[chan] < -16384)    chanout[chan] = -16384;

in chips/ym2151.c:1755 and chips/ym2151.c:1821

If you compare to XM6 Pro-68k, this clipping does not occur. I don't think it happens on the real OPM either.

Changing FINAL_SH doesn't help either, it just makes the signal smaller but still clipped.

Please either remove the clipping check or define it as MINOUT and MAXOUT. Either way, define it as a macro instead of raw numbers.

Thanks!

vampirefrog commented 6 years ago

In fact in MAME it has been removed already https://github.com/mamedev/mame/blob/master/src/devices/sound/ym2151.cpp

superctr commented 6 years ago

We added that intentionally due to a song in X68K Space Harrier which had supposedly intentional clipping.

On Sun, Nov 19, 2017 at 10:51 PM, vampirefrog notifications@github.com wrote:

In fact in MAME it has been removed already https://github.com/mamedev/ mame/blob/master/src/devices/sound/ym2151.cpp

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/vgmrips/vgmplay/issues/32#issuecomment-345552822, or mute the thread https://github.com/notifications/unsubscribe-auth/ABGw8UScgEbeMxVVyq4dZRyuHeBTmPi9ks5s4KL7gaJpZM4QjjZ5 .

vampirefrog commented 6 years ago

oh and don't forget to use MAXOUT and MINOUT either in the chip or in the mixing code. perhaps use soft clipping. For particular games that need clipping, perhaps add a VGM param that would emulate the opamp saturation.

ValleyBell commented 5 years ago

Someone on IRC confirmed that the YM2151 doesn't clip a while ago.
Per-channel clipping was an addition made by me based on the wrong assumption that the YM2151 clips like the YM2612 does.

I forgot to fix the bug for v0.40.9, but it is fixed in libvgm (by not clipping at all anywhere), so I'll consider this issue solved.