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
|
$NetBSD: patch-ab,v 1.8 2013/01/06 00:59:47 ryoon Exp $
--- src/sl/slDSP.cxx.orig Tue Mar 11 02:06:24 2008
+++ src/sl/slDSP.cxx
@@ -413,7 +413,7 @@ void slDSP::stop ()
/* NetBSD/OpenBSD 2.3 this should be very close to SUN Audio */
/* ------------------------------------------------------------ */
-#elif (defined(UL_BSD) && !defined(__FreeBSD__)) || defined(UL_SOLARIS)
+#elif (defined(UL_BSD) && !defined(SL_USING_SNDIO) && !defined(__FreeBSD__) && !defined(__DragonFly__)) || defined(UL_SOLARIS)
void slDSP::open ( const char *device, int _rate, int _stereo, int _bps )
{
@@ -1082,4 +1082,138 @@ float slDSP::secondsUsed ()
#endif
+#if defined(SL_USING_SNDIO)
+#include <poll.h>
+
+static long long realpos, playpos;
+
+void
+movecb(void *v, int delta)
+{
+ realpos += delta;
+}
+
+void
+slDSP::open(const char *device, int _rate, int _stereo, int _bps )
+{
+ error = SL_FALSE;
+
+ if (!strncmp(device, "default", FILENAME_MAX))
+ hdl = sio_open(NULL, SIO_PLAY, 0);
+ else
+ hdl = sio_open(device, SIO_PLAY, 0);
+ if (hdl == NULL) {
+ error = SL_TRUE;
+ fprintf(stderr, "slDSP: open\n");
+ return;
+ }
+
+ sio_initpar(&par);
+ par.pchan = _stereo ? 2 : 1;
+ par.bits = _bps;
+ par.rate = _rate;
+ par.appbufsz = 4096;
+
+ realpos = playpos = 0;
+ sio_onmove(hdl, movecb, NULL);
+
+ if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par) ||
+ !sio_start(hdl)) {
+ fprintf(stderr, "slDSP: sndio params\n");
+ error = SL_TRUE;
+ return;
+ }
+
+ bps = par.bits;
+ rate = par.rate;
+ stereo = par.pchan == 2 ? SL_TRUE : SL_FALSE;
+}
+
+void
+slDSP::close()
+{
+ if (hdl != NULL)
+ sio_close(hdl);
+ hdl = NULL;
+}
+
+int
+slDSP::getDriverBufferSize()
+{
+ if (error)
+ return 0;
+
+ return par.round * par.bps * par.pchan;
+}
+
+void
+slDSP::getBufferInfo()
+{
+ struct pollfd pfd;
+ nfds_t nfd;
+
+ if (error)
+ return;
+
+ /* updates counters */
+ nfd = sio_pollfd(hdl, &pfd, POLLOUT);
+ poll(&pfd, nfd, 0);
+ sio_revents(hdl, &pfd);
+}
+
+void
+slDSP::write(void *buffer, size_t length)
+{
+ int ret, todo, pos;
+
+ if (error || (int)length <= 0)
+ return;
+
+ pos = 0;
+ todo = length;
+ while (todo > 0) {
+ ret = sio_write(hdl, (char *)buffer + pos, todo);
+ pos += ret;
+ todo -= ret;
+ }
+ playpos += length / par.bps / par.pchan;
+}
+
+float
+slDSP::secondsRemaining()
+{
+ if (error)
+ return 0.0f;
+
+ getBufferInfo();
+
+ /* wtf? tuxkart won't play sounds if less ??? */
+ return 0.1f;
+ return((float)(par.appbufsz - (playpos - realpos)) / par.rate);
+}
+
+float
+slDSP::secondsUsed()
+{
+ if (error)
+ return 0.0f ;
+
+ getBufferInfo();
+
+ if (realpos > playpos)
+ return 0.0f;
+
+ return((float)(playpos - realpos) / par.rate);
+}
+
+void
+slDSP::sync()
+{
+}
+
+void slDSP::stop()
+{
+}
+
+#endif
|