We've just updated MediaWiki and its underlying software. If anything doesn't look or work quite right, please mention it to us. --RanAS

N-SPC Engine: Difference between revisions

From SnesLab
Jump to: navigation, search
(Adding extra phrase and some VCMD definitions)
(Rest of the core VCMD set defined.)
Line 1: Line 1:
''WIP: currently a stub''
__TOC__
__TOC__


Line 84: Line 82:
|<tt>$E8</tt> || Tempo Fade || <tt>xx yy</tt>  
|<tt>$E8</tt> || Tempo Fade || <tt>xx yy</tt>  
|-
|-
|<tt>$E9</tt> || Global Transposition || <tt>xx</tt>
|<tt>$E9</tt> || Global Absolute Transposition || <tt>xx</tt>
|-
|-
|<tt>$EA</tt> || Single Channel Transposition || <tt>xx</tt>
|<tt>$EA</tt> || Single Channel Absolute Transposition || <tt>xx</tt>
|-
|-
|<tt>$EB</tt> || Tremolo On || <tt>xx yy zz</tt>
|<tt>$EB</tt> || Tremolo On || <tt>xx yy zz</tt>
Line 108: Line 106:
|<tt>$F4</tt> || Fine Tune || <tt>xx</tt>
|<tt>$F4</tt> || Fine Tune || <tt>xx</tt>
|-
|-
|<tt>$F5</tt> || Echo On || <tt>xx yy zz</tt>
|<tt>$F5</tt> || Echo Bits and Volume || <tt>%xxxxxxxx yy zz</tt>
|-
|-
|<tt>$F6</tt> || Echo Off ||  
|<tt>$F6</tt> || Echo Off ||  
Line 135: Line 133:


===NOP (VCMD <tt>$FB</tt>)===
===NOP (VCMD <tt>$FB</tt>)===
<pre>$FB xx</pre>
<pre>$FB ??</pre>
Reads a single byte, then does absolutely nothing with the command.
Reads a single byte, then does absolutely nothing with the command.


Line 165: Line 163:


By default, percussion uses the same instrument set as the song, and all percussion is keyed on with a note of <tt>$A4</tt>.
By default, percussion uses the same instrument set as the song, and all percussion is keyed on with a note of <tt>$A4</tt>.
The starting ID to use for all channels can be redefined by VCMD <tt>$FA</tt>.
===Instrument (VCMD <tt>$E0</tt>)===
<pre>$E0 xx</pre>
* <tt>xx</tt> is an instrument ID to an array of instruments. See Instrument Format above for the format.
===Panning (VCMD <tt>$E1</tt>)===
<pre>$E1 %xyzzzzz</pre>
* <tt>x</tt> defines a phase inversion switch for the left channel.
* <tt>y</tt> defines a phase inversion switch for the right channel.
* <tt>zzzzz</tt> is five bits for the panning. This refers to an array of values to multiply the volume by after calculating the voice volume via various other parameters set by the VCMDs. Under normal circumstances, center is defined as <tt>$0A</tt> and the maximum value is <tt>$14</tt>.
===Panning Fade (VCMD <tt>$E2</tt>)===
<pre>$E2 xx yy</pre>
* <tt>xx</tt> defines the number of tempo ticks to fade for.
* <tt>yy</tt> is the target pan value. Phase inversion is ''not'' taken into account here, thus only the low five bits should be used here.
===Vibrato On (VCMD <tt>$E3</tt>)===
<pre>$E3 xx yy zz</pre>
* <tt>xx</tt> is the number of tempo ticks to delay the vibrato for.
* <tt>yy</tt> is the rate of the vibrato: specifically, how much to change the pitch on a per-tempo tick basis.
* <tt>zz</tt> is the depth of the vibrato: that is, the maximum pitch offset to use. <tt>$00-$F0</tt> are normal, but <tt>$F1</tt> and up act more like said value ANDed by <tt>$0F</tt> and multiplied by <tt>$0100</tt>, meaning the highest values have drastic differences compared to the lower ones.


