Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sound Quality [Windows (Libretro+SDL)] part 2 #19

Closed
ghost opened this issue Dec 31, 2017 · 65 comments
Closed

Sound Quality [Windows (Libretro+SDL)] part 2 #19

ghost opened this issue Dec 31, 2017 · 65 comments

Comments

@ghost
Copy link

ghost commented Dec 31, 2017

Hi @LIJI32 and thanks for a wonderful and accurate Game Boy emulator!

I have read both #8 and this commit 00623d4 and from what I could understand from it the sound quality should be fixed and the pops and clicks should be gone?

Maybe this is just something on my end but I don't know, I'm running SameBoy 0.10 (libretro@f905c4d) on RetroArch 1.7.0 on Windows 10 Enterprise 2016 LTSB x64 and I can still hear frequent pops and clicks, real strong in Zelda - Link's Awakening.

All you have to do is to start a new game and the music in Mabe village should pop and click like crazy, and this is not happening on either bgb or Gambatte.

I have tried to change the Audio settings in RetroArch to make them similar like bgb for example but the music still pops and clicks.

However this isn't the case for all games I have, but of all 12, Link's Awakening is the worst sounding game.

@LIJI32
Copy link
Owner

LIJI32 commented Dec 31, 2017

  1. Can you reproduce the issue on the Windows SDL port? It handles audio differently.
  2. Can you attach a recording of the issue, with all 3 high-pass filter settings? (Disabled/Emulate Hardware/Preserve Waveforms)?

@ghost
Copy link
Author

ghost commented Dec 31, 2017

@LIJI32

To answer your first question, YES I can indeed reproduce the pops and click noises during playing Zelda - Link's Awakening on the standalone version of SameBoy 0.10 with "Accurate", "Preserve Waveform" and "None (Keep DC Offset)" alternatives.

To answer your second question, I can only say that I have a hard time doing that because I don't know how.

RetroArch won't let me record anything no matter what I do and the standalone version doesn't have any options for recording.

I have attached a physical microphone to the mic jacket on my computer and the microphone is hanging behind the TV speaker but I doubt the sound would be good IF I just knew how to record things because Windows 10 Enterprise 2016 LTSB doesn't really offer much when it comes to record audio.

What should I do here??

@ghost
Copy link
Author

ghost commented Dec 31, 2017

@LIJI32

OK I have now made a recording of the pop and click noise issue via Audacity and saved it as .wav
It's around 20 seconds and you can clearly hear what's wrong.

It's taken straight off RetroArch with "Accurate" High-Pass and what you hear in that file is what I hear in the standalone version of SameBoy too.

Thanks in advance!

Zelda.zip

@LIJI32
Copy link
Owner

LIJI32 commented Dec 31, 2017

Nice. I'll have a look (and a listen) once I'm home.

@LIJI32
Copy link
Owner

LIJI32 commented Dec 31, 2017

Oh wow that sounds bad. I seem to be able to reproduce it on the Cocoa port as well. I'll try and see what's the source of it.

@LIJI32
Copy link
Owner

LIJI32 commented Dec 31, 2017

Turns out this is caused by an incorrect emulation of an APU glitch. Disabling emulation of this glitch completely fixes this issue. Now I just need to see how to emulate this correctly.

@ghost
Copy link
Author

ghost commented Dec 31, 2017

@LIJI32

I wish you all the best with this issue and I really looking forward to your solution to this audio problem.

If there is anything else you need just ask.

Happy new year!

@LIJI32
Copy link
Owner

LIJI32 commented Dec 31, 2017

I've created a test ROM to test this issue and it appear that my behavior is actually correct. The same issue does actually happen on Gambatte as well, but it is significantly less noticeable for some reason. (I had to mute channels 2-4 to actually hear it).

@ghost
Copy link
Author

ghost commented Jan 1, 2018

That's really interesting @LIJI32 , have you gotten any chance to test your ROM in bgb as well?

bgb and Gambatte is pretty much on par when it comes to accuracy I believe but that may only apply to CPU and not APU.

What do you plan to do next and what can be done?

@LIJI32
Copy link
Owner

LIJI32 commented Jan 1, 2018

