Compare commits

..

No commits in common. "master" and "cougar-split" have entirely different histories.

30 changed files with 811 additions and 789 deletions

View file

@ -1,7 +1,7 @@
## Process this file with automake to produce Makefile.in ## Process this file with automake to produce Makefile.in
AUTOMAKE_OPTIONS = foreign AUTOMAKE_OPTIONS = foreign
SUBDIRS = include source RPM SUBDIRS = include source doc RPM
EXTRA_DIST = tools/gas2masm/Makefile tools/gas2masm/gas2masm.c \ EXTRA_DIST = tools/gas2masm/Makefile tools/gas2masm/gas2masm.c \
tools/gas2masm/gas2masm.dsp tools/gas2masm/gas2masm.dsw \ tools/gas2masm/gas2masm.dsp tools/gas2masm/gas2masm.dsw \

0
NEWS Normal file
View file

View file

@ -13,6 +13,9 @@
/* Define this to the QSG standard version you support */ /* Define this to the QSG standard version you support */
#undef QSG_VERSION #undef QSG_VERSION
/* Define if you want to use QF-style defaults instead of Id-style */
#undef NEWSTYLE
/* Define this to the location of the global config file */ /* Define this to the location of the global config file */
#undef FS_GLOBALCFG #undef FS_GLOBALCFG
@ -22,6 +25,9 @@
/* Define this to the unshared game directory root */ /* Define this to the unshared game directory root */
#undef FS_USERPATH #undef FS_USERPATH
/* Define this to the base game for the engine to load */
#undef BASEGAME
/* Define this if you want to use Intel assembly optimizations */ /* Define this if you want to use Intel assembly optimizations */
#undef USE_INTEL_ASM #undef USE_INTEL_ASM

View file

