Interactive NES audio tutorial
Hello! This application is based on the Nerdy Nights Audio Tutorial but aims to be more accessible and interactive, providing a built-in 6502 assembler and APU emulator for runnable examples. The NSF is dynamically built from the editor contents, so you can change things and hear the result.
Before you can use the channels to produce sounds, you need to enable them. Channels are toggled on and off via register $4015:
76543210
|||||
||||+- Square 1 (0: disable; 1: enable)
|||+-- Square 2
||+--- Triangle
|+---- Noise
+----- DMC
Writing the value %00000001
to register $4015 sets the first bit to 1 (on), enabling the Square 1 channel.
Square 1 is controlled by registers $4000-$4003. The first one, $4000, looks like this:
76543210
||||||||
||||++++- Volume
|||+----- Hardware Envelope Disable
||+------ Length Counter Disable
++------- Duty Cycle
In this tutorial, we will not be using the length counter or hardware envelopes at all. This is the most common approach because you get more control by setting the volume and duration manually.
The period lengths are 11 bits, so they are divided between 2 bytes:
Period low - $4002
76543210
||||||||
++++++++- Low 8-bits of period
Period high - $4003
76543210
||||||||
|||||+++- High 3-bits of period
+++++---- Length Counter