Sunday, January 7, 2018

Analogue Nt Mini : Audio Tweaking

The Nt Mini's audio has come under some criticism from such luminaries as the My Life in Gaming channel.  Kevtris has fixed NES audio issues in Jailbreak firmwares v1.0 (MMC5 pulse pitch), v1.3 (audio sweep bug), and v1.8 (crackling static issue).  The excellent MLiG video was using v1.2, so its statements may not hold true for the latest official or jailbroken firmware.  Even so, it is hard to diagnose and fix a problem without being able to define the problem or demonstrate it in a way that would illustrate the problem to the less-technical viewer.  The MLiG video said little more than "We feel that sound might be somewhat further removed from the original hardware experience than any other aspect of the system."  

That MLiG comment is so vague as to suggest that the Nt Mini could be outputting reversed-duty cycle pulse waves like a Famiclone or too low pitched noise as with the NES Classic Edition, which it clearly does not.  Nonetheless, a more articulate critic of kevtris' APU implementation in the Nt Mini and Hi-Def NES Mod is that in certain musical tracks, the triangle and noise channels are too quiet compared to the two pulse channels.  In order to talk about this claim, first we must discuss the mixing levels of NES APU channels.

As is well known, the NES internal audio consists of five channels, two pulse wave channels, a triangle wave channel, a noise channel and a DPCM channel.  Pulse waves tend to be the melody and the accompaniment of a music track whereas the triangle is typically used as a rhythm line and the noise as percussion.  Later games tend to use Delta Modulation for drums and percussion.  It can also be used for crude speech.  Software driven 7-bit PCM was used for realistic speech and digitized sound effects but tended to be used during non-interactive portions of a game.  All channels can be used for sound effects, which tends to rob the music of notes at times.

The first four internal audio channels in the NES (pulse 1, pulse 2, triangle, noise) have 16 levels (4-bit) of volume output.  Programmed volume output for these channels appears to be more linear than logarithmic.  The DPCM channel has 128 levels of volume output (7-bit).  The pulse waves are combined into one output pin on the original NES CPU while the triangle, noise and DPCM are combined into the other output pin.  Pulse waves, especially in their square wave form, tend to sound louder than triangle or noise.  They spend more time at a particular volume level than the triangle (which continually ramps up and down the volume levels) and at a stable period of frequency compared to noise (which randomly adjusts frequency very frequently).  Plus there are two pulse waves, so they tend to hog the audible spectrum if the DPCM channel is not being used.  DPCM also does not allow volume levels to be set, the sample itself determines the volume levels

The way these channels are mixed is rather complex and is defined here :

The summary for those of you who are not technically inclined is that at the same volume levels, triangle is louder than noise, which is louder than pulse.  Two pulses will be louder than triangle or noise, but triangle and noise will be louder than pulse.  DPCM can be far louder than any of the other channels.  Here are a pair of graphs that show the relationships between the channels at identical volume levels :

The graph chart shows a closeup of the first fifteen volume levels, where things are more interesting.  I have used the equasions found on the site above to make these graphs.  As you can see, volume levels are more linear, but volume combinations are not a simple addition between different channels except for the combination of the two CPU pins.

We can see a similar near-linear relationship between the volume levels from both the official Nintendo hardware and the Nt Mini.  Consider the following waveform illustration :

The first waveform consists of pulse waves taken at each volume level, then followed by a lengthier sample of the triangle wave (around the 1 minute mark) and finalized by the noise channel taken at each volume level on an AV Famicom.  The second waveform is the same except for the Nt Mini.  The AV Famicom's illustration is longer for no particular reason.  Unfortunately I could only set the output of one channel at a time.  Note that the volume levels are still pretty linear from both systems.

The mixing inside and outside the CPU of the front loading NES, Famicom and AV Famicom are identical assuming resistor tolerances of 5%.  At their maximum programmed volume output, the triangle wave (-9.9/-14.9, peak/RMS) is louder than one pulse wave (-11.7/-14.2) at their respective peaks.  The noise channel is (-9.3/-13.7) can also be louder than the pulse wave at equally programmed volume levels.  The Nt Mini's triangle and noise channels are too quiet compared to the pulse channel.  Given that the use of two pulse channels increases the volume from those kind of sounds, having a balanced audio output from each channel would not have served Nintendo's purpose.  Feel free to take a listen for yourselves :

Kevtris' Hi-Def NES has a single volume slider for the internal audio, each channel's audio cannot be independently adjusted.  But the genius of the Nt Mini is that the internal audio channels can be individually adjusted through the audio volume menu.  Each channel and most of the expansion audio channels is given a slider from 00-FF, giving 256 linear steps of volume control.

The Nt Mini's default volume mixer settings are 40 for all internal channels, 60 for N163, 80 for MMC5, VRC6 and AY-3-8910, 20 for FDS and 40 for VRC7.

For the internal audio, I would suggest keeping the "square" volumes at 40 and adjust the other levels.  Put triangle to around 4C and the noise to around 57.  A single nudge of the slider will not lead to a great deal of audible change, I would suggest adjusting in increments of 4, 8, 12 or 16.  I knocked the DPCM channel down to 3C because it tends to drown out other channels when set to the default.

I really do not recommend that you fiddle with the external audio adjustments, they sound pretty good.  Even though for example the MMC5's pulse wave channels are supposed to be as loud as the internal pulse wave channels, the 80 setting for MMC5's pulse channels seems to maintain this volume parity with the internal channels being set to 40.  N163 is the exception, each game used different values of mixing resistors.  I would use the information contained here : for a guide on how to adjust the levels.  The default level seems to be around the 6x level given in the chart at the bottom of the page.

