Anonymous

Changes

From Final Fantasy Inside

FF9/Sound/AKAO sequence

16,399 bytes added, 07:03, 11 July 2020
Created page with "== Introduction == AKAO sequence is similar to MIDI sequence - it's custom tracker format for playing sequence sound, well tuned specially for PSX. == File Structure == ===..."
== Introduction ==
AKAO sequence is similar to MIDI sequence - it's custom tracker format for playing sequence sound, well tuned specially for PSX.


== File Structure ==
=== Header (size: 64 bytes) ===

struct AkaoSeqHeader
{
static const uint8_t magic[4]; // "AKAO" C-string
uint16_t id; // song ID, used for playing sequence
uint16_t length; // data length (including this header)
uint16_t reverb_type; // reverb type (range from 0 to 9)
uint8_t field_0A[6];
uint32_t field_10;
uint16_t sample_set_id; // associated sample set ID
uint16_t field_12;
uint32_t field_14;
uint32_t field_18;
uint32_t field_1C;
uint32_t mask; // represents bitmask of used channels in this song
uint32_t field_24;
uint32_t field_28;
uint32_t field_2C;
uint32_t instrument_map_offset; // relative offset to custom instrument map (0 if unused)
uint32_t drum_map_offset; // relative offset to custom drum map (0 if unused)
uint32_t field_38;
uint32_t field_3C;
};

=== Channel Offsets (size: 2 bytes * <channels count>) ===
struct AkaoChannelInfo
{
uint32_t start_offsets[num_channels]; // offsets to channel opcode data
};

AkaoSeqHeader *header;
int num_channels = 0;
while (int bit = 0; header->mask & (1 << bit)) != 0; bit++)
num_channels++;

There is <channels count> offsets to channel opcode data counting from current offset. Each offsets is a relative offset based on the address the offset itself.


=== Channel Commands [AKAO Opcodes] ===
For every channels in an AKAO sequence, there is a set of commands to perform. This is similar to Field opcodes. Here I will call this sound commands "opcodes". Every opcode has its own number of arguments (from no-arguments, to 3 arguments).

=== Drum Instrument Map Table ===

When a song uses a drum kit with [[FF9/Sound/Opcodes/0xfe04|opcode 0xFE 0x04]], a drum instrument map table will be placed at the end of the sequence. The table determines the instrument, channel volume and pan for each keys.

The table consists of a repetition of 8-byte items.

struct AkaoDrumKeyAttr
{
uint8_t instrument; // corresponding to opcode 0xA1
uint8_t key; // note number when playing the drum note
uint8_t ar; // ADSR: attack rate (0-127)
uint8_t sr; // ADSR: sustain rate (0-127)
uint8_t s_mode; // ADSR: sustain mode (1: linear increase, 3: linear decrease, 5: exponential increase, 7: exponential decrease)
uint8_t rr; // ADSR: release rate (0-127)
uint8_t volume; // adjust the percussion volume to n/128 of the original volume (0 will keep the original volume)
uint8_t pan : 7; // corresponding to opcode 0xAA
uint8_t reverb : 1; // reverb on/off (0: off, 1: on)
}


== Sound Opcode List ==

