LIJI32 / SameBoy

Game Boy and Game Boy Color emulator written in C
https://sameboy.github.io/
Other
1.64k stars 207 forks source link

[Regression] [Libretro] Link's Awakening DX Menu Sound Crackle #161

Open Awakened0 opened 5 years ago

Awakened0 commented 5 years ago

In the latest libretro build, there is a sort of stuttery crackle in the BGM whenever you open the menu (Start). It happens when transitioning through some of the menus too, like from title screen to save select. It doesn't happen in an older build I have from Jan 19th.

Awakened0 commented 5 years ago

Just to update, when the libretro mirror updated to 3ee2c648996c6eb3a2fb32113b984215f54b7b02 I checked the buildbot build and still experience this. Haven't noticed any other crackling in other places in LADX or other games, so I don't think it's performance related.

Awakened0 commented 5 years ago

Testing a bit more, I found a little crackle when entering and leaving the pause menu in Kirby's Dream Land 2 as well that's in the new build but not the January one. It's more subtle than in LADX. Seems like it's mostly fade style screen transitions where it happens. But it doesn't happen when opening LADX's map or any of the menus in Oracle of Seasons.

ghost commented 5 years ago

Great findings @Awakened0

I hear what you hear too but I'm not sure if Gambatte or bgb suffers from this as well? Never really thought of it much when I played the game on those but in SameBoy it's definitely more apparent.

LIJI32 commented 5 years ago

Are you referring to the few pops that can be heard when you open the menu in certain areas, and that crackling sound you get when the music fades out? If so, these are not bugs – these can be heard when you play the game on actual hardware. If that's not what you mean, can you please attach an audio recording affected by this bug?

Awakened0 commented 5 years ago

This doesn't sound like the usual GB pops to me. Comparing the older core with the latest one, it sounds like the BGM transitions have a sort of stuttery crackle, whereas they're smooth in the old one. Here's a recording, January core first, latest core from the buildbot second:

LADX Old Vs. New.zip

LIJI32 commented 5 years ago

Do you have actual commit hashes of the versions compared? The only related diff between those dates is in the buffer copy function, and it doesn't explain many of the differences I see between the recordings.

Awakened0 commented 5 years ago

The Jan build has this hash: 3cc57ba Latest is: f1a75fc

LIJI32 commented 5 years ago

Since I suspect the audio buffer copying code, and I've wanted to replace it for quite a while, I rewrote it and redesigned its API, and updated the relevant frontends (libretro wrapper, Cocoa, SDL). Specifically on the libretro port, it leaves most of the work to RetroArch now, which should improve quality and latency. Can you check if anything improved after last commit?

Awakened0 commented 5 years ago

Built it and the issue hasn't changed, unfortunately.

LIJI32 commented 5 years ago