@ -607,12 +607,12 @@ QF_maGiC_VALUE
[ [
#include <sys/asoundlib.h> #include <sys/asoundlib.h>
#if defined(SND_LIB_MAJOR) && defined(SND_LIB_MINOR) #if defined(SND_LIB_MAJOR) && defined(SND_LIB_MINOR)
#if SND_LIB_MAJOR>0 || (SND_LIB_MAJOR==0 && SND_LIB_MINOR>=9) #if SND_LIB_MAJOR>0 || (SND_LIB_MAJOR==0 && SND_LIB_MINOR>=6)
QF_maGiC_VALUE QF_maGiC_VALUE
#endif #endif
#endif #endif
], ],
SNDTYPE="ALSA_0_9" SNDTYPE="ALSA_0_6"
SOUND_LIBS="-lasound" SOUND_LIBS="-lasound"
) )
) )
@ -692,12 +692,12 @@ fi
AC_SUBST(SOUND_LIBS) AC_SUBST(SOUND_LIBS)
AC_SUBST(SOUND_CFLAGS) AC_SUBST(SOUND_CFLAGS)
AM_CONDITIONAL(SNDTYPE_ALSA_0_5, test "$SNDTYPE" = "ALSA_0_5") AM_CONDITIONAL(SNDTYPE_ALSA_0_5, test "$SNDTYPE" = "ALSA_0_5")
AM_CONDITIONAL(SNDTYPE_ALSA_0_9, test "$SNDTYPE" = "ALSA_0_9") AM_CONDITIONAL(SNDTYPE_ALSA_0_6, test "$SNDTYPE" = "ALSA_0_6")
AM_CONDITIONAL(SNDTYPE_MME, test "$SNDTYPE" = "MME") AM_CONDITIONAL(SNDTYPE_MME, test "$SNDTYPE" = "MME")
AM_CONDITIONAL(SNDTYPE_OSS, test "$SNDTYPE" = "OSS") AM_CONDITIONAL(SNDTYPE_OSS, test "$SNDTYPE" = "OSS")
AM_CONDITIONAL(SNDTYPE_SUN, test "$SNDTYPE" = "SUN") AM_CONDITIONAL(SNDTYPE_SUN, test "$SNDTYPE" = "SUN")
AM_CONDITIONAL(SNDTYPE_WIN32, test "$SNDTYPE" = "WIN32") AM_CONDITIONAL(SNDTYPE_WIN32, test "$SNDTYPE" = "WIN32")
AM_CONDITIONAL(SNDTYPE_NULL, test "$SNDTYPE" != "ALSA_0_5" -a "$SNDTYPE" != "ALSA_0_9" -a "$SNDTYPE" != "MME" -a "$SNDTYPE" != "OSS" -a "$SNDTYPE" != "SUN" -a "$SNDTYPE" != "WIN32") AM_CONDITIONAL(SNDTYPE_NULL, test "$SNDTYPE" != "ALSA_0_5" -a "$SNDTYPE" != "ALSA_0_6" -a "$SNDTYPE" != "MME" -a "$SNDTYPE" != "OSS" -a "$SNDTYPE" != "SUN" -a "$SNDTYPE" != "WIN32")
dnl Tests for joystick support dnl Tests for joystick support
AC_MSG_CHECKING(for joystick support) AC_MSG_CHECKING(for joystick support)
@ -776,6 +776,12 @@ AM_CONDITIONAL(CDTYPE_BSD, test "$CDTYPE" = "BSD")
AM_CONDITIONAL(CDTYPE_WIN32, test "$CDTYPE" = "WIN32") AM_CONDITIONAL(CDTYPE_WIN32, test "$CDTYPE" = "WIN32")
AM_CONDITIONAL(CDTYPE_NULL, test "$CDTYPE" != "LINUX" -a "$CDTYPE" != "BSD" -a "$CDTYPE" != "WIN32") AM_CONDITIONAL(CDTYPE_NULL, test "$CDTYPE" != "LINUX" -a "$CDTYPE" != "BSD" -a "$CDTYPE" != "WIN32")
if test "$CDTTPE" = BSD; then
AC_HAVE_STRUCT_FIELD(struct ioc_read_toc_single_entry, entry,
[#include <sys/cdio.h>]
)
fi
dnl ================================================================== dnl ==================================================================
dnl Checks for networking dnl Checks for networking
dnl ================================================================== dnl ==================================================================
@ -842,15 +848,30 @@ dnl Set $prefix and $exec_prefix to $ac_default_prefix if they are not set
test "x$prefix" = xNONE && prefix=$ac_default_prefix test "x$prefix" = xNONE && prefix=$ac_default_prefix
test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
AC_ARG_WITH(newstyle,
[ --with-newstyle compile with defaults a bit different than those
used by Id Software (does not affect gameplay)],
newstyle=$withval, newstyle=auto
)
AC_MSG_CHECKING([configuration style])
if test "x$newstyle" = xyes -o "x$newstyle" = "x"; then
AC_MSG_RESULT([new style])
AC_DEFINE(NEWSTYLE)
AC_DEFINE(BASEGAME, "base")
default_globalconf="/etc/$PACKAGE.conf"
eval foo="$datadir"
default_sharepath="$foo/games/quakeforge"
default_userpath="~/.quakeforge"
else
AC_MSG_RESULT([old style (id Software defaults)])
AC_DEFINE(BASEGAME, "id1")
if test "x$SYSTYPE" = xWIN32; then if test "x$SYSTYPE" = xWIN32; then
default_globalconf="~/${PACKAGE}.conf" default_globalconf="%WINDIR%/$PACKAGE.conf"
else
default_globalconf="/etc/$PACKAGE.conf"
fi
default_sharepath="." default_sharepath="."
default_userpath="." default_userpath="."
else
default_globalconf="/etc/${PACKAGE}.conf"
eval foo="$datadir"
default_sharepath="$foo/games/$PACKAGE"
default_userpath="~/.$PACKAGE"
fi fi
AC_ARG_WITH(global-cfg, AC_ARG_WITH(global-cfg,
@ -1103,7 +1124,6 @@ AC_MSG_RESULT([
Build type: $BUILD_TYPE Build type: $BUILD_TYPE
Targets:$CL_TARGETS Targets:$CL_TARGETS
Server: $ENABLE_DED Server: $ENABLE_DED
Compression support: $HAVE_ZLIB
System game data directory: $sharepath System game data directory: $sharepath
Per-user game data directory: $userpath Per-user game data directory: $userpath

View file

@ -35,5 +35,4 @@ void Chase_Init (void);
void Chase_Reset (void); void Chase_Reset (void);
void Chase_Update (void); void Chase_Update (void);
#endif //__chase_h #endif __chase_h

View file

@ -143,5 +143,4 @@ char *COM_Parse (char *data);
extern struct cvar_s *cl_warncmd; extern struct cvar_s *cl_warncmd;
#endif //__cmd_h #endif __cmd_h

View file

@ -174,10 +174,6 @@ extern cvar_t *loadas8bit;
extern cvar_t *bgmvolume; extern cvar_t *bgmvolume;
extern cvar_t *volume; extern cvar_t *volume;
extern cvar_t *snd_device;
extern cvar_t *snd_rate;
extern cvar_t *snd_bits;
extern cvar_t *snd_stereo;
extern cvar_t *snd_interp; extern cvar_t *snd_interp;
extern cvar_t *snd_stereo_phase_separation; extern cvar_t *snd_stereo_phase_separation;

View file

@ -65,6 +65,16 @@
/* Version strings */ /* Version strings */
#include "version.h" #include "version.h"
/* Define if you want to use QF-style defaults instead of Id-style */
#undef NEWSTYLE
/* Define this to the subdirectory name of the default game */
#ifdef NEWSTYLE
# define BASEGAME "base"
#else
# define BASEGAME "id1"
#endif
/* Define if you have the XFree86 DGA extension */ /* Define if you have the XFree86 DGA extension */
#undef HAVE_DGA #undef HAVE_DGA

View file

@ -65,6 +65,16 @@
/* Version string */ /* Version string */
#include "..\version.h" #include "..\version.h"
/* Define if you want to use QF-style defaults instead of Id-style */
#undef NEWSTYLE
/* Define this to the subdirectory name of the default game */
#ifdef NEWSTYLE
# define BASEGAME "base"
#else
# define BASEGAME "id1"
#endif
/* Define if you have the XFree86 DGA extension */ /* Define if you have the XFree86 DGA extension */
#undef HAVE_DGA #undef HAVE_DGA

View file

@ -1,37 +0,0 @@
/*
version.h
Version numbers for Win32 builds not using autoconf
Copyright (C) 2000 Jeff Teunissen
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
#ifndef _VERSION_H
#define _VERSION_H
/* Version strings */
#define PACKAGE "nuq"
#define PROGRAM "QuakeForge: nuq"
#define VERSION "0.2.99alpha0"
#define QSG_VERSION "1.0"
#define QUAKE_VERSION "1.09"
#endif // _VERSION_H

View file

@ -1,2 +1 @@
set args -nosound -nodga +set _windowed_mouse 0 set args -nosound -nodga +set _windowed_mouse 0
set height 0

View file

@ -70,8 +70,8 @@ EXTRA_libqfsys_a_SOURCES= dirent.c fnmatch.c sys_unix.c sys_win.c
if SNDTYPE_ALSA_0_5 if SNDTYPE_ALSA_0_5
libqfsnd_a_SOURCES= snd_dma.c snd_mem.c snd_mix.c snd_alsa_0_5.c $(sound_ASM) libqfsnd_a_SOURCES= snd_dma.c snd_mem.c snd_mix.c snd_alsa_0_5.c $(sound_ASM)
endif endif
if SNDTYPE_ALSA_0_9 if SNDTYPE_ALSA_0_6
libqfsnd_a_SOURCES= snd_dma.c snd_mem.c snd_mix.c snd_alsa_0_9.c $(sound_ASM) libqfsnd_a_SOURCES= snd_dma.c snd_mem.c snd_mix.c snd_alsa_0_6.c $(sound_ASM)
endif endif
if SNDTYPE_MME if SNDTYPE_MME
libqfsnd_a_SOURCES= snd_dma.c snd_mem.c snd_mix.c snd_mme.c $(sound_ASM) libqfsnd_a_SOURCES= snd_dma.c snd_mem.c snd_mix.c snd_mme.c $(sound_ASM)
@ -89,7 +89,7 @@ if SNDTYPE_NULL
libqfsnd_a_SOURCES= snd_null.c $(sound_ASM) libqfsnd_a_SOURCES= snd_null.c $(sound_ASM)
endif endif
EXTRA_libqfsnd_a_SOURCES= snd_dma.c snd_mem.c snd_mix.c snd_alsa_0_5.c \ EXTRA_libqfsnd_a_SOURCES= snd_dma.c snd_mem.c snd_mix.c snd_alsa_0_5.c \
snd_alsa_0_9.c snd_oss.c snd_sun.c snd_win.c snd_null.c \ snd_alsa_0_6.c snd_oss.c snd_sun.c snd_win.c snd_null.c \
$(sound_ASM) $(sound_ASM)
# #

View file

@ -29,12 +29,6 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#include "draw.h" #include "draw.h"
#include "vid.h" #include "vid.h"

View file

@ -368,7 +368,7 @@ static void Draw_TextureMode_f (void)
Con_Printf ("%s\n", modes[i].name); Con_Printf ("%s\n", modes[i].name);
return; return;
} }
Con_Printf ("current filter is unknown\?\?\?\n"); Con_Printf ("current filter is unknown???\n");
return; return;
} }
@ -1096,12 +1096,9 @@ GL_Upload32
static void GL_Upload32 (unsigned *data, int width, int height, qboolean mipmap, qboolean alpha) static void GL_Upload32 (unsigned *data, int width, int height, qboolean mipmap, qboolean alpha)
{ {
int samples; int samples;
unsigned int *scaled; static unsigned scaled[1024*512]; // [512*256];
int scaled_width, scaled_height; int scaled_width, scaled_height;
if (!width || !height)
return; // Null texture
for (scaled_width = 1 ; scaled_width < width ; scaled_width<<=1) for (scaled_width = 1 ; scaled_width < width ; scaled_width<<=1)
; ;
for (scaled_height = 1 ; scaled_height < height ; scaled_height<<=1) for (scaled_height = 1 ; scaled_height < height ; scaled_height<<=1)
@ -1113,7 +1110,7 @@ static void GL_Upload32 (unsigned *data, int width, int height, qboolean mipmap
scaled_width = min(scaled_width, gl_max_size->int_val); scaled_width = min(scaled_width, gl_max_size->int_val);
scaled_height = min(scaled_height, gl_max_size->int_val); scaled_height = min(scaled_height, gl_max_size->int_val);
if (!(scaled = malloc (scaled_width * scaled_height * sizeof (GLuint)))) if (scaled_width * scaled_height > sizeof(scaled)/4)
Sys_Error ("GL_LoadTexture: too big"); Sys_Error ("GL_LoadTexture: too big");
samples = alpha ? gl_alpha_format : gl_solid_format; samples = alpha ? gl_alpha_format : gl_solid_format;
@ -1176,8 +1173,6 @@ done: ;
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
} }
free (scaled);
} }
void GL_Upload8_EXT (byte *data, int width, int height, qboolean mipmap, qboolean alpha) void GL_Upload8_EXT (byte *data, int width, int height, qboolean mipmap, qboolean alpha)
@ -1185,7 +1180,7 @@ void GL_Upload8_EXT (byte *data, int width, int height, qboolean mipmap, qboole
int i, s; int i, s;
qboolean noalpha; qboolean noalpha;
int samples; int samples;
unsigned char *scaled; static unsigned char scaled[1024*512]; // [512*256];
int scaled_width, scaled_height; int scaled_width, scaled_height;
s = width*height; s = width*height;
@ -1214,7 +1209,7 @@ void GL_Upload8_EXT (byte *data, int width, int height, qboolean mipmap, qboole
scaled_width = min(scaled_width, gl_max_size->int_val); scaled_width = min(scaled_width, gl_max_size->int_val);
scaled_height = min(scaled_height, gl_max_size->int_val); scaled_height = min(scaled_height, gl_max_size->int_val);
if (!(scaled = malloc (scaled_width * scaled_height))) if (scaled_width * scaled_height > sizeof(scaled))
Sys_Error ("GL_LoadTexture: too big"); Sys_Error ("GL_LoadTexture: too big");
samples = 1; // alpha ? gl_alpha_format : gl_solid_format; samples = 1; // alpha ? gl_alpha_format : gl_solid_format;
@ -1277,7 +1272,6 @@ done: ;
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
} }
free (scaled);
} }
extern qboolean VID_Is8bit(); extern qboolean VID_Is8bit();

View file

@ -29,12 +29,6 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#include <math.h> #include <math.h>

View file

