Compare commits

..

19 commits

Author SHA1 Message Date
Bill Currie
7d4cbdf158 compile fix for somebody 2001-12-22 08:21:40 +00:00
Timothy C. McGrath
7bd105178a Another one line hack to get everything compiling with alsa 0.9..
Again, if this causes problems I'll see what I can do about the depreciated
warnings I'm seeing when the clients are lding

Tim McGrath
(Misty-chan)
2001-11-24 01:20:15 +00:00
Bill Currie
308d8a1304 missed the 8 bit upload code 2001-10-02 01:47:04 +00:00
Bill Currie
136a7629cb wasn't this fixed months ago? 2001-10-02 01:46:41 +00:00
Bill Currie
a41b5b975f back port 0.5's scaled image allocation 2001-10-01 20:14:10 +00:00
Bill Currie
b1cf570c7f fix for autoconf 2.50 2001-07-11 18:05:30 +00:00
Bill Currie
e703c3758d more trigraphs :/ 2001-07-02 00:02:14 +00:00
Bill Currie
12b4f480c6 who's idea were these things? 2001-07-01 23:59:01 +00:00
Joseph Carter
8dca32f27d newstyle dies! 2001-06-06 14:29:06 +00:00
Joseph Carter
0598ed57ce NEWS doesn't apply to nuq 2001-05-22 15:01:58 +00:00
Joseph Carter
1911b98020 The end of newstyle in nuq forever! 2001-05-22 14:39:46 +00:00
Thad Ward
5296fb9667 fixing some #endif goofups. some compilers don't like non-comment tokens after one... 2001-05-19 15:08:32 +00:00
Bill Currie
7e5bb9f69a snd_alsa_0_9.c:
update for latest api
version.h:
	d'oh, that's why it was in cvs (cf that long ago checkin)
2001-05-19 01:54:38 +00:00
Bill Currie
d4505ad388 make gdb screens infinitely high so it doesn't stop output and wait 2001-03-27 04:01:32 +00:00
Bill Currie
048a9253ea backport the snd_* setup cvars 2001-03-10 06:00:19 +00:00
Bill Currie
73bc23e117 fix missing string.h/strings.h includes and eol at eof problems 2001-03-07 05:43:24 +00:00
Bill Currie
04d3351727 this file somehow got missed earlier 2001-03-05 01:43:41 +00:00
Ragnvald Maartmann-Moe IV
ddedef8ed9 Remove obsolete support for the never released ALSA 0.6, add support for current 0.9-series cvs development ALSA.
(Thanks again to Abramo)
2001-02-24 08:21:49 +00:00
Bill Currie
928200fa2b add reporting of compression support 2001-02-22 06:06:24 +00:00
30 changed files with 789 additions and 811 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 doc RPM SUBDIRS = include source 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
View file

View file

