mirror of
https://github.com/Stichting-MINIX-Research-Foundation/pkgsrc-ng.git
synced 2025-08-03 09:48:00 -04:00
177 lines
4.5 KiB
Plaintext
177 lines
4.5 KiB
Plaintext
$NetBSD: patch-ad,v 1.5 2009/08/29 19:26:01 wiz Exp $
|
|
|
|
--- QW/client/snd_linux.c.orig 1997-07-07 20:08:00.000000000 +0000
|
|
+++ QW/client/snd_linux.c
|
|
@@ -6,15 +6,42 @@
|
|
#include <sys/mman.h>
|
|
#include <sys/shm.h>
|
|
#include <sys/wait.h>
|
|
+
|
|
+#ifdef __NetBSD__
|
|
+#include <soundcard.h>
|
|
+#endif
|
|
+
|
|
+#if defined(__DragonFly__)
|
|
+#include <sys/soundcard.h>
|
|
+#endif
|
|
+
|
|
+#ifdef __linux__
|
|
#include <linux/soundcard.h>
|
|
+#endif
|
|
+
|
|
#include <stdio.h>
|
|
#include "quakedef.h"
|
|
|
|
-int audio_fd;
|
|
+int audio_fd = -1;
|
|
int snd_inited;
|
|
|
|
static int tryrates[] = { 11025, 22051, 44100, 8000 };
|
|
|
|
+#ifdef __linux__
|
|
+const char *audio_device="/dev/dsp";
|
|
+#define MMAP_PROTECTION PROT_WRITE
|
|
+#endif
|
|
+
|
|
+#ifdef __NetBSD__
|
|
+const char *audio_device="/dev/audio";
|
|
+#define MMAP_PROTECTION PROT_WRITE|PROT_READ
|
|
+#endif
|
|
+
|
|
+#if defined(__DragonFly__)
|
|
+const char *audio_device="/dev/audio";
|
|
+#define MMAP_PROTECTION PROT_WRITE|PROT_READ
|
|
+#endif
|
|
+
|
|
qboolean SNDDMA_Init(void)
|
|
{
|
|
|
|
@@ -28,28 +55,29 @@ qboolean SNDDMA_Init(void)
|
|
|
|
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 +139,11 @@ qboolean SNDDMA_Init(void)
|
|
// 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 +154,8 @@ qboolean SNDDMA_Init(void)
|
|
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 +167,8 @@ qboolean 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(audio_device);
|
|
+ Con_Printf("Could not set %s speed to %d", audio_device, shm->speed);
|
|
close(audio_fd);
|
|
return 0;
|
|
}
|
|
@@ -151,7 +179,7 @@ qboolean SNDDMA_Init(void)
|
|
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 +191,7 @@ qboolean SNDDMA_Init(void)
|
|
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 +199,7 @@ qboolean SNDDMA_Init(void)
|
|
}
|
|
else
|
|
{
|
|
- perror("/dev/dsp");
|
|
+ perror(audio_device);
|
|
Con_Printf("%d-bit sound not supported.", shm->samplebits);
|
|
close(audio_fd);
|
|
return 0;
|
|
@@ -183,7 +211,7 @@ qboolean SNDDMA_Init(void)
|
|
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 +220,7 @@ qboolean SNDDMA_Init(void)
|
|
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 +242,7 @@ int SNDDMA_GetDMAPos(void)
|
|
|
|
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;
|