I'm extremely confused, the APU related differences between those two revisions are:

  1. The buffer copying function
  2. AGB mixing emulation (I assume you're testing on CGB mode and not AGB?)
  3. A few optimization hints for the compiler.

If it's not 1, I'm not sure what could have caused it. Since it won't reproduce on my machine, maybe you can try and git bisect it so I can know which commit changed it?

Awakened0 commented 5 years ago

I was thinking about doing that, but I can't figure out how to checkout an old commit and also apply the libretro buildbot patch to get it built. Normally I just copy the prebuilt bootroms and makefile from the libretro buildbot branch and build using an msys2 environment.

I have no idea how to install dependencies in that to compile directly from this repo. Tried adding BOOTROMS_DIR=./prebuilt with the prebuilt folder under msys64/home/ and no luck there either.

LIJI32 commented 5 years ago

What error are you getting? With BOOTROMS_DIR defined the only unusual requirement for compilation on Windows should be hexdump.

ghost commented 5 years ago

@Awakened0 Some x64 builds. Can't test myself now. https://github.com/LIJI32/SameBoy/commit/9d0aadb83fa0d63fb6810f05ff6089686cf82db4 https://github.com/LIJI32/SameBoy/commit/b3939e8fdcec9882fc57a4e4fbe3722860c3d1ee https://github.com/LIJI32/SameBoy/commit/b6e92dc8a74c850df3c5af49310e6c018d6c6707 https://github.com/LIJI32/SameBoy/commit/5ead9d49f4eac01e2c58de5ac0efe5195358db6b

Awakened0 commented 5 years ago

@funbars https://github.com/LIJI32/SameBoy/commit/9d0aadb83fa0d63fb6810f05ff6089686cf82db4 - Bad https://github.com/LIJI32/SameBoy/commit/b3939e8fdcec9882fc57a4e4fbe3722860c3d1ee - Bad https://github.com/LIJI32/SameBoy/commit/b6e92dc8a74c850df3c5af49310e6c018d6c6707 - Bad https://github.com/LIJI32/SameBoy/commit/5ead9d49f4eac01e2c58de5ac0efe5195358db6b - Good

@LIJI32 Same error as if I hadn't defined the bootroms dir. I tried a bunch of relative paths, but I'm not sure exactly which folder is supposed to be root (home, sameboy, libretro, ?). And I was just using this dir from the libretro repo: https://github.com/libretro/SameBoy/tree/buildbot/BootROMs/prebuilt

ghost commented 5 years ago

@Awakened0 Great! Last ones https://github.com/LIJI32/SameBoy/commit/9d0aadb83fa0d63fb6810f05ff6089686cf82db4 - bad https://github.com/LIJI32/SameBoy/commit/42ef41182d68dfeafe26838d3a13c91eb52bd07b https://github.com/LIJI32/SameBoy/commit/42ef41182d68dfeafe26838d3a13c91eb52bd07b https://github.com/LIJI32/SameBoy/commit/dde06e7cae094859d7e0501bb824fe1e04379b61 https://github.com/LIJI32/SameBoy/commit/dde06e7cae094859d7e0501bb824fe1e04379b61 https://github.com/LIJI32/SameBoy/commit/5ead9d49f4eac01e2c58de5ac0efe5195358db6b - good

Awakened0 commented 5 years ago

42ef411 - Good dde06e7 - Good

LIJI32 commented 5 years ago

I think I see what's going on here. The Game Boy, being able to turn its LCD screen off, does not actually guarantee a stable 59.7 FPS. This thing happens when you open the menu and close it, for example. If I understand correctly, the libretro API does not allow a non constant FPS, so in such cases SameBoy reports a frame that is shorter than usual, which has, as expected, a fewer number of samples. RetroArch simply takes this frame's length, stretches it to the usual size together with the audio, plays the two together. The change that caused this issue slightly altered how specific cases of "irregular" frames are reported to the frontend. In the Cocoa and SDL frontend the video and audio aren't coupled at all which is why I couldn't reproduce it. Now, this effect can easily be mitigated by making the libretro frontend "mimic" the behavior before that change, but this still won't be a perfect/correct solution without proper variable FPS in libretro/RetroArch. Also, is it possible to make RetroArch sync to audio instead of video? This should fix the problem completely.

Awakened0 commented 5 years ago

Hmm, but I'm using "Sync to Exact Content Framerate" under Settings, Throttle with a Gsync display. Thought that would mitigate this sort of issue. The description label under it says "No deviation from core requested timing". I think with that enabled it syncs to audio instead of video, but @Tatsuya79 would know more about it.

Tatsuya79 commented 5 years ago

"Exact sync" just follows info->timing.fps that the core sends. That's pretty basic.

I have constant crackling when I use SGB1 while SGB2 is OK if that can help to figure the issue. For popping when bringing up the menu, I noticed that activating the high pass filter got rid of that (while the core is active, not at start).

LIJI32 commented 5 years ago

Yup, following info->timing.fps is exactly what shouldn't happen in this case, as the frame rate momentarily changes to something a higher, so this option is better off for SameBoy. This also explains crackling in SGB1, as SGB1 runs at a different frame rate yet I didn't updated info->timing.fps accordingly. SGB2 (for the Game Boy perspective, I don't emulate the SFC's frame rate) runs at the same rate so it's not affected.

Also, the high pass filter should really ever be disabled, at the very least it should be set to "Preserve Waveforms", as otherwise the audio will always have DC offset, which not only triggers pops on FPS drops, might also interfere audio playing from other applications. I should probably make it the default setting in the core.

LIJI32 commented 5 years ago

The last commit should make audio on libretro as good as it was before the regression on GB, CGB, GBA and SGB2. I still have to fix the SGB issue but that's a different problem. It's not a proper solution, but it should be equivalent to Gambatte,

Awakened0 commented 5 years ago

Yep, tested LADX and a few other games and everything sounds good. Thanks everyone!

nfp0 commented 2 years ago

I'm having this exact same issue on RetroArch. On Link's Awakening, while opening the start menu, or when transitioning between the startup cutscene -> startscreen -> savefile select, I always get very slight crackling on the audio.

I have tested this on Windows and on Manjaro. Both exhibit the same problem as described on the original post. This does not happen on Gambatte.

Is it related to this? https://github.com/LIJI32/SameBoy/blob/18126994ff35c880677d51728aa5f995219592e1/Core/display.c#L1805

Awakened0 commented 2 years ago

I only hear what should be the hardware accurate pops. Using a Win64 build I made from this repo from commit 2a034d4ebe79613b88921d35396f8228b708c671

nfp0 commented 2 years ago

@Awakened0 Are the pops reproducible every time? Does Gambatte have these same pops? What I hear is a bit irregular, and is not present at all in other GB cores.

nfp0 commented 2 years ago

It is specially noticeable in the transition between the BIOS and the cutscene, and between the cutscene and the start screen.

EDIT: @Awakened0 I also built that specific commit and I got the same results.

Awakened0 commented 2 years ago

@Awakened0 Are the pops reproducible every time? Does Gambatte have these same pops? What I hear is a bit irregular, and is not present at all in other GB cores.

It's pretty consistent on my end. Here's what it sounds like for me:

https://user-images.githubusercontent.com/4565863/165411756-abd86434-f74c-4151-9dc3-0b29acb43a8e.mp4

Awakened0 commented 2 years ago

It is specially noticeable in the transition between the BIOS and the cutscene, and between the cutscene and the start screen.

Looking at my opening post in this thread, that could be a regression. There's definitely a little sound stutter in those transitions. I don't keep old builds of the core around anymore to compare though.

nfp0 commented 2 years ago

It's pretty consistent on my end. Here's what it sounds like for me:

Yeah, that's exactly how it sounds on my end too. That roughness before the waves appear and before the start screen appears is what I'm talking about.

I've checked on the GearBoy, TGB Dual, mGBA and Gambatte cores, and none of them have this behavior. SameBoy is the only one. If this is more accurate, I'm all for it. But I want to make sure that is how real hardware sounded and if this needs to be fixed or not.

Awakened0 commented 2 years ago

Getting the same audio behavior in the Libretro buildbot version which is built from their downstream repo. That repo hasn't been updated since December, so if this is a regression it's older than that.

nfp0 commented 2 years ago

Yeah, same behavior from the Libretro buildbot version here. That's where I noticed this, actually.

I tried building https://github.com/LIJI32/SameBoy/commit/431f1f8199166578b051651e6ff1c0cbd48766ab, from when things were apparently fixed, but I am getting build errors.

error: BootROMs/agb_boot.asm(2) -> BootROMs/cgb_boot.asm(512): syntax error, unexpected newline

nfp0 commented 2 years ago

I have confirmed this only happens on the libretro core. I tried the standalone SameBoy from AUR and the crackling does not happen there. Should I open a new issue on this repo, or on the libretro fork?

Awakened0 commented 2 years ago

I can reopen this and add a libretro tag.

LIJI32 commented 2 years ago

Isn't this solved by #444?

Awakened0 commented 2 years ago

My previous build should be based on that commit, but I just did a fresh one from 18126994ff35c880677d51728aa5f995219592e1 and it still has those little stutters. It only seems to happen on certain screen transitions; in game audio generally seems fine. Mario Land and Kirby's Dream Land also have a less noticeable stutter when transitioning to some new screens or levels. I haven't tested stand alone yet, but assume they aren't there from nfp0's comment.

nfp0 commented 2 years ago

Isn't this solved by #444?

@LIJI32 I've built from master and the issue is still there.

nfp0 commented 1 year ago

Has there been any progress in fixing this issue? If not, I can open an issue on the libretro side to see if anyone familiar with libretro can fix it.

Awakened0 commented 1 year ago

Don't see any improvement with a fresh build.

It might get some more eyes on the problem with a new issue opened over there, so it's probably worth it.

LIJI32 commented 1 year ago

Opening a libretro issue could help. Basically my original fix was essentially a workaround, as the libretro API can't handle cores with variable frame rates correct, and I'm assuming a recent change in how I handle extra frames in LCD on/off scenarios caused a regression again. I'm not sure how RA handles audio stretching and such in these kinds of scenarios, but I'm guessing somebody from libretro could offer some better way to fix or handle this.

Awakened0 commented 1 year ago

Ok, I opened an issue on the libretro repo: https://github.com/libretro/SameBoy/issues/85

nfp0 commented 1 year ago

I've posted this downstream on libretro, but I'll also post it here in case it helps with anything:

I've recorded a bit of gameplay on Link's Awakening DX with Mangohud showing disturbances in frame pacing when the GameBoy changes screens in the game. The crackling is audible too, both on the menus and when entering and exiting the house.

This audio issue does not seem to be happening on standalone SameBoy.

https://user-images.githubusercontent.com/11202422/194921501-e1317a30-efd7-4df4-ac36-e4b56d8a5b15.mp4

nfp0 commented 1 year ago

I've tested this recently and I cannot reproduce the audio crackling anymore. The only crackling remaining is the same present on the standalone version and on other emulators and GB cores, so I assume it's accurate.

Can anyone verify if it's also fixed for them? I'm testing on RetroArch 1.15.0

Awakened0 commented 1 year ago

Tested with a fresh build of the core and RetroArch. I still get the same crackles in Link's Awakening DX when going through the intro screens. I tried the buildbot's older core too (0.15.4) with the same result. On Windows using D3D11 or vulkan with xaudio.

nfp0 commented 1 year ago

I've tried with both the original Link's Awakening and the DX version and none produce the crackling anymore in the intro screen for me. I haven't changed anything in my configuration other than updating the OS and RetroArch. I don't know what fixed it.

I'm on Linux using Vulkan for video and the Pulse driver for audio. What could've fixed it?

nfp0 commented 11 months ago

Listening again, the crackling is still there after all. I've also noticed it sometimes occurs when pressing Start on Super Mario Land's start screen to begin the game.

Awakened0 commented 11 months ago

Yeah, checking after just building the core again I don't hear any improvement with Link's Awakening. I can hear the slight crackle when a stage starts after selecting it from the map screen in SMB Deluxe too.

nfp0 commented 11 months ago

Could this be related to the fact that this core outputs audio at 384000 Hz? No other core I use outputs anything this high. Gambatte outputs at 32768 Hz, for example.

I can hear the slight crackle when a stage starts after selecting it from the map screen in SMB Deluxe too.

Same here. Even though it's not consistent. Seems random. But it's also inconsistent on Link's Awakening.

nfp0 commented 11 months ago

I've made quite an interesting find. This crackling only manifests when I play on a 60hz screen. I cannot hear it when I play on my 180hz monitor. Just moving the window between monitors and resetting Zelda Link's Awakening DX makes the issue reproduce every time.

How to reproduce: 1) Load Link's Awakening DX on SameBoy core on 60hz monitor 2) Listen to crackle right after the GBC boot logo 3) Move window to 180hz monitor 4) Press 'h' to reset the game 5) The crackle is gone

I've tried this more than 10 times, moving the window between monitors and it always reproduces consistently. Can I help debug this?

Awakened0 commented 11 months ago

I exclusively use a single screen running at 120hz. That is with Gsync active, which will use VRR to go down to ~60hz to match the game's FPS, at least in fullscreen. The crackling is there in fullscreen with Gsync at ~60hz or in a window locked to 120hz.