irixxxx / picodrive

Fast MegaDrive/MegaCD/32X emulator
Other
52 stars 24 forks source link

[YM2612] High volume waveforms don't clip #47

Closed freq-mod closed 2 years ago

freq-mod commented 2 years ago

Didn't test it on other platforms. Possible it's again, an ARM 32-bit only flaw. Still: clipbug.zip - zip file with test ROM and recording of how should it sound like. On V90 Picodrive, it sounds like a sine wave, which isn't correct.

EDIT: x86_64 PC picodrive build is also affected

irixxxx commented 2 years ago

Could you check out if this experimental patch behaves correctly? It does clipping and ladder effect (enable under advanced options), but I don't actually have any good test cases for this. y.txt

freq-mod commented 2 years ago

Didn't test on V90 yet, but:

freq-mod commented 2 years ago

@irixxxx bad news, miyoo build erros out:

pico/sound/ym2612_arm.S: Assembler messages: pico/sound/ym2612_arm.S:932: Error: shift expression expected --subne r0,r0,rx,lsl#2'`

irixxxx commented 2 years ago

An overlooked patch part, replace rx by r1

irixxxx commented 2 years ago

I did the ladder effect by subtracting 4 if the sample is negative. Maybe I did it wrong, I'll have a look. Hmm, I can see that it subtracts 4 for negative samples. Ah wait, should that be shifted to bit 4 because of the 9 bit DAC?

freq-mod commented 2 years ago

A certain person described ladder effect as: "[...]however, as mentioned, the YM2612 has a bug in its output DAC in regards to voltage output on the YM2612, since there's a 9-bit DAC, there's a volume range going from -256 to +255, with the center being 0 on the updated YM3438 OPN2 chip, the DAC works more or less as expected, with the crossing from positive to negative values being more or less linear on the YM2612 though, there's an error in voltage that makes the jump between positive and negative values excessively large so say you have a sequence like +4 +3 +2 +1 0 -1 -2 -3 -4 on the YM3438 it'd be more or less output like that on the YM2612, the output would turn into something more similar to +4 +3 +2 +1 -3 -4 -5 -6 -7 , even if internally it's still be +4 +3 +2 +1 0 -1 -2 -3 -4 in essence, the output DAC of the YM2612 outputs something with a signal-noise ration closer to 6-bit than 9-bit, even if the values internally are 9-bit.

irixxxx commented 2 years ago

yes, I know... I did it wrong, on a per channel base. Problem is, I can't do it on the whole sample easily, since the channel values are directly accumulated on sound samples of other hardware, hence I don't know if the total FM output sample is negative or not :-/ So, I'll leave that out for now, I think.

freq-mod commented 2 years ago

I see. Still, main issue is fixed,and ladder effect not being emulated is not the end of the world - old MAME 2612 doesn't have it as well

irixxxx commented 2 years ago

Could you please try if this is any better on ladder effect? y.txt