VAG (PlayStation)
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
- FFmpeg
- PSXAvenc
- vgmstream (previously in_cube) (github)
- Video Game Sound Converter - VGSC is a UI wrapper for vgstream
- vgmstream-web online web player/converter using vgmstream
- zxtune (uses vgmstream library)
- PsyQ sdk - contains graphical editor VAG Editor v1.0 (VAGEDIT.exe) (tutorial)
- PsxSampler
- PlayStation 2 VAG Tool (aka PS2 VAG TOOL aka AIFF2VAG)
- Aikku93's wav2vag
- bITmASTER's wav2vag
- bITmASTER's vag2wav
- PsxSound 1.0 by SM0N (aka PSXSND.EXE) - Convert your PSX VAG/VAB/VB+VH/RAW soundfiles to .WAV
- Psx Audio Tools 0.1 by Mumbly - includes Vab Ripper, Vab 2 Vag and Vag_Depack
- VAG pack and VAG depack v0.1 by bITmASTER - aka PSX VAG-Packer and VAG-Depack
- Search v1.1 by Reptile - searches for PSX files (including VAB and VAG) in any file
- PSound (alt link)
- SoundReaver 2 addon for PSound (specific to Soul Reaver 2 and Blood Omen 2)
- MFAudio
- Winning Eleven Multi Tool 2K24 By CARP (includes VAG Extractor)
- PS2 VAG interleave value guesser and files extractor by Luigi Auriemma (VAGGUESS)
- vag_scanner by id-daemon
- VAG_scanner.bms - QuickBMS script to scan a file for mono VAG files
- VAGPlayer for Windows CE
- Wav to Vag V3.0 for PSP by highboy (info thread)
- FMJ-Software Awave Studio
- WonderFox HD Video Converter Factory Pro
- Watto Studios Game Extractor
- Online conversion from ConvertAll
- VAG Converter (from PSP SDK)
- Multistream F-Packer (from PS2 SDK)
Sample code to run on PS1
- Multiple examples
- sample code to load a VAG file to SPU sound buffer and play it back
- sample code to load VAG samples to the SPU sound buffer and play them back with pad input
- VAG Example (VAG DEMO) - example of how to play VAG audio from the SPU RAM with DMA
Sample files
Notes
- How to make PS1 samples for FREE! from SoundFontGuy on YouTube
- PlayStation file formats pg 212 on psx.arthus.net
- File Format from ABelliqueux
- FileFormat47.pdf pg 209
- LibOver47.pdf pg 271
- LibRef47.pdf pg 980
- notes on VAG looping from Silpheed
- Tutorial: generic SFX ripping for PS1/PS2/PSP
- what instruments or Daw were used to compose music for psx games in the past?
- PlayStation VAG Audio at Reverse Engineering Wiki
- Manually extracting VAG files with a hex editor