@ -1429,7 +1429,7 @@ void M_Keys_Draw (void)
if (keys[0] == -1) if (keys[0] == -1)
{ {
M_Print (140, y, "\?\?\?"); M_Print (140, y, "???");
} }
else else
{ {
@ -2512,7 +2512,7 @@ level_t abysslevels[] = {
{"aopdm3", "Mental Overlord"}, {"aopdm3", "Mental Overlord"},
{"aopdm4", "Mental Overlord II"}, {"aopdm4", "Mental Overlord II"},
{"aopdm5", "Midnight Darkness"}, {"aopdm5", "Midnight Darkness"},
{"aopdm6", "\?\?\?"} {"aopdm6", "???"}
}; };
typedef struct typedef struct

View file

@ -29,12 +29,6 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#include "msg.h" #include "msg.h"
#include "qendian.h" #include "qendian.h"

View file

@ -408,7 +408,7 @@ char *PR_GlobalString (int ofs)
val = (void *)&pr_globals[ofs]; val = (void *)&pr_globals[ofs];
def = ED_GlobalAtOfs(ofs); def = ED_GlobalAtOfs(ofs);
if (!def) if (!def)
snprintf (line, sizeof(line), "%i(\?\?\?)", ofs); snprintf (line, sizeof(line), "%i(???)", ofs);
else else
{ {
s = PR_ValueString (def->type, val); s = PR_ValueString (def->type, val);
@ -431,7 +431,7 @@ char *PR_GlobalStringNoContents (int ofs)
def = ED_GlobalAtOfs(ofs); def = ED_GlobalAtOfs(ofs);
if (!def) if (!def)
snprintf (line, sizeof(line), "%i(\?\?\?)", ofs); snprintf (line, sizeof(line), "%i(???)", ofs);
else else
snprintf (line, sizeof(line), "%i(%s)", ofs, pr_strings + def->s_name); snprintf (line, sizeof(line), "%i(%s)", ofs, pr_strings + def->s_name);

View file

@ -930,7 +930,7 @@ COM_InitFilesystem ( void )
"location of shared (read only) game directories"); "location of shared (read only) game directories");
fs_userpath = Cvar_Get ("fs_userpath", FS_USERPATH, CVAR_ROM, fs_userpath = Cvar_Get ("fs_userpath", FS_USERPATH, CVAR_ROM,
"location of your game directories"); "location of your game directories");
fs_basegame = Cvar_Get ("fs_basegame", "id1", CVAR_ROM, fs_basegame = Cvar_Get ("fs_basegame", BASEGAME, CVAR_ROM,
"game to use by default"); "game to use by default");
/* /*

View file

@ -29,12 +29,6 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#include "sizebuf.h" #include "sizebuf.h"
#include "sys.h" #include "sys.h"

356
source/snd_alsa_0_6.c Normal file
View file

@ -0,0 +1,356 @@
/*
snd_alsa_0_6.c
(description)
Copyright (C) 1999,2000 contributors of the QuakeForge project
Please see the file "AUTHORS" for a list of contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include <sys/asoundlib.h>
#include "console.h"
#include "qargs.h"
#include "sound.h"
#include "va.h"
static int snd_inited;
static snd_pcm_t *pcm_handle;
static snd_pcm_hw_info_t hwinfo;
static snd_pcm_hw_params_t hwparams;
static snd_pcm_sw_params_t swparams;
static const snd_pcm_channel_area_t *mmap_running_areas;
static int card = -1, dev = -1;
int
check_card (int card)
{
snd_ctl_t *handle;
int rc;
if ((rc = snd_ctl_open (&handle, va ("hw:%d", card))) < 0) {
Con_Printf ("Error: control open (%i): %s\n", card, snd_strerror (rc));
return rc;
}
if (dev == -1) {
while (1) {
if ((rc = snd_ctl_pcm_next_device (handle, &dev)) < 0) {
Con_Printf ("Error: next device: %s\n", snd_strerror (rc));
return rc;
}
if (dev < 0)
break;
if ((rc = snd_pcm_open (&pcm_handle, va ("hw:%d,%d", card, dev),
SND_PCM_STREAM_PLAYBACK,
SND_PCM_NONBLOCK)) == 0) {
goto exit;
}
}
} else {
if ((rc = snd_pcm_open (&pcm_handle, va ("hw:%d,%d", card, dev),
SND_PCM_STREAM_PLAYBACK,
SND_PCM_NONBLOCK)) == 0) {
goto exit;
}
Con_Printf ("Error: snd_pcm_open %d: %s\n", dev, snd_strerror (rc));
goto exit;
}
rc = 1;
exit:
snd_ctl_close(handle);
return rc;
}
qboolean
SNDDMA_Init (void)
{
int rc = 0, i;
char *err_msg = "";
int rate = -1, format = -1, stereo = -1, frag_size;
if ((i = COM_CheckParm ("-sndcard")) != 0) {
card = atoi (com_argv[i + 1]);
}
if ((i = COM_CheckParm ("-snddev")) != 0) {
dev = atoi (com_argv[i + 1]);
}
if ((i = COM_CheckParm ("-sndbits")) != 0) {
i = atoi (com_argv[i + 1]);
if (i == 16) {
format = SND_PCM_FMTBIT_S16_LE;
} else if (i == 8) {
format = SND_PCM_FMTBIT_U8;
} else {
Con_Printf ("Error: invalid sample bits: %d\n", i);
return 0;
}
}
if ((i = COM_CheckParm ("-sndspeed")) != 0) {
rate = atoi (com_argv[i + 1]);
if (rate != 44100 && rate != 22050 && rate != 11025) {
Con_Printf ("Error: invalid sample rate: %d\n", rate);
return 0;
}
}
if ((i = COM_CheckParm ("-sndmono")) != 0) {
stereo = 0;
}
if (card == -1) {
if (snd_card_next(&card) < 0 || card < 0) {
Con_Printf ("No sound cards detected\n");
return 0;
}
while (card >= 0) {
rc = check_card (card);
if (rc < 0)
return 0;
if (!rc)
goto dev_openned;
}
} else {
if (dev == -1) {
rc = check_card (card);
if (rc < 0)
return 0;
if (!rc)
goto dev_openned;
} else {
if ((rc = snd_pcm_open (&pcm_handle, va ("hw:%d,%d", card, dev),
SND_PCM_STREAM_PLAYBACK,
SND_PCM_NONBLOCK)) == 0) {
Con_Printf ("Error: audio open error: %s\n", snd_strerror (rc));
return 0;
}
goto dev_openned;
}
}
Con_Printf ("Error: audio open error: %s\n", snd_strerror (rc));
return 0;
dev_openned:
Con_Printf ("Using card %d, device %d.\n", card, dev);
memset (&hwinfo, 0, sizeof (hwinfo));
snd_pcm_hw_info_any (&hwinfo);
hwinfo.access_mask = SND_PCM_ACCBIT_MMAP_INTERLEAVED;
err_msg = "snd_pcm_hw_info";
if ((rc = snd_pcm_hw_info (pcm_handle, &hwinfo)) < 0)
goto error;
Con_Printf ("%08x %08x\n", hwinfo.access_mask, hwinfo.format_mask);
rate = 44100;
frag_size = 4;
#if 0 // XXX
if ((rate == -1 || rate == 44100) && hwinfo.rates & SND_PCM_RATE_44100) {
rate = 44100;
frag_size = 256; /* assuming stereo 8 bit */
} else if ((rate == -1 || rate == 22050)
&& hwinfo.rates & SND_PCM_RATE_22050) {
rate = 22050;
frag_size = 128; /* assuming stereo 8 bit */
} else if ((rate == -1 || rate == 11025)
&& hwinfo.rates & SND_PCM_RATE_11025) {
rate = 11025;
frag_size = 64; /* assuming stereo 8 bit */
} else {
Con_Printf ("ALSA: desired rates not supported\n");
goto error_2;
}
#endif
if ((format == -1 || format == SND_PCM_FMTBIT_S16_LE)
&& hwinfo.format_mask & SND_PCM_FORMAT_S16_LE) {
format = SND_PCM_FORMAT_S16_LE;
} else if ((format == -1 || format == SND_PCM_FORMAT_U8)
&& hwinfo.format_mask & SND_PCM_FORMAT_U8) {
format = SND_PCM_FORMAT_U8;
} else {
Con_Printf ("ALSA: desired formats not supported\n");
goto error_2;
}
// XXX can't support non-interleaved stereo
if (stereo && (hwinfo.access_mask & SND_PCM_ACCBIT_MMAP_INTERLEAVED)
&& hwinfo.channels_max >= 2) {
stereo = 1;
} else {
stereo = 0;
}
memset (&hwparams, 0, sizeof (hwparams));
// XXX can't support non-interleaved stereo
hwparams.access = stereo ? SND_PCM_ACCESS_MMAP_INTERLEAVED
: SND_PCM_ACCESS_MMAP_NONINTERLEAVED;
hwparams.format = format;
hwparams.rate = rate;
hwparams.channels = stereo + 1;
hwparams.fragment_size = 32;
hwparams.fragments = 512;
err_msg = "snd_pcm_hw_params";
if ((rc = snd_pcm_hw_params (pcm_handle, &hwparams)) < 0) {
Con_Printf("failed: %08x\n", hwparams.fail_mask);
goto error;
}
memset (&swparams, 0, sizeof (swparams));
swparams.start_mode = SND_PCM_START_EXPLICIT;
swparams.xrun_mode = SND_PCM_XRUN_FRAGMENT;
swparams.xfer_min = 1;
swparams.xfer_align = 1;
err_msg = "snd_pcm_sw_params";
if ((rc = snd_pcm_sw_params (pcm_handle, &swparams)) < 0) {
Con_Printf("failed: %08x\n", swparams.fail_mask);
goto error;
}
err_msg = "audio prepare";
if ((rc = snd_pcm_prepare (pcm_handle)) < 0)
goto error;
mmap_running_areas = snd_pcm_mmap_areas (pcm_handle);
shm = &sn;
memset ((dma_t *) shm, 0, sizeof (*shm));
shm->splitbuffer = 0;
shm->channels = hwparams.channels;
shm->submission_chunk = frag_size; // don't mix less than this #
shm->samplepos = 0; // in mono samples
shm->samplebits = hwparams.format == SND_PCM_FORMAT_S16_LE ? 16 : 8;
shm->samples = hwparams.fragment_size * hwparams.fragments
* shm->channels; // mono samples in buffer
shm->speed = hwparams.rate;
shm->buffer = (unsigned char *) mmap_running_areas->addr;
Con_Printf ("%5d stereo\n", shm->channels - 1);
Con_Printf ("%5d samples\n", shm->samples);
Con_Printf ("%5d samplepos\n", shm->samplepos);
Con_Printf ("%5d samplebits\n", shm->samplebits);
Con_Printf ("%5d submission_chunk\n", shm->submission_chunk);
Con_Printf ("%5d speed\n", shm->speed);
Con_Printf ("0x%x dma buffer\n", (int) shm->buffer);
Con_Printf ("%5d total_channels\n", total_channels);
snd_inited = 1;
return 1;
error:
Con_Printf ("Error: %s: %s\n", err_msg, snd_strerror (rc));
error_2:
snd_pcm_close (pcm_handle);
return 0;
}
static inline int
get_hw_ptr ()
{
size_t app_ptr;
ssize_t delay;
int hw_ptr;
if (snd_pcm_state (pcm_handle) != SND_PCM_STATE_RUNNING)
return 0;
app_ptr = snd_pcm_mmap_offset (pcm_handle);
snd_pcm_delay (pcm_handle, &delay);
hw_ptr = app_ptr - delay;
return hw_ptr;
}
int
SNDDMA_GetDMAPos (void)
{
int hw_ptr;
if (!snd_inited)
return 0;
hw_ptr = get_hw_ptr ();
hw_ptr *= shm->channels;
shm->samplepos = hw_ptr;
return shm->samplepos;
}
void
SNDDMA_Shutdown (void)
{
if (snd_inited) {
snd_pcm_close (pcm_handle);
snd_inited = 0;
}
}
/*
==============
SNDDMA_Submit
Send sound to device if buffer isn't really the dma buffer
===============
*/
void
SNDDMA_Submit (void)
{
int count = paintedtime - soundtime;
int avail;
int missed;
int state;
int hw_ptr;
int offset;
state = snd_pcm_state (pcm_handle);
switch (state) {
case SND_PCM_STATE_XRUN:
//snd_pcm_reset (pcm_handle);
snd_pcm_prepare (pcm_handle);
//break;
case SND_PCM_STATE_PREPARED:
snd_pcm_mmap_forward (pcm_handle, count);
snd_pcm_start (pcm_handle);
//break;
case SND_PCM_STATE_RUNNING:
hw_ptr = get_hw_ptr ();
missed = hw_ptr - shm->samplepos / shm->channels;
count -= missed;
offset = snd_pcm_mmap_offset (pcm_handle);
if (offset > hw_ptr)
count -= (offset - hw_ptr);
else
count -= (hwparams.fragments - hw_ptr + offset);
if (count < 0) {
snd_pcm_rewind (pcm_handle, -count);
} else if (count > 0) {
avail = snd_pcm_avail_update (pcm_handle);
if (avail > 0 && count > avail) {
snd_pcm_mmap_forward (pcm_handle, avail);
count -= avail;
}
snd_pcm_mmap_forward (pcm_handle, count);
}
break;
default:
printf("snd_alsa: nexpected state: %d\n", state);
break;
}
}

