NES DMC Saw Wave

This describes a way to generate saw waves using the NES DMC channel. It uses the DMC interrupt for sound generation so it doesn't use much CPU time.

The DMC is used to repeatedly play a 1-byte sample at various frequencies to total one wave period. IRQ generation is enabled so that processing can be done each time the DMC finishes a sample. Each wave period the DMC's DAC is reset to the current volume. The sample is all 0 bits and is used to slowly decrement the DAC back to 0 during each wave period. With lower volumes, the DAC will reach 0 before the end of the wave, which isn't a problem because the DMC avoids wrap-around. Multiple segments are necessary because the DMC only has 16 frequency settings, and because the DAC needs to be decremented by more than 16 for sufficient volume.


Output of NES playing various saw waves made up of 4 DMC samples of different frequencies

An earlier version of this hack has more diagrams.

With slight modification the DMC can be made to generate other waveforms. A square wave can be generated by using a $55 sample (basically a flat line), and a triangle wave using $ff and $00 samples for positive and negative ramps.


Back to Blargg's Miscellaneous