Mesen - NES Emulator

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

User avatar
Posts: 39
Joined: Mon May 19, 2014 11:46 pm

Re: Mesen - NES Emulator

Post by nothingtosay » Sat Apr 01, 2017 8:34 pm

Using those bands, most ripples are a bit smaller, but it also made bigger ones at 840 Hz and 6.3 kHz, plus the differences at the bottom and top end are bigger, but that's expected and doesn't really matter. I'll see what I can do about those ripples, but I think these bands are more useful for users, so you should probably just go with these. But this has got me thinking, you said it would be possible to also do presets with a greater number of bands than the EQ presents to users. I'm curious how faithfully 60 bands would work with this EQ. Maybe smaller changes over more closely spaced bands will minimize nonlinearities. If it's not too much work to add and too tedious to put in all those frequencies and decibel values, could we try it?

Here's how I envision you could incorporate it into the GUI. You could make another drop-down menu to the right of the one for filter type where people could choose presets. There would be standard 20-band presets that move the sliders. Like I've said, I think these are good for people to use as a starting point. Say a user wants to make it sound something like the real thing, but they just think the treble could use some tweaking, so they select the preset and change a few bands rather than having to manually set all 20 and trying to figure out by ear where to set the other bands to sound the same. Then you could have in the same drop-down menu options that are named the same as the standard ones, but with something like "(High Precision)" appended, and selecting that would disable the sliders and a 60-band preset would kick in.

Here's an unimportant little semantic dilemma I have: what do you name the output method I've been using, the standard white RCA jack. When referring to video, it's composite, but that's a term specific to video. Sometimes people say A/V, but that's vague, refers to video when there is no video aspect involved here, and might be confusing when one preset is "NES A/V" and another is "A/V Famicom". You plug a coaxial cable with RCA plugs on the end into it, but people don't commonly refer to that kind as coaxial cable and instead use that term for the cables typically used to carry cable/satellite television signals that have F-type plugs on the end... like the NES and some Famicom RF adapters use. But only one end of the RF adapters has an F-type connector, the other end on both Famicom and NES is (drum roll) RCA. :? What the hell can it be called that will convey to a layperson what it is and prevent confusion? Maybe it's just not necessary to say anything and it'll be assumed that output type is the default for systems that have it and RF is the unusual one that needs to be specified. So in this case, the preset would just be "Twin Famicom".

Anyway, here are the 60 values if you're willing to try my suggestion.

Code: Select all

20.0 Hz: -4.4
22.5 Hz: -4.1
25.3 Hz: -3.8
28.4 Hz: -3.5
31.9 Hz: -3.1
35.9 Hz: -2.8
40.4 Hz: -2.3
45.4 Hz: -1.9
51.0 Hz: -1.6
57.4 Hz: -1.3
64.5 Hz: -1.1
72.5 Hz: -0.9
81.5 Hz: -0.7
91.6 Hz: -0.7
103 Hz: -0.6
116 Hz: -0.6
130 Hz: -0.4
146 Hz: -0.1
165 Hz: 0.0
185 Hz: -0.2
208 Hz: -0.3
234 Hz: -0.4
263 Hz: -0.3
295 Hz: -0.5
332 Hz: -0.3
373 Hz: -0.4
420 Hz: -0.2
472 Hz: -0.2
531 Hz: -0.2
596 Hz: -0.3
671 Hz: -0.3
754 Hz: -0.4
848 Hz: -0.4
953 Hz: -0.3
1.07 kHz: -0.2
1.20 kHz: -0.6
1.35 kHz: -0.5
1.52 kHz: -0.7
1.71 kHz: -0.7
1.92 kHz: -1.1
2.16 kHz: -1.4
2.43 kHz: -1.6
2.73 kHz: -1.9
3.07 kHz: -2.3
3.45 kHz: -2.7
3.88 kHz: -3.1
4.37 kHz: -3.6
4.91 kHz: -4.3
5.52 kHz: -4.7
6.20 kHz: -5.4
6.97 kHz: -6.2
7.84 kHz: -7.0
8.81 kHz: -7.8
9.91 kHz: -8.2
11.1 kHz: -8.8
12.5 kHz: -9.4
14.1 kHz: -10.0
15.8 kHz: -10.6
17.3 kHz: -10.9
20.0 kHz: -9.5
I'll give you an updated 20-band set with the new frequencies next time.

Posts: 10080
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Mesen - NES Emulator

Post by lidnariq » Sat Apr 01, 2017 9:15 pm

nothingtosay wrote:what do you name the output method I've been using, the standard white RCA jack.
Without getting way too jargony, I'd call it "line level mono output"

Posts: 815
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour » Sun Apr 02, 2017 5:05 pm

Here's a build that contains a 20-band (customizable) preset, and a 60-band fixed preset.