I didn't reproduce the bug with the test ROM, I did it with the original Link's Awakening ROM – both Gambatte and BGB fail virtually all of my APU test ROMs because they do not emulate the PCMXX registers. I did try to test on BGB though, but because BGB performs non-optional high-pass and low-pass filters I wasn't able to determine if BGB is affected or not.

Now that I know my emulation of that specific APU glitch is probably correct, I need to determine what the game does when it causes these pops, and how SameBoy emulates what it does in way to makes pops more noticeable than on real hardware or on Gambatte.

@ghost
Copy link
Author

ghost commented Jan 1, 2018

I appreciate all the time and effort you are putting on this @LIJI32 and it's real interesting to read all this!

I know it's kinda wrong of me to say that it's good to hear that Gambatte and bgb is failing all of your APU test roms but I think it's great to finally know that they're not as accurate when it comes to sound as I originally expected and hopefully good things will come out from this.

It's also great to know that your emulation of that specific APU glitch is probably correct because that means you can probably solve this for good.

How do you determine/figure out what the game does when it causes these pops? I'm rather curious of all this.

@LIJI32
Copy link
Owner

LIJI32 commented Jan 1, 2018

It's not that Gambatte and BGB are not accurate when it comes to APU emulation (In fact, the test portions that BGB does pass show it surprisingly accurately emulates several undocumented APU behaviors) – the thing is that Gambatte and BGB's accuracy can't be tested by my ROMs because they lack emulation of the PCM12 and PCM34 registers, which is required for my tests.

The next thing I'll probably do is to log the writes the game makes to APU registers with precise timing, before and after a sound pop occurs, and see:

  1. if the timings are identical to other emulators
  2. suggest theories why these writes wouldn't cause a sound pop

@cyberic99
Copy link

I an flowing the discussion and wonder what you think of the accuracy of higan?
(https://byuu.org/)

@ghost
Copy link
Author

ghost commented Jan 1, 2018

@LIJI32
Well that makes perfect sense when you put it that way, of course they can't work if they lack PCM12 and PCM34 registers (I'm an idiot)
I didn't thought of that actually when I wrote my previous comment but thanks for explaining all this.

I look forward to hear your results from your logs!

@cyberic99
Well if you mean higan as in the SNES core it's famous for then all I can say that it's literally a SNES in it's purest software form and you won't find anything like it.
If accuracy is all you want when it comes to SNES then don't bother with anything else.

If you however refer to higan and it's GB core I can't really speak much of it as I haven't tested it out but I know former bsnes used to have Gambatte for SGB emulation.

I would also like to point out that I think SameBoy for GB/GBC emulation and Mesen for NES/FC/FDS emulation is starting to get as good and accurate as higan with it's SNES core even though they're completely different systems.
Basically if accuracy is what you want for GB/GBC and NES/FC/FDS emulation SameBoy and Mesen is what you want.

@LIJI32
Copy link
Owner

LIJI32 commented Jan 3, 2018

Turns out the emulation of the NRX2 write glitch is in fact not accurate in some cases (Although it is "accurate enough" to pass Blargg's APU tests). I'll have to write a better test ROM to figure out what's wrong (I'll probably do it this weekend).

@ghost
Copy link
Author

ghost commented Jan 4, 2018

Great to hear you have made progress @LIJI32

Looking forward to next update from you, keep up the good work!

@LIJI32 LIJI32 closed this as completed in 0a76881 Jan 6, 2018
@ghost
Copy link
Author

ghost commented Jan 6, 2018

@LIJI32
Nice commit!

I'm eagerly awaiting the Libretro buildbot to build the SameBoy core so I can test this out, I'm reporting back once I had a chance to test it, probably tomorrow if the core is built then.

@Awakened0
Copy link

The latest commits were merged into the libretro mirror, so I tested out the newest buildbot build. It seems less poppy in LADX, I think.

There's still this sort of "static" on certain high notes; particularly noticeable if you listen to "Ballad of the Wind Fish" in LADX. I wonder if it sounds smooth in Gambatte just because of some kind of audio filtering it does. Here's a comparison wav (first half is Gambatte, second Sameboy. Both running in RetroArch on Windows):

Ballad Gambatte vs SameBoy.zip

@Awakened0
Copy link

