The DOOM sources as originally released on December 23, 1997

This commit is contained in:
Travis Bradshaw
2012-01-31 15:27:37 -06:00
commit 4eb368a960
149 changed files with 59219 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
##########################################################
#
# $Id:$
#
# $Log:$
#
#
CC=gcc
CFLAGS=-O -DNORMALUNIX -DLINUX
LDFLAGS=
LIBS=-lm
O=linux
all: $(O)/sndserver
clean:
rm -f *.o *~ *.flc
rm -f linux/*
# Target
$(O)/sndserver: \
$(O)/soundsrv.o \
$(O)/sounds.o \
$(O)/wadread.o \
$(O)/linux.o
$(CC) $(CFLAGS) $(LDFLAGS) \
$(O)/soundsrv.o \
$(O)/sounds.o \
$(O)/wadread.o \
$(O)/linux.o -o $(O)/sndserver $(LIBS)
echo make complete.
# Rule
$(O)/%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
+15
View File
@@ -0,0 +1,15 @@
This is the soundserver as used by the original
Linuxdoom release. I separated the source from
the actual Linuxduum source. For various reasons
the separate sound process seems to give the
best results - both synchronous and timer driven
output demonstrate glitches. These might either
be timing issues, or introduced by the changes
I made to the linux sound code while merging it
back into the main tree.
Note that neither John Carmack nor Dave Taylor
are responsible for the current sound handling.
+118
View File
@@ -0,0 +1,118 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id: linux.c,v 1.3 1997/01/26 07:45:01 b1 Exp $
//
// Copyright (C) 1993-1996 by id Software, Inc.
//
// This source is available for distribution and/or modification
// only under the terms of the DOOM Source Code License as
// published by id Software. All rights reserved.
//
// The source is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
// for more details.
//
//
// $Log: linux.c,v $
// Revision 1.3 1997/01/26 07:45:01 b1
// 2nd formatting run, fixed a few warnings as well.
//
// Revision 1.2 1997/01/21 19:00:01 b1
// First formatting run:
// using Emacs cc-mode.el indentation for C++ now.
//
// Revision 1.1 1997/01/19 17:22:45 b1
// Initial check in DOOM sources as of Jan. 10th, 1997
//
//
// DESCRIPTION:
// UNIX, soundserver for Linux i386.
//
//-----------------------------------------------------------------------------
static const char rcsid[] = "$Id: linux.c,v 1.3 1997/01/26 07:45:01 b1 Exp $";
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/soundcard.h>
#include "soundsrv.h"
int audio_fd;
void
myioctl
( int fd,
int command,
int* arg )
{
int rc;
extern int errno;
rc = ioctl(fd, command, arg);
if (rc < 0)
{
fprintf(stderr, "ioctl(dsp,%d,arg) failed\n", command);
fprintf(stderr, "errno=%d\n", errno);
exit(-1);
}
}
void I_InitMusic(void)
{
}
void
I_InitSound
( int samplerate,
int samplesize )
{
int i;
audio_fd = open("/dev/dsp", O_WRONLY);
if (audio_fd<0)
fprintf(stderr, "Could not open /dev/dsp\n");
i = 11 | (2<<16);
myioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &i);
myioctl(audio_fd, SNDCTL_DSP_RESET, 0);
i=11025;
myioctl(audio_fd, SNDCTL_DSP_SPEED, &i);
i=1;
myioctl(audio_fd, SNDCTL_DSP_STEREO, &i);
myioctl(audio_fd, SNDCTL_DSP_GETFMTS, &i);
if (i&=AFMT_S16_LE)
myioctl(audio_fd, SNDCTL_DSP_SETFMT, &i);
else
fprintf(stderr, "Could not play signed 16 data\n");
}
void
I_SubmitOutputBuffer
( void* samples,
int samplecount )
{
write(audio_fd, samples, samplecount*4);
}
void I_ShutdownSound(void)
{
close(audio_fd);
}
void I_ShutdownMusic(void)
{
}
+239
View File
@@ -0,0 +1,239 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id: sounds.c,v 1.3 1997/01/29 22:40:44 b1 Exp $
//
// Copyright (C) 1993-1996 by id Software, Inc.
//
// This source is available for distribution and/or modification
// only under the terms of the DOOM Source Code License as
// published by id Software. All rights reserved.
//
// The source is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
// for more details.
//
//
// $Log: sounds.c,v $
// Revision 1.3 1997/01/29 22:40:44 b1
// Reformatting, S (sound) module files.
//
// Revision 1.2 1997/01/21 19:00:07 b1
// First formatting run:
// using Emacs cc-mode.el indentation for C++ now.
//
// Revision 1.1 1997/01/19 17:22:50 b1
// Initial check in DOOM sources as of Jan. 10th, 1997
//
//
// DESCRIPTION:
// Created by Dave Taylor's sound utility.
// Kept as a sample, DOOM sounds.
//
//-----------------------------------------------------------------------------
static const char rcsid[] = "$Id: sounds.c,v 1.3 1997/01/29 22:40:44 b1 Exp $";
// Not exactly a good idea.
enum { false, true };
#include "sounds.h"
//
// Information about all the music
//
musicinfo_t S_music[] =
{
{ 0 },
{ "e1m1", 0 },
{ "e1m2", 0 },
{ "e1m3", 0 },
{ "e1m4", 0 },
{ "e1m5", 0 },
{ "e1m6", 0 },
{ "e1m7", 0 },
{ "e1m8", 0 },
{ "e1m9", 0 },
{ "e2m1", 0 },
{ "e2m2", 0 },
{ "e2m3", 0 },
{ "e2m4", 0 },
{ "e2m5", 0 },
{ "e2m6", 0 },
{ "e2m7", 0 },
{ "e2m8", 0 },
{ "e2m9", 0 },
{ "e3m1", 0 },
{ "e3m2", 0 },
{ "e3m3", 0 },
{ "e3m4", 0 },
{ "e3m5", 0 },
{ "e3m6", 0 },
{ "e3m7", 0 },
{ "e3m8", 0 },
{ "e3m9", 0 },
{ "inter", 0 },
{ "intro", 0 },
{ "bunny", 0 },
{ "victor", 0 },
{ "introa", 0 },
{ "runnin", 0 },
{ "stalks", 0 },
{ "countd", 0 },
{ "betwee", 0 },
{ "doom", 0 },
{ "the_da", 0 },
{ "shawn", 0 },
{ "ddtblu", 0 },
{ "in_cit", 0 },
{ "dead", 0 },
{ "stlks2", 0 },
{ "theda2", 0 },
{ "doom2", 0 },
{ "ddtbl2", 0 },
{ "runni2", 0 },
{ "dead2", 0 },
{ "stlks3", 0 },
{ "romero", 0 },
{ "shawn2", 0 },
{ "messag", 0 },
{ "count2", 0 },
{ "ddtbl3", 0 },
{ "ampie", 0 },
{ "theda3", 0 },
{ "adrian", 0 },
{ "messg2", 0 },
{ "romer2", 0 },
{ "tense", 0 },
{ "shawn3", 0 },
{ "openin", 0 },
{ "evil", 0 },
{ "ultima", 0 },
{ "read_m", 0 },
{ "dm2ttl", 0 },
{ "dm2int", 0 }
};
//
// Information about all the sfx
//
sfxinfo_t S_sfx[] =
{
{ 0 },
{ "pistol", false, 64, 0, -1, -1, 0 },
{ "shotgn", false, 64, 0, -1, -1, 0 },
{ "sgcock", false, 64, 0, -1, -1, 0 },
{ "dshtgn", false, 64, 0, -1, -1, 0 },
{ "dbopn", false, 64, 0, -1, -1, 0 },
{ "dbcls", false, 64, 0, -1, -1, 0 },
{ "dbload", false, 64, 0, -1, -1, 0 },
{ "plasma", false, 64, 0, -1, -1, 0 },
{ "bfg", false, 64, 0, -1, -1, 0 },
{ "sawup", false, 64, 0, -1, -1, 0 },
{ "sawidl", false, 118, 0, -1, -1, 0 },
{ "sawful", false, 64, 0, -1, -1, 0 },
{ "sawhit", false, 64, 0, -1, -1, 0 },
{ "rlaunc", false, 64, 0, -1, -1, 0 },
{ "rxplod", false, 70, 0, -1, -1, 0 },
{ "firsht", false, 70, 0, -1, -1, 0 },
{ "firxpl", false, 70, 0, -1, -1, 0 },
{ "pstart", false, 100, 0, -1, -1, 0 },
{ "pstop", false, 100, 0, -1, -1, 0 },
{ "doropn", false, 100, 0, -1, -1, 0 },
{ "dorcls", false, 100, 0, -1, -1, 0 },
{ "stnmov", false, 119, 0, -1, -1, 0 },
{ "swtchn", false, 78, 0, -1, -1, 0 },
{ "swtchx", false, 78, 0, -1, -1, 0 },
{ "plpain", false, 96, 0, -1, -1, 0 },
{ "dmpain", false, 96, 0, -1, -1, 0 },
{ "popain", false, 96, 0, -1, -1, 0 },
{ "vipain", false, 96, 0, -1, -1, 0 },
{ "mnpain", false, 96, 0, -1, -1, 0 },
{ "pepain", false, 96, 0, -1, -1, 0 },
{ "slop", false, 78, 0, -1, -1, 0 },
{ "itemup", true, 78, 0, -1, -1, 0 },
{ "wpnup", true, 78, 0, -1, -1, 0 },
{ "oof", false, 96, 0, -1, -1, 0 },
{ "telept", false, 32, 0, -1, -1, 0 },
{ "posit1", true, 98, 0, -1, -1, 0 },
{ "posit2", true, 98, 0, -1, -1, 0 },
{ "posit3", true, 98, 0, -1, -1, 0 },
{ "bgsit1", true, 98, 0, -1, -1, 0 },
{ "bgsit2", true, 98, 0, -1, -1, 0 },
{ "sgtsit", true, 98, 0, -1, -1, 0 },
{ "cacsit", true, 98, 0, -1, -1, 0 },
{ "brssit", true, 94, 0, -1, -1, 0 },
{ "cybsit", true, 92, 0, -1, -1, 0 },
{ "spisit", true, 90, 0, -1, -1, 0 },
{ "bspsit", true, 90, 0, -1, -1, 0 },
{ "kntsit", true, 90, 0, -1, -1, 0 },
{ "vilsit", true, 90, 0, -1, -1, 0 },
{ "mansit", true, 90, 0, -1, -1, 0 },
{ "pesit", true, 90, 0, -1, -1, 0 },
{ "sklatk", false, 70, 0, -1, -1, 0 },
{ "sgtatk", false, 70, 0, -1, -1, 0 },
{ "skepch", false, 70, 0, -1, -1, 0 },
{ "vilatk", false, 70, 0, -1, -1, 0 },
{ "claw", false, 70, 0, -1, -1, 0 },
{ "skeswg", false, 70, 0, -1, -1, 0 },
{ "pldeth", false, 32, 0, -1, -1, 0 },
{ "pdiehi", false, 32, 0, -1, -1, 0 },
{ "podth1", false, 70, 0, -1, -1, 0 },
{ "podth2", false, 70, 0, -1, -1, 0 },
{ "podth3", false, 70, 0, -1, -1, 0 },
{ "bgdth1", false, 70, 0, -1, -1, 0 },
{ "bgdth2", false, 70, 0, -1, -1, 0 },
{ "sgtdth", false, 70, 0, -1, -1, 0 },
{ "cacdth", false, 70, 0, -1, -1, 0 },
{ "skldth", false, 70, 0, -1, -1, 0 },
{ "brsdth", false, 32, 0, -1, -1, 0 },
{ "cybdth", false, 32, 0, -1, -1, 0 },
{ "spidth", false, 32, 0, -1, -1, 0 },
{ "bspdth", false, 32, 0, -1, -1, 0 },
{ "vildth", false, 32, 0, -1, -1, 0 },
{ "kntdth", false, 32, 0, -1, -1, 0 },
{ "pedth", false, 32, 0, -1, -1, 0 },
{ "skedth", false, 32, 0, -1, -1, 0 },
{ "posact", true, 120, 0, -1, -1, 0 },
{ "bgact", true, 120, 0, -1, -1, 0 },
{ "dmact", true, 120, 0, -1, -1, 0 },
{ "bspact", true, 100, 0, -1, -1, 0 },
{ "bspwlk", true, 100, 0, -1, -1, 0 },
{ "vilact", true, 100, 0, -1, -1, 0 },
{ "noway", false, 78, 0, -1, -1, 0 },
{ "barexp", false, 60, 0, -1, -1, 0 },
{ "punch", false, 64, 0, -1, -1, 0 },
{ "hoof", false, 70, 0, -1, -1, 0 },
{ "metal", false, 70, 0, -1, -1, 0 },
{ "chgun", false, 64, &S_sfx[sfx_pistol], 150, 0, 0 },
{ "tink", false, 60, 0, -1, -1, 0 },
{ "bdopn", false, 100, 0, -1, -1, 0 },
{ "bdcls", false, 100, 0, -1, -1, 0 },
{ "itmbk", false, 100, 0, -1, -1, 0 },
{ "flame", false, 32, 0, -1, -1, 0 },
{ "flamst", false, 32, 0, -1, -1, 0 },
{ "getpow", false, 60, 0, -1, -1, 0 },
{ "bospit", false, 70, 0, -1, -1, 0 },
{ "boscub", false, 70, 0, -1, -1, 0 },
{ "bossit", false, 70, 0, -1, -1, 0 },
{ "bospn", false, 70, 0, -1, -1, 0 },
{ "bosdth", false, 70, 0, -1, -1, 0 },
{ "manatk", false, 70, 0, -1, -1, 0 },
{ "mandth", false, 70, 0, -1, -1, 0 },
{ "sssit", false, 70, 0, -1, -1, 0 },
{ "ssdth", false, 70, 0, -1, -1, 0 },
{ "keenpn", false, 70, 0, -1, -1, 0 },
{ "keendt", false, 70, 0, -1, -1, 0 },
{ "skeact", false, 70, 0, -1, -1, 0 },
{ "skesit", false, 70, 0, -1, -1, 0 },
{ "skeatk", false, 70, 0, -1, -1, 0 },
{ "radio", false, 60, 0, -1, -1, 0 }
};
+241
View File
@@ -0,0 +1,241 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id: sounds.h,v 1.3 1997/01/29 22:40:44 b1 Exp $
//
// Copyright (C) 1993-1996 by id Software, Inc.
//
// This source is available for distribution and/or modification
// only under the terms of the DOOM Source Code License as
// published by id Software. All rights reserved.
//
// The source is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
// for more details.
//
//
// $Log: sounds.h,v $
// Revision 1.3 1997/01/29 22:40:44 b1
// Reformatting, S (sound) module files.
//
// Revision 1.2 1997/01/21 19:00:07 b1
// First formatting run:
// using Emacs cc-mode.el indentation for C++ now.
//
// Revision 1.1 1997/01/19 17:22:50 b1
// Initial check in DOOM sources as of Jan. 10th, 1997
//
//
// DESCRIPTION:
// Created by Dave Taylor's sound utility.
// Kept as a sample, DOOM sounds.
//
//-----------------------------------------------------------------------------
#ifndef __SOUNDSH__
#define __SOUNDSH__
#include "soundst.h"
//
// Identifiers for all music in game.
//
typedef enum
{
mus_None,
mus_e1m1,
mus_e1m2,
mus_e1m3,
mus_e1m4,
mus_e1m5,
mus_e1m6,
mus_e1m7,
mus_e1m8,
mus_e1m9,
mus_e2m1,
mus_e2m2,
mus_e2m3,
mus_e2m4,
mus_e2m5,
mus_e2m6,
mus_e2m7,
mus_e2m8,
mus_e2m9,
mus_e3m1,
mus_e3m2,
mus_e3m3,
mus_e3m4,
mus_e3m5,
mus_e3m6,
mus_e3m7,
mus_e3m8,
mus_e3m9,
mus_inter,
mus_intro,
mus_bunny,
mus_victor,
mus_introa,
mus_runnin,
mus_stalks,
mus_countd,
mus_betwee,
mus_doom,
mus_the_da,
mus_shawn,
mus_ddtblu,
mus_in_cit,
mus_dead,
mus_stlks2,
mus_theda2,
mus_doom2,
mus_ddtbl2,
mus_runni2,
mus_dead2,
mus_stlks3,
mus_romero,
mus_shawn2,
mus_messag,
mus_count2,
mus_ddtbl3,
mus_ampie,
mus_theda3,
mus_adrian,
mus_messg2,
mus_romer2,
mus_tense,
mus_shawn3,
mus_openin,
mus_evil,
mus_ultima,
mus_read_m,
mus_dm2ttl,
mus_dm2int,
NUMMUSIC
} musicenum_t;
//
// Identifiers for all sfx in game.
//
typedef enum
{
sfx_None,
sfx_pistol,
sfx_shotgn,
sfx_sgcock,
sfx_dshtgn,
sfx_dbopn,
sfx_dbcls,
sfx_dbload,
sfx_plasma,
sfx_bfg,
sfx_sawup,
sfx_sawidl,
sfx_sawful,
sfx_sawhit,
sfx_rlaunc,
sfx_rxplod,
sfx_firsht,
sfx_firxpl,
sfx_pstart,
sfx_pstop,
sfx_doropn,
sfx_dorcls,
sfx_stnmov,
sfx_swtchn,
sfx_swtchx,
sfx_plpain,
sfx_dmpain,
sfx_popain,
sfx_vipain,
sfx_mnpain,
sfx_pepain,
sfx_slop,
sfx_itemup,
sfx_wpnup,
sfx_oof,
sfx_telept,
sfx_posit1,
sfx_posit2,
sfx_posit3,
sfx_bgsit1,
sfx_bgsit2,
sfx_sgtsit,
sfx_cacsit,
sfx_brssit,
sfx_cybsit,
sfx_spisit,
sfx_bspsit,
sfx_kntsit,
sfx_vilsit,
sfx_mansit,
sfx_pesit,
sfx_sklatk,
sfx_sgtatk,
sfx_skepch,
sfx_vilatk,
sfx_claw,
sfx_skeswg,
sfx_pldeth,
sfx_pdiehi,
sfx_podth1,
sfx_podth2,
sfx_podth3,
sfx_bgdth1,
sfx_bgdth2,
sfx_sgtdth,
sfx_cacdth,
sfx_skldth,
sfx_brsdth,
sfx_cybdth,
sfx_spidth,
sfx_bspdth,
sfx_vildth,
sfx_kntdth,
sfx_pedth,
sfx_skedth,
sfx_posact,
sfx_bgact,
sfx_dmact,
sfx_bspact,
sfx_bspwlk,
sfx_vilact,
sfx_noway,
sfx_barexp,
sfx_punch,
sfx_hoof,
sfx_metal,
sfx_chgun,
sfx_tink,
sfx_bdopn,
sfx_bdcls,
sfx_itmbk,
sfx_flame,
sfx_flamst,
sfx_getpow,
sfx_bospit,
sfx_boscub,
sfx_bossit,
sfx_bospn,
sfx_bosdth,
sfx_manatk,
sfx_mandth,
sfx_sssit,
sfx_ssdth,
sfx_keenpn,
sfx_keendt,
sfx_skeact,
sfx_skesit,
sfx_skeatk,
sfx_radio,
NUMSFX
} sfxenum_t;
extern musicinfo_t S_music[];
extern sfxinfo_t S_sfx[];
#endif
+740
View File
@@ -0,0 +1,740 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id: soundsrv.c,v 1.3 1997/01/29 22:40:44 b1 Exp $
//
// Copyright (C) 1993-1996 by id Software, Inc.
//
// This source is available for distribution and/or modification
// only under the terms of the DOOM Source Code License as
// published by id Software. All rights reserved.
//
// The source is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
// for more details.
//
//
// $Log: soundsrv.c,v $
// Revision 1.3 1997/01/29 22:40:44 b1
// Reformatting, S (sound) module files.
//
// Revision 1.2 1997/01/21 19:00:07 b1
// First formatting run:
// using Emacs cc-mode.el indentation for C++ now.
//
// Revision 1.1 1997/01/19 17:22:50 b1
// Initial check in DOOM sources as of Jan. 10th, 1997
//
//
// DESCRIPTION:
// UNIX soundserver, run as a separate process,
// started by DOOM program.
// Originally conceived fopr SGI Irix,
// mostly used with Linux voxware.
//
//-----------------------------------------------------------------------------
static const char rcsid[] = "$Id: soundsrv.c,v 1.3 1997/01/29 22:40:44 b1 Exp $";
#include <math.h>
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdlib.h>
#include <malloc.h>
#include <sys/stat.h>
#include <sys/time.h>
#include "sounds.h"
#include "soundsrv.h"
#include "wadread.h"
//
// Department of Redundancy Department.
//
typedef struct wadinfo_struct
{
// should be IWAD
char identification[4];
int numlumps;
int infotableofs;
} wadinfo_t;
typedef struct filelump_struct
{
int filepos;
int size;
char name[8];
} filelump_t;
// an internal time keeper
static int mytime = 0;
// number of sound effects
int numsounds;
// longest sound effect
int longsound;
// lengths of all sound effects
int lengths[NUMSFX];
// mixing buffer
signed short mixbuffer[MIXBUFFERSIZE];
// file descriptor of sfx device
int sfxdevice;
// file descriptor of music device
int musdevice;
// the channel data pointers
unsigned char* channels[8];
// the channel step amount
unsigned int channelstep[8];
// 0.16 bit remainder of last step
unsigned int channelstepremainder[8];
// the channel data end pointers
unsigned char* channelsend[8];
// time that the channel started playing
int channelstart[8];
// the channel handles
int channelhandles[8];
// the channel left volume lookup
int* channelleftvol_lookup[8];
// the channel right volume lookup
int* channelrightvol_lookup[8];
// sfx id of the playing sound effect
int channelids[8];
int snd_verbose=1;
int steptable[256];
int vol_lookup[128*256];
static void derror(char* msg)
{
fprintf(stderr, "error: %s\n", msg);
exit(-1);
}
int mix(void)
{
register int dl;
register int dr;
register unsigned int sample;
signed short* leftout;
signed short* rightout;
signed short* leftend;
int step;
leftout = mixbuffer;
rightout = mixbuffer+1;
step = 2;
leftend = mixbuffer + SAMPLECOUNT*step;
// mix into the mixing buffer
while (leftout != leftend)
{
dl = 0;
dr = 0;
if (channels[0])
{
sample = *channels[0];
dl += channelleftvol_lookup[0][sample];
dr += channelrightvol_lookup[0][sample];
channelstepremainder[0] += channelstep[0];
channels[0] += channelstepremainder[0] >> 16;
channelstepremainder[0] &= 65536-1;
if (channels[0] >= channelsend[0])
channels[0] = 0;
}
if (channels[1])
{
sample = *channels[1];
dl += channelleftvol_lookup[1][sample];
dr += channelrightvol_lookup[1][sample];
channelstepremainder[1] += channelstep[1];
channels[1] += channelstepremainder[1] >> 16;
channelstepremainder[1] &= 65536-1;
if (channels[1] >= channelsend[1])
channels[1] = 0;
}
if (channels[2])
{
sample = *channels[2];
dl += channelleftvol_lookup[2][sample];
dr += channelrightvol_lookup[2][sample];
channelstepremainder[2] += channelstep[2];
channels[2] += channelstepremainder[2] >> 16;
channelstepremainder[2] &= 65536-1;
if (channels[2] >= channelsend[2])
channels[2] = 0;
}
if (channels[3])
{
sample = *channels[3];
dl += channelleftvol_lookup[3][sample];
dr += channelrightvol_lookup[3][sample];
channelstepremainder[3] += channelstep[3];
channels[3] += channelstepremainder[3] >> 16;
channelstepremainder[3] &= 65536-1;
if (channels[3] >= channelsend[3])
channels[3] = 0;
}
if (channels[4])
{
sample = *channels[4];
dl += channelleftvol_lookup[4][sample];
dr += channelrightvol_lookup[4][sample];
channelstepremainder[4] += channelstep[4];
channels[4] += channelstepremainder[4] >> 16;
channelstepremainder[4] &= 65536-1;
if (channels[4] >= channelsend[4])
channels[4] = 0;
}
if (channels[5])
{
sample = *channels[5];
dl += channelleftvol_lookup[5][sample];
dr += channelrightvol_lookup[5][sample];
channelstepremainder[5] += channelstep[5];
channels[5] += channelstepremainder[5] >> 16;
channelstepremainder[5] &= 65536-1;
if (channels[5] >= channelsend[5])
channels[5] = 0;
}
if (channels[6])
{
sample = *channels[6];
dl += channelleftvol_lookup[6][sample];
dr += channelrightvol_lookup[6][sample];
channelstepremainder[6] += channelstep[6];
channels[6] += channelstepremainder[6] >> 16;
channelstepremainder[6] &= 65536-1;
if (channels[6] >= channelsend[6])
channels[6] = 0;
}
if (channels[7])
{
sample = *channels[7];
dl += channelleftvol_lookup[7][sample];
dr += channelrightvol_lookup[7][sample];
channelstepremainder[7] += channelstep[7];
channels[7] += channelstepremainder[7] >> 16;
channelstepremainder[7] &= 65536-1;
if (channels[7] >= channelsend[7])
channels[7] = 0;
}
// Has been char instead of short.
// if (dl > 127) *leftout = 127;
// else if (dl < -128) *leftout = -128;
// else *leftout = dl;
// if (dr > 127) *rightout = 127;
// else if (dr < -128) *rightout = -128;
// else *rightout = dr;
if (dl > 0x7fff)
*leftout = 0x7fff;
else if (dl < -0x8000)
*leftout = -0x8000;
else
*leftout = dl;
if (dr > 0x7fff)
*rightout = 0x7fff;
else if (dr < -0x8000)
*rightout = -0x8000;
else
*rightout = dr;
leftout += step;
rightout += step;
}
return 1;
}
void
grabdata
( int c,
char** v )
{
int i;
char* name;
char* doom1wad;
char* doomwad;
char* doomuwad;
char* doom2wad;
char* doom2fwad;
// Now where are TNT and Plutonia. Yuck.
// char *home;
char* doomwaddir;
doomwaddir = getenv("DOOMWADDIR");
if (!doomwaddir)
doomwaddir = ".";
doom1wad = malloc(strlen(doomwaddir)+1+9+1);
sprintf(doom1wad, "%s/doom1.wad", doomwaddir);
doom2wad = malloc(strlen(doomwaddir)+1+9+1);
sprintf(doom2wad, "%s/doom2.wad", doomwaddir);
doom2fwad = malloc(strlen(doomwaddir)+1+10+1);
sprintf(doom2fwad, "%s/doom2f.wad", doomwaddir);
doomuwad = malloc(strlen(doomwaddir)+1+8+1);
sprintf(doomuwad, "%s/doomu.wad", doomwaddir);
doomwad = malloc(strlen(doomwaddir)+1+8+1);
sprintf(doomwad, "%s/doom.wad", doomwaddir);
// home = getenv("HOME");
// if (!home)
// derror("Please set $HOME to your home directory");
// sprintf(basedefault, "%s/.doomrc", home);
for (i=1 ; i<c ; i++)
{
if (!strcmp(v[i], "-quiet"))
{
snd_verbose = 0;
}
}
numsounds = NUMSFX;
longsound = 0;
if (! access(doom2fwad, R_OK) )
name = doom2fwad;
else if (! access(doom2wad, R_OK) )
name = doom2wad;
else if (! access(doomuwad, R_OK) )
name = doomuwad;
else if (! access(doomwad, R_OK) )
name = doomwad;
else if (! access(doom1wad, R_OK) )
name = doom1wad;
// else if (! access(DEVDATA "doom2.wad", R_OK) )
// name = DEVDATA "doom2.wad";
// else if (! access(DEVDATA "doom.wad", R_OK) )
// name = DEVDATA "doom.wad";
else
{
fprintf(stderr, "Could not find wadfile anywhere\n");
exit(-1);
}
openwad(name);
if (snd_verbose)
fprintf(stderr, "loading from [%s]\n", name);
for (i=1 ; i<NUMSFX ; i++)
{
if (!S_sfx[i].link)
{
S_sfx[i].data = getsfx(S_sfx[i].name, &lengths[i]);
if (longsound < lengths[i]) longsound = lengths[i];
} else {
S_sfx[i].data = S_sfx[i].link->data;
lengths[i] = lengths[(S_sfx[i].link - S_sfx)/sizeof(sfxinfo_t)];
}
// test only
// {
// int fd;
// char name[10];
// sprintf(name, "sfx%d", i);
// fd = open(name, O_WRONLY|O_CREAT, 0644);
// write(fd, S_sfx[i].data, lengths[i]);
// close(fd);
// }
}
}
static struct timeval last={0,0};
//static struct timeval now;
static struct timezone whocares;
void updatesounds(void)
{
mix();
I_SubmitOutputBuffer(mixbuffer, SAMPLECOUNT);
}
int
addsfx
( int sfxid,
int volume,
int step,
int seperation )
{
static unsigned short handlenums = 0;
int i;
int rc = -1;
int oldest = mytime;
int oldestnum = 0;
int slot;
int rightvol;
int leftvol;
// play these sound effects
// only one at a time
if ( sfxid == sfx_sawup
|| sfxid == sfx_sawidl
|| sfxid == sfx_sawful
|| sfxid == sfx_sawhit
|| sfxid == sfx_stnmov
|| sfxid == sfx_pistol )
{
for (i=0 ; i<8 ; i++)
{
if (channels[i] && channelids[i] == sfxid)
{
channels[i] = 0;
break;
}
}
}
for (i=0 ; i<8 && channels[i] ; i++)
{
if (channelstart[i] < oldest)
{
oldestnum = i;
oldest = channelstart[i];
}
}
if (i == 8)
slot = oldestnum;
else
slot = i;
channels[slot] = (unsigned char *) S_sfx[sfxid].data;
channelsend[slot] = channels[slot] + lengths[sfxid];
if (!handlenums)
handlenums = 100;
channelhandles[slot] = rc = handlenums++;
channelstep[slot] = step;
channelstepremainder[slot] = 0;
channelstart[slot] = mytime;
// (range: 1 - 256)
seperation += 1;
// (x^2 seperation)
leftvol =
volume - (volume*seperation*seperation)/(256*256);
seperation = seperation - 257;
// (x^2 seperation)
rightvol =
volume - (volume*seperation*seperation)/(256*256);
// sanity check
if (rightvol < 0 || rightvol > 127)
derror("rightvol out of bounds");
if (leftvol < 0 || leftvol > 127)
derror("leftvol out of bounds");
// get the proper lookup table piece
// for this volume level
channelleftvol_lookup[slot] = &vol_lookup[leftvol*256];
channelrightvol_lookup[slot] = &vol_lookup[rightvol*256];
channelids[slot] = sfxid;
return rc;
}
void outputushort(int num)
{
static unsigned char buff[5] = { 0, 0, 0, 0, '\n' };
static char* badbuff = "xxxx\n";
// outputs a 16-bit # in hex or "xxxx" if -1.
if (num < 0)
{
write(1, badbuff, 5);
}
else
{
buff[0] = num>>12;
buff[0] += buff[0] > 9 ? 'a'-10 : '0';
buff[1] = (num>>8) & 0xf;
buff[1] += buff[1] > 9 ? 'a'-10 : '0';
buff[2] = (num>>4) & 0xf;
buff[2] += buff[2] > 9 ? 'a'-10 : '0';
buff[3] = num & 0xf;
buff[3] += buff[3] > 9 ? 'a'-10 : '0';
write(1, buff, 5);
}
}
void initdata(void)
{
int i;
int j;
int* steptablemid = steptable + 128;
for (i=0 ;
i<sizeof(channels)/sizeof(unsigned char *) ;
i++)
{
channels[i] = 0;
}
gettimeofday(&last, &whocares);
for (i=-128 ; i<128 ; i++)
steptablemid[i] = pow(2.0, (i/64.0))*65536.0;
// generates volume lookup tables
// which also turn the unsigned samples
// into signed samples
// for (i=0 ; i<128 ; i++)
// for (j=0 ; j<256 ; j++)
// vol_lookup[i*256+j] = (i*(j-128))/127;
for (i=0 ; i<128 ; i++)
for (j=0 ; j<256 ; j++)
vol_lookup[i*256+j] = (i*(j-128)*256)/127;
}
void quit(void)
{
I_ShutdownMusic();
I_ShutdownSound();
exit(0);
}
fd_set fdset;
fd_set scratchset;
int
main
( int c,
char** v )
{
int done = 0;
int rc;
int nrc;
int sndnum;
int handle = 0;
unsigned char commandbuf[10];
struct timeval zerowait = { 0, 0 };
int step;
int vol;
int sep;
int i;
int waitingtofinish=0;
// get sound data
grabdata(c, v);
// init any data
initdata();
I_InitSound(11025, 16);
I_InitMusic();
if (snd_verbose)
fprintf(stderr, "ready\n");
// parse commands and play sounds until done
FD_ZERO(&fdset);
FD_SET(0, &fdset);
while (!done)
{
mytime++;
if (!waitingtofinish)
{
do {
scratchset = fdset;
rc = select(FD_SETSIZE, &scratchset, 0, 0, &zerowait);
if (rc > 0)
{
// fprintf(stderr, "select is true\n");
// got a command
nrc = read(0, commandbuf, 1);
if (!nrc)
{
done = 1;
rc = 0;
}
else
{
if (snd_verbose)
fprintf(stderr, "cmd: %c", commandbuf[0]);
switch (commandbuf[0])
{
case 'p':
// play a new sound effect
read(0, commandbuf, 9);
if (snd_verbose)
{
commandbuf[9]=0;
fprintf(stderr, "%s\n", commandbuf);
}
commandbuf[0] -=
commandbuf[0]>='a' ? 'a'-10 : '0';
commandbuf[1] -=
commandbuf[1]>='a' ? 'a'-10 : '0';
commandbuf[2] -=
commandbuf[2]>='a' ? 'a'-10 : '0';
commandbuf[3] -=
commandbuf[3]>='a' ? 'a'-10 : '0';
commandbuf[4] -=
commandbuf[4]>='a' ? 'a'-10 : '0';
commandbuf[5] -=
commandbuf[5]>='a' ? 'a'-10 : '0';
commandbuf[6] -=
commandbuf[6]>='a' ? 'a'-10 : '0';
commandbuf[7] -=
commandbuf[7]>='a' ? 'a'-10 : '0';
// p<snd#><step><vol><sep>
sndnum = (commandbuf[0]<<4) + commandbuf[1];
step = (commandbuf[2]<<4) + commandbuf[3];
step = steptable[step];
vol = (commandbuf[4]<<4) + commandbuf[5];
sep = (commandbuf[6]<<4) + commandbuf[7];
handle = addsfx(sndnum, vol, step, sep);
// returns the handle
// outputushort(handle);
break;
case 'q':
read(0, commandbuf, 1);
waitingtofinish = 1; rc = 0;
break;
case 's':
{
int fd;
read(0, commandbuf, 3);
commandbuf[2] = 0;
fd = open((char*)commandbuf, O_CREAT|O_WRONLY, 0644);
commandbuf[0] -= commandbuf[0]>='a' ? 'a'-10 : '0';
commandbuf[1] -= commandbuf[1]>='a' ? 'a'-10 : '0';
sndnum = (commandbuf[0]<<4) + commandbuf[1];
write(fd, S_sfx[sndnum].data, lengths[sndnum]);
close(fd);
}
break;
default:
fprintf(stderr, "Did not recognize command\n");
break;
}
}
}
else if (rc < 0)
{
quit();
}
} while (rc > 0);
}
updatesounds();
if (waitingtofinish)
{
for(i=0 ; i<8 && !channels[i] ; i++);
if (i==8)
done=1;
}
}
quit();
return 0;
}
+58
View File
@@ -0,0 +1,58 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id: soundsrv.h,v 1.3 1997/01/29 22:40:44 b1 Exp $
//
// Copyright (C) 1993-1996 by id Software, Inc.
//
// This source is available for distribution and/or modification
// only under the terms of the DOOM Source Code License as
// published by id Software. All rights reserved.
//
// The source is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
// for more details.
//
//
// $Log: soundsrv.h,v $
// Revision 1.3 1997/01/29 22:40:44 b1
// Reformatting, S (sound) module files.
//
// Revision 1.2 1997/01/21 19:00:07 b1
// First formatting run:
// using Emacs cc-mode.el indentation for C++ now.
//
// Revision 1.1 1997/01/19 17:22:50 b1
// Initial check in DOOM sources as of Jan. 10th, 1997
//
//
// DESCRIPTION:
// UNIX soundserver, separate process.
//
//-----------------------------------------------------------------------------
#ifndef __SNDSERVER_H__
#define __SNDSERVER_H__
#define SAMPLECOUNT 512
#define MIXBUFFERSIZE (SAMPLECOUNT*2*2)
#define SPEED 11025
void I_InitMusic(void);
void
I_InitSound
( int samplerate,
int samplesound );
void
I_SubmitOutputBuffer
( void* samples,
int samplecount );
void I_ShutdownSound(void);
void I_ShutdownMusic(void);
#endif
+312
View File
@@ -0,0 +1,312 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id: soundst.h,v 1.3 1997/01/29 22:40:45 b1 Exp $
//
// Copyright (C) 1993-1996 by id Software, Inc.
//
// This source is available for distribution and/or modification
// only under the terms of the DOOM Source Code License as
// published by id Software. All rights reserved.
//
// The source is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
// for more details.
//
//
// $Log: soundst.h,v $
// Revision 1.3 1997/01/29 22:40:45 b1
// Reformatting, S (sound) module files.
//
// Revision 1.2 1997/01/21 19:00:07 b1
// First formatting run:
// using Emacs cc-mode.el indentation for C++ now.
//
// Revision 1.1 1997/01/19 17:22:50 b1
// Initial check in DOOM sources as of Jan. 10th, 1997
//
//
// DESCRIPTION:
// Sound (utility) related. Hang on.
// See gensounds.h and gensounds.c for what soundst.h is made of.
//
//-----------------------------------------------------------------------------
#ifndef __SOUNDSTH__
#define __SOUNDSTH__
#define S_MAX_VOLUME 127
// when to clip out sounds
// Doesn't fit the large outdoor areas.
#define S_CLIPPING_DIST (1200*0x10000)
// when sounds should be max'd out
#define S_CLOSE_DIST (200*0x10000)
#define S_ATTENUATOR ((S_CLIPPING_DIST-S_CLOSE_DIST)>>FRACBITS)
#define NORM_PITCH 128
#define NORM_PRIORITY 64
#define NORM_VOLUME snd_MaxVolume
#define S_PITCH_PERTURB 1
#define NORM_SEP 128
#define S_STEREO_SWING (96*0x10000)
// % attenuation from front to back
#define S_IFRACVOL 30
#define NA 0
#define S_NUMCHANNELS 2
//
// MusicInfo struct.
//
typedef struct
{
// up to 6-character name
char* name;
// lump number of music
int lumpnum;
// music data
void* data;
// music handle once registered
int handle;
} musicinfo_t;
//
// SoundFX struct.
//
typedef struct sfxinfo_struct sfxinfo_t;
struct sfxinfo_struct
{
// up to 6-character name
char* name;
// Sfx singularity (only one at a time)
int singularity;
// Sfx priority
int priority;
// referenced sound if a link
sfxinfo_t* link;
// pitch if a link
int pitch;
// volume if a link
int volume;
// sound data
void* data;
// this is checked every second to see if sound
// can be thrown out (if 0, then decrement, if -1,
// then throw out, if > 0, then it's in use)
int usefulness;
// lump number of sfx
int lumpnum;
};
typedef struct
{
// sound information (if null, channel avail.)
sfxinfo_t* sfxinfo;
// origin of sound
void* origin;
// handle of the sound being played
int handle;
} channel_t;
enum
{
Music,
Sfx,
SfxLink
};
enum
{
PC=1,
Adlib=2,
SB=4,
Midi=8
}; // cards available
enum
{
sfxThrowOut=-1,
sfxNotUsed=0
};
//
// Initialize the sound code at start of level
//
void S_Start(void);
//
// Start sound for thing at <origin>
// using <sound_id> from sounds.h
//
extern void
S_StartSound
( void* origin,
int sound_id );
// Will start a sound at a given volume.
extern void
S_StartSoundAtVolume
( void* origin,
int sound_id,
int volume );
// Stop sound for thing at <origin>
extern void S_StopSound(void* origin);
// Start music using <music_id> from sounds.h
extern void S_StartMusic(int music_id);
// Start music using <music_id> from sounds.h,
// and set whether looping
extern void
S_ChangeMusic
( int music_id,
int looping );
// Stops the music
extern void S_StopMusic(void);
void S_PauseSound(void);
void S_ResumeSound(void);
//
// Updates music & sounds
//
extern void S_UpdateSounds(void* listener);
void S_SetMusicVolume(int volume);
void S_SetSfxVolume(int volume);
//
// Initializes sound stuff, including volume
//
void
S_Init
( int ,
int );
//
// SOUND IO
//
#define FREQ_LOW 0x40
#define FREQ_NORM 0x80
#define FREQ_HIGH 0xff
void I_SetMusicVolume(int volume);
void I_SetSfxVolume(int volume);
//
// MUSIC I/O
//
void I_PauseSong(int handle);
void I_ResumeSong(int handle);
//
// Called by anything that wishes to start music.
// plays a song, and when the song is done,
// starts playing it again in an endless loop.
// Horrible thing to do, considering.
void
I_PlaySong
( int handle,
int looping );
// stops a song over 3 seconds.
void I_StopSong(int handle);
// registers a song handle to song data
int I_RegisterSong(void *data);
// see above then think backwards
void I_UnRegisterSong(int handle);
// is the song playing?
int I_QrySongPlaying(int handle);
//
// SFX I/O
//
void I_SetChannels(int channels);
int I_GetSfxLumpNum (sfxinfo_t*);
// Starts a sound in a particular sound channel.
int
I_StartSound
( int id,
void* data,
int vol,
int sep,
int pitch,
int priority );
// Updates the volume, separation,
// and pitch of a sound channel.
void
I_UpdateSoundParams
( int handle,
int vol,
int sep,
int pitch );
// Stops a sound channel.
void I_StopSound(int handle);
// Called by S_*()'s to see if a channel is still playing.
// Returns 0 if no longer playing, 1 if playing.
int I_SoundIsPlaying(int handle);
// the complete set of sound effects
extern sfxinfo_t S_sfx[];
// the complete set of music
extern musicinfo_t S_music[];
#endif
+256
View File
@@ -0,0 +1,256 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id: wadread.c,v 1.3 1997/01/30 19:54:23 b1 Exp $
//
// Copyright (C) 1993-1996 by id Software, Inc.
//
// This source is available for distribution and/or modification
// only under the terms of the DOOM Source Code License as
// published by id Software. All rights reserved.
//
// The source is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
// for more details.
//
//
// $Log: wadread.c,v $
// Revision 1.3 1997/01/30 19:54:23 b1
// Final reformatting run. All the remains (ST, W, WI, Z).
//
// Revision 1.2 1997/01/21 19:00:10 b1
// First formatting run:
// using Emacs cc-mode.el indentation for C++ now.
//
// Revision 1.1 1997/01/19 17:22:51 b1
// Initial check in DOOM sources as of Jan. 10th, 1997
//
//
// DESCRIPTION:
// WAD and Lump I/O, the second.
// This time for soundserver only.
// Welcome to Department of Redundancy Department. Again :-).
//
//-----------------------------------------------------------------------------
static const char rcsid[] = "$Id: wadread.c,v 1.3 1997/01/30 19:54:23 b1 Exp $";
#include <malloc.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include "soundsrv.h"
#include "wadread.h"
int* sfxlengths;
typedef struct wadinfo_struct
{
char identification[4];
int numlumps;
int infotableofs;
} wadinfo_t;
typedef struct filelump_struct
{
int filepos;
int size;
char name[8];
} filelump_t;
typedef struct lumpinfo_struct
{
int handle;
int filepos;
int size;
char name[8];
} lumpinfo_t;
lumpinfo_t* lumpinfo;
int numlumps;
void** lumpcache;
#define strcmpi strcasecmp
//
// Something new.
// This version of w_wad.c does handle endianess.
//
#ifndef __BIG_ENDIAN__
#define LONG(x) (x)
#define SHORT(x) (x)
#else
#define LONG(x) ((long)SwapLONG((unsigned long) (x)))
#define SHORT(x) ((short)SwapSHORT((unsigned short) (x)))
unsigned long SwapLONG(unsigned long x)
{
return
(x>>24)
| ((x>>8) & 0xff00)
| ((x<<8) & 0xff0000)
| (x<<24);
}
unsigned short SwapSHORT(unsigned short x)
{
return
(x>>8) | (x<<8);
}
#endif
// Way too many of those...
static void derror(char* msg)
{
fprintf(stderr, "\nwadread error: %s\n", msg);
exit(-1);
}
void strupr (char *s)
{
while (*s)
*s++ = toupper(*s);
}
int filelength (int handle)
{
struct stat fileinfo;
if (fstat (handle,&fileinfo) == -1)
fprintf (stderr, "Error fstating\n");
return fileinfo.st_size;
}
void openwad(char* wadname)
{
int wadfile;
int tableoffset;
int tablelength;
int tablefilelength;
int i;
wadinfo_t header;
filelump_t* filetable;
// open and read the wadfile header
wadfile = open(wadname, O_RDONLY);
if (wadfile < 0)
derror("Could not open wadfile");
read(wadfile, &header, sizeof header);
if (strncmp(header.identification, "IWAD", 4))
derror("wadfile has weirdo header");
numlumps = LONG(header.numlumps);
tableoffset = LONG(header.infotableofs);
tablelength = numlumps * sizeof(lumpinfo_t);
tablefilelength = numlumps * sizeof(filelump_t);
lumpinfo = (lumpinfo_t *) malloc(tablelength);
filetable = (filelump_t *) ((char*)lumpinfo + tablelength - tablefilelength);
// get the lumpinfo table
lseek(wadfile, tableoffset, SEEK_SET);
read(wadfile, filetable, tablefilelength);
// process the table to make the endianness right and shift it down
for (i=0 ; i<numlumps ; i++)
{
strncpy(lumpinfo[i].name, filetable[i].name, 8);
lumpinfo[i].handle = wadfile;
lumpinfo[i].filepos = LONG(filetable[i].filepos);
lumpinfo[i].size = LONG(filetable[i].size);
// fprintf(stderr, "lump [%.8s] exists\n", lumpinfo[i].name);
}
}
void*
loadlump
( char* lumpname,
int* size )
{
int i;
void* lump;
for (i=0 ; i<numlumps ; i++)
{
if (!strncasecmp(lumpinfo[i].name, lumpname, 8))
break;
}
if (i == numlumps)
{
// fprintf(stderr,
// "Could not find lumpname [%s]\n", lumpname);
lump = 0;
}
else
{
lump = (void *) malloc(lumpinfo[i].size);
lseek(lumpinfo[i].handle, lumpinfo[i].filepos, SEEK_SET);
read(lumpinfo[i].handle, lump, lumpinfo[i].size);
*size = lumpinfo[i].size;
}
return lump;
}
void*
getsfx
( char* sfxname,
int* len )
{
unsigned char* sfx;
unsigned char* paddedsfx;
int i;
int size;
int paddedsize;
char name[20];
sprintf(name, "ds%s", sfxname);
sfx = (unsigned char *) loadlump(name, &size);
// pad the sound effect out to the mixing buffer size
paddedsize = ((size-8 + (SAMPLECOUNT-1)) / SAMPLECOUNT) * SAMPLECOUNT;
paddedsfx = (unsigned char *) realloc(sfx, paddedsize+8);
for (i=size ; i<paddedsize+8 ; i++)
paddedsfx[i] = 128;
*len = paddedsize;
return (void *) (paddedsfx + 8);
}
+62
View File
@@ -0,0 +1,62 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id: wadread.h,v 1.3 1997/01/30 19:54:23 b1 Exp $
//
// Copyright (C) 1993-1996 by id Software, Inc.
//
// This source is available for distribution and/or modification
// only under the terms of the DOOM Source Code License as
// published by id Software. All rights reserved.
//
// The source is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
// for more details.
//
//
// $Log: wadread.h,v $
// Revision 1.3 1997/01/30 19:54:23 b1
// Final reformatting run. All the remains (ST, W, WI, Z).
//
// Revision 1.2 1997/01/21 19:00:10 b1
// First formatting run:
// using Emacs cc-mode.el indentation for C++ now.
//
// Revision 1.1 1997/01/19 17:22:52 b1
// Initial check in DOOM sources as of Jan. 10th, 1997
//
//
// DESCRIPTION:
// WAD and Lump I/O, the second.
// This time for soundserver only.
// Welcome to Department of Redundancy Department.
// (Yeah, I said that elsewhere already).
// Note: makes up for a nice w_wad.h.
//
//-----------------------------------------------------------------------------
#ifndef __WADREAD_H__
#define __WADREAD_H__
//
// Opens the wadfile specified.
// Must be called before any calls to loadlump() or getsfx().
//
void openwad(char* wadname);
//
// Gets a sound effect from the wad file. The pointer points to the
// start of the data. Returns a 0 if the sfx was not
// found. Sfx names should be no longer than 6 characters. All data is
// rounded up in size to the nearest MIXBUFFERSIZE and is padded out with
// 0x80's. Returns the data length in len.
//
void*
getsfx
( char* sfxname,
int* len );
#endif