SFX (SA)

From GTAModding
Jump to: navigation, search

San Andreas introduces a different method of dealing with SFX compared to it's antecessor, now not only sound indices are available but packages and banks.

Packages are a way to organize the SFX data in different files and banks are a way to organize SFX data in one package. Each bank contains up to 200 sounds. Normally the entire bank is loaded at once, but depending on some circumstances the game might load only a single sound from the bank.

File Formats

The SFX config formats are pure dumps of game structures, and so contains a lot of irrelevant data. They are stored in the audio/CONFIG directory and have a .dat extension.

PakFiles.dat

This file is used to enumerate SFX Packages, it's structure is just a list of file names.

repeat (any amount) times:
    char[52]     File Name (relative to the audio/SFX directory)

The first named package has the index 0, the second named package the index 1 and so on.

BankLkup.dat

This file is used to enumerate global bank numbers with it's respective SFX Package.

repeat (any amount) times:
    uint8_t     SFX Package index (as specified in PakFiles.dat)
    uint8_t[3]  Unused      (padding)
    uint32_t    Bank offset (where this bank header starts on the package file)
    uint32_t    Bank size   (the size of this entire bank without the header)

The game uses global indices to lookup for banks internally, so changing the order of the enumeration will cause problems.

SFX Packages

Those are the files responsible for storing all the raw sound data. They are at the audio/SFX directory with no extension.

The file structure is basically many bank headers (at any offset) followed by it's sound buffers. The offset where each bank header is located is specified by the file BankLkup.dat.

uint16_t        Number of sounds in this bank (maximum of 200)
uint16_t        Unused (padding)
repeat (400) times:
    uint32_t     Sound buffer offset (relative to the end of this header)
    uint32_t     Loop offset (in samples)
    uint16_t     Sample rate
    uint16_t     Sound headroom

Following this header are the buffer for the sounds in this bank. Each buffer should be in raw Mono PCM 16-bits format.

Even though there is space in the header for 400 sounds, only 200 are allowed.

BankSlot.dat

A bank slot is capable of storing some SFX data, this data can be either one entire bank or one single sound from a bank. There is a total of 45 bank slots.

Each bank slot is used by a specific audio class of the game, for example 10 slots are used for vehicle banks, one slot for the bank of explosions, 4 slots for script speeches (which stores single sounds), and so on.

uint16_t    Number of Slots (must be 45)
repeat (Number of Slots) times
    uint32_t    Sum of all buffer size before this slot (ignored)
    uint32_t    Buffer size for this slot
    uint32_t    Unknown (related to feet sounds)
    uint32_t    Unknown (related to feet sounds)
    byte[4804]  Ignored

Each slot owns a buffer capable of storing some amount of sound data, if this size is lower than the size of the data stored in the slot, sound artifacts will occur in-game.

By default, those buffer sizes are arbitrary values, but it can safely be the size of the highest bank stored in the slot or the size of the highest sound stored in the slot, depending if the slot is used to store a sound or a bank.

Scripting

Sounds can be used in SCM with the following opcodes:

  • 018C – Plays a sound on a specific location
  • 018E – Stops the played sound
  • 03CF – Loads a sound
  • 03D0 – Checks if sound has been loaded
  • 03D1 – Plays the loaded sound
  • 03D2 – Checks if the loaded sound has finished
  • 097A – Plays a audio event
  • 097B – Plays a audio event in an object
  • 09F1 – Plays a audio event in a character
  • 09F7 – Plays a audio event in a vehicle
  • 09D6 – Makes a character say a scripted speech

Tools

  • San Andreas Audio Toolkit – Allows you to modify SFX Packages – It contains a bug related to bank slots causing sound artifacts
  • GTA Net GTAForums: Mod Loader – Allows you to easily change SFX data and fixes the sound artifacts on big sounds.
  • GTA Net GTAForums: Dynamic SFX – Fixes sound artifacts caused by sounds bigger than the original.

See also

External links