$NetBSD: patch-ad,v 1.2 2000/02/01 02:30:33 wiz Exp $ --- QW/client/snd_linux.c Mon Jul 7 20:08:00 1997 +++ ../work/QW/client/snd_linux.c Sun Jan 16 19:35:45 2000 @@ -6,15 +6,33 @@ #include #include #include + +#ifdef __NetBSD__ +#include +#endif + +#ifdef __linux__ #include +#endif + #include #include "quakedef.h" -int audio_fd; +int audio_fd = -1; int snd_inited; static int tryrates[] = { 11025, 22051, 44100, 8000 }; +#ifdef __linux__ +char *audio_device="/dev/dsp"; +#define MMAP_PROTECTION PROT_WRITE +#endif + +#ifdef __NetBSD__ +char *audio_device="/dev/audio"; +#define MMAP_PROTECTION PROT_WRITE|PROT_READ +#endif + qboolean SNDDMA_Init(void) { @@ -28,28 +46,29 @@ snd_inited = 0; -// open /dev/dsp, confirm capability to mmap, and get size of dma buffer +// open /dev/dsp or whatever, confirm capability to mmap, and get size of +// dma buffer - audio_fd = open("/dev/dsp", O_RDWR); + audio_fd = open(audio_device, O_RDWR); if (audio_fd < 0) { - perror("/dev/dsp"); - Con_Printf("Could not open /dev/dsp\n"); + perror(audio_device); + Con_Printf("Could not open %s\n",audio_device); 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(audio_device); + Con_Printf("Could not reset %s\n",audio_device); close(audio_fd); return 0; } if (ioctl(audio_fd, SNDCTL_DSP_GETCAPS, &caps)==-1) { - perror("/dev/dsp"); + perror(audio_device); Con_Printf("Sound driver too old\n"); close(audio_fd); return 0; @@ -111,11 +130,11 @@ // memory map the dma buffer shm->buffer = (unsigned char *) mmap(NULL, info.fragstotal - * info.fragsize, PROT_WRITE, MAP_FILE|MAP_SHARED, audio_fd, 0); + * info.fragsize, MMAP_PROTECTION, MAP_FILE|MAP_SHARED, audio_fd, 0); if (!shm->buffer) { - perror("/dev/dsp"); - Con_Printf("Could not mmap /dev/dsp\n"); + perror(audio_device); + Con_Printf("Could not mmap %s\n",audio_device); close(audio_fd); return 0; } @@ -126,8 +145,8 @@ 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(audio_device); + Con_Printf("Could not set %s to stereo=%d", audio_device, shm->channels); close(audio_fd); return 0; } @@ -139,8 +158,8 @@ 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(audio_device); + Con_Printf("Could not set %s speed to %d", audio_device, shm->speed); close(audio_fd); return 0; } @@ -151,7 +170,7 @@ rc = ioctl(audio_fd, SNDCTL_DSP_SETFMT, &rc); if (rc < 0) { - perror("/dev/dsp"); + perror(audio_device); Con_Printf("Could not support 16-bit data. Try 8-bit.\n"); close(audio_fd); return 0; @@ -163,7 +182,7 @@ rc = ioctl(audio_fd, SNDCTL_DSP_SETFMT, &rc); if (rc < 0) { - perror("/dev/dsp"); + perror(audio_device); Con_Printf("Could not support 8-bit data.\n"); close(audio_fd); return 0; @@ -171,7 +190,7 @@ } else { - perror("/dev/dsp"); + perror(audio_device); Con_Printf("%d-bit sound not supported.", shm->samplebits); close(audio_fd); return 0; @@ -183,7 +202,7 @@ rc = ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp); if (rc < 0) { - perror("/dev/dsp"); + perror(audio_device); Con_Printf("Could not toggle.\n"); close(audio_fd); return 0; @@ -192,7 +211,7 @@ rc = ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp); if (rc < 0) { - perror("/dev/dsp"); + perror(audio_device); Con_Printf("Could not toggle.\n"); close(audio_fd); return 0; @@ -214,7 +233,7 @@ if (ioctl(audio_fd, SNDCTL_DSP_GETOPTR, &count)==-1) { - perror("/dev/dsp"); + perror(audio_device); Con_Printf("Uh, sound dead.\n"); close(audio_fd); snd_inited = 0;