MiSTer-devel / Gameboy_MiSTer

Gameboy for MiSTer
101 stars 48 forks source link

Fix APU DAC handling #216

Closed maij closed 1 year ago

maij commented 1 year ago

Edit: I have made two versions, one where the audio output is unsigned and one where it is signed. I don't have a real gameboy to test on and would appreciate people comparing some games. Unsigned: Gameboy_PR216.zip

Signed : Gameboy_PR216_signed.zip

N.B. the maximum volume is effectively halved by moving to signed values, but this shouldn't affect audio fidelity.


The digital implementation of the DACs for each channel did not have the right value mapping for negative to positive voltages. This PR fixes this issue.

The implementation is based on SameBoy's logic, however each channels wav output is multiplied by 2 there, but I haven't done that, otherwise it creates garbled audio in the core.

Resolves #87, Resolves #176, Resolves #203.

I have made an effort to 'tidy up' the APU, removing the confounding extra bits each channels digital output signal. Actual DMG/CGBs use 4 bit DACs.

I haven't done a lot of regression testing, but for the games I have tested (both in DMG/CGB mode) they worked well. One possible change is to the total volume of the core (some sections may be quieter than before, but this is hard for me to verify). If anyone wants to try it out: Gameboy_PR216.zip

SegaSnatcher commented 1 year ago

I tested your build with this PR and I noticed an odd sound during screen transitions where the music changes in Link's Awakening/Link's Awakening DX that is not present in the current offical core release.

There is also a popping sound when you load a rom in your build.

maij commented 1 year ago

I just tried Link's Awakening and didn't hear what you mean. Do you have a video or any further explanation?

I think the popping is to be expected, since all channels off now has a DC offset. This is more like the actual gameboy. Externally (in the Mister system) audio is handled as signed, so it might be worth modifying the core to use true signed values at some point.

SegaSnatcher commented 1 year ago

Are you using HDMI out? Yes, it happens during the screen transitions where it changes music tracks. It doesn't fade in cleanly like the current official build. There is this added audio anomaly in your build.

Here are some video I made that you can compare, sorry I don't have any proper capture hardware.

Make sure to turn the volume up. Notice the weird clicking sound? I don't know how to describe it well.

(Your PR Build with the audio anomaly)

https://www.youtube.com/watch?v=IHgges3A8_o

(Current Official Build)

https://www.youtube.com/watch?v=ckm446XFSXI

maij commented 1 year ago

Thanks for sharing. I was trying to reproduce this, but I didn't see the issue. After watching your videos I see that the difference is that you're in DMG mode, while I was testing Zelda in CGB mode.

Current official build: https://youtu.be/dO76y2d27So

PR216 Build: https://youtu.be/pD1XsIn7EuA

I'm surprised there is a difference between the DMG/CGB. I will look into this tomorrow.

SegaSnatcher commented 1 year ago

Oh just to clarify, this issue also happens in GBC mode too for me.

maij commented 1 year ago

For what it's worth, this is the same behaviour in Sameboy. sameboy_legend_of_zelda.zip

I don't have a real gameboy to check against.

SegaSnatcher commented 1 year ago

So I tested on my modded GBA handheld and the crackling does seem to be present there, it was just harder to spot because of the low quality mono speaker and low volume. So, I guess this is accurate to real hardware, at least when testing a real GBA.

sorgelig commented 1 year ago

so, does it have regressions? I don't use Gameboy much, so can't test myself.

SegaSnatcher commented 1 year ago

There is technically a new audio anomaly in Link's Awakening, but it does seem to behave in a similar fashion to how it plays on a real GBA.

I don't have an original Gameboy or GBC to test against.

maij commented 1 year ago

I've added an alternative version (which does not have these anomalies, nor the audio popping, see the original post), though I am not sure how accurate it is compared to the real hardware, so I have asked for some help in testing before we proceed here.

paulb-nl commented 1 year ago

I tested Link's awakening on a real Super Gameboy and I hear a similar popping sound:

https://user-images.githubusercontent.com/2227984/200120919-4ae5f123-b046-4117-8528-f23f0f936ec4.mp4

maij commented 1 year ago

@sorgelig I'm really sorry about this, but the latest commit on this PR was not the most accurate version (people's tests showed the unsigned version was most accurate). I would need to revert that commit to go back to the unsigned version. Should I create a new PR to fix this?

sorgelig commented 1 year ago

i've rolled back the code