With this, the "fixed" presets can technically have any number of bands (and the number of bands can change from one preset to another).
The customizable presets need to use the 20 bands shown in the UI, though.

Obviously, more bands means worse performance - so 60 bands is probably as high as we should go.

UI-wise, I'm unsure of the value of the "filter type" dropdown (butterworth, etc). Most users will likely find it confusing, and may end up picking a less-than-optimal filter for the preset they've selected. I'd be tempted to force the butterworth filter at all times?

Also, I fixed a bug in the EQ library that caused performance to plummet when the game played no sound/music (FPS would drop to 20-30).

User avatar
Posts: 39
Joined: Mon May 19, 2014 11:46 pm

Re: Mesen - NES Emulator

Post by nothingtosay » Mon Apr 03, 2017 4:26 pm

I've got the curve of how Mesen using the 60-band preset deviates from the hardware recording. Not bad at all. The picture is zoomed in to show a only 6 dB range, so it's actually much smaller than most of the previous ones. All ripples occur over a range of less than 2 dB and there's only one comparatively large one and it's in a mostly inaudible place. Could you try changing the 15.8 kHz band to -9.6 dB so I can see if that evens it out?

I wonder if high-pass and low-pass filters wouldn't replicate this particular preset in a more linear way while also being more efficient if this uses a ton of CPU, but there's no guarantee the other hardware and output methods, especially RF, could be approximated faithfully with simple filters. I guess we'll see, but for now this sounds quite good and perceptually accurate, even if you can measure the difference.

I agree it probably would be best to just use Butterworth and eliminate the others. Not much reason to have more unintended rippling when adjusting your EQ.

In the 20-band EQ for the Twin Famicom preset, I can just about eliminate the large ripple at 6.3 kHz by adjusting the 6 kHz band, but there isn't one close enough to 850 Hz to fix the one there, and that one is a drop of 5 dB, which is a pretty big volume difference. I wouldn't want to eliminate any of these bands at this point, so I don't suppose you could space the sliders a little closer together and add one more in each row? 850 Hz should be one and then basically the only other areas the frequency response differs much is at the top and bottom, so either 20 Hz or 17.5 kHz. I'd probably go for the latter.

Sorry to ask so much of you. I'm grateful that you're willing to go to these lengths for this pet goal of mine.
EQ Mesen 60-band.png

Posts: 815
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour » Tue Apr 04, 2017 5:15 am

