Sound and music - Falmouth-Games-Academy/comp310-wiki GitHub Wiki

Introduction

There is music available for the NES (Nintendo Entertainment System). The most common file type for music storage on the NES is NSF (Notes Storage Facility) format, which packages data for one or more songs along with code for code from the 6502 architecture to play it back. NSF files are not only limited to the NES they can also be played on a PC with an appropriate player.

Music from a large amount of NES games have been "ripped" into NSF format, and although the NES has been taken out of production there are still users actively creating NES music [1].

Available Channels

The NES has 5 audio channels available for use, these include 2 square wave channels for frequency sweep or constant tone production, a triangle way channel for a fluctuating tone (which also includes a timing element), a noise channel, and "DCM/PCM" playback channel [3], for playing back samples from memory [4] .

The channels are activated in register $4015 with the layout as follows [3].

Bit 0 = Square Wave Channel 1

Bit 1 = Square Wave Channel 2

Bit 2 = Triangle Wave Channel 3

Bit 3 = Noise Channel 4

Bit 4 = DMC/PCM Playback Channel

Bits 5-7 = unused

So to activate the sound channels, a piece of code such as this would be used, bearing in mind that bits are always number #0 on the right and #7 on the far left [3].

lda #%00000001
sta $4015

Expansion Chips

To expand on the frankly poor sound capabilities of the NES, some companies decided to include additional processors within their game carts, one such company was Jaleco, who included a "JF-13" board[7] in the cart of "Moero 6!! Shin Moero!! Pro Yakyuu" for the Japanese release, this board consisted of a host of different ROM chips and some additional decoders to extract, and play the 15 samples of VO that were taken from the onboard ROM chips and decoded into the 6### and 7### banks.

NES APU

The NES APU is the audio processing unit in the NES console that generates sound for NES games. It acts as a separate processor, being on a 2A03 chip, and what differentiates a 2A03 chip to a 6502s. To communicate with the APU you have to write values to memory mapped registers [5].

[5]

The APU has five channels: two pulse wave generators, a triangle wave, noise and delta modulation channel for playing DPCM (Differential pulse-code modulation) samples [2].

This is a rundown of the sections of the APU:

$4000 - $4003 Pulse 1

$4004 - $4007 Pulse 2

$4008 - $400B Triangle

$400C - $400F Noise

$4010 - $4013 DMC

$4015 Channel Enable

[5]

$4000 - $4003 Pulse 1

$4004 - $4007 Pulse 2

Pulse Wave Channel

The pulse wave channels have four different duty cycles: 12.5%, 25%, 50% and 75%. The duty cycle just means how long the pulse wave is active for. It contains a sweep unit that will optionally produce a continuous bend from one pitch to another [6]. Examples of these can be found in this video:

NES Audio: Duty Cycle Modulation

APU Pulse uses "period" values to set the pitch of notes. This is a lookup table that shows note numbers to values to write to the pulse and triangle period registers [12].

; NTSC period table generated by mktables.py .export periodTableLo, periodTableHi .segment "RODATA" periodTableLo: .byt $f1,$7f,$13,$ad,$4d,$f3,$9d,$4c,$00,$b8,$74,$34 .byt $f8,$bf,$89,$56,$26,$f9,$ce,$a6,$80,$5c,$3a,$1a .byt $fb,$df,$c4,$ab,$93,$7c,$67,$52,$3f,$2d,$1c,$0c .byt $fd,$ef,$e1,$d5,$c9,$bd,$b3,$a9,$9f,$96,$8e,$86 .byt $7e,$77,$70,$6a,$64,$5e,$59,$54,$4f,$4b,$46,$42 .byt $3f,$3b,$38,$34,$31,$2f,$2c,$29,$27,$25,$23,$21 .byt $1f,$1d,$1b,$1a,$18,$17,$15,$14 periodTableHi: .byt $07,$07,$07,$06,$06,$05,$05,$05,$05,$04,$04,$04 .byt $03,$03,$03,$03,$03,$02,$02,$02,$02,$02,$02,$02 .byt $01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01 .byt $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 .byt $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 .byt $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 .byt $00,$00,$00,$00,$00,$00,$00,$00

Triangle Wave Channel

$4008 - $400B Triangle

Generates a 4-bit triangle wave output. The waveform loops through in succession which counts down from 15 to 0, and then back up again 0 to 15. The lookup table for the waveform sequencer has 32 entries [6]. There is no volume control, the waveform is either cycling or idle. Instead of a length counter, the Triangle wave uses a linear counter which has higher accuracy and duration than the length counter. The triangle wave channel will play one octave lower than the same settings on a square wave channel. Triangle frequencies unlike square channels can go above 000 0000 1000(such as 000 0000 0100) and play incredibly high pitches [11].

Within the triangle channel there is a timer, length counter,linear counter,linear counter reload flag, control flag and sequencer [10].

Noise Channel

$400C - $400F Noise

Creates a pseudo-random noise at 16 different frequencies [6]. These frequencies can be used on two different modes, which gives 32 separate sounds [8].

Delta Modulation Channel

$4010 - $4013 DMC

Used to play 1-bit encoded samples, usually used for percussion alongside the noise channel or used for other sound effects [6]. NES game makers tended away from using a lot of samples since they require a relatively large amount of ROM space [9].

Making Music

Melodies

The melody for an NES tune is typically created using the pulse wave 1 and 2 channels, the pulse widths of 12.5%, 25%, and 50% offer up different sounds [8], and can almost be thought of as different instruments, which can each be pitched up and down. The pulse widths of 25% and 75% are identical in sound [8].

The 12.5% width sounds the thinnest, with the 25% sounding fuller, and 50% having the most bass sound to it of the treble/melody wave channels.

Baseline

The baseline tends to be created with the triangle wave channel, its singular voicing and lack of volume control [8] make it less expressive and this is a likely the reason that melody for the NES tends to be left to the more versatile pulse wave channels.

The sample/delta modulation channel can be used to create baselines [8].

Percussion

Although the triangle wave channel doesn't offer any fading capability and is either on or off, the pitch can be altered to make percussion [8]. Altering the pitch quickly upward creates a drum type sound.

The triangle wave is able to imitate the sounds of kick drums while the noise channel is more tailored to percussion with a static sound [8] that can resemble various snares and cymbals. The second mode has a slightly more discernible pitch, but still sounds percussive, it can be described as "metallic" [8].

The sample/delta modulation channel allows for bongo style and other percussions on NES tracks [8].

References