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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
*** dacio-linux.c.orig Wed Sep 3 14:57:59 1997
--- dacio-linux.c Wed Sep 3 14:50:20 1997
***************
*** 3,9 ****
--- 3,13 ----
#include <fcntl.h> /*O_WRONLY*/
#include <sys/ioctl.h> /*(ioctl)*/
#include <unistd.h> /*(write)*/
+ #if defined(LINUX)
#include <sys/soundcard.h> /*SNDCTL_XXX*/
+ #else
+ #include <machine/soundcard.h>
+ #endif
#include <errno.h> /*EINTR*/
#include "defs.h" /*u8,u16*/
#include "dacio.h" /*(dacioXXX)*/
***************
*** 47,53 ****
static struct {
union {
u8 *p8;
! u16 *p16;
} p;
u8 *top;
u8 *bot;
--- 51,57 ----
static struct {
union {
u8 *p8;
! i15 *p16;
} p;
u8 *top;
u8 *bot;
***************
*** 67,77 ****
exit(1);
}
#endif
! tmp = AFMT_U8;
if (ioctl(fd, SNDCTL_DSP_SETFMT, &tmp) < 0) {
perror("dacioConf");
exit(1);
}
/*fprintf(stderr, "fmt = 0x%x\n", tmp);*/
if (ioctl(fd, SNDCTL_DSP_STEREO, &dcp->stereo) < 0) {
--- 71,109 ----
exit(1);
}
#endif
! switch (dcp->bits) {
! case 0:
! case 8:
! dcp->bits = 8;
! tmp = AFMT_U8; break;
! case 16:
! tmp = AFMT_S16_LE; break;
! default:
! fprintf(stderr, "Don't know how to handle %d bit output.\n", dcp->bits);
! exit(1);
! break;
! }
!
if (ioctl(fd, SNDCTL_DSP_SETFMT, &tmp) < 0) {
perror("dacioConf");
exit(1);
}
+
+ switch (tmp) {
+ case AFMT_U8:
+ if (dcp->bits != 8) {
+ fprintf(stderr, "soundcard doesn't support 8bits.\n");
+ exit(1);
+ }
+ break;
+ case AFMT_S16_LE:
+ if (dcp->bits != 16) {
+ fprintf(stderr, "soundcard doesn't support 16bits.\n");
+ exit(1);
+ }
+ break;
+ }
+
/*fprintf(stderr, "fmt = 0x%x\n", tmp);*/
if (ioctl(fd, SNDCTL_DSP_STEREO, &dcp->stereo) < 0) {
***************
*** 90,99 ****
perror("dacioConf");
exit(1);
}
! /*fprintf(stderr, "buffer size = 0x%x\n", buf.size);*/
dci = *dcp;
/*if (buf.top != NULL) free(buf.top);*/
! buf.top = memPerm(buf.size * sizeof(u8));
buf.p.p8 = buf.top;
buf.bot = buf.top + buf.size;
}
--- 122,136 ----
perror("dacioConf");
exit(1);
}
! /*fprintf(stderr, "sound buffer size = 0x%x\n", buf.size);*/
! tmp = buf.size;
! while (tmp <= (0.1 * (dcp->speed * (dcp->stereo+1) * (dcp->bits/8))))
! tmp += buf.size;
! buf.size = tmp;
! /*fprintf(stderr, "buffer size = 0x%x\n", buf.size);*/
dci = *dcp;
/*if (buf.top != NULL) free(buf.top);*/
! buf.top = memPerm(buf.size);
buf.p.p8 = buf.top;
buf.bot = buf.top + buf.size;
}
***************
*** 115,121 ****
int s;
if (buf.p.p8 <= buf.top) return;
! for ( ; buf.p.p8 < buf.bot; buf.p.p8++) *buf.p.p8 = 128;
RETRY:
s = write(fd, buf.top, buf.size);
if (s < buf.size) {
--- 152,165 ----
int s;
if (buf.p.p8 <= buf.top) return;
! switch (dci.bits) {
! case 8:
! for ( ; buf.p.p8 < buf.bot; buf.p.p8++) *buf.p.p8 = 128;
! break;
! case 16:
! for ( ; buf.p.p8 < buf.bot; buf.p.p16++) *buf.p.p16 = 0;
! break;
! }
RETRY:
s = write(fd, buf.top, buf.size);
if (s < buf.size) {
***************
*** 179,184 ****
--- 223,230 ----
(tmpvar & ~255)? ~tmpvar >> 16 : tmpvar ) /* 16 will be OK */
/* ~(tmpvar >> 16) makes longer asm */
#endif
+ #define to16bit(x) \
+ (((x) * gv) >> 12)
/* stereo */
static void
***************
*** 186,199 ****
{
const i31 *inbufp = inbuf.p;
u8 *u8p = buf.p.p8;
! for (; n > 0; n--) {
! i31x tmp;
! *u8p++ = to8bit(*inbufp++, tmp); /* L */
! *u8p++ = to8bit(*inbufp++, tmp); /* R */
}
inbuf.p = inbufp;
- buf.p.p8 = u8p;
}
/* mono */
--- 232,257 ----
{
const i31 *inbufp = inbuf.p;
u8 *u8p = buf.p.p8;
+ i15 *s15p = buf.p.p16;
! switch (dci.bits) {
! case 8:
! for (; n > 0; n--) {
! i31x tmp;
! *u8p++ = to8bit(*inbufp++, tmp); /* L */
! *u8p++ = to8bit(*inbufp++, tmp); /* R */
! }
! buf.p.p8 = u8p;
! break;
! case 16:
! for (; n > 0; n--) {
! *s15p++ = to16bit(*inbufp++); /* L */
! *s15p++ = to16bit(*inbufp++); /* R */
! }
! buf.p.p16 = s15p;
! break;
}
inbuf.p = inbufp;
}
/* mono */
***************
*** 202,220 ****
{
const i31 *inbufp = inbuf.p;
u8 *u8p = buf.p.p8;
! for (; n > 0; n--) {
! i31x tmp;
! *u8p++ = to8bit(*inbufp, tmp);
! inbufp += 2;
}
inbuf.p = inbufp;
- buf.p.p8 = u8p;
}
#define dacioOutHirev(x) \
if (dci.stereo) dacioOutHirevS(x); else dacioOutHirevM(x)
! #define bufRest() (dci.stereo? (buf.bot - buf.p.p8)/2 : buf.bot - buf.p.p8)
void
dacioOut(void)
--- 260,290 ----
{
const i31 *inbufp = inbuf.p;
u8 *u8p = buf.p.p8;
+ i15 *s16p = buf.p.p16;
! switch (dci.bits) {
! case 8:
! for (; n > 0; n--) {
! i31x tmp;
! *u8p++ = to8bit(*inbufp, tmp);
! inbufp += 2;
! }
! buf.p.p8 = u8p;
! break;
! case 16:
! for (; n > 0; n--) {
! *s16p++ = to16bit(*inbufp);
! inbufp += 2;
! }
! buf.p.p16 = s16p;
! break;
}
inbuf.p = inbufp;
}
#define dacioOutHirev(x) \
if (dci.stereo) dacioOutHirevS(x); else dacioOutHirevM(x)
! #define bufRest() ((dci.stereo? (buf.bot - buf.p.p8)/2 : buf.bot - buf.p.p8)/(dci.bits/8))
void
dacioOut(void)
|