summaryrefslogtreecommitdiff
path: root/games/quake/patches/patch-ad
blob: 12cfb9274e7474e98c03bbfdbbb0770ebca0d8c6 (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
168
169
170
171
172
173
174
175
176
$NetBSD: patch-ad,v 1.4 2006/05/12 12:40:10 joerg 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;