From CloudModding TWW Wiki

AAF stores sound effect, wave, instrument, and music data.

AAF Header

The file's headers is composed to several int32's packed in a common format.

The first int32 will always read the ID of a section. When you read 0, you stop reading.

Header Entry Structure

id Structure Description
0
(none) Tells to stop reading this section
1
(int32 offset, int32 size, int32 type) Pointer to the BST (Binary Sound Table)
2
(int32 offset, int32 size, int32 flags) until offset = 0 then continue IBNK Pointer Table
3
(int32 offset, int32 size, int32 flags) until offset = 0 then continue WSYS Pointer Table
4
(int32 offset, int32 size, int32 type) Pointer to BSC (Binary Sequence Collection)
5
(int32 offset, int32 size, int32 type) Pointer to the BSM (Binary Stream Map)

Sample Parsing Code

while (true)
{
 var ChunkID = aafRead.ReadUInt32();
 switch (ChunkID)
  {
   case 0:                        
    return;
   case 1: 
   case 5:
   case 4:
   case 6:
   case 7:
   {
       offset = aafRead.ReadUInt32();
       size = aafRead.ReadUInt32();
       type = aafRead.ReadUInt32();
       break;
   }
   case 2: // INST
   {
     while (true)
     {
       var offset = aafRead.ReadUInt32();
       if (offset == 0)
           break;  // 0 means we reached the end.
       var size = aafRead.ReadUInt32();
       var type = aafRead.ReadUInt32();
     }
   }
   break;						
   case 3: // WSYS 
   {
     
     while (true)
     {
       var offset = aafRead.ReadUInt32();
       if (offset == 0)
           break;  // 0 means we reached the end.
       var size = aafRead.ReadUInt32();
       var type = aafRead.ReadUInt32();
     }
     break;
   }
  }
}

IBNK

IBNK Stands for "Instrument Bank". It holds the parameters required to play one of the sounds out of the WSYS as a melodic instrument. They can also contain sound effects. All pointers are relative to the 0th byte of the IBNK

Header

Offset Type Name Description
0x00
int32 0x49424e4b 'IBNK' Magic
0x04
int32 Size Size of the IBNK
0x08
int32 ID Global IBNK ID
0x0C
int32 Flags Flags
0x10
byte[0x14] Padding Padding
0x24
int32 0x42414E4B 'BANK' Magic
0x28
int32*[0xF0] Instrument Pointers Pointers to instrument objects (0 = empty slot)

INST

Offset Type Name Description
0x00
int32 0x494E5354 'INST' Magic
0x04
int32 0 Zero (Padding)
0x08
float frequencyMultiplier Frequency Multiplier
0x0C
float gainMultiplier gainMultiplier
0x10
int32* Osc1* Pointer to first JOscillator (0 = null)
0x14
int32* Osc2* Pointer to second JOscillator(0 = null)
0x18
int32* Eff1* Pointer to first Effect (0 = null)
0x1C
int32* Eff2* Pointer to second Effect (0 = null)
0x20
int32* Sen1* Pointer to first sensor (0 = null)
0x24
int32* Sen2* Pointer to second swnsor (0 = null)
0x28
int32 keyRegionCount Count of key regions
0x2C
InstrumentKeyRegion*[keyRegionCount] Key Regions int32 pointers to key regions

InstrumentKeyRegion

Container for an instruments keys. Usually there's only one. The "root key" item defines the key this specific key object is assigned to. By default, it starts at 0. The next definition fills all the keys in betwen, meaning if the next root key was 127, the keys at 0-127 would be assigned to that region.

A single key has two parts to it. The note, and the velocity. The note is specified by the key region, and the velocity regions are defined by attaching them to key regions.

Velocity regions, being the final part of the sound, handle the finetuning, and wave selection.

Offset Type Name Description
0x00
byte bKey base Key
0x01
byte[3] padding padding
0x04
int32 velocityRegionCount Count of velocity regions
0x08
InstrumentVeloRegion*[velocityRegionCount] velregptr Int32 pointers to each velocity region.

