Namco 163 audio

The Namco 163 offers up to 8 additional sound channels that play wavetable samples while the 175 and 340 do not. Each waveform can be of a configurable length, and each channel has linear volume control. It has $80 bytes of sound RAM shared by channel registers and wavetable samples; at least $40 bytes are dedicated to samples, with more available if not all channels are used.

Like the Ensoniq DOC in the Apple IIGS, the chip is unable to clock every channel at once, so it cycles though channels, updating one every 15 CPU cycles. Because of this, the chip allows the game to configure the number of enabled channels. When fewer channels are enabled, the channels are clocked more often, allowing for higher tones with longer, more detailed waveforms. When more channels are enabled, clocking slows down since each channel has to wait its turn, resulting in lower tones and a high-pitched whining noise at the switching frequency. Most games using this IC used only 4 channels.

Address Port ($F800-$FFFF)

Writing to this register sets the internal address. If the 'I' bit is set, the address will increment on writes and reads to the Data Port ($4800), wrapping $7F->$00 (address is 7 bits wide)

Data Port ($4800-$4FFF)

7 bit 0 (read / write)
---- ----
DDDD DDDD
|||| ||||
++++-++++- Data

This Port accesses the 163's internal $80 bytes of sound RAM. Which of the $80 bytes is determined by the Address register ($F800). When read, the appropriate byte is returned. When written, the appropriate byte is set.

This RAM is used primarily for wavetables. The sound channel control registers are also set by writing to certain addresses in sound RAM:

Sound RAM $7C - High Frequency and Wave Length

Sound RAM $7D - High Phase

7 bit 0
---------
FFFF FFFF
|||| ||||
++++-++++- High 8 bits of Phase

The high byte of the 24-bit phase value directly determines the current sample
position of the channel. Every time a channel is updated, the 18-bit frequency
value is added to the 24-bit phase accumulator, which is stored in these three
registers.

The phase registers may be written to immediately set the phase of
the wave. It is good practice to set the frequency to 0 before doing so.

Again note that the 'C' bits in the final register is only available at address $7F.

When channels are disabled, their registers are unused, and can be used for waveform data instead.

Waveform

Each enabled channel cycles through its waveform at a rate determined by the 18-bit frequency value 'F'. Each step in the waveform is 4-bits wide, and the number of steps is determined by the 'L' bits ((64-L)*4). Two samples are stored to a byte, which is little-endian (unlike the Game Boy's wavetable channel).

The 'A' bits dictate where in the internal sound RAM the waveform starts. 'A' is the address in 4-bit samples, therefore a value of $02 would be the low 4 bits of address $01. A value of $03 would be the high 4 bits of address $01.

Channel Update

Namco's 163 does not internally mix its channels. Instead, each channel is output one at a time. It takes exactly 15 CPU cycles to update and output one channel. When multiple channels are used it will cycle between them. With 6 or fewer channels, the time to update all channels is a rate faster than any audible frequency, and the difference between this serial output and mixing cannot be heard, but for 8 channels it creates a very loud and apparent noise at the update rate. For a Famicom through RF output, this noise is attenuated during demodulation (which performs a lowpass filter), but through A/V output to a TV that does not filter high frequencies, it can be very unpleasant. Only two games used all 8 channels: King of Kings and Erika to Satoru no Yume Bouken.

Channels

Update Rate

1

119318 Hz

2

59659 Hz

3

39773 Hz

4

29830 Hz

5

23864 Hz

6

19886 Hz

7

17045 Hz

8

14915 Hz

The following is a speculative version of a single channel update, occurring every 15 CPU cycles:

The output will be held until the next channel update. The 24-bit phase value will be stored back into w[$7D/$7B/$79].

The sample value is biased by -8, meaning that a waveform value of 8 represents the centre voltage. This means that volume changes have no effect on a sample of 8, will tend negative if <8 and positive if >8.

Frequency

The wave position is driven by the high 8 bits of a 24-bit accumulator. Every 15 CPU clocks, one channel will add its 18-bit frequency to the accumulator. Because only one channel is updated per tick, the output frequency is thus divided by the number of channels enabled.

Mixing

The relative volume of the IC varies from game to game, unfortunately.

A 163 with a single channel enabled is somewhere between ~3.6x and ~8.5x as loud as the APU square at max volume. The two 8-channel games have a louder mix, probably to compensate for the quieter volume when more channels are enabled. Some 4-channel games have a quieter mix. The polarity of the 163 is reversed from the 2A03.

The volume comparison measured on various cartridges:
(Values in parentheses are estimated based on listening/balance.)

4-Channel Game

Volume

Samples

Final Lap

3.6x

1

Mappy Kids

(~6x)

0

Megami Tensei II

4.0x

1

Namco Classic 2

(~6x)

0

Rolling Thunder

6.5x

2

Sangokushi

(~6x)

0

Sangokushi 2

(~4x)

0

8-Channel Game

Volume

Samples

Erika to Satoru no Yumebouken

8.5x

1

King of Kings

7.3x

1

Since the mix appears to be arbitrarily chosen per-game, how to handle this is a difficult choice for an emulator author. It should probably be adjustable. You may choose to simply boost the volume when 8-channels are used. You may try to use a value in between (~6.0x sounds well for all games except Final Lap and Sangokushi 2). You may keep a table of 163 games and their volumes (ignoring potential homebrew), though more data needs to be collected . It should be noted that the 8-channel games do not significantly use the 2A03 for music, except the noise channel, so an accurate mix may be less important.

Because the high frequency generated by the channel cycling can be unpleasant, and emulation of high frequency audio can be difficult, it is often preferred to simply sum the channel outputs, and divide the output volume by the number of channels. To compensate for less drop in apparent volume once the switching frequency crosses the threshold of audibility, it may be desired to slightly increase the volume for >5 channels (perhaps always dividing the output by 6 for 6, 7 or 8 channels).