Forgot to mention I was using the accurate high pass filter setting in that recording. The "static" is there when setting it to off or remove dc offset too.

@ghost
Copy link
Author

ghost commented Jan 8, 2018

While the sound is 1000x better then before I have to agree with @Awakened0 here, I hear what he hears too and I also hear a small distorted sound when I pause/unpause the game to get to the item/quest item screen i Zelda - Link's Awakening.

Otherwise the sound is pretty much perfect.

EDIT:

There seems to be also a distorted sound when enter/leaving houses.

@Awakened0
Copy link

Awakened0 commented Jan 8, 2018

There seems to be also a distorted sound when enter/leaving houses.

I've noticed that in Gambatte too, but it's less pronounced there. It's harsher sounding in SameBoy.

@LIJI32
Copy link
Owner

LIJI32 commented Jan 8, 2018

It's probably due to the better filtering used in Gambatte, as I don't recall hearing this distortion on the Mac version (which renders audio at 96KHz, so these distortions are heavily reduced), but I'll have to check it to verify.

@ghost
Copy link
Author

ghost commented Jan 8, 2018

Raising Audio Output Rate (Hz) in RetroArch to 96000 which is equivalent to 96Khz didn't change anything, I still hear sound distortions pausing and enter/leaving houses.

Hi-pass filter is set to Accurate.

@LIJI32
Copy link
Owner

LIJI32 commented Jan 8, 2018

The libretro core of SameBoy itself is hardcoded to 44.1KHz AFAIK

@ghost
Copy link
Author

ghost commented Jan 8, 2018

OK, well that would explain why I didn't hear any difference.
RetroArch is defaulted to 48000 as far as I know when it comes to Audio Output Rate (Hz).

@LIJI32
Copy link
Owner

LIJI32 commented Jan 8, 2018

I'm unable to reproduce this bug on my Mac even after reducing the sampling frequency to 44.1KHz. I suspect that the cause of this issue is RetroArch resampling 44.1KHz audio to 48KHz. Can any of you check if changing RetroArch's sample rate to 44.1KHz solves this issue?

@Awakened0
Copy link

I tried that and I get ear melting loud static that sounds nothing like the game audio :O

@LIJI32
Copy link
Owner

LIJI32 commented Jan 8, 2018

Mmm that sounds like either a bug in the SameBoy libretro frontend or RetroArch itself. Does it reproduce after changing the setting, quitting RetroArch, reopening it and then testing the game? Also, is there any API a core can use to get the user-set sample rate? Letting RetroArch resample the audio output when it can be directly rendered in the correct rate in the first place sounds like a bad idea.

@Awakened0
Copy link

I changed the setting in my retroarch.cfg before launching, just in case changing it in the menu while the game was running didn't work. Maybe @fr500 or another dev could help you with the API stuff.

@ghost
Copy link
Author

ghost commented Jan 13, 2018

@Fergdog
I see your point but as long as it works it's pretty much fine by my standards.
We'll see if they manage to fix this at some point, 44.1 sounds good enough for my 32 year old ears.

@Awakened0
Copy link

44100 doesn't work on my machine though, or at least it's very buggy. It always starts as loud static noise, but sometimes I can get it to work if I switch to windowed mode. It forced my monitor to 60hz from 120 when going windowed from exclusive fullscreen too, which doesn't happen at 48000 (and that's the only option I changed). I tried setting my monitor to 60hz mode and setting swap interval to 1 before launching at 44100, but I still got static before switching to windowed mode. And sometimes switching to windowed mode doesn't completely fix the sound; I have to switch modes a few times, or sometimes bringing up the menu fixes it. It's bizarre.

The same thing happens with Mesen, so it must be a frontend issue.

@andres-asm
Copy link
Contributor

Hmmm... I can't repro any of this other than some small pops every now and then.
That said, I get no audio in sameboy if I run RA at 44100hz, that seems like a retroarch bug

Not sure if any of this is recent, recently there were some changes that mande the sinc resampler configurable.

Honestly I know very little about audio and I don't really hear anything bad atm...

@andres-asm
Copy link
Contributor

Oh I hear a brrrr when entering houses in LADX, is that the issue at hand?

@andres-asm
Copy link
Contributor

