APU DAC/mixer

Discuss hardware-related topics, such as development cartridges, CopyNES, PowerPak, EPROMs, or whatever.

Moderator: Moderators

User avatar
kyuusaku
Posts: 1665
Joined: Mon Sep 27, 2004 2:13 pm

APU DAC/mixer

Post by kyuusaku »

How many internal DACs are there? Two (for each pin) or five (for each channel)? If there are two, how is mixing done digitally?
strangenesfreak
Posts: 155
Joined: Thu May 03, 2007 3:07 pm
Contact:

Post by strangenesfreak »

The NESdevWiki article on the APU Mixer says that each channel has its own internal DAC.
User avatar
kyuusaku
Posts: 1665
Joined: Mon Sep 27, 2004 2:13 pm

Post by kyuusaku »

It's unclear from that page whether a channel is the physical pin or the output from each sound generator; I read it as if there are two DACs, which do the mixing, which would make sense.
dvdmth
Posts: 354
Joined: Wed Mar 22, 2006 8:00 am

Post by dvdmth »

It's my understanding that there are five DAC's, one for each sound channel. The square channels, as well as the triangle and noise channels, have 4-bit DAC's, while the DPCM channel has a 7-bit DAC.
"Last version was better," says Floyd. "More bugs. Bugs make game fun."
User avatar
blargg
Posts: 3715
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

The only thing we can say for sure is what pair of output voltages we get for a given set of volumes for the five logical sound channels. The Wiki tells how to calculate the two output pins (with a normalized range of 0.0 to 1.0, rather than the actual voltage). Whether there are electrically five or two DACs doesn't really matter. I recently got a multimeter with an RS-232 interface and will be running an automated test that measures hundreds of combinations of sound channel volumes (there are 256 combinations for the squares, and 32768 for the others), so the formula can be fine-tuned.
evildragon
Posts: 98
Joined: Mon Apr 30, 2007 10:44 am

Post by evildragon »

blargg wrote:The only thing we can say for sure is what pair of output voltages we get for a given set of volumes for the five logical sound channels. The Wiki tells how to calculate the two output pins (with a normalized range of 0.0 to 1.0, rather than the actual voltage). Whether there are electrically five or two DACs doesn't really matter. I recently got a multimeter with an RS-232 interface and will be running an automated test that measures hundreds of combinations of sound channel volumes (there are 256 combinations for the squares, and 32768 for the others), so the formula can be fine-tuned.
If I did the stereo mod, extracting audio from the two audio pins, this messes up that calculation, doesn't it?
User avatar
kyuusaku
Posts: 1665
Joined: Mon Sep 27, 2004 2:13 pm

Post by kyuusaku »

blargg wrote:Whether there are electrically five or two DACs doesn't really matter.
It sort of matters to me, I'm going to try to put the APU in a FPGA and would like to eventually match the output level and resistance so I can plop my two outputs right into a similar circuit as the original system. Right now I'll try to approximate your normalized measurements with 5% resistor DACs :lol:

BTW, is there a logged NES audio format like VGM? That would help a lot; I don't have a CPU yet.
User avatar
blargg
Posts: 3715
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

Yes, the stereo mod changes things since you decide how much they are mixed and at what levels.

A logged NES format would be nice for some uses. I'd like th eventually make a logged format suitable for any system, that my sound library could output to for things like this. No reason to have different formats for each system, since logged data is much more similar than ROM-like formats.

kyuusaku, I found my original notes about how the DACs likely work. It's the model I based the formulas on:

DACs appear to be implemented with resistors added together. Approximate resistances generated by each DAC, in ohms, where dac is the value to the dac:

Code: Select all

rdac = runit / dac
Each DAC has its own runit:

Code: Select all

square runit   =  8128 ohms
triangle runit =  8227 ohms
noise runit    = 12241 ohms
DMC runit      = 22638 ohms
Thus, the DMC's DAC at 127 (maximum) acts like a resistor of approximately 178 ohms (22638 ohms / 127).

The DMC, triangle, and noise DACs are connected in parallel to form group 1. The two square DACs are connected in parallel to form group 2. The resistance of a each group can be calculated as follows:

Code: Select all

                              1
rgroup1 = -------------------------------------
          1 / rdmc + 1 / rtriangle + 1 / rnoise

                         1
rgroup2 = ---------------------------
          1 / rsquare1 + 1 / rsquare2
A voltage output for each group is generated by forming a voltage divider with a 100 ohm resistor tied to ground (this is external to the chip), using a 1.17 V input voltage (internal to the chip). The output voltage can be calculated as follows:

Code: Select all

         1.17 * 100
vout =  ------------
        rgroup + 100
The two groups are mixed via 12K and 20K resistors (external to the chip), forming another voltage divider. This can be approximated by simple scaling factors:

Code: Select all

vout = 0.625 * vgroup1 + 0.375 * vgroup2
tepples
Posts: 22720
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

kyuusaku wrote:BTW, is there a logged NES audio format like VGM? That would help a lot; I don't have a CPU yet.
There is NESA, which A/NES emits, but I don't know of any NSF players or PC-based NES emulators that can output NESA, nor any PC-based players that accept NESA.
User avatar
kyuusaku
Posts: 1665
Joined: Mon Sep 27, 2004 2:13 pm

Post by kyuusaku »

So 1.17V is the peak output from each pin when unloaded?

Image

(diagram makes some probably very wrong guesses, like which pin is which & the output R should be 66 instead of 166 I guess)
User avatar
blargg
Posts: 3715
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

I don't have anything beyond those notes. The way I describe it, the voltage divider is formed only once you add the external 100 ohm resistors to ground. Maybe someone more familiar with building these things can offer some theories.
User avatar
kyuusaku
Posts: 1665
Joined: Mon Sep 27, 2004 2:13 pm

Post by kyuusaku »

Well I'm definitely not an expert but they way I see it, each bit acts as a current source when on, so the joined current through the output resistor gives your desired level. The only other thing to consider (I think) is the Thevenin resistance out so you can predict the level under load, but in this case it should just be the output resistor.
User avatar
Bregalad
Posts: 8060
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Post by Bregalad »

Those 100 ohm resistors always made me wondering, they should drain most of the output's power, leaving almost nothing for the rest of the circuitry, which has to re-amplify the signal again. Isn't this very unoptimal ?
Useless, lumbering half-wits don't scare us.
tepples
Posts: 22720
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Bregalad wrote:Those 100 ohm resistors always made me wondering, they should drain most of the output's power, leaving almost nothing for the rest of the circuitry, which has to re-amplify the signal again. Isn't this very unoptimal ?
What matters in an audio signal is the voltage. Power comes into play when amplifying at the output.
User avatar
Bregalad
Posts: 8060
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Post by Bregalad »

Maybe, but still this drops power, and bring unnecesary heat to the CPU chip itself (as it probably drives useless curent in the 100 ohms resistors in the only goal to create a small voltage), and this decreases the power ratio of the system.
Useless, lumbering half-wits don't scare us.
Post Reply