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.
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.
I use 16bit samples, pretty like value << 8.
EDIT: well, it seems to sound nicely, but I had to apply a small cut (>> 1).
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 .