''TODO: Voice Command Descriptions for <tt>$E0-$FE</tt>''
===Vibrato Off (VCMD <tt>$E4</tt>)===
Disables vibrato set by VCMD <tt>$E3</tt>.
 
===Master Volume (VCMD <tt>$E5</tt>)===
<pre>$E5 xx</pre>
* <tt>xx</tt> is the master volume value. This isn't a direct write to the MVOL DSP registers, but rather sets the volume for all of the channels in the song. The value used is a decibel-like value due to the final volume being multiplied by itself to get the final result.
 
===Master Volume Fade (VCMD <tt>$E6</tt>)===
<pre>$E6 xx yy</pre>
* <tt>xx</tt> defines the number of tempo ticks to fade for.
* <tt>yy</tt> is the target master volume.
 
===Tempo (VCMD <tt>$E7</tt>)===
<pre>$E7 xx</pre>
* <tt>xx</tt> defines one tempo tick as one timer 0 tick multiplied by <math>256/x</math>. Zero freezes the song.
 
===Tempo Fade (VCMD <tt>$E8</tt>)===
<pre>$E8 xx yy</pre>
* <tt>xx</tt> defines the number of tempo ticks to fade for.
* <tt>yy</tt> is the target tempo.
 
===Global Absolute Transposition (VCMD <tt>$E9</tt>)===
<pre>$E9 xx</pre>
* <tt>xx</tt> is a signed value defining the number of semitones to transpose subsequent notes. Note that this affects all channels, not just one channel.
 
===Single Channel Absolute Transposition (VCMD <tt>$EA</tt>)===
<pre>$EA xx</pre>
* <tt>xx</tt> is a signed value defining the number of semitones to transpose subsequent notes.
 
===Tremolo On (VCMD <tt>$EB</tt>)===
<pre>$EB xx yy zz</pre>
* <tt>xx</tt> is the number of tempo ticks to delay the tremolo for.
* <tt>yy</tt> is the rate of the tremolo: specifically, how much to change the volume on a per-tempo tick basis.
* <tt>zz</tt> is the depth of the tremolo: that is, the maximum volume offset to use.
 
===Tremolo Off (VCMD <tt>$EC</tt>)===
Disables vibrato set by VCMD <tt>$E3</tt>.
 
===Volume (VCMD <tt>$ED</tt>)===
<pre>$ED xx</pre>
* <tt>xx</tt> is the volume value. The value used is a decibel-like value due to the final volume being multiplied by itself to get the final result.
 
===Volume Fade (VCMD <tt>$EE</tt>)===
<pre>$EE xx yy</pre>
* <tt>xx</tt> defines the number of tempo ticks to fade for.
* <tt>yy</tt> is the target volume.
 
===Subroutine (VCMD <tt>$EF</tt>)===
<pre>$EF xx xx yy</pre>
* <tt>xx xx</tt> is a little endian pointer containing the section of music to play.
* <tt>yy</tt> is the number of times to loop the sub-routine.
 
===Vibrato Fade In (VCMD <tt>$F0</tt>)===
<pre>$F0 xx</pre>
* <tt>xx</tt> is the number of tempo ticks to fade the vibrato for.
The moment this VCMD is executed, the depth is faded in from zero.
 
===Note Pitch Envelope To (VCMD <tt>$F1</tt>)===
<pre>$F1 xx yy zz</pre>
This VCMD is applied to all subsequent notes until turned off or overwritten.
* <tt>xx</tt> is the number of ticks to delay before applying the pitch envelope.
* <tt>yy</tt> is the length of the pitch slide in ticks.
* <tt>zz</tt> is a signed offset in semitones to slide the note to.
 
===Note Pitch Envelope From (VCMD <tt>$F2</tt>)===
<pre>$F2 xx yy zz</pre>
This VCMD is applied to all subsequent notes until turned off or overwritten.
* <tt>xx</tt> is the number of ticks to delay before applying the pitch envelope.
* <tt>yy</tt> is the length of the pitch slide in ticks.
* <tt>zz</tt> is a signed offset in semitones to slide the note from: that is, unlike Note Pitch Envelope To (VCMD <tt>$F1</tt>), this is a starting note offset, rather than an end of pitch envelope note offset.
 
