VAG (PlayStation)

From Just Solve the File Format Problem
(Difference between revisions)
Jump to: navigation, search
(Created page with "'''VAG''' is the PlayStation single waveform data format for ADPCM-encoded data of sampled sounds. == Specification == {| class="wikitable" ! Variable ! Type |-...")
 
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
'''VAG''' is the PlayStation single waveform data format for [[ADPCM|ADPCM-encoded data]] of sampled sounds.
+
{{FormatInfo
 +
|formattype=electronic
 +
|subcat=Audio and Music
 +
|extensions={{ext|vag}}
 +
}}
  
== Specification ==
+
[[Category:Resident Evil (1997)]]
  
 +
'''VAG''' is the PlayStation single waveform data format for 4-bit mono [[ADPCM|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.
 +
 +
 +
== Specification ==
 
{| class="wikitable"
 
{| class="wikitable"
 
! Variable
 
! Variable
Line 17: Line 26:
 
| 4 bytes
 
| 4 bytes
 
|-
 
|-
| Data size
+
| Data size (Bytes)
 
| 4 bytes
 
| 4 bytes
 
|-
 
|-
 
| Sampling frequency
 
| Sampling frequency
 
| 4 bytes
 
| 4 bytes
 +
|-
 +
| Reserved
 +
| 12 bytes
 
|-
 
|-
 
| Name
 
| Name
Line 29: Line 41:
 
| (remainder of data)
 
| (remainder of data)
 
|}
 
|}
 +
 +
Version identifies which version of AIFF2VAG created the file.<br>
 +
— Mac converters<br>
 +
v1.3 ‘00000002’<br>
 +
v1.6+ ‘00000003’<br>
 +
— PC converters<br>
 +
-v1.8 ‘00000000’<br>
 +
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:<br>
 +
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):<br>
 +
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<br>
 +
[or]<br>
 +
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]]
 +
