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
|
*** linux_a.c.orig Mon May 20 17:09:46 1996
--- linux_a.c Tue Jun 16 19:59:01 1998
***************
*** 71,82 ****
then 8-bit unsigned if it fails. If you have a sound device that
can't handle either, let me know. */
static int open_output(void)
{
int fd, tmp, i, warnings=0;
/* Open the audio device */
! fd=open(dpm.name, O_RDWR | O_NDELAY);
if (fd<0)
{
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s",
--- 71,85 ----
then 8-bit unsigned if it fails. If you have a sound device that
can't handle either, let me know. */
+ /* Flag for Luigi Rizzo new sound driver (as opposed to VoxWare) */
+ static luigi_driver = 0;
+
static int open_output(void)
{
int fd, tmp, i, warnings=0;
/* Open the audio device */
! fd=open(dpm.name, O_RDWR);
if (fd<0)
{
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s",
***************
*** 84,89 ****
--- 87,109 ----
return -1;
}
+ /* Figure out if we're running with the Luigi driver or
+ the original VoxWare driver, with code based on dburr/luigi
+ in ports/5607. It'd be great if we could do this before
+ opening the audio device, but oh well... */
+ #if defined(AIOGFMT) /* only defined in Luigi driver */
+ {
+ snd_chan_param s;
+ int i;
+ i = ioctl(fd, AIOGFMT, &s);
+ if (i != -1)
+ luigi_driver = 1;
+ }
+ #endif defined (AIOGFMT)
+
+ ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "Using %s sound driver",
+ luigi_driver ? "luigi" : "VoxWare");
+
/* They can't mean these */
dpm.encoding &= ~(PE_ULAW|PE_BYTESWAP);
***************
*** 92,97 ****
--- 112,140 ----
the other one. */
i=tmp=(dpm.encoding & PE_16BIT) ? 16 : 8;
+ if (luigi_driver)
+ {
+ if (dpm.encoding & PE_16BIT) {
+ int fmt = AFMT_S16_LE ;
+
+ if (ioctl(fd, SNDCTL_DSP_SETFMT, &fmt) < 0 || fmt != AFMT_S16_LE) {
+ fmt = AFMT_U8 ;
+ if (ioctl(fd, SNDCTL_DSP_SETFMT, &fmt) < 0 || fmt != AFMT_U8) {
+ ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
+ "%s doesn't support 16- or 8-bit sample width",
+ dpm.name);
+ close(fd);
+ return -1;
+ }
+ ctl->cmsg(CMSG_WARNING, VERB_VERBOSE,
+ "Sample width adjusted to %d bits", tmp);
+ dpm.encoding ^= PE_16BIT;
+ warnings = 1;
+ }
+ }
+ }
+ else
+ {
if (ioctl(fd, SNDCTL_DSP_SAMPLESIZE, &tmp)<0 || tmp!=i)
{
/* Try the other one */
***************
*** 109,114 ****
--- 152,158 ----
dpm.encoding ^= PE_16BIT;
warnings=1;
}
+ }
if (dpm.encoding & PE_16BIT)
dpm.encoding |= PE_SIGNED;
else
***************
*** 163,168 ****
--- 207,214 ----
/* Set buffer fragments (in extra_param[0]) */
tmp=AUDIO_BUFFER_BITS;
+ if (luigi_driver)
+ tmp += 2;
if (!(dpm.encoding & PE_MONO)) tmp++;
if (dpm.encoding & PE_16BIT) tmp++;
tmp |= (dpm.extra_param[0]<<16);
***************
*** 189,215 ****
return warnings;
}
static void output_data(int32 *buf, int32 count)
{
! if (!(dpm.encoding & PE_MONO)) count*=2; /* Stereo samples */
! if (dpm.encoding & PE_16BIT)
! {
/* Convert data to signed 16-bit PCM */
s32tos16(buf, count);
!
! /* Write the data out. Linux likes to give an EINTR if you suspend
! a program while waiting on a write, so we may need to retry. */
! while ((-1==write(dpm.fd, buf, count * 2)) && errno==EINTR)
! ;
! }
! else
! {
/* Convert to 8-bit unsigned and write out. */
s32tou8(buf, count);
!
! while ((-1==write(dpm.fd, buf, count)) && errno==EINTR)
! ;
}
}
--- 235,264 ----
return warnings;
}
+ /* output_data comes from Luigi's linux_a.c. This version seems to allow
+ for partial writes to the sound device, where as the original version
+ doesn't. */
static void output_data(int32 *buf, int32 count)
{
! char *p;
! int res, l;
! if (!(dpm.encoding & PE_MONO))
! count *= 2; /* Stereo samples */
!
! if (dpm.encoding & PE_16BIT) {
/* Convert data to signed 16-bit PCM */
s32tos16(buf, count);
! res = count*2;
! } else {
/* Convert to 8-bit unsigned and write out. */
s32tou8(buf, count);
! res = count ;
! }
! for (p = (char *) buf ; res > 0 ; res -= l ) {
! l = write(dpm.fd, p, res);
! if (l < 0) return ;
! p += l ;
}
}
|