@ -13,9 +13,6 @@
/* 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
@ -25,9 +22,6 @@
/* 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>=6) #if SND_LIB_MAJOR>0 || (SND_LIB_MAJOR==0 && SND_LIB_MINOR>=9)
QF_maGiC_VALUE QF_maGiC_VALUE
#endif #endif
#endif #endif
], ],
SNDTYPE="ALSA_0_6" SNDTYPE="ALSA_0_9"
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_6, test "$SNDTYPE" = "ALSA_0_6") AM_CONDITIONAL(SNDTYPE_ALSA_0_9, test "$SNDTYPE" = "ALSA_0_9")
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_6" -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_9" -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,12 +776,6 @@ 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 ==================================================================
@ -848,30 +842,15 @@ 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, if test "x$SYSTYPE" = xWIN32; then
[ --with-newstyle compile with defaults a bit different than those default_globalconf="~/${PACKAGE}.conf"
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
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,
@ -1124,6 +1103,7 @@ 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,4 +35,5 @@ 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,4 +143,5 @@ 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,6 +174,10 @@ 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,16 +65,6 @@
/* 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,16 +65,6 @@
/* 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

37
include/win32/version.h Normal file
View file

@ -0,0 +1,37 @@
/*
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 +1,2 @@
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_6 if SNDTYPE_ALSA_0_9
libqfsnd_a_SOURCES= snd_dma.c snd_mem.c snd_mix.c snd_alsa_0_6.c $(sound_ASM) libqfsnd_a_SOURCES= snd_dma.c snd_mem.c snd_mix.c snd_alsa_0_9.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_6.c snd_oss.c snd_sun.c snd_win.c snd_null.c \ snd_alsa_0_9.c snd_oss.c snd_sun.c snd_win.c snd_null.c \
$(sound_ASM) $(sound_ASM)
# #

View file

@ -29,6 +29,12 @@
#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,9 +1096,12 @@ 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;
static unsigned scaled[1024*512]; // [512*256]; unsigned int *scaled;
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)
@ -1110,7 +1113,7 @@ static unsigned scaled[1024*512]; // [512*256];
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_width * scaled_height > sizeof(scaled)/4) if (!(scaled = malloc (scaled_width * scaled_height * sizeof (GLuint))))
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;
@ -1173,6 +1176,8 @@ 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)
@ -1180,7 +1185,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;
static unsigned char scaled[1024*512]; // [512*256]; unsigned char *scaled;
int scaled_width, scaled_height; int scaled_width, scaled_height;
s = width*height; s = width*height;
@ -1209,7 +1214,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_width * scaled_height > sizeof(scaled)) if (!(scaled = malloc (scaled_width * scaled_height)))
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;
@ -1272,6 +1277,7 @@ 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,6 +29,12 @@
#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,6 +29,12 @@
#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", BASEGAME, CVAR_ROM, fs_basegame = Cvar_Get ("fs_basegame", "id1", CVAR_ROM,
"game to use by default"); "game to use by default");
/* /*

View file

@ -29,6 +29,12 @@
#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"

View file

@ -1,356 +0,0 @@
/*
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;
}
}

279
source/snd_alsa_0_9.c Normal file
View file

@ -0,0 +1,279 @@
/*
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

@ -45,12 +45,12 @@
#include "winquake.h" #include "winquake.h"
#endif #endif
void S_Play(void); void S_Play (void);
void S_PlayVol(void); void S_PlayVol (void);
void S_SoundList(void); void S_SoundList (void);
void S_Update_(); void S_Update_ ();
void S_StopAllSounds(qboolean clear); void S_StopAllSounds (qboolean clear);
void S_StopAllSoundsC(void); void S_StopAllSoundsC (void);
// ======================================================================= // =======================================================================
// Internal sound data & structures // Internal sound data & structures
@ -71,7 +71,7 @@ vec3_t listener_origin;
vec3_t listener_forward; vec3_t listener_forward;
vec3_t listener_right; vec3_t listener_right;
vec3_t listener_up; vec3_t listener_up;
vec_t sound_nominal_clip_dist=1000.0; vec_t sound_nominal_clip_dist = 1000.0;
int soundtime; // sample PAIRS int soundtime; // sample PAIRS
int paintedtime; // sample PAIRS int paintedtime; // sample PAIRS
@ -86,11 +86,15 @@ sfx_t *ambient_sfx[NUM_AMBIENTS];
int desired_speed = 11025; int desired_speed = 11025;
int desired_bits = 16; int desired_bits = 16;
int sound_started=0; 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;
@ -120,34 +124,36 @@ qboolean fakedma = false;
int fakedma_updates = 15; int fakedma_updates = 15;
void S_AmbientOff (void) void
S_AmbientOff (void)
{ {
snd_ambient = false; snd_ambient = false;
} }
void S_AmbientOn (void) void
S_AmbientOn (void)
{ {
snd_ambient = true; snd_ambient = true;
} }
void S_SoundInfo_f(void) 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;
} }
Con_Printf("%5d stereo\n", shm->channels - 1); Con_Printf ("%5d stereo\n", shm->channels - 1);
Con_Printf("%5d samples\n", shm->samples); Con_Printf ("%5d samples\n", shm->samples);
Con_Printf("%5d samplepos\n", shm->samplepos); Con_Printf ("%5d samplepos\n", shm->samplepos);
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", shm->buffer); Con_Printf ("0x%x dma buffer\n", (int) shm->buffer);
Con_Printf("%5d total_channels\n", total_channels); Con_Printf ("%5d total_channels\n", total_channels);
} }
@ -157,21 +163,20 @@ S_Startup
================ ================
*/ */
void S_Startup (void) 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
sound_started = 0; sound_started = 0;
return; return;
@ -187,41 +192,55 @@ void S_Startup (void)
S_Init S_Init
================ ================
*/ */
void S_Init (void) void
S_Init (void)
{ {
Con_Printf("\nSound Initialization\n"); Con_Printf ("\nSound Initialization\n");
Cmd_AddCommand("play", S_Play); Cmd_AddCommand ("play", S_Play);
Cmd_AddCommand("playvol", S_PlayVol); Cmd_AddCommand ("playvol", S_PlayVol);
Cmd_AddCommand("stopsound", S_StopAllSoundsC); Cmd_AddCommand ("stopsound", S_StopAllSoundsC);
Cmd_AddCommand("soundlist", S_SoundList); Cmd_AddCommand ("soundlist", S_SoundList);
Cmd_AddCommand("soundinfo", S_SoundInfo_f); Cmd_AddCommand ("soundinfo", S_SoundInfo_f);
nosound = Cvar_Get("nosound", "0", CVAR_NONE, "None"); snd_device = Cvar_Get ("snd_device", "", CVAR_ROM,
volume = Cvar_Get("volume", "0.7", CVAR_ARCHIVE, "None"); "sound device. \"\" is system default");
precache = Cvar_Get("precache", "1", CVAR_NONE, "None"); snd_rate = Cvar_Get ("snd_rate", "0", CVAR_ROM,
loadas8bit = Cvar_Get("loadas8bit", "0", CVAR_NONE, "None"); "sound playback rate. 0 is system default");
bgmvolume = Cvar_Get("bgmvolume", "1", CVAR_ARCHIVE, "None"); snd_bits = Cvar_Get ("snd_bits", "0", CVAR_ROM,
bgmbuffer = Cvar_Get("bgmbuffer", "4096", CVAR_NONE, "None"); "sound sample depth. 0 is system default");
ambient_level = Cvar_Get("ambient_level", "0.3", CVAR_NONE, "None"); snd_stereo = Cvar_Get ("snd_stereo", "1", CVAR_ROM,
ambient_fade = Cvar_Get("ambient_fade", "100", CVAR_NONE, "None"); "sound stereo output");
snd_noextraupdate = Cvar_Get("snd_noextraupdate", "0", CVAR_NONE, "None"); nosound = Cvar_Get ("nosound", "0", CVAR_NONE, "None");
snd_show = Cvar_Get("snd_show", "0", CVAR_NONE, "None"); volume = Cvar_Get ("volume", "0.7", CVAR_ARCHIVE, "None");
snd_interp = Cvar_Get("snd_interp", "1", CVAR_ARCHIVE, "control sample interpolation"); precache = Cvar_Get ("precache", "1", CVAR_NONE, "None");
snd_phasesep = Cvar_Get("snd_phasesep", "0.0", CVAR_ARCHIVE, "max stereo phase separation in ms. 0.6 is for 20cm head"); loadas8bit = Cvar_Get ("loadas8bit", "0", CVAR_NONE, "None");
snd_volumesep = Cvar_Get("snd_volumesep", "1.0", CVAR_ARCHIVE, "max stereo volume separation in ms. 1.0 is max"); bgmvolume = Cvar_Get ("bgmvolume", "1", CVAR_ARCHIVE, "None");
_snd_mixahead = Cvar_Get("_snd_mixahead", "0.1", CVAR_ARCHIVE, "None"); bgmbuffer = Cvar_Get ("bgmbuffer", "4096", CVAR_NONE, "None");
ambient_level = Cvar_Get ("ambient_level", "0.3", CVAR_NONE, "None");
ambient_fade = Cvar_Get ("ambient_fade", "100", CVAR_NONE, "None");
snd_noextraupdate = Cvar_Get ("snd_noextraupdate", "0", CVAR_NONE, "None");
snd_show = Cvar_Get ("snd_show", "0", CVAR_NONE, "None");
snd_interp =
Cvar_Get ("snd_interp", "1", CVAR_ARCHIVE,
"control sample interpolation");
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");
if (COM_CheckParm("-nosound")) if (COM_CheckParm ("-nosound"))
return; return;
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");
} }
@ -236,14 +255,14 @@ void 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;
shm->speed = 22050; shm->speed = 22050;
@ -253,7 +272,7 @@ void S_Init (void)
shm->soundalive = true; shm->soundalive = true;
shm->gamealive = true; shm->gamealive = true;
shm->submission_chunk = 1; shm->submission_chunk = 1;
shm->buffer = Hunk_AllocName(1<<16, "shmbuf"); shm->buffer = Hunk_AllocName (1 << 16, "shmbuf");
} }
Con_Printf ("Sound sampling rate: %i\n", shm->speed); Con_Printf ("Sound sampling rate: %i\n", shm->speed);
@ -274,7 +293,8 @@ void S_Init (void)
// Shutdown sound engine // Shutdown sound engine
// ======================================================================= // =======================================================================
void S_Shutdown(void) void
S_Shutdown (void)
{ {
if (!sound_started) if (!sound_started)
@ -286,9 +306,8 @@ void S_Shutdown(void)
shm = 0; shm = 0;
sound_started = 0; sound_started = 0;
if (!fakedma) if (!fakedma) {
{ SNDDMA_Shutdown ();
SNDDMA_Shutdown();
} }
} }
@ -303,7 +322,8 @@ S_FindName
================== ==================
*/ */
sfx_t *S_FindName (char *name) sfx_t *
S_FindName (char *name)
{ {
int i; int i;
sfx_t *sfx; sfx_t *sfx;
@ -311,13 +331,12 @@ sfx_t *S_FindName (char *name)
if (!name) if (!name)
Sys_Error ("S_FindName: NULL\n"); Sys_Error ("S_FindName: NULL\n");
if (strlen(name) >= MAX_QPATH) if (strlen (name) >= MAX_QPATH)
Sys_Error ("Sound name too long: %s", name); Sys_Error ("Sound name too long: %s", 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];
} }
@ -339,7 +358,8 @@ S_TouchSound
================== ==================
*/ */
void S_TouchSound (char *name) void
S_TouchSound (char *name)
{ {
sfx_t *sfx; sfx_t *sfx;
@ -356,7 +376,8 @@ S_PrecacheSound
================== ==================
*/ */
sfx_t *S_PrecacheSound (char *name) sfx_t *
S_PrecacheSound (char *name)
{ {
sfx_t *sfx; sfx_t *sfx;
@ -380,7 +401,8 @@ sfx_t *S_PrecacheSound (char *name)
SND_PickChannel SND_PickChannel
================= =================
*/ */
channel_t *SND_PickChannel(int entnum, int entchannel) channel_t *
SND_PickChannel (int entnum, int entchannel)
{ {
int ch_idx; int ch_idx;
int first_to_die; int first_to_die;
@ -389,22 +411,27 @@ channel_t *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 ; ch_idx++) for (ch_idx = NUM_AMBIENTS; ch_idx < NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS;
{ 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) ) && (channels[ch_idx].entchannel == entchannel || entchannel == -1)) { // always
{ // 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 && channels[ch_idx].sfx) if (channels[ch_idx].entnum == cl.viewentity && entnum != cl.viewentity
&& 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;
} }
@ -424,7 +451,8 @@ channel_t *SND_PickChannel(int entnum, int entchannel)
SND_Spatialize SND_Spatialize
================= =================
*/ */
void SND_Spatialize(channel_t *ch) void
SND_Spatialize (channel_t *ch)
{ {
vec_t dot; vec_t dot;
vec_t dist; vec_t dist;
@ -433,32 +461,27 @@ void 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 allways be full volume // anything coming from the view entity will always 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;
VectorSubtract(ch->origin, listener_origin, source_vec); VectorSubtract (ch->origin, listener_origin, source_vec);
dist = VectorNormalize(source_vec) * ch->dist_mult; dist = VectorNormalize (source_vec) * ch->dist_mult;
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;
@ -483,7 +506,9 @@ void SND_Spatialize(channel_t *ch)
// Start a sound effect // Start a sound effect
// ======================================================================= // =======================================================================
void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation) void
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;
@ -500,21 +525,21 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f
if (nosound->int_val) if (nosound->int_val)
return; return;
vol = fvol*255; vol = fvol * 255;
// pick a channel to play on // pick a channel to play on
target_chan = SND_PickChannel(entnum, entchannel); target_chan = SND_PickChannel (entnum, entchannel);
if (!target_chan) if (!target_chan)
return; return;
// spatialize // spatialize
memset (target_chan, 0, sizeof(*target_chan)); memset (target_chan, 0, sizeof (*target_chan));
VectorCopy(origin, target_chan->origin); VectorCopy (origin, target_chan->origin);
target_chan->dist_mult = attenuation / sound_nominal_clip_dist; target_chan->dist_mult = attenuation / sound_nominal_clip_dist;
target_chan->master_vol = vol; target_chan->master_vol = vol;
target_chan->entnum = entnum; target_chan->entnum = entnum;
target_chan->entchannel = entchannel; target_chan->entchannel = entchannel;
SND_Spatialize(target_chan); SND_Spatialize (target_chan);
target_chan->oldphase = target_chan->phase; target_chan->oldphase = target_chan->phase;
if (!target_chan->leftvol && !target_chan->rightvol) if (!target_chan->leftvol && !target_chan->rightvol)
@ -522,8 +547,7 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f
// 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
} }
@ -535,13 +559,12 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f
// 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 ; ch_idx++, check++) for (ch_idx = NUM_AMBIENTS; ch_idx < NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS;
{ 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;
target_chan->pos += skip; target_chan->pos += skip;
@ -552,15 +575,14 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f
} }
} }
void S_StopSound(int entnum, int entchannel) void
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;
@ -568,7 +590,8 @@ void S_StopSound(int entnum, int entchannel)
} }
} }
void S_StopAllSounds(qboolean clear) void
S_StopAllSounds (qboolean clear)
{ {
int i; int i;
@ -577,22 +600,24 @@ void S_StopAllSounds(qboolean clear)
total_channels = MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS; // no statics total_channels = MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS; // no statics
for (i=0 ; i<MAX_CHANNELS ; i++) for (i = 0; i < MAX_CHANNELS; i++)
if (channels[i].sfx) if (channels[i].sfx)
channels[i].sfx = NULL; channels[i].sfx = NULL;
memset(channels, 0, MAX_CHANNELS * sizeof(channel_t)); memset (channels, 0, MAX_CHANNELS * sizeof (channel_t));
if (clear) if (clear)
S_ClearBuffer (); S_ClearBuffer ();
} }
void S_StopAllSoundsC (void) void
S_StopAllSoundsC (void)
{ {
S_StopAllSounds (true); S_StopAllSounds (true);
} }
void S_ClearBuffer (void) void
S_ClearBuffer (void)
{ {
int clear; int clear;
@ -609,8 +634,7 @@ void 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;
@ -618,32 +642,31 @@ void S_ClearBuffer (void)
reps = 0; reps = 0;
while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, &pData, &dwSize, NULL, NULL, 0)) != DS_OK) while (
{ (hresult =
if (hresult != DSERR_BUFFERLOST) pDSBuf->lpVtbl->Lock (pDSBuf, 0, gSndBufSize, &pData, &dwSize,
{ 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;
} }
} }
memset(pData, clear, shm->samples * shm->samplebits/8); memset (pData, clear, shm->samples * shm->samplebits / 8);
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);
} }
} }
@ -653,7 +676,8 @@ void S_ClearBuffer (void)
S_StaticSound S_StaticSound
================= =================
*/ */
void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation) void
S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation)
{ {
channel_t *ss; channel_t *ss;
sfxcache_t *sc; sfxcache_t *sc;
@ -661,8 +685,7 @@ void 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;
} }
@ -674,8 +697,7 @@ void 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;
} }
@ -683,7 +705,7 @@ void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation)
ss->sfx = sfx; ss->sfx = sfx;
VectorCopy (origin, ss->origin); VectorCopy (origin, ss->origin);
ss->master_vol = vol; ss->master_vol = vol;
ss->dist_mult = (attenuation/64) / sound_nominal_clip_dist; ss->dist_mult = (attenuation / 64) / sound_nominal_clip_dist;
ss->end = paintedtime + sc->length; ss->end = paintedtime + sc->length;
SND_Spatialize (ss); SND_Spatialize (ss);
@ -698,7 +720,8 @@ void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation)
S_UpdateAmbientSounds S_UpdateAmbientSounds
=================== ===================
*/ */
void S_UpdateAmbientSounds (void) void
S_UpdateAmbientSounds (void)
{ {
mleaf_t *l; mleaf_t *l;
float vol; float vol;
@ -713,15 +736,14 @@ void 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;
for (ambient_channel = 0 ; ambient_channel< NUM_AMBIENTS ; ambient_channel++) 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];
@ -730,14 +752,11 @@ void 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;
@ -755,7 +774,8 @@ S_Update
Called once each time through the main loop Called once each time through the main loop
============ ============
*/ */
void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up) void
S_Update (vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
{ {
int i, j; int i, j;
int total; int total;
@ -765,10 +785,10 @@ void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
if (!sound_started || (snd_blocked > 0)) if (!sound_started || (snd_blocked > 0))
return; return;
VectorCopy(origin, listener_origin); VectorCopy (origin, listener_origin);
VectorCopy(forward, listener_forward); VectorCopy (forward, listener_forward);
VectorCopy(right, listener_right); VectorCopy (right, listener_right);
VectorCopy(up, listener_up); VectorCopy (up, listener_up);
// update general area ambient sound sources // update general area ambient sound sources
S_UpdateAmbientSounds (); S_UpdateAmbientSounds ();
@ -776,43 +796,37 @@ void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
combine = NULL; combine = NULL;
// 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 phase ch->oldphase = ch->phase; // prepare to lerp from prev to next
SND_Spatialize(ch); // respatialize channel // phase
SND_Spatialize (ch); // respatialize channel
if (!ch->leftvol && !ch->rightvol) if (!ch->leftvol && !ch->rightvol)
continue; continue;
// 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;
continue; continue;
} }
// search for one // search for one
combine = channels+MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS; combine = channels + MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS;
for (j=MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS ; j<i; j++, combine++) for (j = MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS; j < i; j++, combine++)
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 {
else if (combine != ch) {
{
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;
@ -827,25 +841,24 @@ void 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,
//Con_Printf ("%3i %3i %s\n", ch->leftvol, ch->rightvol, ch->sfx->name); // 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 GetSoundtime(void) void
GetSoundtime (void)
{ {
int samplepos; int samplepos;
static int buffers; static int buffers;
@ -857,17 +870,16 @@ void GetSoundtime(void)
// it is possible to miscount buffers if it has wrapped twice between // it is possible to miscount buffers if it has wrapped twice between
// calls to S_Update. Oh well. // calls to S_Update. Oh well.
#ifdef __sun__ #ifdef __sun__
soundtime = SNDDMA_GetSamples(); soundtime = SNDDMA_GetSamples ();
#else #else
samplepos = SNDDMA_GetDMAPos(); samplepos = SNDDMA_GetDMAPos ();
if (samplepos < oldsamplepos) if (samplepos < oldsamplepos) {
{
buffers++; // buffer wrapped buffers++; // buffer wrapped
if (paintedtime > 0x40000000) if (paintedtime > 0x40000000) { // time to chop things off to avoid
{ // time to chop things off to avoid 32 bit limits // 32 bit limits
buffers = 0; buffers = 0;
paintedtime = fullsamples; paintedtime = fullsamples;
S_StopAllSounds (true); S_StopAllSounds (true);
@ -875,11 +887,12 @@ void GetSoundtime(void)
} }
oldsamplepos = samplepos; oldsamplepos = samplepos;
soundtime = buffers*fullsamples + samplepos/shm->channels; soundtime = buffers * fullsamples + samplepos / shm->channels;
#endif #endif
} }
void S_ExtraUpdate (void) void
S_ExtraUpdate (void)
{ {
#ifdef _WIN32 #ifdef _WIN32
@ -888,10 +901,11 @@ void S_ExtraUpdate (void)
if (snd_noextraupdate->int_val) if (snd_noextraupdate->int_val)
return; // don't pollute timings return; // don't pollute timings
S_Update_(); S_Update_ ();
} }
void S_Update_(void) void
S_Update_ (void)
{ {
unsigned endtime; unsigned endtime;
int samps; int samps;
@ -900,18 +914,16 @@ void S_Update_(void)
return; return;
// Updates DMA time // Updates DMA time
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);
if (endtime - soundtime > samps) if (endtime - soundtime > samps)
endtime = soundtime + samps; endtime = soundtime + samps;
@ -920,8 +932,7 @@ void 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");
@ -929,7 +940,7 @@ void S_Update_(void)
pDSBuf->lpVtbl->Restore (pDSBuf); pDSBuf->lpVtbl->Restore (pDSBuf);
if (!(dwStatus & DSBSTATUS_PLAYING)) if (!(dwStatus & DSBSTATUS_PLAYING))
pDSBuf->lpVtbl->Play(pDSBuf, 0, 0, DSBPLAY_LOOPING); pDSBuf->lpVtbl->Play (pDSBuf, 0, 0, DSBPLAY_LOOPING);
} }
} }
#endif #endif
@ -947,55 +958,52 @@ console functions
=============================================================================== ===============================================================================
*/ */
void S_Play(void) void
S_Play (void)
{ {
static int hash=345; static int hash = 345;
int i; int i;
char name[256]; char name[256];
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));
{ strcat (name, ".wav");
strcpy(name, Cmd_Argv(i)); } else
strcat(name, ".wav"); strcpy (name, Cmd_Argv (i));
} sfx = S_PrecacheSound (name);
else S_StartSound (hash++, 0, sfx, listener_origin, 1.0, 1.0);
strcpy(name, Cmd_Argv(i));
sfx = S_PrecacheSound(name);
S_StartSound(hash++, 0, sfx, listener_origin, 1.0, 1.0);
i++; i++;
} }
} }
void S_PlayVol(void) void
S_PlayVol (void)
{ {
static int hash=543; static int hash = 543;
int i; int i;
float vol; float vol;
char name[256]; char name[256];
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));
{ strcat (name, ".wav");
strcpy(name, Cmd_Argv(i)); } else
strcat(name, ".wav"); strcpy (name, Cmd_Argv (i));
} sfx = S_PrecacheSound (name);
else vol = atof (Cmd_Argv (i + 1));
strcpy(name, Cmd_Argv(i)); S_StartSound (hash++, 0, sfx, listener_origin, vol, 1.0);
sfx = S_PrecacheSound(name); i += 2;
vol = atof(Cmd_Argv(i+1));
S_StartSound(hash++, 0, sfx, listener_origin, vol, 1.0);
i+=2;
} }
} }
void S_SoundList(void) void
S_SoundList (void)
{ {
int i; int i;
sfx_t *sfx; sfx_t *sfx;
@ -1003,24 +1011,24 @@ void 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;
size = sc->length*sc->width*(sc->stereo+1); size = sc->length * sc->width * (sc->stereo + 1);
total += size; total += size;
if (sc->loopstart >= 0) if (sc->loopstart >= 0)
Con_Printf ("L"); Con_Printf ("L");
else else
Con_Printf (" "); Con_Printf (" ");
Con_Printf("(%2db) %6i : %s\n",sc->width*8, size, sfx->name); Con_Printf ("(%2db) %6i : %s\n", sc->width * 8, size, sfx->name);
} }
Con_Printf ("Total resident: %i\n", total); Con_Printf ("Total resident: %i\n", total);
} }
void S_LocalSound (char *sound) void
S_LocalSound (char *sound)
{ {
sfx_t *sfx; sfx_t *sfx;
@ -1030,8 +1038,7 @@ void 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;
} }
@ -1039,17 +1046,19 @@ void S_LocalSound (char *sound)
} }
void S_ClearPrecache (void) void
S_ClearPrecache (void)
{ {
} }
void S_BeginPrecaching (void) void
S_BeginPrecaching (void)
{ {
} }
void S_EndPrecaching (void) void
S_EndPrecaching (void)
{ {
} }

View file

@ -29,6 +29,12 @@
#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,6 +35,12 @@
# 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,6 +29,12 @@
#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"