summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2005-08-04 21:48:32 +0000
committerSimon Howard2005-08-04 21:48:32 +0000
commit9fa822847de1c2d64b8e2186e9ec74277f28cc16 (patch)
tree170eb5bf0aba9307af2322336a19e65777d3a57f
parent186d0dd6efb317c4e983af04f939704ebd8e510a (diff)
downloadchocolate-doom-9fa822847de1c2d64b8e2186e9ec74277f28cc16.tar.gz
chocolate-doom-9fa822847de1c2d64b8e2186e9ec74277f28cc16.tar.bz2
chocolate-doom-9fa822847de1c2d64b8e2186e9ec74277f28cc16.zip
Turn on compiler optimisation and warning options
Add SDL_mixer sound code Subversion-branch: /trunk/chocolate-doom Subversion-revision: 39
-rw-r--r--TODO4
-rw-r--r--configure.in18
-rw-r--r--src/Makefile.am4
-rw-r--r--src/d_main.c18
-rw-r--r--src/doomdef.h16
-rw-r--r--src/i_sound.c781
-rw-r--r--src/i_sound.h13
-rw-r--r--src/m_misc.c14
-rw-r--r--src/s_sound.c24
9 files changed, 133 insertions, 759 deletions
diff --git a/TODO b/TODO
index 3ef84cb5..4729e0fe 100644
--- a/TODO
+++ b/TODO
@@ -1,8 +1,8 @@
To do:
-* Port sound code to SDL
-* Startup messages
* Fix Final Doom, Ultimate Doom, IWAD selection in general
+* Music
+* Startup messages
* Check quit messages selected correctly
* Setup utility
* Short-circuit Zone memory
diff --git a/configure.in b/configure.in
index 1aec3283..74b58d21 100644
--- a/configure.in
+++ b/configure.in
@@ -1,14 +1,32 @@
AC_INIT(Chocolate Doom, 0.1, fraggle@alkali.org, chocolate-doom)
AC_CONFIG_AUX_DIR(autotools)
+orig_CFLAGS="$CFLAGS"
+
AC_PROG_CC
+if test "$GCC" = "yes"
+then
+ CFLAGS="-O3 $orig_CFLAGS"
+fi
+
+
AM_PATH_SDL(1.1.3)
+AC_CHECK_LIB(SDL_mixer,Mix_LoadMUS,[
+dnl AC_DEFINE(HAVE_LIBSDL_MIXER)
+ MIXER_LIBS="$MIXER_LIBS -lSDL_mixer"
+],echo "*** Compiling without SDL_mixer installed probably won't work"
+,$SDL_LIBS $MIXER_LIBS)
+
+
AM_INIT_AUTOMAKE(AC_PACKAGE_TARNAME,AC_PACKAGE_VERSION)
AM_CONFIG_HEADER(config.h:config.hin)
+AC_SUBST(MIXER_CFLAGS)
+AC_SUBST(MIXER_LIBS)
+
AC_OUTPUT([
Makefile
src/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index da155954..96a762a1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,8 +1,8 @@
bindir = $(prefix)/bin
-CFLAGS = @CFLAGS@ @SDL_CFLAGS@ -DNORMALUNIX -Wall
-LDFLAGS = @LDFLAGS@ @SDL_LIBS@
+CFLAGS = @CFLAGS@ @SDL_CFLAGS@ @MIXER_CFLAGS@ -DNORMALUNIX -Wall
+LDFLAGS = @LDFLAGS@ @SDL_LIBS@ @MIXER_LIBS@
chocolate_doom_SOURCES=\
am_map.c d_think.h i_video.c p_floor.c p_tick.c r_things.h \
diff --git a/src/d_main.c b/src/d_main.c
index aaed9a62..5a8ff2af 100644
--- a/src/d_main.c
+++ b/src/d_main.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: d_main.c 37 2005-08-04 18:42:15Z fraggle $
+// $Id: d_main.c 39 2005-08-04 21:48:32Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -22,6 +22,10 @@
// 02111-1307, USA.
//
// $Log$
+// Revision 1.4 2005/08/04 21:48:32 fraggle
+// Turn on compiler optimisation and warning options
+// Add SDL_mixer sound code
+//
// Revision 1.3 2005/08/04 18:42:15 fraggle
// Silence compiler warnings
//
@@ -41,7 +45,7 @@
//-----------------------------------------------------------------------------
-static const char rcsid[] = "$Id: d_main.c 37 2005-08-04 18:42:15Z fraggle $";
+static const char rcsid[] = "$Id: d_main.c 39 2005-08-04 21:48:32Z fraggle $";
#define BGCOLOR 7
#define FGCOLOR 8
@@ -409,16 +413,6 @@ void D_DoomLoop (void)
// Update display, next frame, with current state.
D_Display ();
-
-#ifndef SNDSERV
- // Sound mixing for the buffer is snychronous.
- I_UpdateSound();
-#endif
- // Synchronous sound output is explicitly called.
-#ifndef SNDINTR
- // Update sound output.
- I_SubmitSound();
-#endif
}
}
diff --git a/src/doomdef.h b/src/doomdef.h
index 27f843ef..0e050192 100644
--- a/src/doomdef.h
+++ b/src/doomdef.h
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: doomdef.h 26 2005-07-24 02:14:04Z fraggle $
+// $Id: doomdef.h 39 2005-08-04 21:48:32Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -81,16 +81,6 @@ typedef enum
// most parameter validation debugging code will not be compiled
#define RANGECHECK
-// Do or do not use external soundserver.
-// The sndserver binary to be run separately
-// has been introduced by Dave Taylor.
-// The integrated sound support is experimental,
-// and unfinished. Default is synchronous.
-// Experimental asynchronous timer based is
-// handled by SNDINTR.
-#define SNDSERV 1
-//#define SNDINTR 1
-
// This one switches between MIT SHM (no proper mouse)
// and XFree86 DGA (mickey sampling). The original
@@ -372,6 +362,10 @@ typedef enum
//-----------------------------------------------------------------------------
//
// $Log$
+// Revision 1.5 2005/08/04 21:48:32 fraggle
+// Turn on compiler optimisation and warning options
+// Add SDL_mixer sound code
+//
// Revision 1.4 2005/07/24 02:14:04 fraggle
// Move to SDL for graphics.
// Translate key scancodes to correct internal format when reading
diff --git a/src/i_sound.c b/src/i_sound.c
index 82019c0d..ce13778b 100644
--- a/src/i_sound.c
+++ b/src/i_sound.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: i_sound.c 23 2005-07-23 21:32:47Z fraggle $
+// $Id: i_sound.c 39 2005-08-04 21:48:32Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -22,6 +22,10 @@
// 02111-1307, USA.
//
// $Log$
+// Revision 1.6 2005/08/04 21:48:32 fraggle
+// Turn on compiler optimisation and warning options
+// Add SDL_mixer sound code
+//
// Revision 1.5 2005/07/23 21:32:47 fraggle
// Add missing errno.h, fix crash on startup when no IWAD present
//
@@ -44,28 +48,12 @@
//-----------------------------------------------------------------------------
static const char
-rcsid[] = "$Id: i_sound.c 23 2005-07-23 21:32:47Z fraggle $";
+rcsid[] = "$Id: i_sound.c 39 2005-08-04 21:48:32Z fraggle $";
#include <stdio.h>
#include <stdlib.h>
-#include <stdarg.h>
-#include <errno.h>
-
-#include <math.h>
-
-#include <sys/time.h>
-#include <sys/types.h>
-
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-
-// Linux voxware output.
-#include <linux/soundcard.h>
-
-// Timer stuff. Experimental.
-#include <time.h>
-#include <signal.h>
+#include <SDL.h>
+#include <SDL_mixer.h>
#include "z_zone.h"
@@ -73,332 +61,78 @@ rcsid[] = "$Id: i_sound.c 23 2005-07-23 21:32:47Z fraggle $";
#include "i_sound.h"
#include "m_argv.h"
#include "m_misc.h"
+#include "m_swap.h"
#include "w_wad.h"
#include "doomdef.h"
-// UNIX hack, to be removed.
-#ifdef SNDSERV
-// Separate sound server process.
-FILE* sndserver=0;
-char* sndserver_filename = "./sndserver ";
-#elif SNDINTR
-
-// Update all 30 millisecs, approx. 30fps synchronized.
-// Linux resolution is allegedly 10 millisecs,
-// scale is microseconds.
-#define SOUND_INTERVAL 500
-
-// Get the interrupt. Set duration in millisecs.
-int I_SoundSetTimer( int duration_of_tick );
-void I_SoundDelTimer( void );
-#else
-// None?
-#endif
-
-
-// A quick hack to establish a protocol between
-// synchronous mix buffer updates and asynchronous
-// audio writes. Probably redundant with gametic.
-static int flag = 0;
-
-// The number of internal mixing channels,
-// the samples calculated for each mixing step,
-// the size of the 16bit, 2 hardware channel (stereo)
-// mixing buffer, and the samplerate of the raw data.
-
-
-// Needed for calling the actual sound output.
-#define SAMPLECOUNT 512
#define NUM_CHANNELS 8
-// It is 2 for 16bit, and 2 for two channels.
-#define BUFMUL 4
-#define MIXBUFFERSIZE (SAMPLECOUNT*BUFMUL)
-
-#define SAMPLERATE 11025 // Hz
-#define SAMPLESIZE 2 // 16bit
-
-// The actual lengths of all sound effects.
-int lengths[NUMSFX];
-
-// The actual output device.
-int audio_fd;
-
-// The global mixing buffer.
-// Basically, samples from all active internal channels
-// are modifed and added, and stored in the buffer
-// that is submitted to the audio device.
-signed short mixbuffer[MIXBUFFERSIZE];
-
-
-// The channel step amount...
-unsigned int channelstep[NUM_CHANNELS];
-// ... and a 0.16 bit remainder of last step.
-unsigned int channelstepremainder[NUM_CHANNELS];
-
-
-// The channel data pointers, start and end.
-unsigned char* channels[NUM_CHANNELS];
-unsigned char* channelsend[NUM_CHANNELS];
-
-
-// Time/gametic that the channel started playing,
-// used to determine oldest, which automatically
-// has lowest priority.
-// In case number of active sounds exceeds
-// available channels.
-int channelstart[NUM_CHANNELS];
-
-// The sound in channel handles,
-// determined on registration,
-// might be used to unregister/stop/modify,
-// currently unused.
-int channelhandles[NUM_CHANNELS];
-
-// SFX id of the playing sound effect.
-// Used to catch duplicates (like chainsaw).
-int channelids[NUM_CHANNELS];
-
-// Volume lookups.
-int vol_lookup[128*256];
-
-// Hardware left and right channel volume lookup.
-int* channelleftvol_lookup[NUM_CHANNELS];
-int* channelrightvol_lookup[NUM_CHANNELS];
-
+static int sound_initialised = 0;
+static Mix_Chunk sound_chunks[NUMSFX];
+static byte *expand_sound_data(byte *data, int samplerate, int length)
+{
+ byte *result = data;
+ int i;
-//
-// Safe ioctl, convenience.
-//
-void
-myioctl
-( int fd,
- int command,
- int* arg )
-{
- int rc;
- extern int errno;
-
- rc = ioctl(fd, command, arg);
- if (rc < 0)
+ if (samplerate == 11025)
{
- fprintf(stderr, "ioctl(dsp,%d,arg) failed\n", command);
- fprintf(stderr, "errno=%d\n", errno);
- exit(-1);
- }
-}
-
-
+ // need to expand to 2 channels, and expand 8 bit samples to 16 bits
+ result = Z_Malloc(length * 4, PU_STATIC, NULL);
+ for (i=0; i<length; ++i)
+ {
+ result[i * 4] = result[i * 4 + 1]
+ = result[i * 4 + 2] = result[i * 4 + 3] = data[i];
+ }
+ }
+ else if (samplerate == 22050)
+ {
+ // need to expand to 2 channels (sample rate is already correct)
-//
-// This function loads the sound data from the WAD lump,
-// for single sound.
-//
-void*
-getsfx
-( char* sfxname,
- int* len )
-{
- unsigned char* sfx;
- unsigned char* paddedsfx;
- int i;
- int size;
- int paddedsize;
- char name[20];
- int sfxlump;
+ result = Z_Malloc(length * 2, PU_STATIC, NULL);
-
- // Get the sound data from the WAD, allocate lump
- // in zone memory.
- sprintf(name, "ds%s", sfxname);
-
- // Now, there is a severe problem with the
- // sound handling, in it is not (yet/anymore)
- // gamemode aware. That means, sounds from
- // DOOM II will be requested even with DOOM
- // shareware.
- // The sound list is wired into sounds.c,
- // which sets the external variable.
- // I do not do runtime patches to that
- // variable. Instead, we will use a
- // default sound for replacement.
- if ( W_CheckNumForName(name) == -1 )
- sfxlump = W_GetNumForName("dspistol");
+ for (i=0; i<length / 2; ++i)
+ {
+ result[i * 4] = result[i * 4 + 2] = data[i * 2];
+ result[i * 4 + 1] = result[i * 4 + 3] = data[i * 2 + 1];
+ }
+ }
else
- sfxlump = W_GetNumForName(name);
-
- size = W_LumpLength( sfxlump );
-
- // Debug.
- // fprintf( stderr, "." );
- //fprintf( stderr, " -loading %s (lump %d, %d bytes)\n",
- // sfxname, sfxlump, size );
- //fflush( stderr );
-
- sfx = (unsigned char*)W_CacheLumpNum( sfxlump, PU_STATIC );
-
- // Pads the sound effect out to the mixing buffer size.
- // The original realloc would interfere with zone memory.
- paddedsize = ((size-8 + (SAMPLECOUNT-1)) / SAMPLECOUNT) * SAMPLECOUNT;
-
- // Allocate from zone memory.
- paddedsfx = (unsigned char*)Z_Malloc( paddedsize+8, PU_STATIC, 0 );
- // ddt: (unsigned char *) realloc(sfx, paddedsize+8);
- // This should interfere with zone memory handling,
- // which does not kick in in the soundserver.
-
- // Now copy and pad.
- memcpy( paddedsfx, sfx, size );
- for (i=size ; i<paddedsize+8 ; i++)
- paddedsfx[i] = 128;
-
- // Remove the cached lump.
- Z_Free( sfx );
-
- // Preserve padded length.
- *len = paddedsize;
+ {
+ I_Error("Unsupported sample rate %i", samplerate);
+ }
- // Return allocated padded data.
- return (void *) (paddedsfx + 8);
+ return result;
}
-
-
-
-
-//
-// This function adds a sound to the
-// list of currently active sounds,
-// which is maintained as a given number
-// (eight, usually) of internal channels.
-// Returns a handle.
-//
-int
-addsfx
-( int sfxid,
- int volume,
- int step,
- int seperation )
+static Mix_Chunk *getsfx(int sound)
{
- static unsigned short handlenums = 0;
-
- int i;
- int rc = -1;
-
- int oldest = gametic;
- int oldestnum = 0;
- int slot;
-
- int rightvol;
- int leftvol;
-
- // Chainsaw troubles.
- // 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 )
- {
- // Loop all channels, check.
- for (i=0 ; i<NUM_CHANNELS ; i++)
- {
- // Active, and using the same SFX?
- if ( (channels[i])
- && (channelids[i] == sfxid) )
- {
- // Reset.
- channels[i] = 0;
- // We are sure that iff,
- // there will only be one.
- break;
- }
- }
- }
-
- // Loop all channels to find oldest SFX.
- for (i=0; (i<NUM_CHANNELS) && (channels[i]); i++)
+ if (sound_chunks[sound].abuf == NULL)
{
- if (channelstart[i] < oldest)
- {
- oldestnum = i;
- oldest = channelstart[i];
- }
- }
+ int lumpnum;
+ int samplerate;
+ int length;
+ byte *data;
- // Tales from the cryptic.
- // If we found a channel, fine.
- // If not, we simply overwrite the first one, 0.
- // Probably only happens at startup.
- if (i == NUM_CHANNELS)
- slot = oldestnum;
- else
- slot = i;
-
- // Okay, in the less recent channel,
- // we will handle the new SFX.
- // Set pointer to raw data.
- channels[slot] = (unsigned char *) S_sfx[sfxid].data;
- // Set pointer to end of raw data.
- channelsend[slot] = channels[slot] + lengths[sfxid];
-
- // Reset current handle number, limited to 0..100.
- if (!handlenums)
- handlenums = 100;
-
- // Assign current handle number.
- // Preserved so sounds could be stopped (unused).
- channelhandles[slot] = rc = handlenums++;
-
- // Set stepping???
- // Kinda getting the impression this is never used.
- channelstep[slot] = step;
- // ???
- channelstepremainder[slot] = 0;
- // Should be gametic, I presume.
- channelstart[slot] = gametic;
-
- // Separation, that is, orientation/stereo.
- // range is: 1 - 256
- seperation += 1;
-
- // Per left/right channel.
- // x^2 seperation,
- // adjust volume properly.
- leftvol =
- volume - ((volume*seperation*seperation) >> 16); ///(256*256);
- seperation = seperation - 257;
- rightvol =
- volume - ((volume*seperation*seperation) >> 16);
-
- // Sanity check, clamp volume.
- if (rightvol < 0 || rightvol > 127)
- I_Error("rightvol out of bounds");
-
- if (leftvol < 0 || leftvol > 127)
- I_Error("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];
-
- // Preserve sound SFX id,
- // e.g. for avoiding duplicates of chainsaw.
- channelids[slot] = sfxid;
-
- // You tell me.
- return rc;
-}
+ // need to load the sound
+ lumpnum = I_GetSfxLumpNum(&S_sfx[sound]);
+ data = W_CacheLumpNum(lumpnum, PU_STATIC);
+ samplerate = (data[3] << 8) | data[2];
+ length = (data[5] << 8) | data[4];
+ sound_chunks[sound].allocated = 1;
+ sound_chunks[sound].abuf = expand_sound_data(data + 8, samplerate, length);
+ sound_chunks[sound].alen = (length * 2 * 22050) / samplerate;
+ sound_chunks[sound].volume = 128;
+ }
+ return &sound_chunks[sound];
+}
//
// SFX API
@@ -411,24 +145,6 @@ addsfx
//
void I_SetChannels()
{
- // Init internal lookups (raw data, mixing buffer, channels).
- // This function sets up internal lookups used during
- // the mixing process.
- int i;
- int j;
-
- // Okay, reset internal mixing channels to zero.
- /*for (i=0; i<NUM_CHANNELS; i++)
- {
- channels[i] = 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)*256)/127;
}
@@ -483,47 +199,27 @@ I_StartSound
int pitch,
int priority )
{
+ Mix_Chunk *chunk = getsfx(id);
+ int channel;
- // UNUSED
- priority = 0;
-
-#ifdef SNDSERV
- if (sndserver)
- {
- fprintf(sndserver, "p%2.2x%2.2x%2.2x%2.2x\n", id, pitch, vol, sep);
- fflush(sndserver);
- }
- // warning: control reaches end of non-void function.
- return id;
-#else
- // Debug.
- //fprintf( stderr, "starting sound %d", id );
-
+ channel = Mix_PlayChannelTimed(-1, chunk, 0, -1);
- // fprintf( stderr, "/handle is %d\n", id );
-
- return id;
-#endif
+ I_UpdateSoundParams(channel, vol, sep, pitch);
+
+ return channel;
}
void I_StopSound (int handle)
{
- // You need the handle returned by StartSound.
- // Would be looping all channels,
- // tracking down the handle,
- // an setting the channel to zero.
-
- // UNUSED.
- handle = 0;
+ Mix_HaltChannel(handle);
}
int I_SoundIsPlaying(int handle)
{
- // Ouch.
- return gametic < handle;
+ return Mix_Playing(handle);
}
@@ -544,119 +240,6 @@ int I_SoundIsPlaying(int handle)
//
void I_UpdateSound( void )
{
-#ifdef SNDINTR
- // Debug. Count buffer misses with interrupt.
- static int misses = 0;
-#endif
-
-
- // Mix current sound data.
- // Data, from raw sound, for right and left.
- register unsigned int sample;
- register int dl;
- register int dr;
-
- // Pointers in global mixbuffer, left, right, end.
- signed short* leftout;
- signed short* rightout;
- signed short* leftend;
- // Step in mixbuffer, left and right, thus two.
- int step;
-
- // Mixing channel index.
- int chan;
-
- // Left and right channel
- // are in global mixbuffer, alternating.
- leftout = mixbuffer;
- rightout = mixbuffer+1;
- step = 2;
-
- // Determine end, for left channel only
- // (right channel is implicit).
- leftend = mixbuffer + SAMPLECOUNT*step;
-
- // Mix sounds into the mixing buffer.
- // Loop over step*SAMPLECOUNT,
- // that is 512 values for two channels.
- while (leftout != leftend)
- {
- // Reset left/right value.
- dl = 0;
- dr = 0;
-
- // Love thy L2 chache - made this a loop.
- // Now more channels could be set at compile time
- // as well. Thus loop those channels.
- for ( chan = 0; chan < NUM_CHANNELS; chan++ )
- {
- // Check channel, if active.
- if (channels[ chan ])
- {
- // Get the raw data from the channel.
- sample = *channels[ chan ];
- // Add left and right part
- // for this channel (sound)
- // to the current data.
- // Adjust volume accordingly.
- dl += channelleftvol_lookup[ chan ][sample];
- dr += channelrightvol_lookup[ chan ][sample];
- // Increment index ???
- channelstepremainder[ chan ] += channelstep[ chan ];
- // MSB is next sample???
- channels[ chan ] += channelstepremainder[ chan ] >> 16;
- // Limit to LSB???
- channelstepremainder[ chan ] &= 65536-1;
-
- // Check whether we are done.
- if (channels[ chan ] >= channelsend[ chan ])
- channels[ chan ] = 0;
- }
- }
-
- // Clamp to range. Left hardware channel.
- // Has been char instead of short.
- // if (dl > 127) *leftout = 127;
- // else if (dl < -128) *leftout = -128;
- // else *leftout = dl;
-
- if (dl > 0x7fff)
- *leftout = 0x7fff;
- else if (dl < -0x8000)
- *leftout = -0x8000;
- else
- *leftout = dl;
-
- // Same for right hardware channel.
- if (dr > 0x7fff)
- *rightout = 0x7fff;
- else if (dr < -0x8000)
- *rightout = -0x8000;
- else
- *rightout = dr;
-
- // Increment current pointers in mixbuffer.
- leftout += step;
- rightout += step;
- }
-
-#ifdef SNDINTR
- // Debug check.
- if ( flag )
- {
- misses += flag;
- flag = 0;
- }
-
- if ( misses > 10 )
- {
- fprintf( stderr, "I_SoundUpdate: missed 10 buffer writes\n");
- misses = 0;
- }
-
- // Increment flag for update.
- flag++;
-#endif
}
@@ -671,8 +254,6 @@ void I_UpdateSound( void )
void
I_SubmitSound(void)
{
- // Write it to DSP device.
- write(audio_fd, mixbuffer, SAMPLECOUNT*BUFMUL);
}
@@ -684,13 +265,9 @@ I_UpdateSoundParams
int sep,
int pitch)
{
- // I fail too see that this is used.
- // Would be using the handle to identify
- // on which channel the sound might be active,
- // and resetting the channel parameters.
-
- // UNUSED.
- handle = vol = sep = pitch = 0;
+ Mix_SetPanning(handle,
+ ((254 - sep) * vol) / 8,
+ ((sep) * vol) / 8);
}
@@ -698,41 +275,11 @@ I_UpdateSoundParams
void I_ShutdownSound(void)
{
-#ifdef SNDSERV
- if (sndserver)
- {
- // Send a "quit" command.
- fprintf(sndserver, "q\n");
- fflush(sndserver);
- }
-#else
- // Wait till all pending sounds are finished.
- int done = 0;
- int i;
-
-
- // FIXME (below).
- fprintf( stderr, "I_ShutdownSound: NOT finishing pending sounds\n");
- fflush( stderr );
-
- while ( !done )
- {
- for( i=0 ; i<8 && !channels[i] ; i++);
-
- // FIXME. No proper channel output.
- //if (i==8)
- done=1;
- }
-#ifdef SNDINTR
- I_SoundDelTimer();
-#endif
-
- // Cleaning up -releasing the DSP device.
- close ( audio_fd );
-#endif
+ if (!sound_initialised)
+ return;
- // Done.
- return;
+ Mix_CloseAudio();
+ SDL_QuitSubSystem(SDL_INIT_AUDIO);
}
@@ -743,91 +290,22 @@ void I_ShutdownSound(void)
void
I_InitSound()
{
-#ifdef SNDSERV
- char buffer[256];
-
- if (getenv("DOOMWADDIR"))
- sprintf(buffer, "%s/%s",
- getenv("DOOMWADDIR"),
- sndserver_filename);
- else
- sprintf(buffer, "%s", sndserver_filename);
-
- // start sound process
- if ( !access(buffer, X_OK) )
- {
- strcat(buffer, " -quiet");
- sndserver = popen(buffer, "w");
- }
- else
- fprintf(stderr, "Could not start sound server [%s]\n", buffer);
-#else
-
- int i;
-
-#ifdef SNDINTR
- fprintf( stderr, "I_SoundSetTimer: %d microsecs\n", SOUND_INTERVAL );
- I_SoundSetTimer( SOUND_INTERVAL );
-#endif
-
- // Secure and configure sound device first.
- fprintf( stderr, "I_InitSound: ");
-
- 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=SAMPLERATE;
-
- 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");
-
- fprintf(stderr, " configured audio device\n" );
-
-
- // Initialize external data (all sounds) at start, keep static.
- fprintf( stderr, "I_InitSound: ");
-
- for (i=1 ; i<NUMSFX ; i++)
- {
- // Alias? Example is the chaingun sound linked to pistol.
- if (!S_sfx[i].link)
+ if (SDL_Init(SDL_INIT_AUDIO) < 0)
{
- // Load data from WAD file.
- S_sfx[i].data = getsfx( S_sfx[i].name, &lengths[i] );
- }
- else
- {
- // Previously loaded already?
- S_sfx[i].data = S_sfx[i].link->data;
- lengths[i] = lengths[(S_sfx[i].link - S_sfx)/sizeof(sfxinfo_t)];
+ printf("Unable to set up sound.\n");
+ return;
}
- }
- fprintf( stderr, " pre-cached all sound data\n");
-
- // Now initialize mixbuffer with zero.
- for ( i = 0; i< MIXBUFFERSIZE; i++ )
- mixbuffer[i] = 0;
-
- // Finished initialization.
- fprintf(stderr, "I_InitSound: sound module ready\n");
+ if (Mix_OpenAudio(22050, AUDIO_U8, 2, 1024) < 0)
+ {
+ printf("Error initialising SDL_mixer: %s\n", SDL_GetError());
+ }
-#endif
+ sound_initialised = 1;
+
+ SDL_PauseAudio(0);
+
+ printf("sound started.\n");
}
@@ -896,96 +374,3 @@ int I_QrySongPlaying(int handle)
-//
-// Experimental stuff.
-// A Linux timer interrupt, for asynchronous
-// sound output.
-// I ripped this out of the Timer class in
-// our Difference Engine, including a few
-// SUN remains...
-//
-#ifdef sun
- typedef sigset_t tSigSet;
-#else
- typedef int tSigSet;
-#endif
-
-
-// We might use SIGVTALRM and ITIMER_VIRTUAL, if the process
-// time independend timer happens to get lost due to heavy load.
-// SIGALRM and ITIMER_REAL doesn't really work well.
-// There are issues with profiling as well.
-static int /*__itimer_which*/ itimer = ITIMER_REAL;
-
-static int sig = SIGALRM;
-
-// Interrupt handler.
-void I_HandleSoundTimer( int ignore )
-{
- // Debug.
- //fprintf( stderr, "%c", '+' ); fflush( stderr );
-
- // Feed sound device if necesary.
- if ( flag )
- {
- // See I_SubmitSound().
- // Write it to DSP device.
- write(audio_fd, mixbuffer, SAMPLECOUNT*BUFMUL);
-
- // Reset flag counter.
- flag = 0;
- }
- else
- return;
-
- // UNUSED, but required.
- ignore = 0;
- return;
-}
-
-// Get the interrupt. Set duration in millisecs.
-int I_SoundSetTimer( int duration_of_tick )
-{
- // Needed for gametick clockwork.
- struct itimerval value;
- struct itimerval ovalue;
- struct sigaction act;
- struct sigaction oact;
-
- int res;
-
- // This sets to SA_ONESHOT and SA_NOMASK, thus we can not use it.
- // signal( _sig, handle_SIG_TICK );
-
- // Now we have to change this attribute for repeated calls.
- act.sa_handler = I_HandleSoundTimer;
-#ifndef sun
- //ac t.sa_mask = _sig;
-#endif
- act.sa_flags = SA_RESTART;
-
- sigaction( sig, &act, &oact );
-
- value.it_interval.tv_sec = 0;
- value.it_interval.tv_usec = duration_of_tick;
- value.it_value.tv_sec = 0;
- value.it_value.tv_usec = duration_of_tick;
-
- // Error is -1.
- res = setitimer( itimer, &value, &ovalue );
-
- // Debug.
- if ( res == -1 )
- fprintf( stderr, "I_SoundSetTimer: interrupt n.a.\n");
-
- return res;
-}
-
-
-// Remove the interrupt. Set duration to zero.
-void I_SoundDelTimer()
-{
- // Debug.
- if ( I_SoundSetTimer( 0 ) == -1)
- fprintf( stderr, "I_SoundDelTimer: failed to remove interrupt. Doh!\n");
-}
diff --git a/src/i_sound.h b/src/i_sound.h
index cfb6207b..50aec5a9 100644
--- a/src/i_sound.h
+++ b/src/i_sound.h
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: i_sound.h 8 2005-07-23 16:44:57Z fraggle $
+// $Id: i_sound.h 39 2005-08-04 21:48:32Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -32,13 +32,6 @@
#include "doomdef.h"
-// UNIX hack, to be removed.
-#ifdef SNDSERV
-#include <stdio.h>
-extern FILE* sndserver;
-extern char* sndserver_filename;
-#endif
-
#include "doomstat.h"
#include "sounds.h"
@@ -125,6 +118,10 @@ void I_UnRegisterSong(int handle);
//-----------------------------------------------------------------------------
//
// $Log$
+// Revision 1.3 2005/08/04 21:48:32 fraggle
+// Turn on compiler optimisation and warning options
+// Add SDL_mixer sound code
+//
// Revision 1.2 2005/07/23 16:44:55 fraggle
// Update copyright to GNU GPL
//
diff --git a/src/m_misc.c b/src/m_misc.c
index 8539cf2c..ca732a58 100644
--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: m_misc.c 37 2005-08-04 18:42:15Z fraggle $
+// $Id: m_misc.c 39 2005-08-04 21:48:32Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -23,6 +23,10 @@
//
//
// $Log$
+// Revision 1.6 2005/08/04 21:48:32 fraggle
+// Turn on compiler optimisation and warning options
+// Add SDL_mixer sound code
+//
// Revision 1.5 2005/08/04 18:42:15 fraggle
// Silence compiler warnings
//
@@ -50,7 +54,7 @@
//-----------------------------------------------------------------------------
static const char
-rcsid[] = "$Id: m_misc.c 37 2005-08-04 18:42:15Z fraggle $";
+rcsid[] = "$Id: m_misc.c 39 2005-08-04 21:48:32Z fraggle $";
#include <sys/stat.h>
#include <sys/types.h>
@@ -232,12 +236,6 @@ extern int showMessages;
extern int numChannels;
-// UNIX hack, to be removed.
-#ifdef SNDSERV
-extern char* sndserver_filename;
-extern int mb_used;
-#endif
-
extern char* chat_macros[];
diff --git a/src/s_sound.c b/src/s_sound.c
index 1d3b18ec..0692db9b 100644
--- a/src/s_sound.c
+++ b/src/s_sound.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: s_sound.c 37 2005-08-04 18:42:15Z fraggle $
+// $Id: s_sound.c 39 2005-08-04 21:48:32Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -22,6 +22,10 @@
// 02111-1307, USA.
//
// $Log$
+// Revision 1.4 2005/08/04 21:48:32 fraggle
+// Turn on compiler optimisation and warning options
+// Add SDL_mixer sound code
+//
// Revision 1.3 2005/08/04 18:42:15 fraggle
// Silence compiler warnings
//
@@ -38,7 +42,7 @@
static const char
-rcsid[] = "$Id: s_sound.c 37 2005-08-04 18:42:15Z fraggle $";
+rcsid[] = "$Id: s_sound.c 39 2005-08-04 21:48:32Z fraggle $";
@@ -380,22 +384,6 @@ S_StartSoundAtVolume
if (sfx->lumpnum < 0)
sfx->lumpnum = I_GetSfxLumpNum(sfx);
-#ifndef SNDSRV
- // cache data if necessary
- if (!sfx->data)
- {
- fprintf( stderr,
- "S_StartSoundAtVolume: 16bit and not pre-cached - wtf?\n");
-
- // DOS remains, 8bit handling
- //sfx->data = (void *) W_CacheLumpNum(sfx->lumpnum, PU_MUSIC);
- // fprintf( stderr,
- // "S_StartSoundAtVolume: loading %d (lump %d) : 0x%x\n",
- // sfx_id, sfx->lumpnum, (int)sfx->data );
-
- }
-#endif
-
// increase the usefulness
if (sfx->usefulness++ < 0)
sfx->usefulness = 1;