VRC7 audio: Difference between revisions

From NESdev Wiki
Jump to navigationJump to search
(→‎Internal patch set: much better patch set)
(→‎Channels: more accurate update frequency)
Line 108: Line 108:
This is combined with a 3-bit octave value from '''$2X''' (''octave'') to define the output frequency (''F''):
This is combined with a 3-bit octave value from '''$2X''' (''octave'') to define the output frequency (''F''):


       49722 hz * freq
       49716 Hz * freq
  F = -----------------
  F = -----------------
       2^(19 - octave)
       2^(19 - octave)
The VRC7 is clocked by an external quartz oscillator running at 3.579545 MHz, and it takes 72 internal clock cycles to update all of its channels, which means each channel is updated with a frequency of 49716 Hz.


Writing to register '''$2X''' either begins a key-on or key-off event, depending on the value in the trigger bit (T).
Writing to register '''$2X''' either begins a key-on or key-off event, depending on the value in the trigger bit (T).

Revision as of 07:03, 16 May 2012

The Konami VRC7, in addition to being a mapper chip, also produces 6 channels of 2-operator FM Synthesis Audio. It is a derivative of the Yamaha YM2413 OPLL, implementing a subset of its features and containing a custom fixed patch set.

VRC7 audio was only used in one game, Lagrange Point. The chip also appears in Tiny Toon Adventures 2, but this cart does not use the audio, and its board lacks required additional audio mixing circuitry.

Registers

Audio Register Select ($9010)

7......0
VVVVVVVV
++++++++- The 8-bit internal register to select for use with $9030

This register is write-only.

After writing to this register, the program must not write to $9030 (or $9010 again) for at least 6 CPU clock cycles while the VRC7 internally sets up the address. (After writing to $9010, Lagrange Point usually performs a JSR to a delay subroutine containing only an RTS instruction.)

Audio Register Write ($9030)

7......0
VVVVVVVV
++++++++- The 8-bit value to write to the internal register selected with $9010

This register is write-only.

After writing to this register, the program must not write to $9010 (or $9030 again) for at least 42 CPU clock cycles while the VRC7 internally handles the write.

Internal Audio Registers

The VRCVII appears to have 26 internal registers. Registers $00-$07 define a custom patch that can be played on any channel set to use instrument $0. Registers $10-$15, $20-25, and $30-35 control 6 channels for FM synthesis. Other register values appear to be ignored.

Custom Patch

Register Bitfield Description
$00 TVSK MMMM Modulator tremolo (T), vibrato (V), sustain (S), key rate scaling (K), multiplier (M)
$01 TVSK MMMM Carrier tremolo (T), vibrato (V), sustain (S), key rate scaling (K), multiplier (M)
$02 KKOO OOOO Modulator key level scaling (K), output level (O)
$03 KK-Q WFFF Carrier key level scaling (K), unused (-), carrier waveform (Q), modulator waveform (W), feedback (F)
$04 AAAA DDDD Modulator attack (A), decay (D)
$05 AAAA DDDD Carrier attack (A), decay (D)
$06 SSSS RRRR Modulator sustain (S), release (R)
$07 SSSS RRRR Carrier sustain (S), release (R)

The patch defines a 2-operator FM unit with a single modulator and carrier. The carrier produces the output tone, and the output of the modulator modulates its frequency. The patch has the following parameters:

  • $00/$01 T Tremolo applies amplitude modulation at a predefined rate.
  • $00/$01 V Vibrato applies pitch modulation at a predefined rate.
  • $00/$01 S Sustain determines whether the operator uses the sustain section of the envelope or not.
  • $00/$01 K Key rate scaling adjusts the ADSR envelope speed, faster for high frequencies, slower for low ones.
  • $00/$01 MMMM Multiplier is a multiplier on the operator's frequency according to a lookup table (see below).
  • $02/$03 KK Key level scaling attenuates the operator at higher frequencies $0 = none, $3 = most.
  • $02 OOOOOO Modulator output level, this value reduces the modulator volume in 0.75db increments.
  • $03 Q/W Operator waveform, 0 = sine, 1 = half-wave rectified sine (where sine values less than 0 are clipped to 0).
  • $03 FFF Feedback applied to modulator according to a lookup table (see below).
  • $04/$05 AAAA Attack is the speed of the attack fade in after key-on. $0 = halt, $1 = slowest, $F = fastest.
  • $04/$05 DDDD Decay is the speed of the decay fade to sustain after attack. $0 = halt, $1 = slowest, $F = fastest.
  • $06/$07 SSSS Sustain is the attenuation after decay, in 3db increments. $0 = highest volume, $F = lowest.
  • $06/$07 RRRR Release is the speed of the release fade to silent after sustain. $0 = halt, $1 = slowest, $F = fastest.

