CLU

From MultimediaWiki
Revision as of 13:20, 14 August 2006 by Dashcloud (talk | contribs) (Correct formatting on page)
Jump to navigation Jump to search

Credit

This document comes from wotsit.org, and originated on GAP's (Game Audio Player) website (now defunct). By Valery V. Anisimovsky (no valid email address known)


CLU Resource Files

All numbers in all structures described in this document are stored in files using little-endian (Intel) byte order.

Music/speech/sound files of Broken Sword 2 are stored in CLU resource files. Each music/speech/sound CLU file has the following header:

struct tagCLUHeader
{
 DWORD dwNumber;
 char	szID[4];
} CLUHeader;


szID -- string ID is always "\xFF\xF0\xFF\xF0".

dwNumber -- the number of files stored in CLU file.

After the header comes the array of (dwNumber) directory entries. Each directory entry contains the info on a file in CLU archive. Each such entry has the following format:

struct tagCLUDirEntry
{
 DWORD dwStart;
 DWORD dwSize;
} CLUDirEntry;

dwStart -- the starting position of the file relative to the beginning of the CLU archive.

dwSize -- the size of the file.

Note that there're some entries with zero (dwStart) or (dwSize) -- they correspond to the files absent in the given CLU archive (the files with the same numbers may be found in the corresponding CLU archive on the other game CD).

After the array of directory entries come the files contained in CLU archive.

NOTE: The CLU files containing other types of game data have different format. It's not described here.

CLUSFX Music/Speech/Sound Files

All of the music/speech/sfx files are of the same format which I refer to as CLUSFX. CLUSFX file has a simple header -- just a starting value of the sample, after which the compressed waveform stream begins. All music/speech/sfx files in Broken Sword 2 are 16-bit mono 22050 Hz. ALL CLUSFX files are compressed using CLU ADPCM compression algorithm. Refer to the following section for the description of CLU ADPCM decompression scheme.

CLU ADPCM Decompression Algorithm

During the decompression SHORT variable should be maintained. This is the current value of the audio sample which is initialized to the CLUSFX header value in the beginning.

Here's the code which decompresses CLU ADPCM compressed stream:


DWORD i;
SHORT iCurSample;
BYTE *inputBuffer[dwSize];
iCurSample=iFirstSample; // from the CLUSFX header
for (i=0;i<dwSize;i++)
{
 if (inputBuffer[i] & 0x8)
   iCurSample-=((SHORT)(inputBuffer[i] & 7)) << (inputBuffer[i]>>4);
 else
   iCurSample+=((SHORT)(inputBuffer[i] & 7)) << (inputBuffer[i]>>4);
 Output(iCurSample);
}

Output() is just a placeholder for any action you would like to perform for decompressed sample value.

PC Games using CLU format