<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multimedia.cx/index.php?action=history&amp;feed=atom&amp;title=Westwood_ADPCM_Audio</id>
	<title>Westwood ADPCM Audio - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multimedia.cx/index.php?action=history&amp;feed=atom&amp;title=Westwood_ADPCM_Audio"/>
	<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Westwood_ADPCM_Audio&amp;action=history"/>
	<updated>2026-05-26T07:24:51Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.5</generator>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Westwood_ADPCM_Audio&amp;diff=5884&amp;oldid=prev</id>
		<title>Dashcloud: Change note section, add category</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Westwood_ADPCM_Audio&amp;diff=5884&amp;oldid=prev"/>
		<updated>2006-08-24T17:30:41Z</updated>

		<summary type="html">&lt;p&gt;Change note section, add category&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 10:30, 24 August 2006&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l5&quot;&gt;Line 5:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 5:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Note==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Note==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Namely, (Vladan) Bato's &lt;/del&gt;AUD3.&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;TXT describes IMA ADPCM compressed AUDs used in C&amp;amp;C and&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;AUD3.&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;txt refers &lt;/ins&gt;to &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Vladan Bato&lt;/ins&gt;'s &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;file which &lt;/ins&gt;is &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;not yet up on &lt;/ins&gt;the &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;wiki&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Red Alert and what I'll try &lt;/del&gt;to &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;describe here is Westwood ADPCM compressed AUDs&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;used in Legend Of Kyrandia III: Malcolm&lt;/del&gt;'s &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Revenge (and, also some files in&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;C&amp;amp;C): Malcolm's music, sound FX, speech and video soundtracks.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Also described &lt;/del&gt;is the &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;format of soundtracks in C&amp;amp;C, Red Alert, Tiberian Sun,&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Dune 2000. Probably, the formats described here are used in some other&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Westwood games, e.g.: Lands Of Lore 2,3, Blade Runner&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== AUD Files ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== AUD Files ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l308&quot;&gt;Line 308:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 302:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[http://www.mobygames.com/game/windows/blade-runner Blade Runner]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[http://www.mobygames.com/game/windows/blade-runner Blade Runner]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Game Formats]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Dashcloud</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Westwood_ADPCM_Audio&amp;diff=5883&amp;oldid=prev</id>
		<title>Dashcloud: Adding Westwood audio format doc</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Westwood_ADPCM_Audio&amp;diff=5883&amp;oldid=prev"/>
		<updated>2006-08-24T13:11:18Z</updated>

		<summary type="html">&lt;p&gt;Adding Westwood audio format doc&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;*Company [[Westwood Studios]]&lt;br /&gt;
