Mesen - NES Emulator

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

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

Re: Mesen - NES Emulator

Post by nothingtosay »

I attached images of the EQ curve produced when matching spectra using 30 points and 60 points. This is from Voxengo CurveEQ, by the way. 60 is what I used in my example audio file, but the curves look pretty similar and sound even more similar than they look. It's something that could probably be audibly approximated well with high-pass and low-pass filtering, the question is how much precision in replicating hardware you want. Although I know that's a pretty fuzzy thing itself, as this is just my individual hardware specimens recorded using my setup and there's gonna be a range of results with different ones. But you've already found an EQ library and EQs are more customizable, so let's work with that.

If there will be a configurable EQ for the user to play with, 60 bands would be rather unnecessary and pretty tedious to tune, unless there were a mode to move multiple sliders in tandem when moving one, as some EQs offer. 30 bands can be a bit much for a regular end user too, but I wouldn't want to go lower than 20 for presets as the curve loses a lot of detail with this example below that. Don't know how many bands would be necessary for hardware I haven't recorded yet, but I wouldn't expect drastic differences. RF appears to be an even simpler curve to replicate, so it probably doesn't get more complex than the one I've given images of. I'll order a pin converter so I can get NES recordings using my Famicom Everdrive and I'll cruise eBay for deals on an A/V Famicom or toploader NES.

20 Hz to 20 kHz is the range CurveEQ covers as well, so that's cool. I can give gain values for any point along that spectrum, but we can just go with the frequency bands CurveEQ uses when set to the number you decide to use. I'd recommend choosing 20, 25, or 30 bands. Once you settle on a number, I'll give you the list of frequencies the bands are set at and the gain adjustments for the different hardware and output methods. The best practice would probably be to do all negative dB values to ensure there can't be any clipping, but I wonder if people might dislike the volume decrease and choose not to use it because of our ears' natural "louder is better" bias. Oh well.
Attachments
EQ curve 60-point.png
EQ curve 30-point.png
lidnariq
Posts: 11430
Joined: Sun Apr 13, 2008 11:12 am

Re: Mesen - NES Emulator

Post by lidnariq »

Labels for the two Y axes? I tentatively think the right one should be decibels, but...

Also, I'm surprised by the ripple you're showing in the passband. Could you describe your entire analysis setup?
Sour
Posts: 890
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour »

lidnariq wrote:Butterworth: No ripple in either pass band or stop band; the steepest possible filter per order without any ripple
Chebyshev 1: Ripple in pass band, no ripple in stop band
Chebyshev 2: Ripple in stop band, no ripple in pass band
Thanks for the explanation - so in this case Butterworth would probably make the most sense?
nothingtosay wrote:If there will be a configurable EQ for the user to play with, 60 bands would be rather unnecessary and pretty tedious to tune, unless there were a mode to move multiple sliders in tandem when moving one, as some EQs offer. 30 bands can be a bit much for a regular end user too, but I wouldn't want to go lower than 20 for presets as the curve loses a lot of detail with this example below that.
Realistically, 20 is pretty much the limit of what I could fit into a config screen and keep it fairly usable - if 20 bands gives enough precision, it might be best in this case.
Otherwise, there's always the possibly of having preset filters with 30+ bands and then offer a more limited EQ in the UI (e.g 10 bands) - only downside being I couldn't visually show what the presets are on the EQ sliders.
nothingtosay wrote:The best practice would probably be to do all negative dB values to ensure there can't be any clipping
I agree - there may already be some conditions where the output comes close to clipping, so negative DB values would make the most sense.
lidnariq
Posts: 11430
Joined: Sun Apr 13, 2008 11:12 am

Re: Mesen - NES Emulator

Post by lidnariq »

Sour wrote:Thanks for the explanation - so in this case Butterworth would probably make the most sense?
Really depends. Given that nothingtosay's EQ shows ripple in the passband, it might actually make sense to use some Chebyshev 1 filters after all. I don't know.

It looks like there's a 3rd order lowpass starting at 2kHz and a 1st order highpass starting at 80Hz, but I'd really like more details on the measurement setup first.

I don't actually distrust the corner frequencies, but I am shocked at just how much of the higher frequencies are being thrown away...
User avatar
nothingtosay
Posts: 39
Joined: Mon May 19, 2014 11:46 pm

Re: Mesen - NES Emulator

Post by nothingtosay »

lidnariq wrote:Labels for the two Y axes? I tentatively think the right one should be decibels, but...

Also, I'm surprised by the ripple you're showing in the passband. Could you describe your entire analysis setup?
I believe the numbers on the right don't actually apply at all to what I'm measuring there. They're for something else that can be displayed in the same window. It's like RMS decibel levels for every frequency band in a recorded spectrum or something, and there's normally a transparent outline of it but I turned it off for clarity. I should have cropped those numbers out. The pertinent numbers are on the left side and they're also decibels. Looking at the right is why it seemed like the low-pass is third-order, so I apologize. It's definitely not that severe!

