summaryrefslogtreecommitdiff
path: root/games/quake/patches/patch-ad
blob: 9f29dc2dae9fa371a294dbb1292e1d70707629fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
$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 <sys/mman.h>
 #include <sys/shm.h>
 #include <sys/wait.h>
+
+#ifdef __NetBSD__
+#include <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__
+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;