Largely whitespace, some opts, reverse order in which command-line parms

and environment variables are used. Command-line should ALWAYS override
the environment.
This commit is contained in:
Jeff Teunissen 2000-12-08 04:40:02 +00:00
parent ebc281c279
commit d3da228aef

View file

@ -84,7 +84,6 @@ SNDDMA_Init(void)
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
audio_fd = open ("/dev/dsp", O_RDWR); audio_fd = open ("/dev/dsp", O_RDWR);
if (audio_fd < 0) { // Failed open, retry up to 3 times if it's busy if (audio_fd < 0) { // Failed open, retry up to 3 times if it's busy
while ((audio_fd < 0) && retries-- && while ((audio_fd < 0) && retries-- &&
@ -99,32 +98,27 @@ SNDDMA_Init(void)
} }
} }
rc = ioctl(audio_fd, SNDCTL_DSP_RESET, 0); if ((rc = ioctl (audio_fd, SNDCTL_DSP_RESET, 0)) < 0) {
if (rc < 0)
{
perror ("/dev/dsp"); perror ("/dev/dsp");
Con_Printf ("Could not reset /dev/dsp\n"); Con_Printf ("Could not reset /dev/dsp\n");
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 ("/dev/dsp");
Con_Printf ("Sound driver too old\n"); Con_Printf ("Sound driver too old\n");
close (audio_fd); close (audio_fd);
return 0; return 0;
} }
if (!(caps & DSP_CAP_TRIGGER) || !(caps & DSP_CAP_MMAP)) if (!(caps & DSP_CAP_TRIGGER) || !(caps & DSP_CAP_MMAP)) {
{ Con_Printf ("Error: Sound device can't do memory-mapped I/O.\n");
Con_Printf("Sorry but your soundcard can't do this\n");
close (audio_fd); close (audio_fd);
return 0; return 0;
} }
if (ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info)==-1) if (ioctl (audio_fd, SNDCTL_DSP_GETOSPACE, &info) == -1) {
{
perror ("GETOSPACE"); perror ("GETOSPACE");
Con_Printf ("Um, can't do GETOSPACE?\n"); Con_Printf ("Um, can't do GETOSPACE?\n");
close (audio_fd); close (audio_fd);
@ -135,42 +129,51 @@ SNDDMA_Init(void)
shm->splitbuffer = 0; shm->splitbuffer = 0;
// set sample bits & speed // set sample bits & speed
if ((i = COM_CheckParm ("-sndbits"))) {
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]); shm->samplebits = atoi (com_argv[i+1]);
if (shm->samplebits != 16 && shm->samplebits != 8) } else {
{ if ((s = getenv ("QF_SND_BITS"))) {
ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &fmt); shm->samplebits = atoi (s);
if (fmt & AFMT_S16_LE) shm->samplebits = 16; }
else if (fmt & AFMT_U8) shm->samplebits = 8;
} }
s = getenv("QUAKE_SOUND_SPEED"); if (shm->samplebits != 16 && shm->samplebits != 8) {
if (s) shm->speed = atoi(s); ioctl (audio_fd, SNDCTL_DSP_GETFMTS, &fmt);
else if ((i = COM_CheckParm("-sndspeed")) != 0)
if (fmt & AFMT_S16_LE) { // little-endian 16-bit signed
shm->samplebits = 16;
} else {
if (fmt & AFMT_U8) { // unsigned 8-bit ulaw
shm->samplebits = 8;
}
}
}
if ((i = COM_CheckParm ("-sndspeed"))) {
shm->speed = atoi (com_argv[i+1]); shm->speed = atoi (com_argv[i+1]);
else } else if ((s = getenv ("QF_SND_SPEED"))) {
{ shm->speed = atoi (s);
for (i=0 ; i<sizeof(tryrates)/4 ; i++) } else {
if (!ioctl(audio_fd, SNDCTL_DSP_SPEED, &tryrates[i])) break; for (i = 0; i < (sizeof (tryrates) / 4); i++)
if (!ioctl (audio_fd, SNDCTL_DSP_SPEED, &tryrates[i]))
break;
shm->speed = tryrates[i]; shm->speed = tryrates[i];
} }
s = getenv("QUAKE_SOUND_CHANNELS"); if ((i = COM_CheckParm ("-sndmono"))) {
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) } else if ((i = COM_CheckParm ("-sndstereo"))) {
shm->channels = 2; shm->channels = 2;
else shm->channels = 2; } else if ((s = getenv ("QF_SND_CHANNELS"))) {
shm->channels = atoi (s);
} else {
shm->channels = 2;
}
shm->samples = info.fragstotal * info.fragsize / (shm->samplebits/8); shm->samples = info.fragstotal * info.fragsize / (shm->samplebits/8);
shm->submission_chunk = 1; shm->submission_chunk = 1;
// memory map the dma buffer // memory map the dma buffer
shm->buffer = (unsigned char *) mmap(NULL, info.fragstotal shm->buffer = (unsigned char *) mmap(NULL, info.fragstotal
* info.fragsize, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, audio_fd, 0); * info.fragsize, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, audio_fd, 0);