I have put together some sound samples of real cartridges running on a real pre-GPM Famicom to give you examples of the proper volume balance between the internal APU and external audio if you feel that the default Nt Mini's mixer are not doing them justice :  (125MB download)

Legend of Zelda 2 uses expansion audio for the title screen music and somewhat sparingly for in-game sound effects.  Listen at 0:26 for a flute like sound and at 1:54 for "speech", this is the expansion audio.  Bio Miracle, Akumajou Densetsu, Rolling Thunder and Lagrange Point use expansion audio almost exclusively for music.  Gimmick uses expansion audio for the star attack but also uses it to supplement the music, more as you progress further in the game.

You may have noted that these recordings are not quite so crisp as they might be from an AV Famicom.  That is because I used the only official way to receive audio and video input from a Famicom, through the RF Modulator.  That was attached to a VRC, set to channel 96 and then the VRC turned it into composite video and audio.  That audio output is what was recorded.  If it sounds more muffled than you are used to, note that there is strong low-pass filtering going on in an RF Modulator.

Kevtris indicated that he lacked the FPGA resources to implement a low pass filter for FDS audio, there just were not enough multipliers to implement it.  This may not necessarily be a bad thing, and I have been meaning to comment on it since my first blog entry in this series.  When internal audio is mixed with the FDS audio, a low pass filter is applied to all audio I believe.  The Nt Mini does not send analog audio to the Famicom slot to be mixed in like a real system, it digitizes whatever audio comes from the Famicom slot.  So when you use a FDS Adapter in the Nt Mini, the audio from it sounds rather muffled compared to the internal audio.  However, if you use the Nt Mini's FDS audio feature instead, you will hear FDS audio of comparable crispness to internal audio.  I would rather have internal and external be crisp or muffled rather than have one crisp and the other muffled.  [I do not mean to imply that "crisp" is superior to "muffled" or vice versa here, these are just terms I used for convenience.]

The Nt Mini's internal audio, at the default settings, is nowhere nearly as loud as an AV Famicom.  You need to get the internal audio levels into the A0-B0 territory before you can compete with the base volume level from the AV Famicom.  However, this can have a deleterious effect on dynamic range and may prevent proper balance of the volume levels, so use your volume dial on your speakers instead.  Moreover, once you start adjusting the internal volume levels, you have to adjust the external volume levels to compensate.

One interesting feature of the Nt Mini can be found in the Core - Audio menu.  This menu is available both for the NSF player as well as the NES Core.  In this menu there is a setting to "disable looped noise."  What this does will not likely be apparent to most people.  The looped noise function is a bit that turns ordinary noise into a shorter sound.  This has the effect of making the noise sound much more metallic.  The short noise can be heard in the music for Fire Man's stage in Mega Man 1 and Quick Man's stage in Mega Man 2.  Looped noise did not exist in the original revisionless 2A03 CPUs found in the oldest Famicoms.  The game over music in Balloon Fight, an early game, may use the short noise by mistake as the last note.  In order to use the looped noise function, you must enable it every time you load a game.  Don't count on the looped noise to be disabled if you see the checkbox next to the option marked, manually uncheck and recheck the box to ensure it will be disabled.  There is another feature called "disable square reload", but it does not seem to have any function.

The NSF player provides the same audio options as the NES Core, so you can set volume and panning levels independently.   The NSF player runs on the NES Core and is essentially a ROM that is aware of the Nt Mini and can use it to load NSF files.  kevtris created the original NSF specification, and the Nt Mini follows that specification.  The original NSF had no issue with just about anything except 7-bit PCM.  PCM requires IRQ usage for timing, which may conflict with other usage of the IRQ by the NSF player.  It is much easier to handle IRQs through software emulation than hardware simulation.  The result is that for some NSF files that use PCM, when played on the Nt Mini the NSF may not load, may not be able to switch tracks within the NSF or may not be able to play another track until the PCM sample is finished playing. 

Update 01/18/17 : I did not initially know what the "disable square reload" function did, but kevtris recently explained it.  Oddly enough, the way it arose was when I identified an issue with the Time count-down sound at the end of a level in Super Mario Land for the Game Boy.  He initially thought I was talking about a similar sound effect in Super Mario Bros. for the NES.  He explained that the "disable square reload" option will turn the ringing Time count-down in Super Mario Bros. into a constant tone.  Fortunately the option is disabled by default, but turning it on gave me the constant tone.  Kevtris put the feature in there because some NSF files sound better with the disable square reload option on. 

The Time count-down sound in both games sounds very similar.  What I believe is happening is that in the NES when you write a value to one of the pulse wave's length counters, it will reset the sequencer which is generating the pulse wave.  This can cause an audible click or pop or in this case, ringing.   However, some NES emulators also reset the pulse wave clock divider, which results in the constant tone.  The pulse wave channels behave very similarly in the NES and the Game Boy, so it appears that this feature was not included on the Game Boy core.  Now that kevtris knows about it, it should be a quick bug-fix the next time he gets around to updating his Nt Mini Game Boy core.  

1 comment:

Anonymous said...

Kevtris' comment to this article: "I do not have the "Exact" mixing a real system does, because it isn't possible to have true stereo if you do. This was a tradeoff I made to allow stereo. The DPCM level (i.e. 4011 write, where the DAC ends up after a DPCM sample) affects triangle/noise volume a little bit. I had this in there originally, but took it out to make the channels stereo. If I kept it in, then there would've been channel crosstalk between all the channels and it would've sounded pretty terrible.

As for expansion volume relative to the main channels, it can vary from revision to revision of the famicom, and things like N163 have different value resistors to control volume, so that's why there are sliders. Also, some people tend to like some channels louder or softer than others, as well."