InstrumentVeloRegion

The velocity region of a KeyRegion. The "root velocity" operates identically to the Key Region.

Offset Type Name Description
0x00
byte bKey root velocity
0x01
byte[3] padding padding
0x04
short wsysID WSYS that the sound for this instrument is in.
0x06
short waveID WaveID in the WSYS that the sound for this instrument is in.
0x08
float gainMultFT Finetune float for gain / volume
0x0C
float freqMultFT Finetune float for pitch / frequency

PER2

A type of INST that doesn't have a pitch or gain on the main instrument, or as many features (like oscillators)

Offset Type Name Description
0x00
int32 0x50455232 'PER2' Magic
0x04
byte[0x84] 0 Unused
0x8C
PercussionKey*[100] 100 percussion entries Int32 pointers to percussion keys

PercussionKey

Key type for PER2's instrument data (Not regioned)

Offset Type Name Description
0x00
float pitch Finetune Pitch
0x04
float volume Finetune Gain
0x08
byte[8] unused unused
0x10
int32 velocityRegionCount Count of velocity regions
0x14
InstrumentVeloRegion*[velocityRegionCount] velregptr Int32 Pointers to each velocity region.

JOscillator

JAITOscillator is an internal name. It stands for JAudioInterface:TOscillator.


They have no header data, and no other identifying data. , they are pointed to directly by INST objects.

The width and vertex operators are used mainly for effects like vibrato.

Offset Type Name Description
0x00
byte JOscillatorMode Mode / Target
0x01
byte[3] padding padding
0x04
float rate rate
0x08
int32* attackEnvOffset Int32 pointer to attack JEnvelope
0x0C
int32* releaseEnvOffset Int32 pointer to release JEnvelope
0x10
float width Width of the oscillator
0x14
float vertex Vertex of the oscillator

JOscillatorMode

Different modes that the JOscillator can target.

mode Name Desc
0x01
Volume Changes volume of instrument
0x02
Pitch Changes pitch of instrument
0x03
Pan Changes pan of instrument
0x04
FX Changes filter
0x05
Dolby (Unused) for digital sound output / dolby surround

JEnvelope

JEnvelopes are only referenced by a JOscillator.

Similar to their parent, they have no identifying header data. In addition, they have no static length. They are ended by an end marker (Which in practice, will require a double scan)

A JEnvelope is composed of vectors with modes with a structure as follows:

Offset Type Name Description
0x00
short JEnvelopeMode Mode selection for this vector
0x02
short time Time that this takes place (In ticks)
0x06
short value Value of this vector at this time
0x10
int32 velocityRegionCount Count of velocity regions

JEnvelopeMode

mode Name Desc
0x00
Linear Linear approach to the next vector value
0x01
Square Square curve approach to the next vector value
0x02
Square Square Root (n^0.5) curve approach to the next vector value
0x03
SampleCell Unknown, (Unused?)
0x0D
Loop Command vector, defines a loop point
0x0E
Hold Pauses the envelope, usually used after it completes
0x0F
Stop Stops both the instrument and the envelope

WSYS

Internally, Wave System.

This section contains all of the information required for decoding the AW File as well as other information for melodic tuning, root key, and other various parts of JAudio.


Offset Type Name Description
0x00
int32 0x57535953 'WSYS' Magic
0x04
int32 size WSYS Size
0x08
int32 wsysID WSYS ID (This is how insts select the wsys)
0x0C
int32 flags Flags
0x10
int32 [[AAF#WINF WINF Pointer]]
0x14
int32 [[AAF#WINF WBCT Pointer]]

WINF

WINF is a pointer container. They point to the Wave Groups.

The ID's for every wave group are controlled by the | SCNE object. They line up, WaveGroup[1] uses WaveScenes[1]


Offset Type Name Description
0x00
int32 0x57494E46 'INF' Magic
0x04
int32 waveGroupCount Count of wavegroups
0x08
WaveGroup*[] (int32) waveGroupPointers Pointers to the individual wavegroups.