VAG (PlayStation)

From Just Solve the File Format Problem
Jump to: navigation, search
File Format
Name VAG (PlayStation)
Ontology
Extension(s) .vag

VAG is the PlayStation single waveform data format for 4-bit mono ADPCM-encoded data of sampled sounds. While the VAG format is most commonly associated with PS1 games, it is also used in some notable PS2 and PSP games.

Multiple VAG files can be combined in a VAB file.


Contents

Specification

Variable Type
Signature VAGp
Version 4 bytes
Reserved 4 bytes
Data size (Bytes) 4 bytes
Sampling frequency 4 bytes
Reserved 12 bytes
Name 16 bytes
Waveform data (remainder of data)

Version identifies which version of AIFF2VAG created the file.
— Mac converters
v1.3 ‘00000002’
v1.6+ ‘00000003’
— PC converters
-v1.8 ‘00000000’
v2.0+ ‘00000020’

Sampling frequency can be used to determine the pitch at which to play the VAG. pitch = (sampling frequency <<12)/44100L

Ex: 44.1kHz=0x1000, 22.05kHz=0x800, etc.

All VAGs must have a lead-in of 16 bytes of zero data. This data initializes the SPU in order to prevent clipping noises.

Restrictions of the SPU sound source memory requires that the total of VAG data be 520,160 bytes or less. Since ADPCM has 3.5:1 compression, the source samples would have to fit into a maximum of 1.7MB.

For any loops, the SPU requires that all parameters be in multiples of 28. Thus the starting frame of the loop, the ending frame of the loop, and the length of the loop must be multiples of 28.

The data (after the 48 byte header) is arranged into 16 byte sections. There are 2 header bytes, followed by 14 compressed bytes of sound data. The second header byte is the interesting one as far as looping is concerned. In a non looping sample, the sections will be like this:

XX 00 XX XX XX XX XX XX XX XX XX XX XX XX XX XX

The second header byte is always set to 0. (except for the very last two 16 byte blocks of a non-looping sample (see below).)

For a looping sample, you can really only set the loop starting point - the end of the loop can only be at the end of the sample. You set the two points by setting the appropriate bits in the second header byte of the 16 byte section you want them to be in. Like this:

Start of loop:
XX 06 XX XX XX XX XX XX XX XX XX XX XX XX XX XX

End of loop (also the last 16 bytes of the sample):
XX 03 XX XX XX XX XX XX XX XX XX XX XX XX XX XX

(BTW, the second header byte of the second last 16 byte section of a non-looping sample will be set to 01 instead of 03. This is then followed by a 16 byte SPU irq clear block, which looks like this:

00 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[or]
00 07 77 77 77 77 77 77 77 77 77 77 77 77 77 77

As you can see, you can only set loop points at the 16 byte block level, you cannot be more accurate than that. (Actually its worse than that, because each 16 byte block corresponds to 28 bytes of the original uncompressed sample data).


Software


Sample code to run on PS1


Sample files


Notes

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox