summaryrefslogtreecommitdiff
path: root/emulators/darcnes/patches/patch-ac
blob: a9921d42248f665d94c78a5c8b0965c983838dcd (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
$NetBSD: patch-ac,v 1.2 2000/02/14 02:44:35 wiz Exp $

--- ./snd_unix.c.orig	Wed Jan 26 21:22:18 2000
+++ ./snd_unix.c	Mon Feb 14 00:38:09 2000
@@ -8,13 +8,21 @@
 
 /* #define SOUND_LINUX */	/* use linux sound header */
-#define SOUND_FREEBSD		/* use freebsd sound header */
+/* #define SOUND_FREEBSD */	/* use freebsd sound header */
+#define SOUND_NETBSD		/* use netbsd sound system */
 
 #ifdef SOUND_LINUX
 #define SOUND_HEADER <sys/soundcard.h>
+#define SOUND_DEVICE "/dev/dsp"
 #endif
 
 #ifdef SOUND_FREEBSD
 #define SOUND_HEADER <machine/soundcard.h>
+#define SOUND_DEVICE "/dev/dsp"
+#endif
+
+#ifdef SOUND_NETBSD
+#define SOUND_HEADER <sys/audioio.h>
+#define SOUND_DEVICE "/dev/sound"
 #endif
 
 #include <stdio.h>
@@ -66,16 +74,21 @@
 
 int snd_open(int samples_per_sync, int sample_rate)
 {
-    int tmp;
     int result;
+#if defined(SOUND_LINUX) || defined(SOUND_FREEBSD)
+    int tmp;
     int sound_rate;
     int sound_frag;
+#endif
+#ifdef SOUND_NETBSD
+    audio_info_t info;
+#endif    
 
     waveptr = 0;
     wavflag = 0;
     
-    printf("opening /dev/dsp...");
-    sound_fd = open("/dev/dsp", O_WRONLY);
+    printf("opening "SOUND_DEVICE"...");
+    sound_fd = open(SOUND_DEVICE, O_WRONLY);
     if (sound_fd < 0) {
 	perror("failed");
 	sound_fd = 0;
@@ -83,7 +96,8 @@
     } else {
 	printf("done.\n");
     }
-    
+
+#if defined(SOUND_LINUX) || defined(SOUND_FREEBSD)
     printf("setting unsigned 8-bit format...");
     tmp = AFMT_U8;
     result = ioctl(sound_fd, SNDCTL_DSP_SETFMT, &tmp);
@@ -132,7 +146,41 @@
     } else {
 	printf("done.\n");
     }
+#endif
+#ifdef SOUND_NETBSD
+    AUDIO_INITINFO(&info);
+    printf("setting unsigned 8-bit format...");
+    info.play.encoding = AUDIO_ENCODING_ULINEAR;
+    /* this doesn't work for me, so ignore results */
+    result = ioctl(sound_fd, AUDIO_SETINFO, &info);
+    if (result < 0)
+    {
+	perror("warning: unsigned linear mode failed, using signed");
+	info.play.encoding = AUDIO_ENCODING_SLINEAR;
+    }
 
+    printf("setting sound rate to %dHz...", sample_rate);
+    info.play.sample_rate = sample_rate;
+    /* 8 bits per sample */
+    info.play.precision = 8;
+    printf("setting mono mode...");
+    info.play.channels = 1;
+    info.mode = AUMODE_PLAY_ALL;
+    /* "frag size" */
+    info.blocksize = 1 << 8;
+    /* "number of frags", hiwater mark */
+    info.hiwat = 8;
+    result = ioctl(sound_fd, AUDIO_SETINFO, &info);
+    if (result < 0) {
+	perror("initializing sound failed");
+	close(sound_fd);
+	sound_fd = 0;
+	return 0;
+    } else {
+	printf("done.\n");
+    }
+#endif    
+    
     return 1;
 }
 
@@ -141,6 +189,7 @@
     if (sound_fd) {
 	close(sound_fd);
     }
+    sound_fd = 0;
 }
 
 /*