View file

@ -1,279 +0,0 @@
/*
snd_alsa_0_9.c
Support for ALSA 0.9 sound driver (cvs development version)
Copyright (C) 1999,2000 contributors of the QuakeForge project
Please see the file "AUTHORS" for a list of contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include <alsa/asoundlib.h>
#include "qtypes.h"
#include "sound.h"
#include "qargs.h"
#include "console.h"
static int snd_inited;
static snd_pcm_t *pcm;
static char *pcmname = NULL;
size_t buffer_size;
qboolean
SNDDMA_Init(void)
{
int err,i;
int rate=-1,bps=-1,stereo=-1,frag_size;
snd_pcm_hw_params_t *hw;
snd_pcm_sw_params_t *sw;
snd_pcm_hw_params_alloca(&hw);
snd_pcm_sw_params_alloca(&sw);
if ((i=COM_CheckParm("-sndpcm"))!=0) {
pcmname=com_argv[i+1];
}
if ((i=COM_CheckParm("-sndbits")) != 0) {
bps = atoi(com_argv[i+1]);
if (bps != 16 && bps != 8) {
Con_Printf("Error: invalid sample bits: %d\n", i);
return 0;
}
}
if ((i=COM_CheckParm("-sndspeed")) != 0) {
rate = atoi(com_argv[i+1]);
if (rate!=44100 && rate!=22050 && rate!=11025) {
Con_Printf("Error: invalid sample rate: %d\n", rate);
return 0;
}
}
if ((i=COM_CheckParm("-sndmono")) != 0) {
stereo=0;
}
if ((i=COM_CheckParm("-sndstereo")) != 0) {
stereo=1;
}
if (!pcmname)
pcmname = "plug:0,0";
if ((err=snd_pcm_open(&pcm, pcmname,
SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK))<0) {
Con_Printf("Error: audio open error: %s\n", snd_strerror(err));
return 0;
}
Con_Printf("Using PCM %s.\n", pcmname);
snd_pcm_hw_params_any(pcm, hw);
switch (rate) {
case -1:
if (snd_pcm_hw_params_set_rate_near(pcm, hw, 44100, 0) >= 0) {
frag_size = 256; /* assuming stereo 8 bit */
rate = 44100;
} else if (snd_pcm_hw_params_set_rate_near(pcm, hw, 22050, 0) >= 0) {
frag_size = 128; /* assuming stereo 8 bit */
rate = 22050;
} else if (snd_pcm_hw_params_set_rate_near(pcm, hw, 11025, 0) >= 0) {
frag_size = 64; /* assuming stereo 8 bit */
rate = 11025;
} else {
Con_Printf("ALSA: no useable rates\n");
goto error;
}
break;
case 11025:
case 22050:
case 44100:
if (snd_pcm_hw_params_set_rate_near(pcm, hw, rate, 0) >= 0) {
frag_size = 64 * rate / 11025; /* assuming stereo 8 bit */
break;
}
/* Fall through */
default:
Con_Printf("ALSA: desired rate not supported\n");
goto error;
}
switch (bps) {
case -1:
if (snd_pcm_hw_params_set_format(pcm, hw, SND_PCM_FORMAT_S16_LE) >= 0) {
bps = 16;
} else if (snd_pcm_hw_params_set_format(pcm, hw, SND_PCM_FORMAT_U8) >= 0) {
bps = 8;
} else {
Con_Printf("ALSA: no useable formats\n");
goto error;
}
break;
case 8:
case 16:
if (snd_pcm_hw_params_set_format(pcm, hw,
bps == 8 ? SND_PCM_FORMAT_U8 :
SND_PCM_FORMAT_S16) >= 0) {
break;
}
/* Fall through */
default:
Con_Printf("ALSA: desired format not supported\n");
goto error;
}
if (snd_pcm_hw_params_set_access(pcm, hw,
SND_PCM_ACCESS_MMAP_INTERLEAVED) < 0) {
Con_Printf("ALSA: interleaved is not supported\n");
goto error;
}
switch (stereo) {
case -1:
if (snd_pcm_hw_params_set_channels(pcm, hw, 2) >= 0) {
stereo = 1;
} else if (snd_pcm_hw_params_set_channels(pcm, hw, 1) >= 0) {
stereo = 0;
} else {
Con_Printf("ALSA: no useable channels\n");
goto error;
}
break;
case 0:
case 1:
if (snd_pcm_hw_params_set_channels(pcm, hw, stereo ? 2 : 1) >= 0)
break;
/* Fall through */
default:
Con_Printf("ALSA: desired channels not supported\n");
goto error;
}
snd_pcm_hw_params_set_period_size_near(pcm, hw, frag_size, 0);
err = snd_pcm_hw_params(pcm, hw);
if (err < 0) {
Con_Printf("ALSA: unable to install hw params\n");
goto error;
}
snd_pcm_sw_params_current(pcm, sw);
snd_pcm_sw_params_set_start_mode(pcm, sw, SND_PCM_START_EXPLICIT);
snd_pcm_sw_params_set_xrun_mode(pcm, sw, SND_PCM_XRUN_NONE);
err = snd_pcm_sw_params(pcm, sw);
if (err < 0) {
Con_Printf("ALSA: unable to install sw params\n");
goto error;
}
shm=&sn;
memset((dma_t*)shm,0,sizeof(*shm));
shm->splitbuffer = 0;
shm->channels=stereo+1;
shm->submission_chunk = snd_pcm_hw_params_get_period_size (hw, 0); // don't mix less than this #
shm->samplepos=0; // in mono samples
shm->samplebits=bps;
buffer_size = snd_pcm_hw_params_get_buffer_size(hw);
shm->samples=buffer_size*shm->channels; // mono samples in buffer
shm->speed=rate;
SNDDMA_GetDMAPos ();//XXX sets shm->buffer
Con_Printf("%5d stereo\n", shm->channels - 1);
Con_Printf("%5d samples\n", shm->samples);
Con_Printf("%5d samplepos\n", shm->samplepos);
Con_Printf("%5d samplebits\n", shm->samplebits);
Con_Printf("%5d submission_chunk\n", shm->submission_chunk);
Con_Printf("%5d speed\n", shm->speed);
Con_Printf("0x%x dma buffer\n", (int)shm->buffer);
Con_Printf("%5d total_channels\n", total_channels);
snd_inited=1;
return 1;
error:
snd_pcm_close(pcm);
return 0;
}
int
SNDDMA_GetDMAPos(void)
{
snd_pcm_uframes_t offset;
snd_pcm_uframes_t nframes = shm->samples/shm->channels;
const snd_pcm_channel_area_t *areas;
if (!snd_inited)
return 0;
snd_pcm_mmap_begin (pcm, &areas, &offset, &nframes);
offset *= shm->channels;
nframes *= shm->channels;
shm->samplepos = offset;
shm->buffer = areas->addr;//XXX FIXME there's an area per channel
return shm->samplepos;
}
void
SNDDMA_Shutdown(void)
{
if (snd_inited) {
snd_pcm_close(pcm);
snd_inited = 0;
}
}
/*
SNDDMA_Submit
Send sound to device if buffer isn't really the dma buffer
*/
void
SNDDMA_Submit(void)
{
snd_pcm_uframes_t offset;
snd_pcm_uframes_t nframes;
const snd_pcm_channel_area_t *areas;
int state;
int count = paintedtime - soundtime;
nframes = count / shm->channels;
snd_pcm_mmap_begin (pcm, &areas, &offset, &nframes);
state = snd_pcm_state (pcm);
switch (state) {
case SND_PCM_STATE_PREPARED:
snd_pcm_mmap_commit (pcm, offset, nframes);
snd_pcm_start (pcm);
break;
case SND_PCM_STATE_RUNNING:
snd_pcm_mmap_commit (pcm, offset, nframes);
break;
default:
break;
}
}