I updated the last download link with a new build.
Run it once, and then close Mesen again - if you go in Documents\Mesen and open up the settings.xml file, you should see tags named <TwinFamicom60Bands> and <TwinFamicom60Gains> - these define the bands and gains for the 60-band preset. You can change these while Mesen is closed to customize the preset manually. (The BandXXGain tags are for the custom preset in the UI, so those aren't the ones you want to adjust). You can also add/remove bands if you want, but you need to make sure you have the same number of values in TwinFamicom60Bands and TwinFamicom60Gains otherwise it might crash.

The EQ has more end-user value than low/high pass filters, though. Since it doubles up as a way to customize bass/treble, etc. Performance-wise the 60-band presets do make the max FPS drop quite a bit (varies by game), but even then the slowest games I know of (MMC5 games) are still able to run at 180FPS on my 7-year-old CPU, so it's not really that much of an issue (considering this is an optional feature - much like the video filters)

For the 20-band presets, let's wait until you have measurements for other consoles - even if I were to add 2 more bands for the twin famicom preset, we may end up needing more bands (at other frequencies) for other presets down the road, so it may be best to get some more presets tested out and then see if/where we need to adjust bands overall? (and if it can be done without adding too many bands). Also, technically you could modify the 60-band preset in the settings.xml file to be a 22-band preset that matches this - so you should be able to try it out on your end pretty easily.

User avatar
Posts: 39
Joined: Mon May 19, 2014 11:46 pm

Re: Mesen - NES Emulator

Post by nothingtosay » Wed Apr 05, 2017 3:08 pm

Okay, that's really great! I'm happy to mess with the EQ myself instead of troubling you each time I try to play Whack-A-Mole with a ripple. I got my pin converter. Gotta find where my NES's power supply went and then I'll make recordings with it. My A/V Famicom has also entered America and that should be here soon, so I'll report back with my findings soon. Thanks for all this stuff, Sour.

Posts: 815
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour » Sat Apr 15, 2017 2:17 pm

Just released 0.8.1.

The main changes are:
-Lots of code optimizations that make Mesen 15-35% faster (depends on game) than before. This makes it more or less even with FCEUX when using the "New PPU" option (overall, some games are faster in Mesen, others faster in FCEUX).
-Audio equalizer (no presets available just yet)
-PAL/MMC5/FDS emulation accuracy fixes
-Support for UPS/BPS patch files
-Option to enable OAM RAM decay emulation (decays to $FF after 3000 cpu cycles with no read/write access, roughly 1.7ms)

Posts: 10080
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Mesen - NES Emulator

Post by lidnariq » Sat Apr 15, 2017 2:40 pm

At least with my 2C02G in my NES-CPU-07, its OAM DRAM seems to decay to a value of $10 for both X and Y coordinates. (I don't know about the other two bytes per sprite entry).

Posts: 815
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour » Sat Apr 15, 2017 3:16 pm

Ah, that's good to know. I picked $FF based on thefox's earlier observations:
(sprites started disappearing, which must mean that the bits tended towards ones (EDIT: or zeroes, if TV/capture card wasn't displaying the top 8 pixels).
Though that quote does imply it could also have been $00.

$FF has the benefit of making the sprites disappear entirely, which makes it very obvious that something is wrong (from the perspective of a game developer I mean). But either way, it might be a good idea to add an option to select the actual value the RAM decays to.

Posts: 92
Joined: Sat May 09, 2015 7:21 pm

Re: Mesen - NES Emulator

Post by hex_usr » Sun Apr 30, 2017 11:00 am

I just noticed this as I was setting up Mesen for the first time:

In the Video Options window, the Aspect Ratio setting has the following:
  • Auto (results in square pixels for me)
  • NTSC (8:7)
  • PAL (11:8)
  • Standard (4:3)
  • Widescreen (16:9)
If you're intending for NTSC and PAL to be accurate to hardware, you are actually interpreting "8:7" and "11:8" the wrong way. These are not display aspect ratios, they are pixel aspect ratios. By interpreting them as display aspect ratios, you are making the display thinner than it really should be.

For example, NTSC at 2× is giving me 548×480, which would require a pixel aspect ratio of 15:14. In an actual Famicom and NTSC NES, 8:7 is the pixel aspect ratio, so the display aspect ratio is 128:105 (1.219). When I select 2×, the display should actually be 585×480, not 548×480. Note that this is not counting the border regions at the left and right.

PAL at 2× is giving me 664×480. It should be 709×480. The pixel aspect ratio in PAL is 2,950,000:2,128,137 (approximately 11:8), which would make the display aspect ratio 9,440,000/6,384,411 (1.479). Therefore, the 2× resolution should be 709×480.

EDIT: Wow, I've already gotten used to apostrophes as digit separators in C++, and they're seeping into my posts! By the way, more on pixel aspect ratio vs. display aspect ratio here.
Last edited by hex_usr on Sun Apr 30, 2017 11:17 am, edited 1 time in total.
bsnes-mcfly: the bsnes v073 and bsnes-classic killer (GitLab repository)

Posts: 22224
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)

Re: Mesen - NES Emulator

Post by tepples » Sun Apr 30, 2017 11:08 am

And if you need a test case, you can tell that the video output stage is using the correct 8:7 or 11:8 sample aspect ratio if the circles in the "Linearity" test of 240p Test Suite are circular.

Posts: 815
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour » Sun Apr 30, 2017 12:20 pm

Thanks - I always had a suspicion that this was incorrect, but never really took the time to look into it.
I'll take a look at it when I get a chance, but in the meantime, you can use the "Custom" option in that dropdown to specify any ratio you want manually.

User avatar
Formerly Fx3
Posts: 3222
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil

Re: Mesen - NES Emulator

Post by Zepper » Mon May 01, 2017 8:04 am

Here's an example. I own a full HD monitor (1920x1080 pixels). Well, assuming 256x240 pixels (no overscan, no cut-off scanlines), if I run my emulator using a PPU output of 512x480 pixels in this display, the aspect ratio is 16:15 (pixel perfect). If I change the monitor's resolution into 640x480 pixels, the aspect ratio is no more 16:15 - I don't know the calculations now, just pointing out the non-standard resolution (640x480) in a full HD monitor changes the PPU output aspect ratio, obviously.

In short words, I don't mind about the display aspect ratio. A NES image upscaled to 640x480 is 4:3. If I'm running over a native PC monitor resolution (let's say 1920x1080), the aspect ratio is perfectly fine. By displaying the PPU image over any other non-standard PC monitor resolution will break the default PPU image shape, as more (or less) wide.

Posts: 815
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour » Mon May 01, 2017 3:37 pm

It was a simple fix in the end, I just replaced the ratios I was using with the ones you gave me. 2x NTSC now outputs 585x480 and 2x PAL is 709x480.
With that, the circles in the 240p test rom are perfectly circular - looks a lot better than the older ratios. :)

Thanks for letting me know about this!

User avatar
Posts: 10
Joined: Tue Apr 12, 2016 7:39 pm

Re: Mesen - NES Emulator

Post by BaconIsGood16 » Tue May 02, 2017 5:10 pm

Hello, I just wanted to ask if Mesen is one of the more accurate NES Emulators, why is it not mentioned on TASVideos's NES Accuracy Test Chart? Just asking, not trying to be a rude asshole.

Post Reply