aliens

Author Topic: Need help with sound files?  (Read 5528 times)

Offline michal

  • Commander
  • *****
  • Posts: 629
    • View Profile
Need help with sound files?
« on: July 03, 2010, 07:57:21 am »
Hello, you've written:
Quote
- 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:

Code: [Select]
   @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.
« Last Edit: July 03, 2010, 08:01:14 am by michal »

Offline SupSuper

  • Lazy Developer
  • Administrator
  • Commander
  • *****
  • Posts: 2159
    • View Profile
Re: Need help with sound files?
« Reply #1 on: July 04, 2010, 09:46:07 pm »
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.
« Last Edit: July 04, 2010, 09:47:38 pm by SupSuper »

Offline SupSuper

  • Lazy Developer
  • Administrator
  • Commander
  • *****
  • Posts: 2159
    • View Profile
Re: Need help with sound files?
« Reply #2 on: July 19, 2010, 05:56:06 am »
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.