View file

@ -91,10 +91,6 @@ int sound_started = 0;
cvar_t *bgmvolume; cvar_t *bgmvolume;
cvar_t *volume; cvar_t *volume;
cvar_t *snd_device;
cvar_t *snd_rate;
cvar_t *snd_bits;
cvar_t *snd_stereo;
cvar_t *nosound; cvar_t *nosound;
cvar_t *precache; cvar_t *precache;
cvar_t *loadas8bit; cvar_t *loadas8bit;
@ -124,24 +120,22 @@ qboolean fakedma = false;
int fakedma_updates = 15; int fakedma_updates = 15;
void void S_AmbientOff (void)
S_AmbientOff (void)
{ {
snd_ambient = false; snd_ambient = false;
} }
void void S_AmbientOn (void)
S_AmbientOn (void)
{ {
snd_ambient = true; snd_ambient = true;
} }
void void S_SoundInfo_f(void)
S_SoundInfo_f (void) {
if (!sound_started || !shm)
{ {
if (!sound_started || !shm) {
Con_Printf ("sound system not started\n"); Con_Printf ("sound system not started\n");
return; return;
} }
@ -152,7 +146,7 @@ S_SoundInfo_f (void)
Con_Printf("%5d samplebits\n", shm->samplebits); Con_Printf("%5d samplebits\n", shm->samplebits);
Con_Printf("%5d submission_chunk\n", shm->submission_chunk); Con_Printf("%5d submission_chunk\n", shm->submission_chunk);
Con_Printf("%5d speed\n", shm->speed); Con_Printf("%5d speed\n", shm->speed);
Con_Printf ("0x%x dma buffer\n", (int) shm->buffer); Con_Printf("0x%x dma buffer\n", shm->buffer);
Con_Printf("%5d total_channels\n", total_channels); Con_Printf("%5d total_channels\n", total_channels);
} }
@ -163,18 +157,19 @@ S_Startup
================ ================
*/ */
void void S_Startup (void)
S_Startup (void)
{ {
int rc; int rc;
if (!snd_initialized) if (!snd_initialized)
return; return;
if (!fakedma) { if (!fakedma)
{
rc = SNDDMA_Init(); rc = SNDDMA_Init();
if (!rc) { if (!rc)
{
#ifndef _WIN32 #ifndef _WIN32
Con_Printf("S_Startup: SNDDMA_Init failed.\n"); Con_Printf("S_Startup: SNDDMA_Init failed.\n");
#endif #endif
@ -192,8 +187,7 @@ S_Startup (void)
S_Init S_Init
================ ================
*/ */
void void S_Init (void)
S_Init (void)
{ {
Con_Printf("\nSound Initialization\n"); Con_Printf("\nSound Initialization\n");
@ -204,14 +198,6 @@ S_Init (void)
Cmd_AddCommand("soundlist", S_SoundList); Cmd_AddCommand("soundlist", S_SoundList);
Cmd_AddCommand("soundinfo", S_SoundInfo_f); Cmd_AddCommand("soundinfo", S_SoundInfo_f);
snd_device = Cvar_Get ("snd_device", "", CVAR_ROM,
"sound device. \"\" is system default");
snd_rate = Cvar_Get ("snd_rate", "0", CVAR_ROM,
"sound playback rate. 0 is system default");
snd_bits = Cvar_Get ("snd_bits", "0", CVAR_ROM,
"sound sample depth. 0 is system default");
snd_stereo = Cvar_Get ("snd_stereo", "1", CVAR_ROM,
"sound stereo output");
nosound = Cvar_Get("nosound", "0", CVAR_NONE, "None"); nosound = Cvar_Get("nosound", "0", CVAR_NONE, "None");
volume = Cvar_Get("volume", "0.7", CVAR_ARCHIVE, "None"); volume = Cvar_Get("volume", "0.7", CVAR_ARCHIVE, "None");
precache = Cvar_Get("precache", "1", CVAR_NONE, "None"); precache = Cvar_Get("precache", "1", CVAR_NONE, "None");
@ -222,15 +208,9 @@ S_Init (void)
ambient_fade = Cvar_Get("ambient_fade", "100", CVAR_NONE, "None"); ambient_fade = Cvar_Get("ambient_fade", "100", CVAR_NONE, "None");
snd_noextraupdate = Cvar_Get("snd_noextraupdate", "0", CVAR_NONE, "None"); snd_noextraupdate = Cvar_Get("snd_noextraupdate", "0", CVAR_NONE, "None");
snd_show = Cvar_Get("snd_show", "0", CVAR_NONE, "None"); snd_show = Cvar_Get("snd_show", "0", CVAR_NONE, "None");
snd_interp = snd_interp = Cvar_Get("snd_interp", "1", CVAR_ARCHIVE, "control sample interpolation");
Cvar_Get ("snd_interp", "1", CVAR_ARCHIVE, snd_phasesep = Cvar_Get("snd_phasesep", "0.0", CVAR_ARCHIVE, "max stereo phase separation in ms. 0.6 is for 20cm head");
"control sample interpolation"); snd_volumesep = Cvar_Get("snd_volumesep", "1.0", CVAR_ARCHIVE, "max stereo volume separation in ms. 1.0 is max");
snd_phasesep =
Cvar_Get ("snd_phasesep", "0.0", CVAR_ARCHIVE,
"max stereo phase separation in ms. 0.6 is for 20cm head");
snd_volumesep =
Cvar_Get ("snd_volumesep", "1.0", CVAR_ARCHIVE,
"max stereo volume separation in ms. 1.0 is max");
_snd_mixahead = Cvar_Get("_snd_mixahead", "0.1", CVAR_ARCHIVE, "None"); _snd_mixahead = Cvar_Get("_snd_mixahead", "0.1", CVAR_ARCHIVE, "None");
if (COM_CheckParm("-nosound")) if (COM_CheckParm("-nosound"))
@ -239,7 +219,8 @@ S_Init (void)
if (COM_CheckParm("-simsound")) if (COM_CheckParm("-simsound"))
fakedma = true; fakedma = true;
if (host_parms.memsize < 0x800000) { if (host_parms.memsize < 0x800000)
{
Cvar_Set(loadas8bit, "1"); Cvar_Set(loadas8bit, "1");
Con_Printf ("loading all sounds as 8bit\n"); Con_Printf ("loading all sounds as 8bit\n");
} }
@ -256,12 +237,12 @@ S_Init (void)
SND_InitScaletable (); SND_InitScaletable ();
known_sfx = Hunk_AllocName (MAX_SFX*sizeof(sfx_t), "sfx_t"); known_sfx = Hunk_AllocName (MAX_SFX*sizeof(sfx_t), "sfx_t");
num_sfx = 0; num_sfx = 0;
// create a piece of DMA memory // create a piece of DMA memory
if (fakedma) { if (fakedma)
{
shm = (void *) Hunk_AllocName(sizeof(*shm), "shm"); shm = (void *) Hunk_AllocName(sizeof(*shm), "shm");
shm->splitbuffer = 0; shm->splitbuffer = 0;
shm->samplebits = 16; shm->samplebits = 16;
@ -293,8 +274,7 @@ S_Init (void)
// Shutdown sound engine // Shutdown sound engine
// ======================================================================= // =======================================================================
void void S_Shutdown(void)
S_Shutdown (void)
{ {
if (!sound_started) if (!sound_started)
@ -306,7 +286,8 @@ S_Shutdown (void)
shm = 0; shm = 0;
sound_started = 0; sound_started = 0;
if (!fakedma) { if (!fakedma)
{
SNDDMA_Shutdown(); SNDDMA_Shutdown();
} }
} }
@ -322,8 +303,7 @@ S_FindName
================== ==================
*/ */
sfx_t * sfx_t *S_FindName (char *name)
S_FindName (char *name)
{ {
int i; int i;
sfx_t *sfx; sfx_t *sfx;
@ -336,7 +316,8 @@ S_FindName (char *name)
// see if already loaded // see if already loaded
for (i=0 ; i < num_sfx ; i++) for (i=0 ; i < num_sfx ; i++)
if (!strcmp (known_sfx[i].name, name)) { if (!strcmp(known_sfx[i].name, name))
{
return &known_sfx[i]; return &known_sfx[i];
} }
@ -358,8 +339,7 @@ S_TouchSound
================== ==================
*/ */
void void S_TouchSound (char *name)
S_TouchSound (char *name)
{ {
sfx_t *sfx; sfx_t *sfx;
@ -376,8 +356,7 @@ S_PrecacheSound
================== ==================
*/ */
sfx_t * sfx_t *S_PrecacheSound (char *name)
S_PrecacheSound (char *name)
{ {
sfx_t *sfx; sfx_t *sfx;
@ -401,8 +380,7 @@ S_PrecacheSound (char *name)
SND_PickChannel SND_PickChannel
================= =================
*/ */
channel_t * channel_t *SND_PickChannel(int entnum, int entchannel)
SND_PickChannel (int entnum, int entchannel)
{ {
int ch_idx; int ch_idx;
int first_to_die; int first_to_die;
@ -411,27 +389,22 @@ SND_PickChannel (int entnum, int entchannel)
// Check for replacement sound, or find the best one to replace // Check for replacement sound, or find the best one to replace
first_to_die = -1; first_to_die = -1;
life_left = 0x7fffffff; life_left = 0x7fffffff;
for (ch_idx = NUM_AMBIENTS; ch_idx < NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS; for (ch_idx=NUM_AMBIENTS ; ch_idx < NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS ; ch_idx++)
ch_idx++) { {
if (entchannel != 0 // channel 0 never overrides if (entchannel != 0 // channel 0 never overrides
&& channels[ch_idx].entnum == entnum && channels[ch_idx].entnum == entnum
&& (channels[ch_idx].entchannel == entchannel || entchannel == -1)) { // always && (channels[ch_idx].entchannel == entchannel || entchannel == -1) )
// { // allways override sound from same entity
//
// override
// sound
// from
// same
// entity
first_to_die = ch_idx; first_to_die = ch_idx;
break; break;
} }
// don't let monster sounds override player sounds // don't let monster sounds override player sounds
if (channels[ch_idx].entnum == cl.viewentity && entnum != cl.viewentity if (channels[ch_idx].entnum == cl.viewentity && entnum != cl.viewentity && channels[ch_idx].sfx)
&& channels[ch_idx].sfx)
continue; continue;
if (channels[ch_idx].end - paintedtime < life_left) { if (channels[ch_idx].end - paintedtime < life_left)
{
life_left = channels[ch_idx].end - paintedtime; life_left = channels[ch_idx].end - paintedtime;
first_to_die = ch_idx; first_to_die = ch_idx;
} }
@ -451,8 +424,7 @@ SND_PickChannel (int entnum, int entchannel)
SND_Spatialize SND_Spatialize
================= =================
*/ */
void void SND_Spatialize(channel_t *ch)
SND_Spatialize (channel_t *ch)
{ {
vec_t dot; vec_t dot;
vec_t dist; vec_t dist;
@ -461,13 +433,15 @@ SND_Spatialize (channel_t *ch)
vec3_t source_vec; vec3_t source_vec;
sfx_t *snd; sfx_t *snd;
// anything coming from the view entity will always be full volume // anything coming from the view entity will allways be full volume
if (ch->entnum == cl.viewentity) { if (ch->entnum == cl.viewentity)
{
ch->leftvol = ch->master_vol; ch->leftvol = ch->master_vol;
ch->rightvol = ch->master_vol; ch->rightvol = ch->master_vol;
ch->phase = 0; ch->phase = 0;
return; return;
} }
// calculate stereo seperation and distance attenuation // calculate stereo seperation and distance attenuation
snd = ch->sfx; snd = ch->sfx;
@ -477,11 +451,14 @@ SND_Spatialize (channel_t *ch)
dot = DotProduct(listener_right, source_vec); dot = DotProduct(listener_right, source_vec);
if (shm->channels == 1) { if (shm->channels == 1)
{
rscale = 1.0; rscale = 1.0;
lscale = 1.0; lscale = 1.0;
phase = 0; phase = 0;
} else { }
else
{
rscale = 1.0 + dot * snd_volumesep->value; rscale = 1.0 + dot * snd_volumesep->value;
lscale = 1.0 - dot * snd_volumesep->value; lscale = 1.0 - dot * snd_volumesep->value;
phase = snd_phasesep->value * 0.001 * shm->speed * dot; phase = snd_phasesep->value * 0.001 * shm->speed * dot;
@ -506,9 +483,7 @@ SND_Spatialize (channel_t *ch)
// Start a sound effect // Start a sound effect
// ======================================================================= // =======================================================================
void void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin,
float fvol, float attenuation)
{ {
channel_t *target_chan, *check; channel_t *target_chan, *check;
sfxcache_t *sc; sfxcache_t *sc;
@ -547,7 +522,8 @@ S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin,
// new channel // new channel
sc = S_LoadSound (sfx); sc = S_LoadSound (sfx);
if (!sc) { if (!sc)
{
target_chan->sfx = NULL; target_chan->sfx = NULL;
return; // couldn't load the sound's data return; // couldn't load the sound's data
} }
@ -559,11 +535,12 @@ S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin,
// if an identical sound has also been started this frame, offset the pos // if an identical sound has also been started this frame, offset the pos
// a bit to keep it from just making the first one louder // a bit to keep it from just making the first one louder
check = &channels[NUM_AMBIENTS]; check = &channels[NUM_AMBIENTS];
for (ch_idx = NUM_AMBIENTS; ch_idx < NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS; for (ch_idx=NUM_AMBIENTS ; ch_idx < NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS ; ch_idx++, check++)
ch_idx++, check++) { {
if (check == target_chan) if (check == target_chan)
continue; continue;
if (check->sfx == sfx && !check->pos) { if (check->sfx == sfx && !check->pos)
{
skip = rand () % (int)(0.1*shm->speed); skip = rand () % (int)(0.1*shm->speed);
if (skip >= target_chan->end) if (skip >= target_chan->end)
skip = target_chan->end - 1; skip = target_chan->end - 1;
@ -575,14 +552,15 @@ S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin,
} }
} }
void void S_StopSound(int entnum, int entchannel)
S_StopSound (int entnum, int entchannel)
{ {
int i; int i;
for (i = 0; i < MAX_DYNAMIC_CHANNELS; i++) { for (i=0 ; i<MAX_DYNAMIC_CHANNELS ; i++)
{
if (channels[i].entnum == entnum if (channels[i].entnum == entnum
&& channels[i].entchannel == entchannel) { && channels[i].entchannel == entchannel)
{
channels[i].end = 0; channels[i].end = 0;
channels[i].sfx = NULL; channels[i].sfx = NULL;
return; return;
@ -590,8 +568,7 @@ S_StopSound (int entnum, int entchannel)
} }
} }
void void S_StopAllSounds(qboolean clear)
S_StopAllSounds (qboolean clear)
{ {
int i; int i;
@ -610,14 +587,12 @@ S_StopAllSounds (qboolean clear)
S_ClearBuffer (); S_ClearBuffer ();
} }
void void S_StopAllSoundsC (void)
S_StopAllSoundsC (void)
{ {
S_StopAllSounds (true); S_StopAllSounds (true);
} }
void void S_ClearBuffer (void)
S_ClearBuffer (void)
{ {
int clear; int clear;
@ -634,7 +609,8 @@ S_ClearBuffer (void)
clear = 0; clear = 0;
#ifdef _WIN32 #ifdef _WIN32
if (pDSBuf) { if (pDSBuf)
{
DWORD dwSize; DWORD dwSize;
DWORD *pData; DWORD *pData;
int reps; int reps;
@ -642,17 +618,17 @@ S_ClearBuffer (void)
reps = 0; reps = 0;
while ( while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, &pData, &dwSize, NULL, NULL, 0)) != DS_OK)
(hresult = {
pDSBuf->lpVtbl->Lock (pDSBuf, 0, gSndBufSize, &pData, &dwSize, if (hresult != DSERR_BUFFERLOST)
NULL, NULL, 0)) != DS_OK) { {
if (hresult != DSERR_BUFFERLOST) {
Con_Printf ("S_ClearBuffer: DS::Lock Sound Buffer Failed\n"); Con_Printf ("S_ClearBuffer: DS::Lock Sound Buffer Failed\n");
S_Shutdown (); S_Shutdown ();
return; return;
} }
if (++reps > 10000) { if (++reps > 10000)
{
Con_Printf ("S_ClearBuffer: DS: couldn't restore buffer\n"); Con_Printf ("S_ClearBuffer: DS: couldn't restore buffer\n");
S_Shutdown (); S_Shutdown ();
return; return;
@ -663,7 +639,8 @@ S_ClearBuffer (void)
pDSBuf->lpVtbl->Unlock(pDSBuf, pData, dwSize, NULL, 0); pDSBuf->lpVtbl->Unlock(pDSBuf, pData, dwSize, NULL, 0);
} else }
else
#endif #endif
{ {
memset(shm->buffer, clear, shm->samples * shm->samplebits/8); memset(shm->buffer, clear, shm->samples * shm->samplebits/8);
@ -676,8 +653,7 @@ S_ClearBuffer (void)
S_StaticSound S_StaticSound
================= =================
*/ */
void void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation)
S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation)
{ {
channel_t *ss; channel_t *ss;
sfxcache_t *sc; sfxcache_t *sc;
@ -685,7 +661,8 @@ S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation)
if (!sfx) if (!sfx)
return; return;
if (total_channels == MAX_CHANNELS) { if (total_channels == MAX_CHANNELS)
{
Con_Printf ("total_channels == MAX_CHANNELS\n"); Con_Printf ("total_channels == MAX_CHANNELS\n");
return; return;
} }
@ -697,7 +674,8 @@ S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation)
if (!sc) if (!sc)
return; return;
if (sc->loopstart == -1) { if (sc->loopstart == -1)
{
Con_Printf ("Sound %s not looped\n", sfx->name); Con_Printf ("Sound %s not looped\n", sfx->name);
return; return;
} }
@ -720,8 +698,7 @@ S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation)
S_UpdateAmbientSounds S_UpdateAmbientSounds
=================== ===================
*/ */
void void S_UpdateAmbientSounds (void)
S_UpdateAmbientSounds (void)
{ {
mleaf_t *l; mleaf_t *l;
float vol; float vol;
@ -736,14 +713,15 @@ S_UpdateAmbientSounds (void)
return; return;
l = Mod_PointInLeaf (listener_origin, cl.worldmodel); l = Mod_PointInLeaf (listener_origin, cl.worldmodel);
if (!l || !ambient_level->value) { if (!l || !ambient_level->value)
for (ambient_channel = 0; ambient_channel < NUM_AMBIENTS; {
ambient_channel++) for (ambient_channel = 0 ; ambient_channel< NUM_AMBIENTS ; ambient_channel++)
channels[ambient_channel].sfx = NULL; channels[ambient_channel].sfx = NULL;
return; return;
} }
for (ambient_channel = 0; ambient_channel < NUM_AMBIENTS; ambient_channel++) { for (ambient_channel = 0 ; ambient_channel< NUM_AMBIENTS ; ambient_channel++)
{
chan = &channels[ambient_channel]; chan = &channels[ambient_channel];
chan->sfx = ambient_sfx[ambient_channel]; chan->sfx = ambient_sfx[ambient_channel];
@ -752,11 +730,14 @@ S_UpdateAmbientSounds (void)
vol = 0; vol = 0;
// don't adjust volume too fast // don't adjust volume too fast
if (chan->master_vol < vol) { if (chan->master_vol < vol)
{
chan->master_vol += host_frametime * ambient_fade->value; chan->master_vol += host_frametime * ambient_fade->value;
if (chan->master_vol > vol) if (chan->master_vol > vol)
chan->master_vol = vol; chan->master_vol = vol;
} else if (chan->master_vol > vol) { }
else if (chan->master_vol > vol)
{
chan->master_vol -= host_frametime * ambient_fade->value; chan->master_vol -= host_frametime * ambient_fade->value;
if (chan->master_vol < vol) if (chan->master_vol < vol)
chan->master_vol = vol; chan->master_vol = vol;
@ -774,8 +755,7 @@ S_Update
Called once each time through the main loop Called once each time through the main loop
============ ============
*/ */
void void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
S_Update (vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
{ {
int i, j; int i, j;
int total; int total;
@ -797,11 +777,11 @@ S_Update (vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
// update spatialization for static and dynamic sounds // update spatialization for static and dynamic sounds
ch = channels+NUM_AMBIENTS; ch = channels+NUM_AMBIENTS;
for (i = NUM_AMBIENTS; i < total_channels; i++, ch++) { for (i=NUM_AMBIENTS ; i<total_channels; i++, ch++)
{
if (!ch->sfx) if (!ch->sfx)
continue; continue;
ch->oldphase = ch->phase; // prepare to lerp from prev to next ch->oldphase = ch->phase; // prepare to lerp from prev to next phase
// phase
SND_Spatialize(ch); // respatialize channel SND_Spatialize(ch); // respatialize channel
if (!ch->leftvol && !ch->rightvol) if (!ch->leftvol && !ch->rightvol)
continue; continue;
@ -809,9 +789,11 @@ S_Update (vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
// try to combine static sounds with a previous channel of the same // try to combine static sounds with a previous channel of the same
// sound effect so we don't mix five torches every frame // sound effect so we don't mix five torches every frame
if (i >= MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS) { if (i >= MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS)
{
// see if it can just use the last one // see if it can just use the last one
if (combine && combine->sfx == ch->sfx) { if (combine && combine->sfx == ch->sfx)
{
combine->leftvol += ch->leftvol; combine->leftvol += ch->leftvol;
combine->rightvol += ch->rightvol; combine->rightvol += ch->rightvol;
ch->leftvol = ch->rightvol = 0; ch->leftvol = ch->rightvol = 0;
@ -823,10 +805,14 @@ S_Update (vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
if (combine->sfx == ch->sfx) if (combine->sfx == ch->sfx)
break; break;
if (j == total_channels) { if (j == total_channels)
{
combine = NULL; combine = NULL;
} else { }
if (combine != ch) { else
{
if (combine != ch)
{
combine->leftvol += ch->leftvol; combine->leftvol += ch->leftvol;
combine->rightvol += ch->rightvol; combine->rightvol += ch->rightvol;
ch->leftvol = ch->rightvol = 0; ch->leftvol = ch->rightvol = 0;
@ -841,24 +827,25 @@ S_Update (vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
// //
// debugging output // debugging output
// //
if (snd_show->int_val) { if (snd_show->int_val)
{
total = 0; total = 0;
ch = channels; ch = channels;
for (i=0 ; i<total_channels; i++, ch++) for (i=0 ; i<total_channels; i++, ch++)
if (ch->sfx && (ch->leftvol || ch->rightvol)) { if (ch->sfx && (ch->leftvol || ch->rightvol) )
// Con_Printf ("%3i %3i %s\n", ch->leftvol, ch->rightvol, {
// ch->sfx->name); //Con_Printf ("%3i %3i %s\n", ch->leftvol, ch->rightvol, ch->sfx->name);
total++; total++;
} }
Con_Printf ("----(%i)----\n", total); Con_Printf ("----(%i)----\n", total);
} }
// mix some sound // mix some sound
S_Update_(); S_Update_();
} }
void void GetSoundtime(void)
GetSoundtime (void)
{ {
int samplepos; int samplepos;
static int buffers; static int buffers;
@ -875,11 +862,12 @@ GetSoundtime (void)
samplepos = SNDDMA_GetDMAPos(); samplepos = SNDDMA_GetDMAPos();
if (samplepos < oldsamplepos) { if (samplepos < oldsamplepos)
{
buffers++; // buffer wrapped buffers++; // buffer wrapped
if (paintedtime > 0x40000000) { // time to chop things off to avoid if (paintedtime > 0x40000000)
// 32 bit limits { // time to chop things off to avoid 32 bit limits
buffers = 0; buffers = 0;
paintedtime = fullsamples; paintedtime = fullsamples;
S_StopAllSounds (true); S_StopAllSounds (true);
@ -891,8 +879,7 @@ GetSoundtime (void)
#endif #endif
} }
void void S_ExtraUpdate (void)
S_ExtraUpdate (void)
{ {
#ifdef _WIN32 #ifdef _WIN32
@ -904,8 +891,7 @@ S_ExtraUpdate (void)
S_Update_(); S_Update_();
} }
void void S_Update_(void)
S_Update_ (void)
{ {
unsigned endtime; unsigned endtime;
int samps; int samps;
@ -917,10 +903,12 @@ S_Update_ (void)
GetSoundtime(); GetSoundtime();
// check to make sure that we haven't overshot // check to make sure that we haven't overshot
if (paintedtime < soundtime) { if (paintedtime < soundtime)
{
//Con_Printf ("S_Update_ : overflow\n"); //Con_Printf ("S_Update_ : overflow\n");
paintedtime = soundtime; paintedtime = soundtime;
} }
// mix ahead of current position // mix ahead of current position
endtime = soundtime + _snd_mixahead->value * shm->speed; endtime = soundtime + _snd_mixahead->value * shm->speed;
samps = shm->samples >> (shm->channels-1); samps = shm->samples >> (shm->channels-1);
@ -932,7 +920,8 @@ S_Update_ (void)
{ {
DWORD dwStatus; DWORD dwStatus;
if (pDSBuf) { if (pDSBuf)
{
if (pDSBuf->lpVtbl->GetStatus (pDSBuf, &dwStatus) != DD_OK) if (pDSBuf->lpVtbl->GetStatus (pDSBuf, &dwStatus) != DD_OK)
Con_Printf ("Couldn't get sound buffer status\n"); Con_Printf ("Couldn't get sound buffer status\n");
@ -958,8 +947,7 @@ console functions
=============================================================================== ===============================================================================
*/ */
void void S_Play(void)
S_Play (void)
{ {
static int hash=345; static int hash=345;
int i; int i;
@ -967,11 +955,14 @@ S_Play (void)
sfx_t *sfx; sfx_t *sfx;
i = 1; i = 1;
while (i < Cmd_Argc ()) { while (i<Cmd_Argc())
if (!strrchr (Cmd_Argv (i), '.')) { {
if (!strrchr(Cmd_Argv(i), '.'))
{
strcpy(name, Cmd_Argv(i)); strcpy(name, Cmd_Argv(i));
strcat(name, ".wav"); strcat(name, ".wav");
} else }
else
strcpy(name, Cmd_Argv(i)); strcpy(name, Cmd_Argv(i));
sfx = S_PrecacheSound(name); sfx = S_PrecacheSound(name);
S_StartSound(hash++, 0, sfx, listener_origin, 1.0, 1.0); S_StartSound(hash++, 0, sfx, listener_origin, 1.0, 1.0);
@ -979,8 +970,7 @@ S_Play (void)
} }
} }
void void S_PlayVol(void)
S_PlayVol (void)
{ {
static int hash=543; static int hash=543;
int i; int i;
@ -989,11 +979,14 @@ S_PlayVol (void)
sfx_t *sfx; sfx_t *sfx;
i = 1; i = 1;
while (i < Cmd_Argc ()) { while (i<Cmd_Argc())
if (!strrchr (Cmd_Argv (i), '.')) { {
if (!strrchr(Cmd_Argv(i), '.'))
{
strcpy(name, Cmd_Argv(i)); strcpy(name, Cmd_Argv(i));
strcat(name, ".wav"); strcat(name, ".wav");
} else }
else
strcpy(name, Cmd_Argv(i)); strcpy(name, Cmd_Argv(i));
sfx = S_PrecacheSound(name); sfx = S_PrecacheSound(name);
vol = atof(Cmd_Argv(i+1)); vol = atof(Cmd_Argv(i+1));
@ -1002,8 +995,7 @@ S_PlayVol (void)
} }
} }
void void S_SoundList(void)
S_SoundList (void)
{ {
int i; int i;
sfx_t *sfx; sfx_t *sfx;
@ -1011,7 +1003,8 @@ S_SoundList (void)
int size, total; int size, total;
total = 0; total = 0;
for (sfx = known_sfx, i = 0; i < num_sfx; i++, sfx++) { for (sfx=known_sfx, i=0 ; i<num_sfx ; i++, sfx++)
{
sc = Cache_Check (&sfx->cache); sc = Cache_Check (&sfx->cache);
if (!sc) if (!sc)
continue; continue;
@ -1027,8 +1020,7 @@ S_SoundList (void)
} }
void void S_LocalSound (char *sound)
S_LocalSound (char *sound)
{ {
sfx_t *sfx; sfx_t *sfx;
@ -1038,7 +1030,8 @@ S_LocalSound (char *sound)
return; return;
sfx = S_PrecacheSound (sound); sfx = S_PrecacheSound (sound);
if (!sfx) { if (!sfx)
{
Con_Printf ("S_LocalSound: can't cache %s\n", sound); Con_Printf ("S_LocalSound: can't cache %s\n", sound);
return; return;
} }
@ -1046,19 +1039,17 @@ S_LocalSound (char *sound)
} }
void void S_ClearPrecache (void)
S_ClearPrecache (void)
{ {
} }
void void S_BeginPrecaching (void)
S_BeginPrecaching (void)
{ {
} }
void void S_EndPrecaching (void)
S_EndPrecaching (void)
{ {
} }

View file

@ -29,12 +29,6 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#include "sound.h" #include "sound.h"
#include "compat.h" #include "compat.h"

View file

@ -352,7 +352,7 @@ Shared_Init8bitPalette()
} }
is8bit = true; is8bit = true;
if (strstr(gl_renderer, "Mesa Glide")) { if strstr(gl_renderer, "Mesa Glide") {
#ifdef HAVE_TDFXGL #ifdef HAVE_TDFXGL
load_texture(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, (void *) thePalette); load_texture(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, (void *) thePalette);
#endif #endif

View file

@ -35,12 +35,6 @@
# include <config.h> # include <config.h>
#endif #endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>

View file

@ -29,12 +29,6 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#include "qendian.h" #include "qendian.h"
#include "wad.h" #include "wad.h"