CLU: Difference between revisions

From MultimediaWiki
Jump to navigation Jump to search
m (Correct formatting on page)
(Add to formats missing in FFmpeg category.)
 
(6 intermediate revisions by 3 users not shown)
Line 2: Line 2:
* Company: [[Revolution Studios]]
* Company: [[Revolution Studios]]


==Credit==
== Credit ==
This document comes from wotsit.org, and originated on GAP's (Game Audio Player) website (now defunct).
The information on this page is based on a document found on http://www.wotsit.org/ and other sites on the internet, and originated on [[GAP]]'s (Game Audio Player) website (now defunct). The information was originally by Valery V. Anisimovsky (no valid email address known)
By Valery V. Anisimovsky (no valid email address known)
 
 


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


Music/speech/sound files of Broken Sword 2 are stored in CLU resource
Music/speech/sound files of Broken Sword 2 are stored in CLU resource
Line 52: Line 48:
format. It's not described here.
format. It's not described here.


== CLUSFX Music/Speech/Sound Files==
== CLUSFX Music/Speech/Sound Files ==
All of the music/speech/sfx files are of the same format which is referred to here as CLUSFX. A CLUSFX file has a simple format -- just a 16-bit initial predictor value followed by a compressed waveform stream. When decompressed, all music/speech/sfx files are 16-bit mono [[PCM]] samples replayed at 22050 Hz. ''(signed or unsigned? presumably signed --[[User:Multimedia Mike|Multimedia Mike]])''


All of the music/speech/sfx files are of the same format which I refer
All CLUSFX files are compressed using CLU ADPCM compression algorithm.
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==
== CLU ADPCM Decompression Algorithm==
A CLU file begins with a 16-bit initial predictor value that is not sent to the output. The compressed stream is comprised of a sequence of bytes. The 8 bits of each byte have the following meaning:


During the decompression SHORT variable should be maintained. This is
  bits 7-4    delta magnifier
the current value of the audio sample which is initialized to the CLUSFX
  bit 3      sign bit
header value in the beginning.
  bits 2-0    delta base
 
Here's the code which decompresses CLU ADPCM compressed stream:


 
For each byte:
DWORD i;
  delta = (delta base) << (delta magnifier)
SHORT iCurSample;
   if the sign bit is cleared
BYTE *inputBuffer[dwSize];
     predictor += delta
 
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
   else
     iCurSample+=((SHORT)(inputBuffer[i] & 7)) << (inputBuffer[i]>>4);
     predictor -= delta
   Output(iCurSample);
   send predictor to the output as the next audio sample
}


Output() is just a placeholder for any action you would like to perform for
Presumably, the output sample should be saturated within an appropriate value range.
decompressed sample value.


==PC Games using CLU format==
== PC Games using CLU format ==
*[http://bodhost.com/web-hosting/index.php/2006/11/09/clu/ CLU Historic Basics]
*[http://www.mobygames.com/game/windows/broken-sword-the-smoking-mirror Broken Sword 2: The Smoking Mirror]
*[http://www.mobygames.com/game/windows/broken-sword-the-smoking-mirror Broken Sword 2: The Smoking Mirror]


[[Category:Audio Codecs]]
[[Category:ADPCM Audio Codecs]]
[[Category:Game Formats]]
[[Category:Game Formats]]
[[Category: Formats missing in FFmpeg]]

Latest revision as of 15:46, 10 April 2007

Credit

The information on this page is based on a document found on http://www.wotsit.org/ and other sites on the internet, and originated on GAP's (Game Audio Player) website (now defunct). The information was originally by Valery V. Anisimovsky (no valid email address known)

CLU Resource Files

All numbers in all structures described 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 is referred to here as CLUSFX. A CLUSFX file has a simple format -- just a 16-bit initial predictor value followed by a compressed waveform stream. When decompressed, all music/speech/sfx files are 16-bit mono PCM samples replayed at 22050 Hz. (signed or unsigned? presumably signed --Multimedia Mike)

All CLUSFX files are compressed using CLU ADPCM compression algorithm.

CLU ADPCM Decompression Algorithm

A CLU file begins with a 16-bit initial predictor value that is not sent to the output. The compressed stream is comprised of a sequence of bytes. The 8 bits of each byte have the following meaning:

 bits 7-4    delta magnifier
 bit 3       sign bit
 bits 2-0    delta base

For each byte:

 delta = (delta base) << (delta magnifier)
 if the sign bit is cleared
   predictor += delta
 else
   predictor -= delta
 send predictor to the output as the next audio sample

Presumably, the output sample should be saturated within an appropriate value range.

PC Games using CLU format