Hello everyone! Today I’m going to explain how to compress WAV/RAW files by using a trick to batch convert them to OGG- and be able to convert them back to WAV/RAW easily for usage.

To explain the actual usefulness or reason to do this, first I want to mention how some PC games (most of the time the old ones) use WAV or RAW (most of the time if not always the extension is different, but they tend to be RAW audio files), as these formats mantain the exact quality intended and keep said quality in playback. However, as these audio formats are uncompressed, their filesizes tend to be bigger than normal, and container formats have been made to reduce the filesizes drastically but keep the audio content and quality as if it was the same. For example, here is a screenshot of a WAV file along with the same audio file but converted to OGG:

Sin título.png

With this said, if you want or need to have a game or a group of WAV files compressed to save space (because WAV files don’t get compressed a lot by archive formats like .rar, .zip, .uha, etc), you can use this trick to get them to a much smaller size, and then be able to unpack it back to the format needed.

The method to do this is using SoX: a command line audio tool, which can convert several audio formats. However, you can use any other program to convert the WAV files to OGG, like Format Factory or oggenc, but for now here we will only cover how to do it with SoX. By extracting the entire archive into the folder with the WAV files, you can use this command through the CMD window to convert the WAV files to OGG automatically:

FOR %I IN (*.WAV) DO (sox "%I" "%~pnI.OGG")

Or if you prefer to use a batch file, put this line in a empty batch file and then run it:

FOR %%I IN (*.WAV) DO (sox "%%I" "%%~pnI.OGG")

This will batch convert every WAV file in the folder to OGG. Now you can delete the WAV files to free disk space. With that done, now you need to set up a batch file that does the inverse: Convert the OGG files back to WAV for their usage.

Placing ths line in a batch file where the OGG files are and then running it, you can make SoX batch convert the OGG files back to WAV:

FOR %%I IN (*.OGG) DO (sox "%%I" "%%~pnI.WAV")

After converting the OGG files back to WAV, you are done!

Now, it may not look as there is a lot of use to this, as you may be pretty much converting WAV to OGG and back, and the compression isn’t useful if you want to use the game/WAV files constantly. However, it can really help for sharing or moving them without wasting too much space and keeping it in a manageable size (can also help for archiving), and with some batch files modifications, you can make it easier to unpack: Say that you want to have a batch file that converts the OGG files inside a folder, and delete them after that. Using a batch file with these lines:

CD DIRECTORYFOLDER
ECHO Please wait while data is converting. This may take some minutes.
FOR %%I IN (*.OGG) DO (sox %%I %%~pnI.WAV)
del *.OGG
ECHO Done!
pause
exit

And then changing the “DIRECTORYFOLDER” in it for the name of the folder where the files are, you should be able to convert the OGG files to WAV and delete the remaining OGG files. Note that the ECHO messages can be modified, and it’s recommended to have them to inform that a unpacking/conversion process is currently in process and to inform that said process is complete. If you know about making or handling CMD and batch files, you can potentially modify it to your taste to add other features or functions. Note that you can also use another format you wish, like FLAC (which only seems to halve the WAV filesizes, but it’s lossless) or MP3, by replacing “OGG” by the format you want to use as long as SoX supports it.

Now, about the RAW files, you can just do the process described above but replacing every mention of “WAV” for “RAW. If you suspect that there are audio files that are RAW but don’t know (as I said, there can be RAW audio that uses a different extension), you can use Audacity and use the Import RAW data option to see if Audacity can open the file (If the audio seems to be rather sped-up, most of the time that is normal in games that use them, and you shouldn’t alter the pitch or speed of it). If it does, it’s recommended that you convert them to OGG from Audacity instead of using SoX (There are ways to batch convert audio thru Audacity), and in the batch file that would convert the OGG files back to RAW, you add the line “ren *.RAW *.extension” (without the quotes) below the “del *.OGG” line, replacing the “extension” with the extension it had before.

If this was helpful to you, don’t forget to drop by a comment and be sure to check here for more stuff. But until then, see you later!

Advertisement