What font did ID Software used for the first three games?

Here, you can get help with anything or just chat about the original Commander Keen games.
User avatar
Posts: 11
Joined: Sat Mar 29, 2008 11:33

Post by Hyrule_boy » Thu Apr 03, 2008 17:39

CK Guy wrote:Here's the code, reposted, in case Archive.org isn't cooperating with you (like it often isn't for me):

Code: Select all


Very quick hack to extract Commander Keen sounds from SOUNDS1.CK1.
The output files are raw 16-bit Intel byte order stereo PCMs.

By Anders Gavare <g@dd.chalmers.se>


#include <stdio.h>
#include <errno.h>
#include <math.h>

FILE *f, *fout;
unsigned char buf[16];

double t = 0.0;
double dt = 1.0/44100.0;
//double freqdiv = 1193180.0;
double freqdiv = 1193180.0;

int short_while = 44100/128;

void write_freq (int freq)
    /*  write a short while of 'freq':  */
    /*  y = Amplitude * sin (omega * t)  where omega = 2*PI*freq  */

    double y;
    int b,b1,b2;
    int j;

    for (j=0; j<short_while; j++)
	if (freq)
		y = 10000.0 * sin (2.0*M_PI*freqdiv/(double)freq*t);
		y = 0.0;

if (y>1) y=10000;
if (y<1) y=-10000;

	t = t + dt;
	b = y;
	b1 = b & 255;
	b2 = b / 256;
	fwrite (&b1, 1, 1, fout);
	fwrite (&b2, 1, 1, fout);
	fwrite (&b1, 1, 1, fout);
	fwrite (&b2, 1, 1, fout);

void save_sound (int ofs)
    unsigned char minibuf[2];
    int freq;

    fseek (f, ofs, 0);
    fread (minibuf, 2, 1, f);

    while (minibuf[0]!=0xff && minibuf[1]!=0xff)
	freq = minibuf[0]+minibuf[1]*256;
printf (" %i", freq);
	write_freq (freq);

	/*  read next minibuf:  */
	fread (minibuf, 2, 1, f);
    printf ("\n");

int main (int argc, char *argv[])
    int nr_of_sounds, i;

    if (argc==1)
	printf ("usage: %s SOUNDS.CK1  or similar.\n"
		"This will create lots of raw sound files in the current directory.\n",
	exit (0);

    f = fopen (argv[1], "r");
    if (!f)
	exit (errno);

    /*  get nr of sounds from the header:  */
    fread (buf, 16, 1, f);
    nr_of_sounds = buf[6]+buf[7]*256;

    for (i=1; i<=nr_of_sounds; i++)
	fseek (f, 16*i, 0);
	fread (buf, 16, 1, f);

	if (buf[3]==8)
	    fout = fopen (buf+4, "w");
	    if (!fout)
	      exit (errno);
		save_sound (buf[0]+buf[1]*256);
		fclose (fout);

    return 0;
Maybe I can work on getting some WAVs, but not today. I know that format isn't that complicated, just some header data and then the PCM data. I've combined WAVs manually several times, using a hexeditor. 8)
Well if you could do that for me then I would be most gratefull. And I will make sure you get credit, and the demos before anybody else gets them.

User avatar
Commander Spleen
Lord of the Foobs
Posts: 2360
Joined: Wed Oct 31, 2007 22:54
Location: Border Village

Post by Commander Spleen » Thu May 08, 2008 9:29

Does anyone know whether a RAW file can be converted back into PC speaker sound data? I get the impression the format is more complex than I'd initially thought.

I compiled this program and extracted the RAW files for ZXD, and he intended to use GoldWave to edit them and then find a way to convert them back to Keen's native format. But "the output's square waves aren't at all as perfect as the PC Speaker's".

I haven't seen this for myself, but it sounds to me that the RAW data is of a higher resolution than the PC speaker data--rather than having single points that create the effect of a square wave when they differ from one another, I theorise that GoldWave must implemented them as lines of equal values with an antialiasing effect.

If you know what I mean...

Any thoughts?

User avatar
Zero X. Diamond
Posts: 36
Joined: Sat Jan 19, 2008 15:03
Location: The Planet of the Tiny Hut People

Post by Zero X. Diamond » Thu May 08, 2008 10:34

Oh, you misconstrued my meaning: I didn't mean that the output you SENT me was imperfect--it has perfectly square waves. I was referring to the output from the program I had used to generate a sound effect. Sorry for that mix up!
"I know what I am doing here with my collection of papers, for crying out loud. It isn't worth a nickel to two guys like you or me, but to a collector it is worth a fortune; it is priceless." - Dutch Schultz

Post Reply