OpenXcom Forum
Contributions => Programming => Topic started by: michal on July 03, 2010, 07:57:21 am
-
Hello, you've written:
- Looking into implementing sound effects, they make the game more lively, and they're one of the more advanced game formats I need to look into eventually.
First some theory: https://www.ufopaedia.org/index.php?title=SOUND
Actually this cat format is very simple. I've written an extractor program for ufo:tts, part of it's functionality is to read this file (it works for CE version of ufo) and save wavs:
@Override
public void convert() throws Exception
{
int file[] = Utils.readFile(srcFile, 1);
int offset = Utils.readInt(file, this.objIndex * 8, 4);
int length = Utils.readInt(file, this.objIndex * 8 + 4, 4);
File f = new File(dstFile);
f.getParentFile().mkdirs();
Utils.saveFile(dstFile, file, offset + 3, length);
}
Basically, every cat file is made of multiple wav files. You need to know offset and length of every wav - those are stored in header - two 4 bytes integers for every object (sound in this case). After that you can simply read length bytes from offset.
As you see i've added +3 to offset. Now, i don't remember why :P Maybe there were some garbage at those 3 bytes.
In CE version those wavs contain headers, in dos versions they probably don't.
-
Thanks, I had already looked up the format since it's also used in other Microprose games: https://www.ttdpatch.net/chris_becke_ttdlx.html#hack
The main challenge is having the game properly detect and handle the various game versions (DOS, Windows, etc) and seeing if SDL_mixer supports all those formats. ;) UFO:TTS only accepts the Window version AFAIK.
-
Basically, every cat file is made of multiple wav files. You need to know offset and length of every wav - those are stored in header - two 4 bytes integers for every object (sound in this case). After that you can simply read length bytes from offset.
As you see i've added +3 to offset. Now, i don't remember why :P Maybe there were some garbage at those 3 bytes.
In CE version those wavs contain headers, in dos versions they probably don't.
[/quote]
Just so you know, I found out by looking at other Microprose games that those 3 bytes of "garbage" are actually the filename of the wav. This is handy for referencing individual wavs in a pack, but sadly all the X-Com wavs are just named "0" (1 byte for the string size + 1 byte for '0' and 1 byte for '\0' = 3 bytes) :( but if you wanna write a foolproof converter, you just have to read the first byte to get the string size, and skip that amount.
You're right that the DOS wavs don't contain headers and SDL_mixer doesn't seem to like it, I hope I can add them in manually.