The recording that produced those curves was made from a Turbo Twin Famicom's RCA output over a 3-foot double-shielded RG6 coaxial cable, which I know is way overkill, especially for that distance, but I think then you can be pretty sure it's affecting the signal only minimally. It goes into the left channel analog input of my M-Audio 2496 sound card and is recorded in Sound Forge 11 at 48 kHz. The card's specifications say "Frequency Response: 22Hz-22kHz, -0.4, +/-0.4dB" but I suppose I could actually put it to the test. I don't doubt that there could be slightly more accurate recording devices, but for what it's worth this sound card is pretty highly regarded and recommended (although I know audiophiles aren't exactly the most trustworthy group when it comes to the scientific aspects of sound) and I don't think it's responsible for a large treble loss. That little uptick at the top end of the frequency range is actually caused by Mesen having a significant drop in volume up there.

I recorded more than 20 seconds of pink noise from the test ROM, and did the same in Mesen. Then I captured an average of the spectra of my recordings, which were more than long enough for the average to stabilize. Then I used CurveEQ's match spectrum feature which allows you to apply a reference frequency profile to another and those curves show how the subject (Mesen) has to be changed to take on the characteristics of the reference (Twin Famicom). It seems to me that it did a pretty good job at that on my processed example file.
Sour wrote:Realistically, 20 is pretty much the limit of what I could fit into a config screen and keep it fairly usable - if 20 bands gives enough precision, it might be best in this case.
Otherwise, there's always the possibly of having preset filters with 30+ bands and then offer a more limited EQ in the UI (e.g 10 bands) - only downside being I couldn't visually show what the presets are on the EQ sliders.
Yeah, 20 should be fine. I think that combined with the presets would be a very good place to be in. People can use a preset as a starting point and then quickly customize to their preference a handful of bands they dislike if they want to. I decided I don't quite like CurveEQ's default bands at 20 points since it has more at the bottom and fewer at the top than I'd like, so I went with Sound Forge's own 20-band EQ's values (except I cut two in order to add 17.5 kHz and 20 kHz to capture that uptick) and got the values for each frequency. Let's try this:

20 Hz: -4.4
40 Hz: -2.2
56 Hz: -1.0
80 Hz: -0.7
113 Hz: -0.3
160 Hz: 0.0
225 Hz: -0.2
320 Hz: -0.3
450 Hz: 0.0
640 Hz: -0.3
1.0 kHz: -0.4
1.8 kHz: -0.9
2.5 kHz: -1.7
3.6 kHz: -2.8
5.1 kHz: -4.4
7.2 kHz: -6.5
10 kHz: -8.3
15 kHz: -10.3
17.5 kHz: -10.9
20 kHz: -9.4

I assume you don't want to do a release with only a Twin Famicom A/V preset and no NES or first-party Nintendo Famicom ones, but if you could give me a build with the EQ, I'd like to play with it and see what I think of using these bands.
lidnariq
Posts: 11430
Joined: Sun Apr 13, 2008 11:12 am

Re: Mesen - NES Emulator

Post by lidnariq »

nothingtosay wrote:That little uptick at the top end of the frequency range is actually caused by Mesen having a significant drop in volume up there.
Ok, so this is actually a graph of the differences in magnitude at each between your recording and the raw audio out of Mesen. Any chance you could share a graph against an ideal pink noise curve also?

I don't know if Mesen is currently doing any filtering...

Just to be overly specific, this is NOT the modulated RF path? just baseband line-level audio?
User avatar
nothingtosay
Posts: 39
Joined: Mon May 19, 2014 11:46 pm

Re: Mesen - NES Emulator

Post by nothingtosay »

lidnariq wrote:Ok, so this is actually a graph of the differences in magnitude at each between your recording and the raw audio out of Mesen.

Right.
lidnariq wrote:Any chance you could share a graph against an ideal pink noise curve also?
Assuming Sound Forge's pink noise generator is ideal, I've attached the difference curves for Mesen and the Twin Famicom for good measure. But the pink noise from the ROM would also have to be the same for this to be a perfectly fair comparison.
lidnariq wrote:Just to be overly specific, this is NOT the modulated RF path? just baseband line-level audio?
Correct, this is not RF. I have recorded that, but haven't posted a graph. It's from the standard RCA audio jack of the Twin Famicom.
Attachments
EQ curve pink noise Mesen.png
EQ curve pink noise Twin.png
Sour
Posts: 890
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour »

nothingtosay wrote:I assume you don't want to do a release with only a Twin Famicom A/V preset and no NES or first-party Nintendo Famicom ones, but if you could give me a build with the EQ, I'd like to play with it and see what I think of using these bands.
I'm in the middle of optimizing a bunch of stuff to try and squeeze a bit more performance out of Mesen at the moment, but I'll try to get you a build with a basic EQ UI over the weekend.
lidnariq wrote:I don't know if Mesen is currently doing any filtering...
It might - I use blargg's blip_buf C library to resample the APU's output to the target sample rate and feed blip_buf's output to DirectSound/SDL. Taking a quick look at blip_buf's code, it seems to have (at the very least) a high-pass filter built into it.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Mesen - NES Emulator

Post by tepples »

nothingtosay wrote:Assuming Sound Forge's pink noise generator is ideal
Also assuming the test ROM is ideal. For one thing, pink noise is tricky to generate in an environment where you can't, say, run a sixth-order IIR filter. For another, I am potentially imperfect.

In particular, I haven't thoroughly tested the ROM by running it in a 6502 simulator, logging $4011 writes, and doing big FFTs to ensure a 1/f power spectrum density. Instead, I recorded FCEUX's output in Audacity, and when it looked close to -10 dB/decade, I deemed it close enough.
Sour
Posts: 890
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour »

Here's a build with the (unfinished) equalizer UI: link (windows-only build)

It allows you to set all 20 bands from +20dB to -20dB (200 = +20, -200 = -20) and select the filter type ("None" will disable the equalizer completely).
Seems to be working fairly well - at the very least, the output seems to be a lot closer to your recording with the DB values you gave me.
User avatar
nothingtosay
Posts: 39
Joined: Mon May 19, 2014 11:46 pm

Re: Mesen - NES Emulator

Post by nothingtosay »

Cool, thanks for doing that! I recorded the preset with each type of filter. The attached curves show deviation from the hardware recording of the Zelda title screen music. Butterworth allows the closest representation with all frequencies being less than plus or minus 2 decibels off from the reference. Chebyshev 1 is about plus or minus 5 decibels, so that's pretty significant, and then I didn't even bother measuring Chebyshev 2 because if you switch to it it's immediately apparent that it's quite wrong.

I know it'll never be exact with 20 bands, but I figured I'd try to compensate for some of the deviations when using the Butterworth filter. The third attached picture is the same as the second one but zoomed in. The fourth is the result of my efforts at adjusting and you can see it swings up and down over mostly a bit smaller range. The largest valley is at 3 kHz despite us having bands at 2.5 kHz and 3.6 kHz, so you'd think there wouldn't be such nonlinearity in the middle between them, but there it is. That spike up at 12.5 kHz (the tallest one on the right side) makes me think it might be better to delete the 20 Hz band, since it's relatively smooth down there and barely audible even with a subwoofer, and add one at 12.5 kHz since that's much more audible and useful for adjusting treble. Would you mind making that adjustment and letting me test it?

But in the end, this still sounds close as it is, despite the appearance of the curve. And it's not as though every other Twin Famicom is gonna sound exactly like mine so it doesn't need to be a perfect match. RF will have even more tolerance for imprecision since it's not clear what an ideal demodulation method is, if there is one at all. My demodulator is a surprisingly pricey dedicated device ($80 for the model with analog output and $130 for HDMI output; I have the HDMI model) and is probably better than most of the ones built into TVs, so the preset we'll make based on my recording may even sound optimistic compared to what most people experienced back in the day.

P.S. My order for a pin converter is placed and I assume should get to me next week; you can count on NES frequency profiles when it does. The week after that I should get an A/V Famicom in the mail, and that weekend I'll get paid again and buy an NES-101 from a local store. Not sure there'll be big differences compared to other models using the same output method, but there's only one way to find out.
Attachments
EQ Chebyshev 1.png
EQ Butterworth.png
EQ Butterworth zoom.png
EQ compensated.png
Sour
Posts: 890
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour »

I tried a few different games, and haven't been able to hear any change from the 20Hz, 17.5kHz and 20kHz bands.
40Hz is just barely audible with my sub woofer, 15kHz has a pretty audible effect on the sound.

Is there any value in keeping the 17.5kHz and 20kHz bands? Is this just a case of my speakers/sound card/ears not being able to hear the difference?
If not, we could remove those and add 3 more bands to try and smooth out the deviations as much as possible.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Mesen - NES Emulator

Post by tepples »

Back when I was in college, I tested myself and couldn't hear a sine sweep above 17 kHz. So it might be your ears.
User avatar
nothingtosay
Posts: 39
Joined: Mon May 19, 2014 11:46 pm

Re: Mesen - NES Emulator

Post by nothingtosay »

True, way up there isn't very audible, unless you're boosting significantly, otherwise the frequencies get masked by the lower, more audible ones. Plus, many people won't be able to hear 17.5 kHz basically at all and 20 kHz even less. Those bands were necessary for reproducing the shape of th curve at that point, but that's pretty low priority when you can't hear it. So you could try eliminating those bands and rearranging things a bit and, starting after the 1 kHz band, have 2 kHz, 3 kHz, 4 kHz, 5 kHz, 6 kHz, 7 kHz, 10 kHz, 12.5 kHz, and 15 kHz. That would address the largest peaks and valleys, though I wouldn't be surprised if it creates more ripples. But let's give it a shot and see what happens.
Sour
Posts: 890
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour »

I tried a couple of online tests, and it seems like I can't hear anything beyond 15.1kHz or so.

Here's another build: link

I removed the 20Hz, 17.5kHz, 20kHz bands, rearranged the 1+kHz bands like you said, and added another band between 450hz & 1khz:
Before: 450, 640 After: 450, 600, 750

(I didn't change the default dB gains, so the default values don't make sense anymore)
Post Reply