{| class="wikitable"
! Opcode
! Summary
! Length
! Operands
! Note
|-
|[[FF9/Sound/Opcodes/0x0099|0x00-0x99]]
|Note, Tie, Rest
|1
|
|The opcode indicates the note key and length. The note will be keyed off 2 ticks before the next note.
|-
|0x9A-0x9F
|Unimplemented
|1
|
|Should not be used.
|-
|[[FF9/Sound/Opcodes/0xa0|0xA0]]
|Finish Channel
|1
|
|
|-
|[[FF9/Sound/Opcodes/0xa1|0xA1]]
|Load Instrument
|2
|instrument: byte (0-127)
|
|-
|[[FF9/Sound/Opcodes/0x0099|0xA2]]
|Overwrite Next Note Length
|2
|length: byte
|Ignores the regular length (delta-time) of the next note and overwrites it with the specified length.
|-
|[[FF9/Sound/Opcodes/0xa8aa|0xA3]]
|Channel Master Volume
|2
|volume: byte (0-127)
|
|-
|[[FF9/Sound/Opcodes/0xa4|0xA4]]
|Pitch Bend Slide
|3
|length: byte, semitones: signed byte
|When <code>length</code> is 0, it will be translated to 256 ticks.
|-
|[[FF9/Sound/Opcodes/0xa5|0xA5]]
|Set Octave
|2
|octave: byte (0-15)
|
|-
|[[FF9/Sound/Opcodes/0xa5|0xA6]]
|Increase Octave
|1
|
|
|-
|[[FF9/Sound/Opcodes/0xa5|0xA7]]
|Decrease Octave
|1
|
|
|-
|[[FF9/Sound/Opcodes/0xa8aa|0xA8]]
|Channel Volume
|2
|volume: byte (0-127)
|
|-
|[[FF9/Sound/Opcodes/0xa9|0xA9]]
|Channel Volume Slide
|3
|length: byte, volume: byte (0-127)
|When <code>length</code> is 0, it will be translated to 256 ticks.
|-
|[[FF9/Sound/Opcodes/0xa8aa|0xAA]]
|Channel Pan
|2
|pan: byte (0-127)
|64 is the center.
|-
|[[FF9/Sound/Opcodes/0xab|0xAB]]
|Channel Pan Slide
|3
|length: byte, pan: byte (0-127)
|When <code>length</code> is 0, it will be translated to 256 ticks.
|-
|[[FF9/Sound/Opcodes/0xac|0xAC]]
|Noise Clock Frequency
|2
|clock: byte (0x00-0x3f)
|
|-
|[[FF9/Sound/Opcodes/ADSR|0xAD]]
|ADSR: Attack Rate
|2
|attack_rate: byte (0x00-0x7f)
|
|-
|[[FF9/Sound/Opcodes/ADSR|0xAE]]
|ADSR: Decay Rate
|2
|decay_rate: byte (0x00-0x0f)
|
|-
|[[FF9/Sound/Opcodes/ADSR|0xAF]]
|ADSR: Sustain Level
|2
|sustain_level: byte (0x00-0x0f)
|
|-
|[[FF9/Sound/Opcodes/ADSR|0xB0]]
|ADSR: Decay Rate & Sustain Level
|3
|decay_rate: byte (0x00-0x0f), sustain_level: byte (0x00-0x0f)
|
|-
|[[FF9/Sound/Opcodes/ADSR|0xB1]]
|ADSR: Sustain Rate
|2
|sustain_rate: byte (0x00-0x7f)
|
|-
|[[FF9/Sound/Opcodes/ADSR|0xB2]]
|ADSR: Release Rate
|2
|release_rate: byte (0x00-0x1f)
|
|-
|[[FF9/Sound/Opcodes/ADSR|0xB3]]
|ADSR: Reset ADSR
|1
|
|
|-
|[[FF9/Sound/Opcodes/0xb4b5|0xB4]]
|Channel Pitch LFO (Vibrato)
|4
|delay: byte, rate: byte, type: byte (0-15)
|When <code>rate</code> is 0, it will be translated to 256 ticks.
|-
|[[FF9/Sound/Opcodes/0xb4b5|0xB5]]
|Channel Pitch LFO Depth
|2
|depth: byte
|The most significant bit of the <code>depth</code> determines the amplitude range.

When it is 0, the range is up to about ± 50 cents (amplitude is 15/256 compared with range type 1).

When it is 1, the range is up to about ± 700 cents.
|-
|[[FF9/Sound/Opcodes/0xb4b5|0xB6]]
|Turn Off Channel Pitch LFO
|1
|
|
|-
|[[FF9/Sound/Opcodes/ADSR|0xB7]]
|ADSR: Attack Mode
|2
|attack_mode: byte (1 or 5)
|
|-
|[[FF9/Sound/Opcodes/0xb8b9|0xB8]]
|Channel Volume LFO (Tremolo)
|4
|delay: byte, rate: byte, type: byte (0-15)
|When <code>rate</code> is 0, it will be translated to 256 ticks.
|-
|[[FF9/Sound/Opcodes/0xb8b9|0xB9]]
|Channel Volume LFO Depth
|2
|depth: byte
|
|-
|[[FF9/Sound/Opcodes/0xb8b9|0xBA]]
|Turn Off Channel Volume LFO
|1
|
|
|-
|[[FF9/Sound/Opcodes/ADSR|0xBB]]
|ADSR: Sustain Mode
|2
|sustain_mode: byte (1, 3, 5 or 7)
|
|-
|[[FF9/Sound/Opcodes/0xbcbd|0xBC]]
|Channel Pan LFO
|3
|rate: byte, type: byte (0-15)
|When <code>rate</code> is 0, it will be translated to 256 ticks.
|-
|[[FF9/Sound/Opcodes/0xbcbd|0xBD]]
|Channel Pan LFO Depth
|2
|depth: byte
|
|-
|[[FF9/Sound/Opcodes/0xbcbd|0xBE]]
|Turn Off Channel Pan LFO
|1
|
|
|-
|[[FF9/Sound/Opcodes/0xbf|0xBF]]
|ADSR: Release Mode
|2
|release_mode: byte (3 or 7)
|
|-
|[[FF9/Sound/Opcodes/0xc0c1|0xC0]]
|Channel Transpose (Absolute)
|2
|semitones: signed byte
|
|-
|[[FF9/Sound/Opcodes/0xc0c1|0xC1]]
|Channel Transpose (Relative)
|2
|semitones: signed byte
|
|-
|[[FF9/Sound/Opcodes/0xc2c3|0xC2]]
|Turn On Reverb
|1
|
|
|-
|[[FF9/Sound/Opcodes/0xc2c3|0xC3]]
|Turn Off Reverb
|1
|
|
|-
|[[FF9/Sound/Opcodes/0xc4c5|0xC4]]
|Turn On Noise
|1
|
|
|-
|[[FF9/Sound/Opcodes/0xc4c5|0xC5]]
|Turn Off Noise
|1
|
|
|-
|[[FF9/Sound/Opcodes/0xc6c7|0xC6]]
|Turn On Frequency Modulation
|1
|
|
|-
|[[FF9/Sound/Opcodes/0xc6c7|0xC7]]
|Turn Off Frequency Modulation
|1
|
|
|-
|[[FF9/Sound/Opcodes/0xc8c9|0xC8]]
|Loop Point
|1
|
|Remember the current offset as a loop point and increase the nesting level of the loop.
|-
|[[FF9/Sound/Opcodes/0xc8c9|0xC9]]
|Return to Loop Point Up to N Times
|2
|times: byte
|On the Nth repeat, this instruction will end the current loop by decrementing the nesting level of the loop. Otherwise, it will increment the loop counter and return to the loop point.
When <code>times</code> is 0, it will be translated to 256 times.
|-
|[[FF9/Sound/Opcodes/0xc8c9|0xCA]]
|Return to Loop Point
|1
|
|This instruction will increment the loop counter.
|-
|[[FF9/Sound/Opcodes/0xcb|0xCB]]
|Reset Sound Effects
|1
|
|Reset sound effects such as noise, frequency modulation, reverb, overlay voice and alternate voice.
|-
|[[FF9/Sound/Opcodes/0xcccd|0xCC]]
|Turn On Legato
|1
|
|This instruction will stop the regular key on and key off performance of the subsequent notes and update the pitch only.
|-
|[[FF9/Sound/Opcodes/0xcccd|0xCD]]
|Turn Off Legato
|1
|
|
|-
|[[FF9/Sound/Opcodes/0xcecf|0xCE]]
|Turn On Noise and Toggle Noise On/Off after a Period of Time
|2
|delay: byte
|When <code>delay</code> is 0, it will be translated to 257 ticks.
|-
|[[FF9/Sound/Opcodes/0xcecf|0xCF]]
|Toggle Noise On/Off after a Period of Time
|2
|delay: byte
|When <code>delay</code> is 0, it will be translated to 257 ticks.
|-
|[[FF9/Sound/Opcodes/0xd0d1|0xD0]]
|Turn On Full-Length Note Mode
|1
|
|This instruction will stop the regular key off performance of the subsequent notes.
|-
|[[FF9/Sound/Opcodes/0xd0d1|0xD1]]
|Turn Off Full-Length Note Mode
|1
|
|
|-
|[[FF9/Sound/Opcodes/0xd2d3|0xD2]]
|Turn On Frequency Modulation and Toggle Frequency Modulation On/Off after a Period of Time
|2
|delay: byte
|When <code>delay</code> is 0, it will be translated to 257 ticks.
|-
|[[FF9/Sound/Opcodes/0xd2d3|0xD3]]
|Toggle Frequency Modulation On/Off after a Period of Time
|2
|delay: byte
|When <code>delay</code> is 0, it will be translated to 257 ticks.
|-
|[[FF9/Sound/Opcodes/0xd4d5|0xD4]]
|Turn On Playback Rate Side Chain
|1
|
|Duplicate and use the playback frequency of the previous voice channel.
|-
|[[FF9/Sound/Opcodes/0xd4d5|0xD5]]
|Turn Off Playback Rate Side Chain
|1
|
|
|-
|[[FF9/Sound/Opcodes/0xd6d7|0xD6]]
|Turn On Pitch-Volume Side Chain
|1
|
|Multiply the playback frequency of the previous voice channel to the output volume. Lower pitch will make the volume smaller.
|-
|[[FF9/Sound/Opcodes/0xd6d7|0xD7]]
|Turn Off Pitch-Volume Side Chain
|1
|
|
|-
|[[FF9/Sound/Opcodes/0xd8d9|0xD8]]
|Channel Fine Tuning (Absolute)
|2
|amount: signed byte
|The pitch can be changed in the range of one octave above and below.
The <code>amount</code> is the multiplicand for the playback frequency, not a log-based parameter like cents. For example, when the <code>amount</code> is 127, the pitch will be multiplied by 127/128 (about +1 octave). Negative value ​​will lower the pitch.
|-
|[[FF9/Sound/Opcodes/0xd8d9|0xD9]]
|Channel Fine Tuning (Relative)
|2
|amount: signed byte
|The <code>amount</code> will be added to the current tuning amount.
|-
|[[FF9/Sound/Opcodes/0xdadb|0xDA]]
|Turn On Portamento
|2
|speed: byte
|When <code>speed</code> is 0, it will be translated to 256 ticks.
|-
|[[FF9/Sound/Opcodes/0xdadb|0xDB]]
|Turn Off Portamento
|1
|
|
|-
|[[FF9/Sound/Opcodes/0x0099|0xDC]]
|Fix Note Length
|2
|length_to_add: signed byte
|Ignore the regular length (delta-time) of subsequent notes and set to the fixed length. The <code>length_to_add</code> parameter will be added to the current length value. (the initial value is 0)
|-
|[[FF9/Sound/Opcodes/0xdd|0xDD]]
|Channel Pitch LFO Depth Slide
|3
|length: byte, depth: byte
|When <code>length</code> is 0, it will be translated to 256 ticks.
|-
|[[FF9/Sound/Opcodes/0xde|0xDE]]
|Channel Volume LFO Depth Slide
|3
|length: byte, depth: byte
|When <code>length</code> is 0, it will be translated to 256 ticks.
|-
|[[FF9/Sound/Opcodes/0xdf|0xDF]]
|Channel Pan LFO Depth Slide
|3
|length: byte, depth: byte
|When <code>length</code> is 0, it will be translated to 256 ticks.
|-
|[[FF9/Sound/Opcodes/0xe0|0xE0]]
|Unknown
|1
|
|
|-
|[[FF9/Sound/Opcodes/0xe1|0xE1]]
|Unknown
|2
|value: byte
|
|-
|[[FF9/Sound/Opcodes/0xe2|0xE2]]
|Unknown
|1
|
|Clears the effect of opcode 0xE1
|-
|[[FF9/Sound/Opcodes/0xe3|0xE3]]
|Unimplemented
|1
|
|Code-referenced to 0xA0. Should not be used.
|-
|[[FF9/Sound/Opcodes/0xe4|0xE4]]
|Channel Pitch LFO Rate Slide
|3
|length: byte, rate: byte
|When <code>length</code> is 0, it will be translated to 256 ticks.
|-
|[[FF9/Sound/Opcodes/0xe5|0xE5]]
|Channel Volume LFO Rate Slide
|3
|length: byte, rate: byte
|When <code>length</code> is 0, it will be translated to 256 ticks.
|-
|[[FF9/Sound/Opcodes/0xe6|0xE6]]
|Channel Pan LFO Rate Slide
|3
|length: byte, rate: byte
|When <code>length</code> is 0, it will be translated to 256 ticks.
|-
|[[FF9/Sound/Opcodes/0xa0|0xE7-0xEF]]
|Unimplemented
|1
|
|Code-referenced to 0xA0. Should not be used.
|-
|[[FF9/Sound/Opcodes/0xf0fd|0xF0-0xFD]]
|Note, Tie, Rest with Length
|2
|length: byte
|
|-
|[[FF9/Sound/Opcodes/0xfe00|0xFE 0x00]]
|Tempo
|4
|tempo: uint16
|bpm = tempo / 218.453333 (approximate)
More strictly, <code>bpm = 60.0 / (48 * (65536.0 / tempo) * (0x43D1 / (33868800.0 / 8)))</code>

Note that this coefficient is different from other games with PlayStation AKAO.
|-
|[[FF9/Sound/Opcodes/0xfe00|0xFE 0x01]]
|Tempo Slide
|5
|length: byte, tempo: uint16
|When <code>length</code> is 0, it will be translated to 256 ticks.
|-
|[[FF9/Sound/Opcodes/0xfe02|0xFE 0x02]]
|Reverb Depth
|4
|depth: uint16
|
|-
|[[FF9/Sound/Opcodes/0xfe02|0xFE 0x03]]
|Reverb Depth Slide
|5
|length: byte, depth: uint16
|When <code>length</code> is 0, it will be translated to 256 ticks.
|-
|[[FF9/Sound/Opcodes/0xfe04|0xFE 0x04]]
|Turn On Drum Mode
|2
|
|The drum map offset is recorded in the file header.
|-
|[[FF9/Sound/Opcodes/0xfe04|0xFE 0x05]]
|Turn Off Drum Mode
|2
|
|
|-
|[[FF9/Sound/Opcodes/0xfe06|0xFE 0x06]]
|Unconditional Jump
|4
|destination_offset: signed int16
|This instruction can be used to make an infinite loop.
|-
|[[FF9/Sound/Opcodes/0xfe07|0xFE 0x07]]
|CPU-Conditional Jump
|5
|condition: byte, destination_offset: signed int16
|Jump if the condition variable matches <code>condition</code>. The value of the condition variable can be set from the game program.
|-
|[[FF9/Sound/Opcodes/0xfe08|0xFE 0x08]]
|Jump on the Nth Repeat
|5
|times: byte, destination_offset: signed int16
|When <code>times</code> is 0, it will be translated to 256 times.
|-
|[[FF9/Sound/Opcodes/0xfe08|0xFE 0x09]]
|Break the Loop on the Nth Repeat
|5
|times: byte, destination_offset: signed int16
|Unlike 0xF0, this instruction will end the current loop by decrementing the nesting level of the loop.
When <code>times</code> is 0, it will be translated to 256 times.
|-
|[[FF9/Sound/Opcodes/0xa1|0xFE 0x0A]]
|Load Instrument (With Some Unknown Effect)
|3
|instrument: byte
|
|-
|[[FF9/Sound/Opcodes/0xfe0b|0xFE 0x0B]]
|Unknown
|6
|offset: signed int16, offset2: signed int16
|
|-
|[[FF9/Sound/Opcodes/0xa0|0xFE 0x0C-0x0D]]
|Unimplemented
|2
|
|Code-referenced to 0xA0. Should not be used.
|-
|[[FF9/Sound/Opcodes/0xfe0e|0xFE 0x0E]]
|Subroutine Jump
|4
|destination_offset: signed int16
|The subroutine jump cannot be nested. It will overwrite the return address.
|-
|[[FF9/Sound/Opcodes/0xfe0f|0xFE 0x0F]]
|Return from Subroutine
|2
|
|
|-
|[[FF9/Sound/Opcodes/0xfe10|0xFE 0x10]]
|Unknown
|3
|value: byte
|
|-
|[[FF9/Sound/Opcodes/0xfe10|0xFE 0x11]]
|Unknown
|2
|
|Clears the effect of opcode 0xFE 0x10
|-
|[[FF9/Sound/Opcodes/0xa3|0xFE 0x12]]
|Channel Master Volume Slide
|3
|length: byte, volume: byte (0-127)
|When <code>length</code> is 0, it will be translated to 256 ticks.
|-
|[[FF9/Sound/Opcodes/0xa0|0xFE 0x13]]
|Unimplemented
|2
|
|Code-referenced to 0xA0. Should not be used.
|-
|[[FF9/Sound/Opcodes/0xfe14|0xFE 0x14]]
|Load Custom Instrument (Key-Split Instrument)
|3
|instrument: byte
|The custom instrument number corresponds to the custom instrument map pointed from the file header. Note that the number is different from the regular sample number used in opcode 0xA1.
|-
|[[FF9/Sound/Opcodes/0xfe15|0xFE 0x15]]
|Time Signature
|4
|ticks_per_beat: byte, beats_per_measure: byte
|Note that two parameters can be 0. This pattern is used for initialization.
|-
|[[FF9/Sound/Opcodes/0xfe16|0xFE 0x16]]
|Measure Number
|3
|measure: byte
|
|-
|[[FF9/Sound/Opcodes/0xa0|0xFE 0x17-0x18]]
|Unimplemented
|2
|
|Code-referenced to 0xA0. Should not be used.
|-
|[[FF9/Sound/Opcodes/0xfe19|0xFE 0x19]]
|Unknown
|?
|?
|
|-
|[[FF9/Sound/Opcodes/0xfe1a|0xFE 0x1A]]
|Unknown
|?
|?
|
|-
|[[FF9/Sound/Opcodes/0xfe1b|0xFE 0x1B]]
|Unknown
|?
|?
|
|-
|[[FF9/Sound/Opcodes/0xfe1c|0xFE 0x1C]]
|Unknown
|?
|?
|
|-
|[[FF9/Sound/Opcodes/0xfe1d|0xFE 0x1D]]
|Unknown
|?
|?
|
|-
|[[FF9/Sound/Opcodes/0xfe1e|0xFE 0x1E]]
|Unknown
|?
|?
|
|-
|[[FF9/Sound/Opcodes/0xa0|0xFE 0x1F]]
|Unimplemented
|2
|
|Code-referenced to 0xA0. Should not be used.
|-
|0xFE 0x20-0xFF
|Unimplemented (Out of Range)
|n/a
|
|Do not use.
|-
|[[FF9/Sound/Opcodes/0xa0|0xFF]]
|Unimplemented
|1
|
|Code-referenced to 0xA0. Should not be used.
|}
112
edits