* [https://github.com/WonderfulToolchain/psxavenc PSXAvenc]
 +
* [https://vgmstream.org/ vgmstream (previously in_cube)] ([https://github.com/vgmstream/vgmstream github])
 +
** [https://wiki.vg-resource.com/Video_Game_Sound_Converter Video Game Sound Converter] - VGSC is a UI wrapper for vgstream
 +
** [https://katiefrogs.github.io/vgmstream-web vgmstream-web] online web player/converter using vgmstream
 +
** [https://zxtune.bitbucket.io/ zxtune] (uses vgmstream library)
 +
* [https://psx.arthus.net/sdk/Psy-Q/PSYQ_SDK.zip PsyQ sdk] - contains graphical editor VAG Editor v1.0 (VAGEDIT.exe) ([https://web.archive.org/web/20221104183535/https://winningeleven-games.com/showthread.php?tid=8880 tutorial])
 +
* [https://github.com/BodbDearg/PlayStation1Vsts/releases PsxSampler]
 +
* [https://github.com/eurotools/es-ps2-vag-tool PlayStation 2 VAG Tool (aka PS2 VAG TOOL aka AIFF2VAG)]
 +
* [https://github.com/Aikku93/wav2vag Aikku93's wav2vag]
 +
* [https://github.com/ColdSauce/psxsdk/blob/master/tools/wav2vag.c bITmASTER's wav2vag]
 +
** [https://github.com/ABelliqueux/nolibgs_hello_worlds/wiki/VAG tutorial to convert mp3 to vag with FFmpeg and wav2vag]
 +
** [http://psx.arthus.net/code/VAG/wav2vag-win32.zip compiled version of wav2vag for win32]
 +
* [https://github.com/ColdSauce/psxsdk/blob/master/tools/vag2wav.c bITmASTER's vag2wav]
 +
* [https://hitmen.c02.at/html/psx_tools.html PsxSound 1.0 by SM0N (aka PSXSND.EXE)] - Convert your PSX VAG/VAB/VB+VH/RAW soundfiles to .WAV
 +
* [https://hitmen.c02.at/html/psx_tools.html Psx Audio Tools 0.1 by Mumbly] - includes Vab Ripper, Vab 2 Vag and Vag_Depack
 +
* [https://hitmen.c02.at/html/psx_sources.html VAG pack and VAG depack v0.1 by bITmASTER] - aka PSX VAG-Packer and VAG-Depack
 +
* [https://consolecopyworld.com/psx/psx_utils_prg.shtml Search v1.1 by Reptile] - searches for PSX files (including VAB and VAG) in any file
 +
* [http://snailrush.online.fr/ PSound] ([https://www.romhacking.net/utilities/679/ alt link])
 +
** [http://www.thelostworlds.net/Software/PSound_and_SoundReaver_2.html SoundReaver 2 addon for PSound] (specific to Soul Reaver 2 and Blood Omen 2)
 +
* [https://www.zophar.net/utilities/ps2util/mfaudio-1-1.html MFAudio]
 +
* [https://youtu.be/kPmGVZocLag?t=1012 Winning Eleven Multi Tool 2K24 By CARP] (includes VAG Extractor)
 +
** [https://www.mediafire.com/file/ogjndjjj4c6j3mn/WE_MultiTool.7z/file direct link]
 +
** [https://zonawe.forosactivos.net/t2614-winning-eleven-multi-tool-mi-aporte-final-y-despedida-by-carp-maxiducoli-actualizacion-18-11-2024 forum thread]
 +
* [https://web.archive.org/web/20220309170433/https://aluigi.altervista.org/papers/vagguess.zip PS2 VAG interleave value guesser and files extractor by Luigi Auriemma (VAGGUESS)]
 +
* [https://zenhax.com/viewtopic.php@t=2299&start=20.html vag_scanner by id-daemon]
 +
* [https://web.archive.org/web/20230513174441/http://forum.xentax.com/viewtopic.php?f=13&p=43263 VAG_scanner.bms] - QuickBMS script to scan a file for mono VAG files
 +
* [https://www.cebeans.com/Programs/VAG/VAGPlayerp.htm VAGPlayer for Windows CE]
 +
* [https://web.archive.org/web/20141201133734/https://492caf50c305ba6a67e35b7283324b352a2462f1.googledrive.com/host/0BwYVUA7ansC5cHQ0aEZaNHppVGc/WavtoVagV3.0.zip Wav to Vag V3.0 for PSP by highboy] ([https://endlessparadigm.com/forum/showthread.php?tid=13094 info thread])
 +
* [https://www.fmjsoft.com/awavestudio.html#main FMJ-Software Awave Studio]
 +
* [https://www.videoconverterfactory.com/hd-video-converter/ WonderFox HD Video Converter Factory Pro]
 +
* [https://www.watto.org/game_extractor.html Watto Studios Game Extractor]
 +
* [https://convertall.com/en/vag-converter Online conversion from ConvertAll]
 +
* VAG Converter (from PSP SDK)
 +
* Multistream F-Packer (from PS2 SDK)
 +
 +
 +
== Sample code to run on PS1 ==
 +
* [http://psx.arthus.net/code/VAG/ Multiple examples]
 +
* [https://github.com/ABelliqueux/nolibgs_hello_worlds/blob/main/hello_vag/hello_vag.c sample code to load a VAG file to SPU sound buffer and play it back]
 +
* [https://github.com/ABelliqueux/nolibgs_hello_worlds/blob/main/hello_multi_vag/hello_multi_vag.c sample code to load VAG samples to the SPU sound buffer and play them back with pad input]
 +
* [http://www.psxdev.net/forum/viewtopic.php?t=153 VAG Example (VAG DEMO)] - example of how to play VAG audio from the SPU RAM with DMA
 +
** [http://www.psxdev.net/forum/viewtopic.php?t=3368 Updates to VAG DEMO]
 +
 +
 +
 +
== Sample files ==
 +
* {{DexvertSamples|audio/vag}}
 +
* [https://github.com/ABelliqueux/nolibgs_hello_worlds/tree/main/VAG samples from ABelliqueux]
 +
 +
 +
== Notes ==
 +
* [https://www.youtube.com/watch?v=AnHmD2z8zJk How to make PS1 samples for FREE!] from SoundFontGuy on YouTube
 +
* [https://psx.arthus.net/sdk/Psy-Q/DOCS/Devrefs/Filefrmt.pdf PlayStation file formats pg 212] on ''psx.arthus.net''
 +
* [https://github.com/ABelliqueux/nolibgs_hello_worlds/wiki/VAG File Format from ABelliqueux]
 +
* [http://psx.arthus.net/sdk/Psy-Q/DOCS/FileFormat47.pdf FileFormat47.pdf pg 209]
 +
* [http://psx.arthus.net/sdk/Psy-Q/DOCS/LibOver47.pdf LibOver47.pdf pg 271]
 +
* [https://psx.arthus.net/sdk/Psy-Q/DOCS/LibRef47.pdf LibRef47.pdf pg 980]
 +
* [https://github.com/SoapyMan/medal_of_honor_psx/blob/master/doc_VAB_hack.txt notes on VAG looping from Silpheed]
 +
* [https://archive.vg-resource.com/archive/index.php/thread-41234.html Tutorial: generic SFX ripping for PS1/PS2/PSP]
 +
* [https://old.reddit.com/r/gamemusic/comments/r450xx/what_instruments_or_daw_were_used_to_compose/ what instruments or Daw were used to compose music for psx games in the past?]
 +
* [https://rewiki.miraheze.org/wiki/PlayStation_VAG_Audio PlayStation VAG Audio at Reverse Engineering Wiki]
 +
* [https://zenhax.com/viewtopic.php@t=12912.html Manually extracting VAG files with a hex editor]

Latest revision as of 05:57, 3 January 2026

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

[edit] 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).


[edit] Software


[edit] Sample code to run on PS1


[edit] Sample files


[edit] Notes

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox