PC Speaker Sound Player by Frenkel Smeijers, July 30 2001.

This programs plays the PC Speaker sound fx from games. The program is
tested on the following files and games: Sounds.ca2     The Catacomb
                                         Sounds.slo     Slordax
                                         Sounds.ck1     Commander Keen1
                                         Sounds.rov     Rescue Rover
                                         Sounds.hov     Hovertank 3-D
                                         Sounds.par     Paragon
                                         Duke1.dn1      Duke Nukum
                                         Duke1-b.dn1
                                         Duke2.dn2
                                         Duke2-b.dn2
                                         Duke3.dn3
                                         Duke3-b.dn3

These files requier my Todd Replogle Extractor:
                                         Sounds.mni     Cosmo's Cosmic
                                         Sounds2.mni     Adventure
                                         Sound3.mni
                                         Drsound.snd    Major Stryker
                                         Drsound2.snd

These files are stored into the EXE file of the game:
                                         Sounds.ck2     Commander Keen2
                                         Sounds.ck3     Commander Keen3
                                         Sounds.nin     Shadow Knights

Keys:
ESC	  quit sndplay
Left	  one sound back
Right     one sound forward
Spacebar  Repeat same sound


I found the format of the sound files on the Commander Keen 1-3 for 
Unix Port/Clone Project Page which you can find on 
http://durdin.net/andy/keen/Gavare


Sound file format
This is probably not 100% correct, it was found by trial-and-error kind
of research. In Keen 1, the sound data is stored in SOUNDS.CK1, but in
Keen 2 and 3 the data is stored directly in the main executable. 

Offset: Len: Description: 
 0x00    3   "SND" 
 0x03    1   0x00 
 0x04    2   total file length 
 0x06    2   nr_of_sounds (0x3f in Keen 1) 
 0x08    2   (unknown) 
 0x0a    6   0x00 0x00 0x00 0x00 0x00 0x00 
 0x10   16   header for sound #1 
 0x20   16   header for sound #2 
 ..      2   .. 
 0x400   2   data for sound #1 begins here... (Keen 1) 

There is one "header" for each sound (#1, #2, ..) which has the
following format: 

Offset: Len: Description: 
+ 0x00   2   file offset to sound data 
+ 0x02   1   priority, 0xff means guaranteed foreground play 
+ 0x03   1   (unknown, 8 if sound exists, 1 if non-existant???) 
+ 0x04  12   name, padded with zeroes if neccessary 

Sound data is given as a number of 2-byte Intel words. A word of 0xffff
ends the sound. A 0x0000 means quiet. All other values are inverted
frequency data. A simple test shows that approx 1000000/value sounds 
almost like the sounds in the game. The 1000000 could be 1193180 (the 
PC's timer base value) or something else. I'm not sure. The duration of
each sound data sample is probably around 1/128 of a second. 

Whenever the sound playing function is called, the priority of the new
sample is compared to the sample which is currently playing (if any).
If the priority of the new sample is higher than or equal to the 
priority of the currently playing sample, then we switch to playing the
new one, otherwise we do nothing (which means that the old sample 
continues). 

Here's a quick hack which extracts the audio and saves it as 16-bit PCM
samples: 

File:         Description: 
sounds2raw.c  C source code to extract sounds from SOUNDS.CK1 

http://durdin.net/andy/keen/Gavare/files/sounds2raw.c


My Todd Replogle Extractor and the sound extracters for Shadow Knights
and Commander Keen 2&3 are on my homepage at
http://www.student.tue.nl/u/a.f.smeijers/sfp

Frenkel Smeijers
frenkel_smeijers@hotmail.com