&lt;br /&gt;
== Credit ==&lt;br /&gt;
The information below was originally based on one of the many format documents written up by Valery V. Anisimovsky, available on http://wotsit.org/ and many other sites across the internet.&lt;br /&gt;
&lt;br /&gt;
==Note==&lt;br /&gt;
Namely, (Vladan) Bato's AUD3.TXT describes IMA ADPCM compressed AUDs used in C&amp;amp;C and&lt;br /&gt;
Red Alert and what I'll try to describe here is Westwood ADPCM compressed AUDs&lt;br /&gt;
used in Legend Of Kyrandia III: Malcolm's Revenge (and, also some files in&lt;br /&gt;
C&amp;amp;C): Malcolm's music, sound FX, speech and video soundtracks.&lt;br /&gt;
Also described is the format of soundtracks in C&amp;amp;C, Red Alert, Tiberian Sun,&lt;br /&gt;
Dune 2000. Probably, the formats described here are used in some other&lt;br /&gt;
Westwood games, e.g.: Lands Of Lore 2,3, Blade Runner.&lt;br /&gt;
&lt;br /&gt;
== AUD Files ==&lt;br /&gt;
&lt;br /&gt;
Malcolm's AUD files have the same format as C&amp;amp;C's AUDs (which is described&lt;br /&gt;
in AUD3.TXT) with only one exception: there's no OutSize field in their header.&lt;br /&gt;
So it looks like the following:&lt;br /&gt;
&lt;br /&gt;
 struct AUDHeaderOld&lt;br /&gt;
 {&lt;br /&gt;
    WORD  wSampleRate;&lt;br /&gt;
    DWORD dwSize;&lt;br /&gt;
    BYTE  bFlags;&lt;br /&gt;
    BYTE  bType;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
''bType'' is equal to 0x01 for WS ADPCM compressed AUDs.&lt;br /&gt;
All WS ADPCM compressed sounds I've ever encountered are 8-bit.&lt;br /&gt;
&lt;br /&gt;
The meanings of the other fields in AUD header are the same as for C&amp;amp;C AUDs.&lt;br /&gt;
These AUDs are divided in chunks with the chunk header being the same as for&lt;br /&gt;
C&amp;amp;C, but those chunks have variable size (may be NOT 512 bytes) unlike C&amp;amp;C&lt;br /&gt;
AUDs!&lt;br /&gt;
&lt;br /&gt;
Note that WS ADPCM compressed AUDs in C&amp;amp;C (death screams) have just the same&lt;br /&gt;
format as other AUDs in this game, i.e. with OutSize field.&lt;br /&gt;
&lt;br /&gt;
== WS ADPCM Decompression Algorithm ==&lt;br /&gt;
&lt;br /&gt;
Each AUD chunk may be decompressed independently of others. This lets you&lt;br /&gt;
implement the seeking for WS ADPCM AUDs (unlike IMA ADPCM ones).&lt;br /&gt;
But during the decompression of the given chunk a variable (''CurSample'') should&lt;br /&gt;
be maintained for this whole chunk:&lt;br /&gt;
&lt;br /&gt;
 SHORT CurSample;&lt;br /&gt;
 BYTE  InputBuffer[InputBufferSize]; // input buffer containing the whole chunk&lt;br /&gt;
 WORD  wSize, wOutSize; // Size and OutSize values from this chunk's header&lt;br /&gt;
 BYTE  code;&lt;br /&gt;
 CHAR  count; // this is a signed char!&lt;br /&gt;
 WORD  i; // index into InputBuffer&lt;br /&gt;
 WORD  input; // shifted input&lt;br /&gt;
 &lt;br /&gt;
 if (wSize==wOutSize) // such chunks are NOT compressed&lt;br /&gt;
 {&lt;br /&gt;
  for (i=0;i&amp;lt;wOutSize;i++)&lt;br /&gt;
      Output(InputBuffer[i]); // send to output stream&lt;br /&gt;
  return; // chunk is done!&lt;br /&gt;
 }&lt;br /&gt;
  &lt;br /&gt;
 // otherwise we need to decompress chunk&lt;br /&gt;
  &lt;br /&gt;
 CurSample=0x80; // unsigned 8-bit&lt;br /&gt;
 i=0;&lt;br /&gt;
 &lt;br /&gt;
 // note that wOutSize value is crucial for decompression!&lt;br /&gt;
 &lt;br /&gt;
 while (wOutSize&amp;gt;0) // until wOutSize is exhausted!&lt;br /&gt;
 {&lt;br /&gt;
  input=InputBuffer[i++];&lt;br /&gt;
  input&amp;lt;&amp;lt;=2;&lt;br /&gt;
  code=HIBYTE(input);&lt;br /&gt;
  count=LOBYTE(input)&amp;gt;&amp;gt;2;&lt;br /&gt;
  switch (code) // parse code&lt;br /&gt;
  {&lt;br /&gt;
    case 2: // no compression...&lt;br /&gt;
 	 if (count &amp;amp; 0x20)&lt;br /&gt;
 	 {&lt;br /&gt;
 	   count&amp;lt;&amp;lt;=3;		// here it's significant that (count) is signed:&lt;br /&gt;
 	   CurSample+=count&amp;gt;&amp;gt;3; // the sign bit will be copied by these shifts!&lt;br /&gt;
 &lt;br /&gt;
 	   Output((BYTE)CurSample);&lt;br /&gt;
 &lt;br /&gt;
 	   wOutSize--; // one byte added to output&lt;br /&gt;
 	 }&lt;br /&gt;
 	 else // copy (count+1) bytes from input to output&lt;br /&gt;
 	 {&lt;br /&gt;
 	   for (count++;count&amp;gt;0;count--,wOutSize--,i++)&lt;br /&gt;
 	       Output(InputBuffer[i]);&lt;br /&gt;
 	   CurSample=InputBuffer[i-1]; // set (CurSample) to the last byte sent to output&lt;br /&gt;
 	 }&lt;br /&gt;
 	 break;&lt;br /&gt;
    case 1: // ADPCM 8-bit -&amp;gt; 4-bit&lt;br /&gt;
 	 for (count++;count&amp;gt;0;count--) // decode (count+1) bytes&lt;br /&gt;
 	 {&lt;br /&gt;
 	   code=InputBuffer[i++];&lt;br /&gt;
 &lt;br /&gt;
 	   CurSample+=WSTable4bit[(code &amp;amp; 0x0F)]; // lower nibble&lt;br /&gt;
 &lt;br /&gt;
 	   CurSample=Clip8BitSample(CurSample);&lt;br /&gt;
 	   Output((BYTE)CurSample);&lt;br /&gt;
 &lt;br /&gt;
 	   CurSample+=WSTable4bit[(code &amp;gt;&amp;gt; 4)]; // higher nibble&lt;br /&gt;
  &lt;br /&gt;
 	   CurSample=Clip8BitSample(CurSample);&lt;br /&gt;
 	   Output((BYTE)CurSample);&lt;br /&gt;
  &lt;br /&gt;
 	   wOutSize-=2; // two bytes added to output&lt;br /&gt;
 	 }&lt;br /&gt;
 	 break;&lt;br /&gt;
    case 0: // ADPCM 8-bit -&amp;gt; 2-bit&lt;br /&gt;
 	 for (count++;count&amp;gt;0;count--) // decode (count+1) bytes&lt;br /&gt;
 	 {&lt;br /&gt;
 	   code=InputBuffer[i++];&lt;br /&gt;
  &lt;br /&gt;
 	   CurSample+=WSTable2bit[(code &amp;amp; 0x03)]; // lower 2 bits&lt;br /&gt;
 &lt;br /&gt;
 	   CurSample=Clip8BitSample(CurSample);&lt;br /&gt;
 	   Output((BYTE)CurSample);&lt;br /&gt;
 &lt;br /&gt;
 	   CurSample+=WSTable2bit[((code&amp;gt;&amp;gt;2) &amp;amp; 0x03)]; // lower middle 2 bits&lt;br /&gt;
 &lt;br /&gt;
 	   CurSample=Clip8BitSample(CurSample);&lt;br /&gt;
 	   Output((BYTE)CurSample);&lt;br /&gt;
 &lt;br /&gt;
 	   CurSample+=WSTable2bit[((code&amp;gt;&amp;gt;4) &amp;amp; 0x03)]; // higher middle 2 bits&lt;br /&gt;
 &lt;br /&gt;
 	   CurSample=Clip8BitSample(CurSample);&lt;br /&gt;
 	   Output((BYTE)CurSample);&lt;br /&gt;
 &lt;br /&gt;
 	   CurSample+=WSTable2bit[((code&amp;gt;&amp;gt;6) &amp;amp; 0x03)]; // higher 2 bits&lt;br /&gt;
 &lt;br /&gt;
 	   CurSample=Clip8BitSample(CurSample);&lt;br /&gt;
 	   Output((BYTE)CurSample);&lt;br /&gt;
 &lt;br /&gt;
 	   wOutSize-=4; // 4 bytes sent to output&lt;br /&gt;
 	 }&lt;br /&gt;
 	 break;&lt;br /&gt;
    default: // just copy (CurSample) (count+1) times to output&lt;br /&gt;
 	 for (count++;count&amp;gt;0;count--,wOutSize--)&lt;br /&gt;
 	     Output((BYTE)CurSample);&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
HIBYTE and LOBYTE are just higher and lower bytes of WORD:&lt;br /&gt;
 #define HIBYTE(word) ((word) &amp;gt;&amp;gt; 8)&lt;br /&gt;
 #define LOBYTE(word) ((word) &amp;amp; 0xFF)&lt;br /&gt;
Note that depending on your compiler you may need to use additional byte&lt;br /&gt;
separation in these defines, e.g. (((byte) &amp;gt;&amp;gt; 8) &amp;amp; 0xFF). The same holds for&lt;br /&gt;
4-bit and 2-bit nibble separation in the code above.&lt;br /&gt;
&lt;br /&gt;
WSTable4bit and WSTable2bit are the delta tables given in the next section.&lt;br /&gt;
&lt;br /&gt;
Output() is just a placeholder for any action you would like to perform for&lt;br /&gt;
decompressed sample value.&lt;br /&gt;
&lt;br /&gt;
Clip8BitSample is quite evident:&lt;br /&gt;
&lt;br /&gt;
 SHORT Clip8BitSample(SHORT sample)&lt;br /&gt;
 {&lt;br /&gt;
  if (sample&amp;gt;255)&lt;br /&gt;
     return 255;&lt;br /&gt;
  else if (sample&amp;lt;0)&lt;br /&gt;
     return 0;&lt;br /&gt;
  else&lt;br /&gt;
     return sample;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
This algorithm is ONLY for mono 8-bit unsigned sound, as I've never seen any&lt;br /&gt;
other sound format used with WS ADPCM compression.&lt;br /&gt;
&lt;br /&gt;
Of course, the decompression routine described above may be greatly&lt;br /&gt;
optimized.&lt;br /&gt;
&lt;br /&gt;
== WS ADPCM Tables ==&lt;br /&gt;
&lt;br /&gt;
 CHAR WSTable2bit[]=&lt;br /&gt;
 {&lt;br /&gt;
    -2,&lt;br /&gt;
    -1,&lt;br /&gt;
     0,&lt;br /&gt;
     1&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 CHAR WSTable4bit[]=&lt;br /&gt;
 {&lt;br /&gt;
    -9, -8, -6, -5, -4, -3, -2, -1,&lt;br /&gt;
     0,  1,  2,  3,  4,  5,  6,  8&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
== AUDs in Legend Of Kyrandia III: Malcolm's Revenge ==&lt;br /&gt;
&lt;br /&gt;
The WS ADPCM compression described above is used for all audio in this game:&lt;br /&gt;
&lt;br /&gt;
Music is stand-alone .AUD files.&lt;br /&gt;
Speech is AUDs in .TLK resource files.&lt;br /&gt;
Sounds are AUDs in .PAK resource files.&lt;br /&gt;
&lt;br /&gt;
These .TLKs and .PAKs do not use any compression or encryption for AUDs, so&lt;br /&gt;
AUDs are stored &amp;quot;as is&amp;quot; in them. If you want to extract/play an AUD from&lt;br /&gt;
PAK or TLK you just need to search the PAK or TLK for the AUD id, that is,&lt;br /&gt;
DWORD value equal to 0x0000DEAF (or, in other words, string &amp;quot;\xAF\xDE\0\0&amp;quot;).&lt;br /&gt;
Refer to Vladan Bato's AUD3.TXT for more details on AUD file structure.&lt;br /&gt;
&lt;br /&gt;
== VQA Movie Soundtracks ==&lt;br /&gt;
&lt;br /&gt;
Soundtrack of VQA movie in Malcolm, C&amp;amp;C, Red Alert and C&amp;amp;C: Tiberian Sun is&lt;br /&gt;
stored in SND0, SND1 or SND2 blocks. Refer to VQA_FRMT.TXT by Aaron Glover for&lt;br /&gt;
details on the structure of VQA files. Here I only describe the contents of&lt;br /&gt;
VQA sound blocks and VQHD (header) block.&lt;br /&gt;
&lt;br /&gt;
VQHD block contains header for VQA. To the best of my knowledge, it has the&lt;br /&gt;
following format:&lt;br /&gt;
&lt;br /&gt;
 struct VQAHeader&lt;br /&gt;
 {&lt;br /&gt;
    WORD  wVersion;&lt;br /&gt;
    WORD  unknown1;&lt;br /&gt;
    WORD  wNumFrames;&lt;br /&gt;
    WORD  wWidth;&lt;br /&gt;
    WORD  wHeight;&lt;br /&gt;
    WORD  unknown2;&lt;br /&gt;
    WORD  unknown3;&lt;br /&gt;
    WORD  unknown4;&lt;br /&gt;
    WORD  unknown5;&lt;br /&gt;
    DWORD unknown6;&lt;br /&gt;
    WORD  unknown7;&lt;br /&gt;
    WORD  wSampleRate;&lt;br /&gt;
    BYTE  bChannels;&lt;br /&gt;
    BYTE  bResolution;&lt;br /&gt;
    char  unknown8[14];&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
''wVersion'' -- version of VQA: 1 -- oldest Malcolm's VQAs, 2 -- C&amp;amp;C, Red Alert,&lt;br /&gt;
3 -- C&amp;amp;C: Tiberian Sun.&lt;br /&gt;
&lt;br /&gt;
''wNumFrames'' -- number of frames in VQA. Note that number of sound blocks is&lt;br /&gt;
(''wNumFrames+1'') for VQAs of version 2 (C&amp;amp;C, Red Alert), and (''wNumFrames'') for&lt;br /&gt;
versions 1 and 3. But Dune2000 VQAs have also (''wNumFrames'') sound blocks&lt;br /&gt;
while they're version 2 VQAs.&lt;br /&gt;
&lt;br /&gt;
''wSampleRate'' -- sample rate for soundtrack. Note that version 1 (Malcolm's)&lt;br /&gt;
VQAs may have this value set to 0x0000! Use 22050 Hz in such cases.&lt;br /&gt;
&lt;br /&gt;
''bChannels'' -- number of channels (1 -- mono, 2 -- stereo). Note that version 1&lt;br /&gt;
VQAs may have this set to 0x00, so use 1 (mono) for such files.&lt;br /&gt;
&lt;br /&gt;
''bResolution'' -- resolution of soundtrack (0x10 -- 16-bit, 0x8 -- 8-bit). Note&lt;br /&gt;
that version 1 VQAs may have this set to 0x00, so use 0x8 for such files.&lt;br /&gt;
&lt;br /&gt;
All VQAs in Malcolm have their sound in either SND0 or SND1 blocks.&lt;br /&gt;
SND0 blocks contain non-compressed PCM data.&lt;br /&gt;
SND1 blocks contain small header and WS ADPCM compressed sound data.&lt;br /&gt;
The header is the following:&lt;br /&gt;
&lt;br /&gt;
 struct SND1Header&lt;br /&gt;
 {&lt;br /&gt;
  WORD wOutSize;&lt;br /&gt;
  WORD wSize;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
Following the header comes WS ADPCM compressed sound data.&lt;br /&gt;
Each SND1 sound block may be decompressed, just like a chunk of AUD file,&lt;br /&gt;
independently of the others and the routine described above may be used for&lt;br /&gt;
its decompression without any changes, provided you use wOutSize from the&lt;br /&gt;
SND1Header.&lt;br /&gt;
&lt;br /&gt;
As to VQAs in C&amp;amp;C and Red Alert their sound is in the SND2 blocks and&lt;br /&gt;
compressed with IMA ADPCM algorithm, described in Vladan Bato's AUD3.TXT.&lt;br /&gt;
The contents of SND2 block is just compressed data, without any headers and&lt;br /&gt;
those blocks should be decompressed in their turn just like chunks of IMA ADPCM&lt;br /&gt;
compressed AUD file as it's described in AUD3.TXT. This holds only for mono&lt;br /&gt;
soundtracks.&lt;br /&gt;
&lt;br /&gt;
But there're also stereo soundtracks in C&amp;amp;C and C&amp;amp;C: Tiberian Sun. They have&lt;br /&gt;
different left/right channel nibbles layout.&lt;br /&gt;
&lt;br /&gt;
For C&amp;amp;C (version 2) VQAs the layout is the following:&lt;br /&gt;
LL RR LL RR ...&lt;br /&gt;
That is, first byte contains two nibbles for two left channel values, next&lt;br /&gt;
byte contains nibbles for right channel, etc. Note that lower nibble should&lt;br /&gt;
be processed first and then higher one (see AUD3.TXT).&lt;br /&gt;
&lt;br /&gt;
For C&amp;amp;C: Tiberian Sun (version 3) VQAs the layout is different: in SND2 block&lt;br /&gt;
first go all nibbles for left channel, then all nibbles for right channel:&lt;br /&gt;
LL LL LL ... LL RR RR RR ... RR&lt;br /&gt;
Note that nibbles should be processed in the same turn: lower nibble first.&lt;br /&gt;
So, when decoding SND2 block, just decompress first half of the block data&lt;br /&gt;
for left channel, then second half -- for right channel.&lt;br /&gt;
&lt;br /&gt;
==PC Games Using this Format==&lt;br /&gt;
[http://www.mobygames.com/game/win3x/legend-of-kyrandia-malcolms-revenge Legend of Kyrandia III: Malcom's Revenge]&lt;br /&gt;
&lt;br /&gt;
[http://www.mobygames.com/game/command-conquer Command &amp;amp; Conquer]&lt;br /&gt;
&lt;br /&gt;
[http://www.mobygames.com/game/command-conquer-red-alert Command &amp;amp; Conquer Red Alert]&lt;br /&gt;
&lt;br /&gt;
[http://www.mobygames.com/game/command-conquer-tiberian-sun Command &amp;amp; Conquer Tiberian Sun]&lt;br /&gt;
&lt;br /&gt;
[http://www.mobygames.com/game/windows/dune-2000 Dune 2000]&lt;br /&gt;
&lt;br /&gt;
Possibly using the format:&lt;br /&gt;
&lt;br /&gt;
[http://www.mobygames.com/game/windows/lands-of-lore-guardians-of-destiny Lands of Lore: Guardians of Destiny]&lt;br /&gt;
&lt;br /&gt;
[http://www.mobygames.com/game/windows/lands-of-lore-iii Lands of Lore III]&lt;br /&gt;
&lt;br /&gt;
[http://www.mobygames.com/game/windows/blade-runner Blade Runner]&lt;/div&gt;</summary>
		<author><name>Dashcloud</name></author>
	</entry>
</feed>