Some more insight, I get no audio at 44100 unless I raise latency a bit (was at 64 before). I still don't see any noticeable difference at 44100 vs 48000 though.

@Awakened0
Copy link

Setting my audio latency to 80 fixed the problems I was having with 44100. It doesn't really sound any different than 48000 to me either though; the "static" on high notes when Marin is singing in LADX (or the real GBC or GB BIOS sound) is still there. The door entering sound doesn't sound any less harsh as far as I can tell either.

@LIJI32
Copy link
Owner

LIJI32 commented Jan 14, 2018

Can you any of you reproduce these artifacts on the standalone version? I highly suspect this is caused by double resampling – SameBoy resamples the 2 MHz audio to 44.1 KHz, then RetroArch resamples that to whatever rate it uses (and if I understand correctly, it might be a bit a bit lower or higher then what is actually configured). When resampling from one sample rate to a very similar sample rate it is very likely to introduce such artifacts. A possible solution is to make the SameBoy core render at a very high rate (384KHz, for example. Due to how audio rendering works, it shouldn't make a noticeable performance difference) and let RetroArch handle downsampling (Which it does better than SameBoy anyway).

@andres-asm
Copy link
Contributor

I did! I tested standalone on win 10, lots of popping but that's not relevant.
The BRRR noise when entering houses still exists.

@LIJI32
Copy link
Owner

LIJI32 commented Jan 14, 2018

Yeah the pops in 0.10 are already fixed on master. I'll see what happens with the house noises, probably a core issue then.

@Awakened0
Copy link

Awakened0 commented Jan 15, 2018

I plugged my GBC into my desktop's mic port to record it and compare to the Gambatte and SameBoy cores. There's some line noise, so it's not as clean as I would like, but I think it sounds less "clicky" than the emulators. Gambatte's "clicks" near the end of the sound aren't as harsh as SameBoy's; could this be due to lack of a low pass filter? I do like the cleaner sound of SameBoy, but the "clicks" in high pitched notes like the BIOS sound bother me a bit. It might be nice to have a low pass option if that could smooth those out. Here's the wav (Hardware -> Gambatte -> SameBoy):

Hardware-Gambatte-SameBoy.zip

@LIJI32
Copy link
Owner

LIJI32 commented Jan 15, 2018

@fr500 I hear those BRRR noises, seems like an APU bug (My guess is that it's similar to the one I just fixed), I'll look into it.
@Awakened0 Seems like a combination of sample rate mismatch and Gambatte's filters being better. I think I know how to fix it.

@LIJI32
Copy link
Owner

LIJI32 commented Jan 15, 2018

Just pushed a commit that redid the way the libretro port did audio. Audio is now sent to libretro at 384KHz, which is then resampled by RetroArch to whatever rate the user configured. This should greatly improve audio quality on the RetroArch port, which by this commit should sound even better than the standalone versions.

@Awakened0
Copy link

Awesome, I managed to compile it using msys2 (it takes like two seconds to build, wow) and that made the high notes in the BIOS and LADX smooth!

There are a couple things I noticed in Super Mario Land 2 I figured I'd note. On the load game screen, there's sort of a buzzing sound that plays in the background. I think it's barely there in Gambatte too; not sure if that's less noticeable there because of it's filtering or not. Also, Mario's swim sound effect likes to pop a lot in SameBoy. I don't hear that at all in Gambatte.

@LIJI32
Copy link
Owner

LIJI32 commented Jan 15, 2018

Glad this one is finally fixed. All of the other bugs are probably the same issue as that BRRR noise in LADX, which is caused by incorrectly emulated edge case of an APU glitch (See http://gbdev.gg8.se/wiki/articles/Gameboy_sound_hardware#Volume_Envelope). I found it while investigating the original bug described in this issue, but I haven't fixed it yet. I'll probably fix it later this week.

@LIJI32
Copy link
Owner

LIJI32 commented Jan 18, 2018

@fr500 Checked that BRRR noise, it appears to be the correct behavior and should reproduce on real hardware (haven't tested it on my CGB yet, though). It does reproduce on BGB, and should probably reproduce on Gambatte as well.

Edit: It indeed reproduces on Gambatte as well.
Edit 2: It will in fact happen whenever the game fades in and out the music from one track to another, especially when either one of the tracks is relatively silent.

@LIJI32
Copy link
Owner

LIJI32 commented Jan 18, 2018

@Awakened0 Fixed the sound pops and buzz in SML2's load screen. Haven't checked if it fixed swimming as well.

Edit: Seems like swimming is fixed as well.

@Awakened0
Copy link

Yep, sounds great to me now! With all these little issues ironed out I really enjoy the cleaner sound of SameBoy :)

@Awakened0
Copy link

I went and tested more stuff and there were only two other oddities with the sound that stood out to me. One, in Donkey Kong (94) there are random pops in the left channel. I'm attaching a save file for that; if you load it and start from level 8-5, you can hear the left channel popping when walking back and forth. I couldn't reproduce that in Gambatte.

DK Save.zip

Two, in Pokemon Puzzle Challenge, there are loud pops that usually happen when the background changes. Like from the opening cutscene to main menu, or after selecting new game. An easy way to get it is opening or closing the pause menu during a game. In Gambatte, instead of a loud pop there is just a slight "click" that is barely noticeable. Maybe SameBoy's pop is more accurate to hardware though.

@LIJI32
Copy link
Owner

LIJI32 commented Jan 19, 2018

I'm not entirely sure about that Pokémon Puzzle Challenge issue. I can't reproduce it on my CGB, but the line noise is VERY audible on it so I can't tell if it's masking the noise. I also can't reproduce it on my SGB2 because the PPC's hidden DMG mode does not stop the music on pause.

Edit: Never mind found a stupid bug and fixed it :P

@LIJI32
Copy link
Owner

LIJI32 commented Jan 19, 2018

@Awakened0 Mmm I can't reproduce that DK94 bug though, I might be doing something wrong. Got a recording of it?

@Awakened0
Copy link

It's a bit less pronounced, but I imagine it'd drive you nuts if you use headphones. One place it's easy to get is right when you press start on title screen. I also hear it twice when pressing start to select a game. And when the map screen to select a level comes up. A lot of these aren't consistent; some I won't hear if I reset and go through the menus again. But I always hear a few left channel pops on the way to getting into the game.

I'm thinking maybe the walking pop is accurate, since I think I hear it in Gambatte now. Though it's in the right channel there, which is weird. I don't notice any pops going through the menus in the left or right channels in Gambatte. I made a wav with two examples; SameBoy is first in both. The first is the walking sound effect in 8-5, while the second is pressing start on the title screen:

DK SameBoy-Gambatte.zip

@LIJI32
Copy link
Owner

LIJI32 commented Jan 26, 2018

@Awakened0 Seems like the same fix I did for Pokémon Puzzle Challenge fixed Donkey Kong as well. Basically it's caused by the game quickly changing the pan of channel 1, while SameBoy incorrectly delayed the effect of that change. You can still hear the pops while walking in both SameBoy and Gambatte (A simple center-cut filter makes it very noticeable), but now it's far less loud.

@Awakened0
Copy link

@LIJI32 I compared DK94's audio in both cores again and I think even the little pops I heard in the left channel while going through the menus are there in Gambatte too. They're just so muffled there that they're barely noticeable. I don't have any audio complaints now :)

@fr500 When you get some time it'd be cool to have the latest commits merged into the LR mirror so it goes up on the buildbot. The audio improvements are great and there's a hardware selection core option now.

@andres-asm
Copy link
Contributor

Done

@andres-asm
Copy link
Contributor

aaaand it doesn't build, LOL hold on a bit.

@andres-asm
Copy link
Contributor

should work now :P

@LIJI32
Copy link
Owner

LIJI32 commented Jan 27, 2018

Awesome! Thank you all for all of your reports, you all did a great job finding all those little bugs! :)

@budtz
Copy link

budtz commented Feb 9, 2018

I still get the brrr sound. Is it also on Real hardware? Its there in gambette but its lower.

@LIJI32
Copy link
Owner

LIJI32 commented Feb 11, 2018

From a digital perspective, the "brr" sound is correct and should theoretically reproduce on real hardware. From an analog perspective, this could be affected by this quirk, which might lower its volume.

@ghost ghost mentioned this issue May 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants