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 *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;
|
||||||
|
|
||||||
|
|
|
@ -125,14 +125,11 @@ SNDDMA_Init (void)
|
||||||
Con_Printf ("No sound cards detected\n");
|
Con_Printf ("No sound cards detected\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if ((i = COM_CheckParm ("-sndcard")) != 0) {
|
if (snd_device->string[0]) {
|
||||||
card = atoi (com_argv[i + 1]);
|
sscanf (snd_device->string, "%d,%d", &card, &dev);
|
||||||
}
|
}
|
||||||
if ((i = COM_CheckParm ("-snddev")) != 0) {
|
if (snd_bits->int_val) {
|
||||||
dev = atoi (com_argv[i + 1]);
|
i = snd_bits->int_val;
|
||||||
}
|
|
||||||
if ((i = COM_CheckParm ("-sndbits")) != 0) {
|
|
||||||
i = atoi (com_argv[i + 1]);
|
|
||||||
if (i == 16) {
|
if (i == 16) {
|
||||||
format = SND_PCM_SFMT_S16_LE;
|
format = SND_PCM_SFMT_S16_LE;
|
||||||
} else if (i == 8) {
|
} else if (i == 8) {
|
||||||
|
@ -142,16 +139,14 @@ SNDDMA_Init (void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((i = COM_CheckParm ("-sndspeed")) != 0) {
|
if (snd_rate->int_val) {
|
||||||
rate = atoi (com_argv[i + 1]);
|
rate = snd_rate->int_val;
|
||||||
if (rate != 44100 && rate != 22050 && rate != 11025) {
|
if (rate != 44100 && rate != 22050 && rate != 11025) {
|
||||||
Con_Printf ("Error: invalid sample rate: %d\n", rate);
|
Con_Printf ("Error: invalid sample rate: %d\n", rate);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((i = COM_CheckParm ("-sndmono")) != 0) {
|
stereo = snd_stereo->int_val;
|
||||||
stereo = 0;
|
|
||||||
}
|
|
||||||
if (card == -1) {
|
if (card == -1) {
|
||||||
for (card = 0; card < SND_CARDS; card++) {
|
for (card = 0; card < SND_CARDS; card++) {
|
||||||
if (!(mask & (1 << card)))
|
if (!(mask & (1 << card)))
|
||||||
|
|
|
@ -50,7 +50,7 @@ size_t buffer_size;
|
||||||
qboolean
|
qboolean
|
||||||
SNDDMA_Init (void)
|
SNDDMA_Init (void)
|
||||||
{
|
{
|
||||||
int err, i;
|
int err;
|
||||||
int rate = -1, bps = -1, stereo = -1, frag_size;
|
int rate = -1, bps = -1, stereo = -1, frag_size;
|
||||||
snd_pcm_hw_params_t *hw;
|
snd_pcm_hw_params_t *hw;
|
||||||
snd_pcm_sw_params_t *sw;
|
snd_pcm_sw_params_t *sw;
|
||||||
|
@ -58,29 +58,23 @@ SNDDMA_Init (void)
|
||||||
snd_pcm_hw_params_alloca (&hw);
|
snd_pcm_hw_params_alloca (&hw);
|
||||||
snd_pcm_sw_params_alloca (&sw);
|
snd_pcm_sw_params_alloca (&sw);
|
||||||
|
|
||||||
if ((i = COM_CheckParm ("-sndpcm")) != 0) {
|
if (snd_device->string[0])
|
||||||
pcmname = com_argv[i + 1];
|
pcmname = snd_device->string;
|
||||||
}
|
if (snd_bits->int_val) {
|
||||||
if ((i = COM_CheckParm ("-sndbits")) != 0) {
|
bps = snd_bits->int_val;
|
||||||
bps = atoi (com_argv[i + 1]);
|
|
||||||
if (bps != 16 && bps != 8) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((i = COM_CheckParm ("-sndspeed")) != 0) {
|
if (snd_rate->int_val) {
|
||||||
rate = atoi (com_argv[i + 1]);
|
rate = snd_rate->int_val;
|
||||||
if (rate != 44100 && rate != 22050 && rate != 11025) {
|
if (rate != 44100 && rate != 22050 && rate != 11025) {
|
||||||
Con_Printf ("Error: invalid sample rate: %d\n", rate);
|
Con_Printf ("Error: invalid sample rate: %d\n", rate);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((i = COM_CheckParm ("-sndmono")) != 0) {
|
stereo = snd_stereo->int_val;
|
||||||
stereo = 0;
|
|
||||||
}
|
|
||||||
if ((i = COM_CheckParm ("-sndstereo")) != 0) {
|
|
||||||
stereo = 1;
|
|
||||||
}
|
|
||||||
if (!pcmname)
|
if (!pcmname)
|
||||||
pcmname = "plug:0,0";
|
pcmname = "plug:0,0";
|
||||||
if ((err = snd_pcm_open (&pcm, pcmname,
|
if ((err = snd_pcm_open (&pcm, pcmname,
|
||||||
|
|
|
@ -91,6 +91,10 @@ 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;
|
||||||
|
@ -200,6 +204,14 @@ S_Init (void)
|
||||||
Cmd_AddCommand ("soundlist", S_SoundList, "No Description");
|
Cmd_AddCommand ("soundlist", S_SoundList, "No Description");
|
||||||
Cmd_AddCommand ("soundinfo", S_SoundInfo_f, "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");
|
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");
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
snd_oss.c
|
snd_oss.c
|
||||||
|
|
||||||
|
@ -46,8 +45,9 @@
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
#include "qargs.h"
|
#include "qargs.h"
|
||||||
|
|
||||||
int audio_fd;
|
static int audio_fd;
|
||||||
int snd_inited;
|
static int snd_inited;
|
||||||
|
static char *snd_dev = "/dev/dsp";
|
||||||
|
|
||||||
static int tryrates[] = { 11025, 22051, 44100, 8000 };
|
static int tryrates[] = { 11025, 22051, 44100, 8000 };
|
||||||
|
|
||||||
|
@ -59,31 +59,32 @@ SNDDMA_Init (void)
|
||||||
int fmt;
|
int fmt;
|
||||||
int tmp;
|
int tmp;
|
||||||
int i;
|
int i;
|
||||||
char *s;
|
|
||||||
struct audio_buf_info info;
|
struct audio_buf_info info;
|
||||||
int caps;
|
int caps;
|
||||||
|
|
||||||
snd_inited = 0;
|
snd_inited = 0;
|
||||||
|
|
||||||
// open /dev/dsp, confirm capability to mmap, and get size of dma buffer
|
// 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) {
|
if (audio_fd < 0) {
|
||||||
perror ("/dev/dsp");
|
perror (snd_dev);
|
||||||
Con_Printf ("Could not open /dev/dsp\n");
|
Con_Printf ("Could not open %s\n", snd_dev);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = ioctl (audio_fd, SNDCTL_DSP_RESET, 0);
|
rc = ioctl (audio_fd, SNDCTL_DSP_RESET, 0);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
perror ("/dev/dsp");
|
perror (snd_dev);
|
||||||
Con_Printf ("Could not reset /dev/dsp\n");
|
Con_Printf ("Could not reset %s\n", snd_dev);
|
||||||
close (audio_fd);
|
close (audio_fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl (audio_fd, SNDCTL_DSP_GETCAPS, &caps) == -1) {
|
if (ioctl (audio_fd, SNDCTL_DSP_GETCAPS, &caps) == -1) {
|
||||||
perror ("/dev/dsp");
|
perror (snd_dev);
|
||||||
Con_Printf ("Sound driver too old\n");
|
Con_Printf ("Sound driver too old\n");
|
||||||
close (audio_fd);
|
close (audio_fd);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -107,11 +108,8 @@ SNDDMA_Init (void)
|
||||||
|
|
||||||
// set sample bits & speed
|
// set sample bits & speed
|
||||||
|
|
||||||
s = getenv ("QUAKE_SOUND_SAMPLEBITS");
|
if (snd_bits->int_val)
|
||||||
if (s)
|
shm->samplebits = snd_bits->int_val;
|
||||||
shm->samplebits = atoi (s);
|
|
||||||
else if ((i = COM_CheckParm ("-sndbits")) != 0)
|
|
||||||
shm->samplebits = atoi (com_argv[i + 1]);
|
|
||||||
if (shm->samplebits != 16 && shm->samplebits != 8) {
|
if (shm->samplebits != 16 && shm->samplebits != 8) {
|
||||||
ioctl (audio_fd, SNDCTL_DSP_GETFMTS, &fmt);
|
ioctl (audio_fd, SNDCTL_DSP_GETFMTS, &fmt);
|
||||||
if (fmt & AFMT_S16_LE)
|
if (fmt & AFMT_S16_LE)
|
||||||
|
@ -120,11 +118,8 @@ SNDDMA_Init (void)
|
||||||
shm->samplebits = 8;
|
shm->samplebits = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = getenv ("QUAKE_SOUND_SPEED");
|
if (snd_rate->int_val)
|
||||||
if (s)
|
shm->speed = snd_rate->int_val;
|
||||||
shm->speed = atoi (s);
|
|
||||||
else if ((i = COM_CheckParm ("-sndspeed")) != 0)
|
|
||||||
shm->speed = atoi (com_argv[i + 1]);
|
|
||||||
else {
|
else {
|
||||||
for (i = 0; i < sizeof (tryrates) / 4; i++)
|
for (i = 0; i < sizeof (tryrates) / 4; i++)
|
||||||
if (!ioctl (audio_fd, SNDCTL_DSP_SPEED, &tryrates[i]))
|
if (!ioctl (audio_fd, SNDCTL_DSP_SPEED, &tryrates[i]))
|
||||||
|
@ -132,13 +127,8 @@ SNDDMA_Init (void)
|
||||||
shm->speed = tryrates[i];
|
shm->speed = tryrates[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
s = getenv ("QUAKE_SOUND_CHANNELS");
|
if (!snd_stereo->int_val)
|
||||||
if (s)
|
|
||||||
shm->channels = atoi (s);
|
|
||||||
else if ((i = COM_CheckParm ("-sndmono")) != 0)
|
|
||||||
shm->channels = 1;
|
shm->channels = 1;
|
||||||
else if ((i = COM_CheckParm ("-sndstereo")) != 0)
|
|
||||||
shm->channels = 2;
|
|
||||||
else
|
else
|
||||||
shm->channels = 2;
|
shm->channels = 2;
|
||||||
|
|
||||||
|
@ -152,8 +142,8 @@ SNDDMA_Init (void)
|
||||||
PROT_READ | PROT_WRITE,
|
PROT_READ | PROT_WRITE,
|
||||||
MAP_FILE | MAP_SHARED, audio_fd, 0);
|
MAP_FILE | MAP_SHARED, audio_fd, 0);
|
||||||
if (!shm->buffer || shm->buffer == MAP_FAILED) {
|
if (!shm->buffer || shm->buffer == MAP_FAILED) {
|
||||||
perror ("/dev/dsp");
|
perror (snd_dev);
|
||||||
Con_Printf ("Could not mmap /dev/dsp\n");
|
Con_Printf ("Could not mmap %s\n", snd_dev);
|
||||||
close (audio_fd);
|
close (audio_fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -163,8 +153,8 @@ SNDDMA_Init (void)
|
||||||
tmp = 1;
|
tmp = 1;
|
||||||
rc = ioctl (audio_fd, SNDCTL_DSP_STEREO, &tmp);
|
rc = ioctl (audio_fd, SNDCTL_DSP_STEREO, &tmp);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
perror ("/dev/dsp");
|
perror (snd_dev);
|
||||||
Con_Printf ("Could not set /dev/dsp to stereo=%d", shm->channels);
|
Con_Printf ("Could not set %s to stereo=%d", snd_dev, shm->channels);
|
||||||
close (audio_fd);
|
close (audio_fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -175,8 +165,8 @@ SNDDMA_Init (void)
|
||||||
|
|
||||||
rc = ioctl (audio_fd, SNDCTL_DSP_SPEED, &shm->speed);
|
rc = ioctl (audio_fd, SNDCTL_DSP_SPEED, &shm->speed);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
perror ("/dev/dsp");
|
perror (snd_dev);
|
||||||
Con_Printf ("Could not set /dev/dsp speed to %d", shm->speed);
|
Con_Printf ("Could not set %s speed to %d", snd_dev, shm->speed);
|
||||||
close (audio_fd);
|
close (audio_fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -185,7 +175,7 @@ SNDDMA_Init (void)
|
||||||
rc = AFMT_S16_LE;
|
rc = AFMT_S16_LE;
|
||||||
rc = ioctl (audio_fd, SNDCTL_DSP_SETFMT, &rc);
|
rc = ioctl (audio_fd, SNDCTL_DSP_SETFMT, &rc);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
perror ("/dev/dsp");
|
perror (snd_dev);
|
||||||
Con_Printf ("Could not support 16-bit data. Try 8-bit.\n");
|
Con_Printf ("Could not support 16-bit data. Try 8-bit.\n");
|
||||||
close (audio_fd);
|
close (audio_fd);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -194,13 +184,13 @@ SNDDMA_Init (void)
|
||||||
rc = AFMT_U8;
|
rc = AFMT_U8;
|
||||||
rc = ioctl (audio_fd, SNDCTL_DSP_SETFMT, &rc);
|
rc = ioctl (audio_fd, SNDCTL_DSP_SETFMT, &rc);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
perror ("/dev/dsp");
|
perror (snd_dev);
|
||||||
Con_Printf ("Could not support 8-bit data.\n");
|
Con_Printf ("Could not support 8-bit data.\n");
|
||||||
close (audio_fd);
|
close (audio_fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
perror ("/dev/dsp");
|
perror (snd_dev);
|
||||||
Con_Printf ("%d-bit sound not supported.", shm->samplebits);
|
Con_Printf ("%d-bit sound not supported.", shm->samplebits);
|
||||||
close (audio_fd);
|
close (audio_fd);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -211,7 +201,7 @@ SNDDMA_Init (void)
|
||||||
tmp = 0;
|
tmp = 0;
|
||||||
rc = ioctl (audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp);
|
rc = ioctl (audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
perror ("/dev/dsp");
|
perror (snd_dev);
|
||||||
Con_Printf ("Could not toggle.\n");
|
Con_Printf ("Could not toggle.\n");
|
||||||
close (audio_fd);
|
close (audio_fd);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -219,7 +209,7 @@ SNDDMA_Init (void)
|
||||||
tmp = PCM_ENABLE_OUTPUT;
|
tmp = PCM_ENABLE_OUTPUT;
|
||||||
rc = ioctl (audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp);
|
rc = ioctl (audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
perror ("/dev/dsp");
|
perror (snd_dev);
|
||||||
Con_Printf ("Could not toggle.\n");
|
Con_Printf ("Could not toggle.\n");
|
||||||
close (audio_fd);
|
close (audio_fd);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -242,7 +232,7 @@ SNDDMA_GetDMAPos (void)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (ioctl (audio_fd, SNDCTL_DSP_GETOPTR, &count) == -1) {
|
if (ioctl (audio_fd, SNDCTL_DSP_GETOPTR, &count) == -1) {
|
||||||
perror ("/dev/dsp");
|
perror (snd_dev);
|
||||||
Con_Printf ("Uh, sound dead.\n");
|
Con_Printf ("Uh, sound dead.\n");
|
||||||
close (audio_fd);
|
close (audio_fd);
|
||||||
snd_inited = 0;
|
snd_inited = 0;
|
||||||
|
|
Loading…
Reference in a new issue