mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
all -snd* params and environment checking have been removed from the sound
subsystem in favor of Cvars. These new cvars are: o snd_device defaults to "" which selects the default device of the system (eg, plug:0,0 for ALSA 0.9 or /dev/dsp for OSS) o snd_rate defaults to 0 which selects the system default rate. o snd_bits defaults to 0 which selects the system default bit depth. o snd_stereo defaults to 1 (0 is mono)
This commit is contained in:
parent
1fce1ea12e
commit
95e5b5e4cf
5 changed files with 60 additions and 65 deletions
|
@ -174,6 +174,10 @@ extern cvar_t *loadas8bit;
|
|||
extern cvar_t *bgmvolume;
|
||||
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_stereo_phase_separation;
|
||||
|
||||
|
|
|
@ -125,14 +125,11 @@ SNDDMA_Init (void)
|
|||
Con_Printf ("No sound cards detected\n");
|
||||
return 0;
|
||||
}
|
||||
if ((i = COM_CheckParm ("-sndcard")) != 0) {
|
||||
card = atoi (com_argv[i + 1]);
|
||||
if (snd_device->string[0]) {
|
||||
sscanf (snd_device->string, "%d,%d", &card, &dev);
|
||||
}
|
||||
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 (snd_bits->int_val) {
|
||||
i = snd_bits->int_val;
|
||||
if (i == 16) {
|
||||
format = SND_PCM_SFMT_S16_LE;
|
||||
} else if (i == 8) {
|
||||
|
@ -142,16 +139,14 @@ SNDDMA_Init (void)
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
if ((i = COM_CheckParm ("-sndspeed")) != 0) {
|
||||
rate = atoi (com_argv[i + 1]);
|
||||
if (snd_rate->int_val) {
|
||||
rate = snd_rate->int_val;
|
||||
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;
|
||||
}
|
||||
stereo = snd_stereo->int_val;
|
||||
if (card == -1) {
|
||||
for (card = 0; card < SND_CARDS; card++) {
|
||||
if (!(mask & (1 << card)))
|
||||
|
|
|
@ -50,7 +50,7 @@ size_t buffer_size;
|
|||
qboolean
|
||||
SNDDMA_Init (void)
|
||||
{
|
||||
int err, i;
|
||||
int err;
|
||||
int rate = -1, bps = -1, stereo = -1, frag_size;
|
||||
snd_pcm_hw_params_t *hw;
|
||||
snd_pcm_sw_params_t *sw;
|
||||
|
@ -58,29 +58,23 @@ SNDDMA_Init (void)
|
|||
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 (snd_device->string[0])
|
||||
pcmname = snd_device->string;
|
||||
if (snd_bits->int_val) {
|
||||
bps = snd_bits->int_val;
|
||||
if (bps != 16 && bps != 8) {
|
||||
Con_Printf ("Error: invalid sample bits: %d\n", i);
|
||||
Con_Printf ("Error: invalid sample bits: %d\n", bps);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((i = COM_CheckParm ("-sndspeed")) != 0) {
|
||||
rate = atoi (com_argv[i + 1]);
|
||||
if (snd_rate->int_val) {
|
||||
rate = snd_rate->int_val;
|
||||
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;
|
||||
}
|
||||
stereo = snd_stereo->int_val;
|
||||
if (!pcmname)
|
||||
pcmname = "plug:0,0";
|
||||
if ((err = snd_pcm_open (&pcm, pcmname,
|
||||
|
|
|
@ -91,6 +91,10 @@ int sound_started = 0;
|
|||
cvar_t *bgmvolume;
|
||||
cvar_t *volume;
|
||||
|
||||
cvar_t *snd_device;
|
||||
cvar_t *snd_rate;
|
||||
cvar_t *snd_bits;
|
||||
cvar_t *snd_stereo;
|
||||
cvar_t *nosound;
|
||||
cvar_t *precache;
|
||||
cvar_t *loadas8bit;
|
||||
|
@ -200,6 +204,14 @@ S_Init (void)
|
|||
Cmd_AddCommand ("soundlist", S_SoundList, "No Description");
|
||||
Cmd_AddCommand ("soundinfo", S_SoundInfo_f, "No Description");
|
||||
|
||||
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");
|
||||
volume = Cvar_Get ("volume", "0.7", CVAR_ARCHIVE, "None");
|
||||
precache = Cvar_Get ("precache", "1", CVAR_NONE, "None");
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/*
|
||||
snd_oss.c
|
||||
|
||||
|
@ -46,8 +45,9 @@
|
|||
#include "sound.h"
|
||||
#include "qargs.h"
|
||||
|
||||
int audio_fd;
|
||||
int snd_inited;
|
||||
static int audio_fd;
|
||||
static int snd_inited;
|
||||
static char *snd_dev = "/dev/dsp";
|
||||
|
||||
static int tryrates[] = { 11025, 22051, 44100, 8000 };
|
||||
|
||||
|
@ -59,31 +59,32 @@ SNDDMA_Init (void)
|
|||
int fmt;
|
||||
int tmp;
|
||||
int i;
|
||||
char *s;
|
||||
struct audio_buf_info info;
|
||||
int caps;
|
||||
|
||||
snd_inited = 0;
|
||||
|
||||
// open /dev/dsp, confirm capability to mmap, and get size of dma buffer
|
||||
if (snd_device->string[0])
|
||||
snd_dev = snd_device->string;
|
||||
|
||||
audio_fd = open ("/dev/dsp", O_RDWR);
|
||||
audio_fd = open (snd_dev, O_RDWR);
|
||||
if (audio_fd < 0) {
|
||||
perror ("/dev/dsp");
|
||||
Con_Printf ("Could not open /dev/dsp\n");
|
||||
perror (snd_dev);
|
||||
Con_Printf ("Could not open %s\n", snd_dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
rc = ioctl (audio_fd, SNDCTL_DSP_RESET, 0);
|
||||
if (rc < 0) {
|
||||
perror ("/dev/dsp");
|
||||
Con_Printf ("Could not reset /dev/dsp\n");
|
||||
perror (snd_dev);
|
||||
Con_Printf ("Could not reset %s\n", snd_dev);
|
||||
close (audio_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ioctl (audio_fd, SNDCTL_DSP_GETCAPS, &caps) == -1) {
|
||||
perror ("/dev/dsp");
|
||||
perror (snd_dev);
|
||||
Con_Printf ("Sound driver too old\n");
|
||||
close (audio_fd);
|
||||
return 0;
|
||||
|
@ -107,11 +108,8 @@ SNDDMA_Init (void)
|
|||
|
||||
// set sample bits & speed
|
||||
|
||||
s = getenv ("QUAKE_SOUND_SAMPLEBITS");
|
||||
if (s)
|
||||
shm->samplebits = atoi (s);
|
||||
else if ((i = COM_CheckParm ("-sndbits")) != 0)
|
||||
shm->samplebits = atoi (com_argv[i + 1]);
|
||||
if (snd_bits->int_val)
|
||||
shm->samplebits = snd_bits->int_val;
|
||||
if (shm->samplebits != 16 && shm->samplebits != 8) {
|
||||
ioctl (audio_fd, SNDCTL_DSP_GETFMTS, &fmt);
|
||||
if (fmt & AFMT_S16_LE)
|
||||
|
@ -120,11 +118,8 @@ SNDDMA_Init (void)
|
|||
shm->samplebits = 8;
|
||||
}
|
||||
|
||||
s = getenv ("QUAKE_SOUND_SPEED");
|
||||
if (s)
|
||||
shm->speed = atoi (s);
|
||||
else if ((i = COM_CheckParm ("-sndspeed")) != 0)
|
||||
shm->speed = atoi (com_argv[i + 1]);
|
||||
if (snd_rate->int_val)
|
||||
shm->speed = snd_rate->int_val;
|
||||
else {
|
||||
for (i = 0; i < sizeof (tryrates) / 4; i++)
|
||||
if (!ioctl (audio_fd, SNDCTL_DSP_SPEED, &tryrates[i]))
|
||||
|
@ -132,13 +127,8 @@ SNDDMA_Init (void)
|
|||
shm->speed = tryrates[i];
|
||||
}
|
||||
|
||||
s = getenv ("QUAKE_SOUND_CHANNELS");
|
||||
if (s)
|
||||
shm->channels = atoi (s);
|
||||
else if ((i = COM_CheckParm ("-sndmono")) != 0)
|
||||
if (!snd_stereo->int_val)
|
||||
shm->channels = 1;
|
||||
else if ((i = COM_CheckParm ("-sndstereo")) != 0)
|
||||
shm->channels = 2;
|
||||
else
|
||||
shm->channels = 2;
|
||||
|
||||
|
@ -152,8 +142,8 @@ SNDDMA_Init (void)
|
|||
PROT_READ | PROT_WRITE,
|
||||
MAP_FILE | MAP_SHARED, audio_fd, 0);
|
||||
if (!shm->buffer || shm->buffer == MAP_FAILED) {
|
||||
perror ("/dev/dsp");
|
||||
Con_Printf ("Could not mmap /dev/dsp\n");
|
||||
perror (snd_dev);
|
||||
Con_Printf ("Could not mmap %s\n", snd_dev);
|
||||
close (audio_fd);
|
||||
return 0;
|
||||
}
|
||||
|
@ -163,8 +153,8 @@ SNDDMA_Init (void)
|
|||
tmp = 1;
|
||||
rc = ioctl (audio_fd, SNDCTL_DSP_STEREO, &tmp);
|
||||
if (rc < 0) {
|
||||
perror ("/dev/dsp");
|
||||
Con_Printf ("Could not set /dev/dsp to stereo=%d", shm->channels);
|
||||
perror (snd_dev);
|
||||
Con_Printf ("Could not set %s to stereo=%d", snd_dev, shm->channels);
|
||||
close (audio_fd);
|
||||
return 0;
|
||||
}
|
||||
|
@ -175,8 +165,8 @@ SNDDMA_Init (void)
|
|||
|
||||
rc = ioctl (audio_fd, SNDCTL_DSP_SPEED, &shm->speed);
|
||||
if (rc < 0) {
|
||||
perror ("/dev/dsp");
|
||||
Con_Printf ("Could not set /dev/dsp speed to %d", shm->speed);
|
||||
perror (snd_dev);
|
||||
Con_Printf ("Could not set %s speed to %d", snd_dev, shm->speed);
|
||||
close (audio_fd);
|
||||
return 0;
|
||||
}
|
||||
|
@ -185,7 +175,7 @@ SNDDMA_Init (void)
|
|||
rc = AFMT_S16_LE;
|
||||
rc = ioctl (audio_fd, SNDCTL_DSP_SETFMT, &rc);
|
||||
if (rc < 0) {
|
||||
perror ("/dev/dsp");
|
||||
perror (snd_dev);
|
||||
Con_Printf ("Could not support 16-bit data. Try 8-bit.\n");
|
||||
close (audio_fd);
|
||||
return 0;
|
||||
|
@ -194,13 +184,13 @@ SNDDMA_Init (void)
|
|||
rc = AFMT_U8;
|
||||
rc = ioctl (audio_fd, SNDCTL_DSP_SETFMT, &rc);
|
||||
if (rc < 0) {
|
||||
perror ("/dev/dsp");
|
||||
perror (snd_dev);
|
||||
Con_Printf ("Could not support 8-bit data.\n");
|
||||
close (audio_fd);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
perror ("/dev/dsp");
|
||||
perror (snd_dev);
|
||||
Con_Printf ("%d-bit sound not supported.", shm->samplebits);
|
||||
close (audio_fd);
|
||||
return 0;
|
||||
|
@ -211,7 +201,7 @@ SNDDMA_Init (void)
|
|||
tmp = 0;
|
||||
rc = ioctl (audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp);
|
||||
if (rc < 0) {
|
||||
perror ("/dev/dsp");
|
||||
perror (snd_dev);
|
||||
Con_Printf ("Could not toggle.\n");
|
||||
close (audio_fd);
|
||||
return 0;
|
||||
|
@ -219,7 +209,7 @@ SNDDMA_Init (void)
|
|||
tmp = PCM_ENABLE_OUTPUT;
|
||||
rc = ioctl (audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp);
|
||||
if (rc < 0) {
|
||||
perror ("/dev/dsp");
|
||||
perror (snd_dev);
|
||||
Con_Printf ("Could not toggle.\n");
|
||||
close (audio_fd);
|
||||
return 0;
|
||||
|
@ -242,7 +232,7 @@ SNDDMA_GetDMAPos (void)
|
|||
return 0;
|
||||
|
||||
if (ioctl (audio_fd, SNDCTL_DSP_GETOPTR, &count) == -1) {
|
||||
perror ("/dev/dsp");
|
||||
perror (snd_dev);
|
||||
Con_Printf ("Uh, sound dead.\n");
|
||||
close (audio_fd);
|
||||
snd_inited = 0;
|
||||
|
|
Loading…
Reference in a new issue