unsigned samples?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
unsigned samples?
by on (#138352)
Hi.

I added an option to output unsigned samples. The pulse waves and triangle have a max output of $0F. What about $4011? It's value & $7F. How is this value "worked" for the proper output?

No, I'm not using that mixer formula.
Re: unsigned samples?
by on (#138355)
If you don't want to do the correct non-linear mixing, you'll want something like sample = 3×(triangle+pulse1+pulse2) + 2×noise + dmc. (http://wiki.nesdev.com/w/index.php/APU_ ... roximation )

Of course, that doesn't fit in a uint8_t anymore. If you want that, you could fake it even more and just use a volume factor of two for the four non-DMC channels.
Re: unsigned samples?
by on (#138381)
I use 16bit samples, pretty like value << 8.

EDIT: well, it seems to sound nicely, but I had to apply a small cut (>> 1).
Re: unsigned samples?
by on (#138406)
If you just want an integer math version of the linear mixing, rather than using a bitshift, multiply the floating point numbers on the Linear Approximation section by 65536:
round(0.00752×65536)=493 (pulse wave channels gain)
round(0.00851×65536)=558 (triangle wave channel gain)
round(0.00494×65536)=324 (noise channel gain)
round(0.00335×65536)=220 (dmc gain)

It won't overflow: 493×30+558×15+324×15+220×127 = 55960 .