===Note Pitch Envelope Off (VCMD <tt>$F3</tt>)===
Disables a pitch envelope.
 
===Fine Tune (VCMD <tt>$F4</tt>)===
<pre>$F4 xx</pre>
* <tt>xx</tt> defines the amount to shift the pitch up. This is in 256ths of a semitone, albeit done via measuring the distance between note and multiplying it by this value.
 
===Echo Bits and Volume (VCMD <tt>$F5</tt>)===
<pre>$F5 %xxxxxxxx yy zz</pre>
* <tt>xxxxxxxx</tt> defines the channels to turn on for the echo (one per bit), which translates to a direct write to the EON DSP register.
* <tt>yy</tt> defines a value for EVOLL DSP register.
* <tt>zz</tt> defines a value for EVOLR DSP register.
 
===Echo Off (VCMD <tt>$F6</tt>)===
This disables echo for ''all'' channels, as well as zeroing out the echo volume and disabling echo writes.
 
===Echo Parameter Setup (VCMD <tt>$F7</tt>)===
<pre>$F7 xx yy zz</pre>
* <tt>xx</tt> defines a value for the EDL DSP register.
* <tt>yy</tt> defines a value for the EFB DSP register.
* <tt>zz</tt> defines an ID to an array of FIR coefficient values.
 
===Echo Volume Fade (VCMD <tt>$F8</tt>)===
<pre>$F8 xx yy zz</pre>
* <tt>xx</tt> defines the number of tempo ticks to fade for.
* <tt>yy</tt> defines the target value for EVOLL DSP register.
* <tt>zz</tt> defines the targer value for EVOLR DSP register.
 
===Pitch Slide To Note (VCMD <tt>$F9</tt>)===
<pre>$F9 xx yy zz</pre>
* <tt>xx</tt> defines the number of tempo ticks to delay the slide for.
* <tt>yy</tt> defines the length of the pitch slide in tempo ticks.
* <tt>zz</tt> is the target note.
 
===Percussion Patch Base Redefine (VCMD <tt>$FA</tt>)===
<pre>$FA xx</pre>
* <tt>xx</tt> is the starting patch ID. Note that this affects all channels.
 
===Channel Mute (VCMD <tt>$FC</tt>)===
Causes the channel to not key on subsequent notes.
 
===Fast Forward On (VCMD <tt>$FD</tt>)===
Fast Forward causes the song to stop playing and the player rapidly progresses throughout the song. Thus, this can effectively act as a skip.
 
===Fast Forward Off (VCMD <tt>$FE</tt>)===
Disables Fast Forward and continues playing the song normally.


==Variants==
==Variants==
[[N-SPC Engine/Prototype|Prototype]]
[[N-SPC Engine/Prototype|Prototype]]
''TODO: There are a lot of variants... these will be split into sub-pages depending on the modifications made''


==References==
==References==
Line 177: Line 316:
* [http://gdri.smspower.org/wiki/index.php/Super_Famicom/Super_NES_Sound_Driver_List GDRI - Super Famicom/Super NES Sound Driver List]
* [http://gdri.smspower.org/wiki/index.php/Super_Famicom/Super_NES_Sound_Driver_List GDRI - Super Famicom/Super NES Sound Driver List]
* [https://github.com/vgmtrans/vgmtrans/issues/173 Github - N-SPC VCMD $FB-$FE identifications]
* [https://github.com/vgmtrans/vgmtrans/issues/173 Github - N-SPC VCMD $FB-$FE identifications]
''TODO: There are a lot of variants... these will be split into sub-pages depending on the modifications made''


[[Category:SPC Sound Engines]]
[[Category:SPC Sound Engines]]

Revision as of 19:09, 9 October 2020

Nintendo SPC Sound Engine, abbreviated N-SPC and officially known as Kankichi-kun [1], is the most common sound engine used in all of the SNES/SFC games. Only the music portion was initially provided in the source code included in the IS-Sound unit along with some templating for a protocol for music and sound effects [2]: usually it was modified by developers on an individual basis, resulting in many different variants, some of them more heavily modifying the sound driver than others. Usually what was added on was sound effect support, but sometimes the music VCMDs were modified as well.

The following games are purely based off of the source code provided with the IS-Sound unit, and are either unmodified or barely modified, if at all:

Game Name VCMD Table Location (usually $E0 and up) ROM Offset
Hong Kong '97 0x0DEC, relative to 0x0D2C 0x0F800A (both versions)
SM Choukyoushi Hitomi - Bangai Hen 0x0DEC, relative to 0x0D2C 0x01801C
SM Choukyoushi Hitomi Vol. 2 Trial Version 0x0DEC, relative to 0x0D2C 0x01801C
SM Choukyoushi Hitomi Vol. 2 0x0DEC, relative to 0x0D2C 0x03801C
SM Choukyoushi Hitomi Vol. 2 Remix 0x0DEC, relative to 0x0D2C 0x01801C
SM Choukyoushi Hitomi Vol. 3 Trial Version 0x0DEC, relative to 0x0D2C 0x018058
SM Choukyoushi Hitomi Vol. 3 (Alt 1) 0x0DF0, relative to 0x0D30 0x018076
Wheel of Fortune - Deluxe Edition 0x0DEC, relative to 0x0D2C 0x01D842

Of the games listed here, two of them are very minor edits...

  • Wheel of Fortune - Deluxe Edition's build is unused and is missing an opcode near the *Ver S1.20* string.
  • SM Choukyoushi Hitomi Vol. 3 (Alt 1)'s program starts with a JMP opcode, and contains a NOP between the first and second opcodes of the actual program.

Instrument Format

The instrument format is most commonly defined as direct writes to DSP registers for the first four bytes, followed by two pitch-related bytes. They are defined in this order, from top to bottom...

  • SRCN
    • If this value is above $7F, noise is used, and the lowest five bits contains the noise clock rate.
  • ADSR1
  • ADSR2
  • GAIN
  • Pitch Base Multiplier
  • Pitch Base Fractional Multiplier (in 256ths)

Phrase Format

Song entries point to a list of phrases for the song to play. If the high byte is zero, then the low byte is a loop counter, and a second pointer is defined as a jump pointer. If the loop counter is $FF, then the jump always executes, rather than executing 255 times. If the loop counter is also zero, the song terminates, and no second pointer is required.

Each phrase is a pointer to a collection of eight pointers to track data. If the pointer is zero, there is no track data.

Voice Command Format

NOTE: This is not representative of every single variant. Instead, it represents the collection of VCMDs from the source code included in the IS-Sound unit, which in turn is carried over to most variants.

VCMD ID Description Arguments
$00 Phrase Termination/End of Subroutine
$01-$7F Note Duration xy
$80-$C7 Note
$C8 Tie
$C9 Rest
$CA-$DF Percussion
$E0 Instrument xx
$E1 Panning %xyzzzzz
$E2 Panning Fade xx yy
$E3 Vibrato On xx yy zz
$E4 Vibrato Off
$E5 Master Volume xx
$E6 Master Volme Fade xx yy zz
$E7 Tempo xx
$E8 Tempo Fade xx yy
$E9 Global Absolute Transposition xx
$EA Single Channel Absolute Transposition xx
$EB Tremolo On xx yy zz
$EC Tremolo Off
$ED Volume xx
$EE Volume Fade xx yy
$EF Subroutine xx xx yy
$F0 Vibrato Fade In xx
$F1 Note Pitch Envelope To xx yy zz
$F2 Note Pitch Envelope From xx yy zz
$F3 Note Pitch Envelope Off
$F4 Fine Tune xx
$F5 Echo Bits and Volume %xxxxxxxx yy zz
$F6 Echo Off
$F7 Echo Parameter Setup xx yy zz
$F8 Echo Volume Fade xx yy zz
$F9 Pitch Slide to Note xx yy zz
$FA Percussion Patch Base Redefine xx
$FB NOP ??
$FC Channel Mute
$FD Fast Forward On
$FE Fast Forward Off
$FF Invalid

Invalid (VCMD $FF)

Crashes the sound driver due to being outside of the array of pointers, and thus jumping to an invalid pointer.

NOP (VCMD $FB)

$FB ??

Reads a single byte, then does absolutely nothing with the command.

Phrase Termination/End of Subroutine (VCMD $00)

This VCMD's operation depends on whether or not it is inside a subroutine or not. If it is inside a subroutine, it exits the subroutine and song execution continues. Otherwise, the phrase is terminated. This affects all channels in the music: any other channels still playing are interrupted.

Note Duration (VCMD $01-$7F)

%0xxxxxxx (yz)
  • xxxxxxx represents your note length (as seven bits) in tempo ticks.
  • y, if less than $8, defines the quantization. It is an index value to a table of values that indicate, in 256ths, how far along the note to play before keying it off. This table can vary on a per-game basis.
  • z, which is only defined if y is less than $8, defines the velocity. It is an index to a table of values that indicate the volume in a decibel-like number (due to the final volume calculation being multiplied by itself at the end). This table can vary on a per-game basis.

Notes and/or special VCMDs, by default, are forced after the parameter byte is read. Attempting to use $00-$7F again results in an invalid note.

Note (VCMD $80-$C7)

Plays a note and delays the channel for one note length before reading another VCMD.

Tie (VCMD $C8)

Continues playing the previous note and delays the channel for one note length before reading another VCMD.

Rest (VCMD $C9)

Keys off the previous note and delays the channel for one note length before reading another VCMD.

Percussion (VCMD $CA-$DF)

Plays a percussion note.

By default, percussion uses the same instrument set as the song, and all percussion is keyed on with a note of $A4. The starting ID to use for all channels can be redefined by VCMD $FA.

Instrument (VCMD $E0)

$E0 xx
  • xx is an instrument ID to an array of instruments. See Instrument Format above for the format.

Panning (VCMD $E1)

$E1 %xyzzzzz
  • x defines a phase inversion switch for the left channel.
  • y defines a phase inversion switch for the right channel.
  • zzzzz is five bits for the panning. This refers to an array of values to multiply the volume by after calculating the voice volume via various other parameters set by the VCMDs. Under normal circumstances, center is defined as $0A and the maximum value is $14.

Panning Fade (VCMD $E2)

$E2 xx yy
  • xx defines the number of tempo ticks to fade for.
  • yy is the target pan value. Phase inversion is not taken into account here, thus only the low five bits should be used here.

Vibrato On (VCMD $E3)

$E3 xx yy zz
  • xx is the number of tempo ticks to delay the vibrato for.
  • yy is the rate of the vibrato: specifically, how much to change the pitch on a per-tempo tick basis.
  • zz is the depth of the vibrato: that is, the maximum pitch offset to use. $00-$F0 are normal, but $F1 and up act more like said value ANDed by $0F and multiplied by $0100, meaning the highest values have drastic differences compared to the lower ones.

Vibrato Off (VCMD $E4)

Disables vibrato set by VCMD $E3.

Master Volume (VCMD $E5)

$E5 xx
  • xx is the master volume value. This isn't a direct write to the MVOL DSP registers, but rather sets the volume for all of the channels in the song. The value used is a decibel-like value due to the final volume being multiplied by itself to get the final result.

Master Volume Fade (VCMD $E6)

$E6 xx yy
  • xx defines the number of tempo ticks to fade for.
  • yy is the target master volume.

Tempo (VCMD $E7)

$E7 xx
  • xx defines one tempo tick as one timer 0 tick multiplied by . Zero freezes the song.

Tempo Fade (VCMD $E8)

$E8 xx yy
  • xx defines the number of tempo ticks to fade for.
  • yy is the target tempo.

Global Absolute Transposition (VCMD $E9)

$E9 xx
  • xx is a signed value defining the number of semitones to transpose subsequent notes. Note that this affects all channels, not just one channel.

Single Channel Absolute Transposition (VCMD $EA)

$EA xx
  • xx is a signed value defining the number of semitones to transpose subsequent notes.

Tremolo On (VCMD $EB)

$EB xx yy zz
  • xx is the number of tempo ticks to delay the tremolo for.
  • yy is the rate of the tremolo: specifically, how much to change the volume on a per-tempo tick basis.
  • zz is the depth of the tremolo: that is, the maximum volume offset to use.

Tremolo Off (VCMD $EC)

Disables vibrato set by VCMD $E3.

Volume (VCMD $ED)

$ED xx
  • xx is the volume value. The value used is a decibel-like value due to the final volume being multiplied by itself to get the final result.

Volume Fade (VCMD $EE)

$EE xx yy
  • xx defines the number of tempo ticks to fade for.
  • yy is the target volume.

Subroutine (VCMD $EF)

$EF xx xx yy
  • xx xx is a little endian pointer containing the section of music to play.
  • yy is the number of times to loop the sub-routine.

Vibrato Fade In (VCMD $F0)

$F0 xx
  • xx is the number of tempo ticks to fade the vibrato for.

The moment this VCMD is executed, the depth is faded in from zero.

Note Pitch Envelope To (VCMD $F1)

$F1 xx yy zz

This VCMD is applied to all subsequent notes until turned off or overwritten.

  • xx is the number of ticks to delay before applying the pitch envelope.
  • yy is the length of the pitch slide in ticks.
  • zz is a signed offset in semitones to slide the note to.

Note Pitch Envelope From (VCMD $F2)

$F2 xx yy zz

This VCMD is applied to all subsequent notes until turned off or overwritten.

  • xx is the number of ticks to delay before applying the pitch envelope.
  • yy is the length of the pitch slide in ticks.
  • zz is a signed offset in semitones to slide the note from: that is, unlike Note Pitch Envelope To (VCMD $F1), this is a starting note offset, rather than an end of pitch envelope note offset.

Note Pitch Envelope Off (VCMD $F3)

Disables a pitch envelope.

Fine Tune (VCMD $F4)

$F4 xx
  • xx defines the amount to shift the pitch up. This is in 256ths of a semitone, albeit done via measuring the distance between note and multiplying it by this value.

Echo Bits and Volume (VCMD $F5)

$F5 %xxxxxxxx yy zz
  • xxxxxxxx defines the channels to turn on for the echo (one per bit), which translates to a direct write to the EON DSP register.
  • yy defines a value for EVOLL DSP register.
  • zz defines a value for EVOLR DSP register.

Echo Off (VCMD $F6)

This disables echo for all channels, as well as zeroing out the echo volume and disabling echo writes.

Echo Parameter Setup (VCMD $F7)

$F7 xx yy zz
  • xx defines a value for the EDL DSP register.
  • yy defines a value for the EFB DSP register.
  • zz defines an ID to an array of FIR coefficient values.

Echo Volume Fade (VCMD $F8)

$F8 xx yy zz
  • xx defines the number of tempo ticks to fade for.
  • yy defines the target value for EVOLL DSP register.
  • zz defines the targer value for EVOLR DSP register.

Pitch Slide To Note (VCMD $F9)

$F9 xx yy zz
  • xx defines the number of tempo ticks to delay the slide for.
  • yy defines the length of the pitch slide in tempo ticks.
  • zz is the target note.

Percussion Patch Base Redefine (VCMD $FA)

$FA xx
  • xx is the starting patch ID. Note that this affects all channels.

Channel Mute (VCMD $FC)

Causes the channel to not key on subsequent notes.

Fast Forward On (VCMD $FD)

Fast Forward causes the song to stop playing and the player rapidly progresses throughout the song. Thus, this can effectively act as a skip.

Fast Forward Off (VCMD $FE)

Disables Fast Forward and continues playing the song normally.

Variants

Prototype

TODO: There are a lot of variants... these will be split into sub-pages depending on the modifications made

References