The Famicom's and the NES's Audio Path

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
The Famicom's and the NES's Audio Path
by on (#262)
I always thought the Famicom's audio path was rather odd, at least how it related to special chips. But today, after looking at the Famicom's schematics I finally figured it out. After the 2A03's internal five channel audio is outputted and mixed (any input from the second controller's built-in microphone is added at this point), it goes to the cartridge connector pin #45. If there is extra sound hardware in the cartridge the sound will be mixed with the NES's internal sound, then be outputted from pin #46 to the audio output and thence to the speakers. If there is no sound hardware on the cartridge, then the cartridge will connect pins #45 and #46 together, making a loop that goes straight to the audio output without further ado.

On the NES, the addition of the unused expansion port complicates matters somewhat. The NES's audio is routed straight to an RCA jack and the RF circuitry. Pin #3 is audio input. This allows sound produced on a cartridge to be mixed with the NES's sound. In contrast to the Famicom, which mixed expansion sounds in the cartridge, the NES must mix the sounds inside the console itself. All you have to do is get pin the Famicom cartridge's pin #46 to pin #3 of the expansion connector.

by on (#284)
I solved this problem a different way.
Inside the NES there is junction point where audio from the input of the 2A03 is mixed with the input of the bottom connect, its easy to spot because there are 3 22K resistors lined up.
I used an unused pin (typically) of the NES edge connector (pin 18), passed it from pin 46 of the famicom (audio out), through a 4.7uF non-polar cap and a 100K resistor to raise the impedance, into one of the 22k resistors (audio junction).
It works great, Akumajo Densetsu sounds great, as does the FDS (another story).

I'll tryand get pictures.
Re: The Famicom's and the NES's Audio Path
by on (#205478)
Apologies for resurrecting an old thread, but it seemed the most appropriate place to ask my question...

What signal / voltage level is expected at that 22K resistor, coming in from the NES expansion port?

I would like to directly attach a 0-5V PWM signal from a microcontroller, but my feeling is that is going to overload or distort the input, and will probably need some extra circuitry in place?
Re: The Famicom's and the NES's Audio Path
by on (#205491)
OK, some more digging, there aren't 3 x 22K resistors - actually 2 x 20K and 1 x 12K.

Looking at schematics, 'Audio In' (pin 3 on the Expansion Port) feeds into R9 (20K resistor) before the 'amplifier' circuit... so definitely seems like putting 5V into a circuit that expects something much smaller, needing amplification, is a bad idea.

Would adding in a 47K resistor for a total of 67K resistance (as seems to be the standard for audio coming from a PowerPak) be enough to safely input the 5V signal?

Attachment:
dscn0510.jpg
dscn0510.jpg [ 103.05 KiB | Viewed 5867 times ]

Attachment:
NESAudio.gif
NESAudio.gif [ 4.15 KiB | Viewed 5867 times ]

Attachment:
schem4.jpg
schem4.jpg [ 122.22 KiB | Viewed 5867 times ]
Re: The Famicom's and the NES's Audio Path
by on (#205492)
It's hard to give you a straight answer without directly measuring the voltages on CPU pins 1/2.

You can be confident, however, that if you choose the same voltage range as CPU pin 1, due to the 20kΩ resistor from the expansion port, it'll be the same voltage (loudness) after all three signals are mixed together.

If you want to use a 5Vpp source, and CPU pin 1 is less than 5 Vpp, then you should be able to effectively match the volume by setting the currents to match—e.g. if Vpp(one pulse wave at maximum volume) is 1V, and you want your output to be the same volume, then adding 80k in series should make the volumes match. (80k+20k=100k ; 100k/20k = 5 = 5V/1V)
Re: The Famicom's and the NES's Audio Path
by on (#205531)
lidnariq wrote:
It's hard to give you a straight answer without directly measuring the voltages on CPU pins 1/2.


Absolutely. Your reply was very helpful though, thanks!

Dug out my PropScope and the NES today and took some measurements from those CPU pins. Showed a voltage range of around 0.3V (ranging from around -0.226V to +68.9mV).

So I should be aiming to attenuate that 5V signal down to around 0.3V then?

Attachment:
0.png
0.png [ 233.69 KiB | Viewed 5799 times ]


PS. Testing was done using the 'test2-mmc3.nes' ROM from https://ahefner.livejournal.com/12368.html - pulse set to full volume:

Attachment:
test2-mmc3-0.png
test2-mmc3-0.png [ 2.24 KiB | Viewed 5799 times ]
Re: The Famicom's and the NES's Audio Path
by on (#205532)
uXe wrote:
So I should be aiming to attenuate that 5V signal down to around 0.3V then?
Depends on how many different audio signals your microcontroller is generating.

If you're just generating a single pulse wave, and you want that pulse wave to be the same volume at maximum as the NES's pulse waves, which are 0.3V, then yes; this attenuation could be achieved by putting an extra ≈313kΩ in series with R9. On the other hand, if you're mixing 4 waves, and you want all of them to be the same volume, you'd want to add ≈63kΩ.

But ... I have to admit I'm a little surprised it's only 0.3V. I'm also really surprised the voltage went negative: that's supposed to be a unipolar pull-up DAC inside the CPU (with an external 100Ω pulldown resistor)—nothing should be creating negative voltages here.
Re: The Famicom's and the NES's Audio Path
by on (#205533)
lidnariq wrote:
But ... I have to admit I'm a little surprised it's only 0.3V. I'm also really surprised the voltage went negative: that's supposed to be a unipolar pull-up DAC inside the CPU (with an external 100Ω pulldown resistor)—nothing should be creating negative voltages here.


I read something about negative current here:

http://nesdev.com/2A03%20technical%20reference.txt

+-----------+
| 4-bit DAC |
+-----------+
"This is just a standard 4-bit DAC with 16 steps of output voltage
resolution, and is used by all 4 sound channels. On the 2A03, rectangle wave
1 & 2 are mixed together, and are available via pin 1. Triangle & noise are
available on pin 2.

These analog outputs require a negative current source, to attain linear
symmetry on the various output voltage levels generated by the channel(s)
(moreover, to get the sound to be audible). Instead of current sources, the
NES uses external 100 ohm pull-down resistors."

Was reading another thread earlier that may help indirectly explain too, that this negative DC offset out of the CPU pins is corrected in the mixing / amplification circuit:

viewtopic.php?f=3&t=11432#p131160

Would be great if somebody else could confirm my readings on their own NES though.
Re: The Famicom's and the NES's Audio Path
by on (#205534)
I have an oscilloscope, but unfortunately nothing resembling a useful test cart. (I still just have the ridiculous m218 cart I made)

Taking a random game and looking at pin 1, I see voltages approximately around 0.3V(max) and 0V(min)... so I guess the range is accurate.

(Did you set your 'scope to AC coupled? Or failed to connect ground? Not important, tho.)
Re: The Famicom's and the NES's Audio Path
by on (#205535)
Had to look up Mapper 218 - love it! :D

Good to at least have confirmation of the 0.3V - thanks again for all of your input on this!
Re: The Famicom's and the NES's Audio Path
by on (#205542)
lidnariq wrote:
I have an oscilloscope, but unfortunately nothing resembling a useful test cart. (I still just have the ridiculous m218 cart I made)

I have an assembler. What would you like to see in a mixing test cart designed for mapper 218?
Re: The Famicom's and the NES's Audio Path
by on (#205545)
If you're offering your time...

There's two separate measurements to be made. Pin 1, for the pulse waves, is simpler. There doesn't seem to be any realistic bandwidth constraints, so just picking the maximum frequency, a 3/4 duty cycle, and letting me adjust the volume for each of the two channels independently, would be good enough.

Pin 2 is a little hairier because the triangle wave can't be set to a fixed value — at least not without trying tying CPU pin 30 to CPU A3. It doesn't seem wrong to just ignore it and just set the pulse wave volume and DPCM DAC. Although maybe some cleverness can ease measurements of the triangle wave as well?

... huh, to describe the actual problem is to put it in scope.
Re: The Famicom's and the NES's Audio Path
by on (#205554)
lidnariq wrote:
the triangle wave can't be set to a fixed value

You can advance its position by a fixed amount, though. If you're willing to take 32 measurements you could put it into every phase? (Or with live/interactive measurement you really could just set the phase how you want this way.)
Re: The Famicom's and the NES's Audio Path
by on (#205555)
I forget: Does the Reset button do anything to triangle phase? Or should this be included in the test ROM?
Re: The Famicom's and the NES's Audio Path
by on (#205556)
The triangle phase, tri_c0 through tri_c4, is cleared on reset. For example, check visual2a03 t13993.
Re: The Famicom's and the NES's Audio Path
by on (#205661)
Quote:
I would like to directly attach a 0-5V PWM signal from a microcontroller

Did some testing of my own because I'm looking to do the same thing!

My test is pretty simple. I've attached it in case anyone else want to try. The rom only runs from $E000-FFFF so it should be fairly mapper independent assuming the last bank is fixed. Visually it doesn't display anything worthwhile, just some junk from my CICOp register test.

Only SQ1 & SQ2 channels are enabled, SQ1 is set to C4 (middle C) and SQ2 is set to E4. Both have 50% duty and max volume.

I did not find any negative voltage. I found a max output level of 350mV (note 10x probe used in scope shot) this is when both channels are active (summed). When only one channel was pulsing high, it's output is 200mV.

I can run some other simple tests like this if it's of interest, but this pretty much answered my questions.
Re: The Famicom's and the NES's Audio Path
by on (#205662)
infiniteneslives wrote:
Did some testing of my own because I'm looking to do the same thing!


Great minds :wink:

...and you plan on adding 313K of resistance to compensate? or you have a better solution in mind?
Re: The Famicom's and the NES's Audio Path
by on (#205663)
uXe wrote:
...and you plan on adding 313K of resistance to compensate? or you have a better solution in mind?


What's your thinking on 313K? 0-5v signal from mcu, trying to get down to 200mV is a factor of 25. Thus you need 20k * (25 - 1) = 480K..?

Being a PWM DAC, it's fairly easy to reduce the synthesized channel to less than 5v. In an 8bit DAC a simple implementation would be for a square channel to have 4 bits of volume similar to the APU/VRC6/etc. So the channels max would be a DAC level of 15 out of 255 equates to 5.9% of 5v = 295mV for that channel without tweaking anything. A little beyond the target 150-200mV per channel to match the APU.

Couple ways to tweak things to match. An added 20K resistor would work, but I kinda like/have to assume many people simply soldered in a 47k for the audio mod. That's my preferred condition, and then adjust the PWM levels to match. So 67k divides that channel by 3.35, so 295mV -> 88mV equavalence if I'm understanding everything.

To get to a volume comparable to the APU, the level needs doubled bringing it to ~175mV. That can be done in the mcu by shifting the final output volume left by 1 bit. Sort of cuts an 8bit DAC down to 7bits in terms of number of total full volume channels prior to clipping, but that's manageable. 7bits would provide room for quite a few full volume channels at once. The lower bit really isn't lost either, channels could simply have 5 bits of volume to equal an APU square if they've got a use for the extra resolution.

P.S. I'm guessing I've made an error in my math/knowledge somewhere..
Re: The Famicom's and the NES's Audio Path
by on (#205667)
infiniteneslives wrote:
What's your thinking on 313K? 0-5v signal from mcu, trying to get down to 200mV is a factor of 25. Thus you need 20k * (25 - 1) = 480K..?


Was just going on lidnariq's numbers from earlier in this thread:

viewtopic.php?f=9&t=56&start#p205492

Both CPU pin 1 and Expansion Port pin 3 feed into separate 20K resistors in the audio mixing / amplification circuit, so to match CPU pin 1's 0.3V as I understand it: 5V / 0.3V = 16.666666667 * 20 = 333.333333333 minus the 20K already in place equals 313K?

My problem is that I would not be using a DAC with amplitude settings, and be able to just reduce the signal down that way. I'm looking at a PWM pin on an 8-bit AVR, or likely just software PWM on a digital pin, so it's either on or off, 0 or 5V, full stop.
Re: The Famicom's and the NES's Audio Path
by on (#205669)
It may actually be a benefit if an ext audio synth is a bit quieter than the internal APU.

This is because the steps between the 15 audio levels are quite coarse. Less full volume = finer steps, leading to smoother envelopes; something the APU can't* offer but a synth with a similar 4-bit interface can. That would enable using slow-moving envelopes (in a satisfactory/transparent way) more readily.

The max volume of the APU squares aren't very useful, IMO. There's many times i've wished for an "x.5" setting but i've never felt the need for maxing the squares. Rather, i avoid it.


*There's a workaround for the apu wich is chorusing two square channels and then you can kind of get doubly fine volume steps at the expense of independent movement/having the sound to be slightly detuned. Sometimes, you can even hide the coarse stepping in a second square voice at another interval than unison, but it is circumstantial (dependent on the harmonics of the tone, i presume).
Re: The Famicom's and the NES's Audio Path
by on (#205676)
uXe wrote:
Was just going on lidnariq's numbers from earlier in this thread:
313K assumes the APU channels have a max volume of 300mV. Take it for what it's worth, but based on my testing a single APU square @ max volume is more like 150-200mV. 300-350mV is both squares summed, I'm guessing that is what your and lidnariq's tests were measuring.

Quote:
My problem is that I would not be using a DAC with amplitude settings, and be able to just reduce the signal down that way. I'm looking at a PWM pin on an 8-bit AVR, or likely just software PWM on a digital pin, so it's either on or off, 0 or 5V, full stop.
Oh my bad, I read too far into your statement, I thought you were implementing a PWM DAC too. Your single square channel with invariable volume will be pretty limited.. Why not add a cap to your resistor to unlock your 8bit AVR's PWM DAC ability.? Give yourself ability to adjust the channel's volume, even allows multiple channels of varying shape if you want to get fancy. Obviously up to you, but just wanted to make sure you were aware of how simple a PWM DAC is to implement on a 8bit mcu. Open music labs has a pretty good article that showed me the light, along with an arduino sketch tutorial.

FrankenGraphics wrote:
The max volume of the APU squares aren't very useful, IMO. There's many times i've wished for an "x.5" setting but i've never felt the need for maxing the squares. Rather, i avoid it.
As always, thanks for the insight, these are the types of things I don't have a good sense for.
Re: The Famicom's and the NES's Audio Path
by on (#205680)
infiniteneslives wrote:
313K assumes the APU channels have a max volume of 300mV. Take it for what it's worth, but based on my testing a single APU square @ max volume is more like 150-200mV. 300-350mV is both squares summed, I'm guessing that is what your and lidnariq's tests were measuring.
Exactly.

If the OEM pulse channels are 150mV each into 20kΩ, then that's 7.5µA at max; 5V and 7.5µA is 670kΩ. To match the NES's built-in 20kΩ and the typical 47kΩ added, I'd assume you'd want a ≈600kΩ resistor out of the PWM DAC ... if it's still only one channel being mixed in.

Personally, I'd be tempted to mix multiple channels.

uXe wrote:
My problem is that I would not be using a DAC with amplitude settings, and be able to just reduce the signal down that way. I'm looking at a PWM pin on an 8-bit AVR, or likely just software PWM on a digital pin, so it's either on or off, 0 or 5V, full stop.
It's completely ridiculous, but you could add an external resistor DAC to add volume control without having to manage the IRQs from a PWM DAC.

Something like:
Code:
 PWM ---R---+
 PA0 ---R---+
 PA1 --2R---+
 PA2 --4R---+
 PA3 --8R---+---500k---expansion port


And you could then toggle bits in DDRA to adjust the volume.


I say "ridiculous" because in practice, your microcontroller is probably not too busy to manage updating the PWM value to serve as a DAC.


FrankenGraphics wrote:
The max volume of the APU squares aren't very useful, IMO. There's many times i've wished for an "x.5" setting but i've never felt the need for maxing the squares. Rather, i avoid it.
In thinking about this, it occurs to me that we could sink current out of the mixing node to add software-controlled master volume control.

If we had something like this:
Code:
                              ||
                   +--- expansion port --- 20k --- mixing node
                  /           ||
 PWM ---R-+-+---|< npn        ||
          | |     \           ||
          R C      |          ||
          | |      |          ||
          +-+------+--gnd     ||
although it might be more useful to pull the mixing node up to 5V (instead of pulling it down to ground as in this schematic) for greater dynamic range.
Re: The Famicom's and the NES's Audio Path
by on (#205681)
lidnariq wrote:
master volume control

:shock: Sounds like it could be useful for:
-fade in/out
-half-mute (for example in a menu).
-tri envelope when playing solo
-super-exponential decays/swells of squares/noise/samples playing solo or with shared rythm
-maybe even improved dynamic range and/or fizz reduction of samples

Quote:
to pull the mixing node up to 5V.


For one thing, many studio synthesizers use a swing of 5v or even greater for audio prior to the output stage - this to keep the noise floor down relative to the signal on analog audio lines. This becomes increasingly important when mixing a large number of signals; effectively raising the noise floor.

Consumer-grade outputs however have a nominal swing of 0.447V peak-to-peak using a single sine, or more importantly 0.316V root mean square (pretty close to the NES?)

Studio equipment should have a nominal output of 1.228Vrms.

I think Sunsoft 5B audio breaks the consumer-grade nominal levels by quite a bit. It has one benefit, though:
using its coarse, loud squares as the reference point, it'll relatively push the full APU dynamic range into useful range and make its steps seem finer by comparison. Use Sunsoft for quick and loud envelopes, and the APU's for "quiet" and more nuanced/slow ones. This has the unfortunate side effect of the hypothetical game/music becoming the loudest in the nes library and will see users reaching for the volume control of their tv/speakers/laptop, but fwiw it almost works like having a finer envelope range.

Then the sunsoft synth has that 5-bit internal hardware envelope to mitigate its coarseness, but no game has ever used it...
Re: The Famicom's and the NES's Audio Path
by on (#205682)
lidnariq wrote:
we could sink current out of the mixing node to add software-controlled master volume control.

If we had something like this:
Code:
                              ||
                   +--- expansion port --- 20k --- mixing node
                  /           ||
 PWM ---R-+-+---|< npn        ||
          | |     \           ||
          R C      |          ||
          | |      |          ||
          +-+------+--gnd     ||


This ability would be significantly more limited if operating with the assumption of a fixed 47k EXP port audio mod right? Gives more reason to include the pot in my EXP port dongle..

I'm a little confused how one would integrate expansion audio channels and master volume at the same time in terms of the PWM DAC's output level calculation.
Re: The Famicom's and the NES's Audio Path
by on (#205685)
Rather than BJT tomfoolery, it's probably better to just pretend we're going to use a digitally controlled potentiometer. Then it's a lot easier to see what's going on:

Code:
pin1 -- 20k --+
pin2 -- 12k --+-- 1uf -- rest of audio hardware
              |
    +-- 20k --+
    |
   pot
    |
   gnd


Quickly playing around with falstad's circuit simulator, assuming pin1 is a 150mV(max) square wave and pin2 is just 100Ω to ground, adjusting the pot between 0 and ∞ yields 41mVpp to 56mVpp ... that's not very good, only a couple dB

That 20k resistor is a pain.

Fine, so we add a negative impedance converter to undo the 20k that we can't get rid of. It'll require that we synthesize a negative voltage, but this already crazy analogland, so whatever.

And, yup: that lets us get an arbitrary volume attenuation. Synthesizing a different regulated choice of "ground" for the NIC other than 0V should make it possible to not need sophisticated power circuitry to create a negative voltage:

Code:
pin1 -- 20k --+
pin2 -- 12k --+-- 1uf -- rest of audio hardware
              |
    +-- 20k --+
    |
    +-- pot --+
    |         |
    |  |\     |
    +--|+ \   |
       |    >-+
    +--|- /   |
    |  |/     |
    |         |
    +-- 10k --+
    |
    +-- 10k -- Vreg
A 20k pot here would become a -20k pot. When set to -20k, we've magically made a 0 ohm resistor and attenuation is ≈infinite. When set to 0, it's only 3dB (20·log10(56÷41)) quieter than without this add-on hardware.


Quote:
I'm a little confused how one would integrate expansion audio channels and master volume at the same time in terms of the PWM DAC's output level calculation.
The math becomes gross but it should still be doable. An electrically super simple and lazy option would be to replace Vreg with the external mixed in audio signal, but the mixing equation becomes a little weird.



If we're going to be even more completely ridiculous, a NIC allows us to multiply the complex reactances of three different passives. By changing some of them to have some imaginary component (e.g. a capacitor or inductor) we can instead have a programmatically controlled high-/low- pass audio filter.