If a note is released before the attack or decay finishes, release begins from the current volume level. If the sustain bit is not set in $00/$01 S, release begins immediately after decay.

If the sustain bit is set in the channel control register $2X S (see Channels section below), the release value in the patch is ignored and replaced with $5.

$00/$01 MMMM $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $A $B $C $D $E $F
Multiplier 1/2 1 2 3 4 5 6 7 8 9 10 10 12 12 15 15
$03 FFF $0 $1 $2 $3 $4 $5 $6 $7
Modulation Index 0 π/16 π/8 π/4 π/2 π

Channels

Register Bitfield Description
$10-$15 LLLL LLLL Channel low 8 bits of frequency
$20-$25 --ST OOOH Channel sustain (S), trigger (T), octave (O), high bit of frequency (H)
$30-$35 IIII VVVV Channel instrument (I), volume (V)

Each channel X is controlled by three registers at $1X, $2X, and $3X.

The 8 bits of $1X with a 9th bit from bit 0 of $2X create a 9-bit frequency value (freq). This is combined with a 3-bit octave value from $2X (octave) to define the output frequency (F):

     49716 Hz * freq
F = -----------------
     2^(19 - octave)

The VRC7 is clocked by an external quartz oscillator running at 3.579545 MHz, and it takes 72 internal clock cycles to update all of its channels, which means each channel is updated with a frequency of 49716 Hz.

Writing to register $2X either begins a key-on or key-off event, depending on the value in the trigger bit (T). If the trigger bit is 1, a new note begins, if it is 0 it will begin the release portion of its envelope which will eventually silence the channel (unless release is $0). If it was already 0, no new key-off will be generated. Note that the octave and high frequency bit cannot be altered between key-on and key-off, but the low 8 bits of frequency in $1X can be used to apply vibrato and pitch bends.

Using the sustain bit (S) in $2X overrides the normal release value for the patch with a value of $5.

Register $3X selects the instrument patch to use, and chooses a volume. Note that volume value is inverted: $F is the lowest volume and $0 is the highest. There is no silent volume value; its output scale is logarithmic in 3db increments.

Internal patch set

There are 16 different instrument patches available on the VRC7. With the exception of instrument $0, which can be controlled by registers $00-$07 (see above), these are hardwired into the chip and cannot be altered.

Exact values for the fixed patch set are not known, but the following table is very close:

     00 01 02 03 04 05 06 07
     -----------------------
 0 | -- -- -- -- -- -- -- --
 1 | 03 21 04 06 8D F2 42 17
 2 | 13 41 05 0E 99 96 63 12
 3 | 31 11 10 0A F0 9C 32 02
 4 | 21 61 1D 07 9F 64 20 27
 5 | 22 21 1E 06 F0 76 08 28
 6 | 02 01 06 00 F0 F2 03 95
 7 | 21 61 1C 07 82 81 16 07
 8 | 23 21 1A 17 EF 82 25 15
 9 | 25 11 1F 00 86 41 20 11
 A | 85 01 1F 0F E4 A2 11 12
 B | 07 C1 2B 45 B4 F1 24 F4
 C | 61 23 11 06 96 96 13 16
 D | 01 02 D3 05 82 A2 31 51
 E | 61 22 0D 02 C3 7F 24 05
 F | 21 62 0E 00 A1 A0 44 17

Differences from OPLL

The synthesis core is related to the Yamaha YM2413 OPLL, which is itself a cost-reduced version of the YM3182 OPL2 chip made popular by AdLib and SoundBlaster sound cards.

  • Register layout is the same.
  • VRC7 has 6 channels, OPLL has 9.
  • VRC7 has no rhythm channels, OPLL does (the last 3 channels are either FM or Rhythm on OPLL).
  • VRC7 built-in instruments are NOT the same as OPLL instruments (except for instruments 4,5,7,8 which might be the same on both?).
  • VRC7 has no readily-accessible status register, under normal circumstances it is write-only; OPLL has an undocumented, 2-bit 'internal state' register.
  • VRC7 has an internal state output pin (may be serial version of the 2 bit internal state register) and has one output pin for audio, multiplexed for all 6 channels; OPLL has two output pins, one for FM and one for Rhythm, and has no special status pin.

References