root / audio / ossaudio.c @ 86cc1ce0
History | View | Annotate | Download (19.8 kB)
1 | 85571bc7 | bellard | /*
|
---|---|---|---|
2 | 1d14ffa9 | bellard | * QEMU OSS audio driver
|
3 | 1d14ffa9 | bellard | *
|
4 | 1d14ffa9 | bellard | * Copyright (c) 2003-2005 Vassili Karpov (malc)
|
5 | 1d14ffa9 | bellard | *
|
6 | 85571bc7 | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 85571bc7 | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | 85571bc7 | bellard | * in the Software without restriction, including without limitation the rights
|
9 | 85571bc7 | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 85571bc7 | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | 85571bc7 | bellard | * furnished to do so, subject to the following conditions:
|
12 | 85571bc7 | bellard | *
|
13 | 85571bc7 | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | 85571bc7 | bellard | * all copies or substantial portions of the Software.
|
15 | 85571bc7 | bellard | *
|
16 | 85571bc7 | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 85571bc7 | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 85571bc7 | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 85571bc7 | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 85571bc7 | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 85571bc7 | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 85571bc7 | bellard | * THE SOFTWARE.
|
23 | 85571bc7 | bellard | */
|
24 | f0c757e4 | ths | #include <stdlib.h> |
25 | 85571bc7 | bellard | #include <sys/mman.h> |
26 | 85571bc7 | bellard | #include <sys/types.h> |
27 | 85571bc7 | bellard | #include <sys/ioctl.h> |
28 | f0c757e4 | ths | #ifdef __OpenBSD__
|
29 | f0c757e4 | ths | #include <soundcard.h> |
30 | f0c757e4 | ths | #else
|
31 | 85571bc7 | bellard | #include <sys/soundcard.h> |
32 | f0c757e4 | ths | #endif
|
33 | fb065187 | bellard | #include "vl.h" |
34 | fb065187 | bellard | |
35 | 1d14ffa9 | bellard | #define AUDIO_CAP "oss" |
36 | 1d14ffa9 | bellard | #include "audio_int.h" |
37 | fb065187 | bellard | |
38 | 1d14ffa9 | bellard | typedef struct OSSVoiceOut { |
39 | 1d14ffa9 | bellard | HWVoiceOut hw; |
40 | fb065187 | bellard | void *pcm_buf;
|
41 | fb065187 | bellard | int fd;
|
42 | fb065187 | bellard | int nfrags;
|
43 | fb065187 | bellard | int fragsize;
|
44 | fb065187 | bellard | int mmapped;
|
45 | fb065187 | bellard | int old_optr;
|
46 | 1d14ffa9 | bellard | } OSSVoiceOut; |
47 | 85571bc7 | bellard | |
48 | 1d14ffa9 | bellard | typedef struct OSSVoiceIn { |
49 | 1d14ffa9 | bellard | HWVoiceIn hw; |
50 | 1d14ffa9 | bellard | void *pcm_buf;
|
51 | 1d14ffa9 | bellard | int fd;
|
52 | 1d14ffa9 | bellard | int nfrags;
|
53 | 1d14ffa9 | bellard | int fragsize;
|
54 | 1d14ffa9 | bellard | int old_optr;
|
55 | 1d14ffa9 | bellard | } OSSVoiceIn; |
56 | 85571bc7 | bellard | |
57 | 85571bc7 | bellard | static struct { |
58 | 85571bc7 | bellard | int try_mmap;
|
59 | 85571bc7 | bellard | int nfrags;
|
60 | 85571bc7 | bellard | int fragsize;
|
61 | 1d14ffa9 | bellard | const char *devpath_out; |
62 | 1d14ffa9 | bellard | const char *devpath_in; |
63 | 8ead62cf | bellard | int debug;
|
64 | 85571bc7 | bellard | } conf = { |
65 | 85571bc7 | bellard | .try_mmap = 0,
|
66 | 85571bc7 | bellard | .nfrags = 4,
|
67 | 85571bc7 | bellard | .fragsize = 4096,
|
68 | 1d14ffa9 | bellard | .devpath_out = "/dev/dsp",
|
69 | 8ead62cf | bellard | .devpath_in = "/dev/dsp",
|
70 | 8ead62cf | bellard | .debug = 0
|
71 | 85571bc7 | bellard | }; |
72 | 85571bc7 | bellard | |
73 | 85571bc7 | bellard | struct oss_params {
|
74 | 85571bc7 | bellard | int freq;
|
75 | 85571bc7 | bellard | audfmt_e fmt; |
76 | 85571bc7 | bellard | int nchannels;
|
77 | 85571bc7 | bellard | int nfrags;
|
78 | 85571bc7 | bellard | int fragsize;
|
79 | 85571bc7 | bellard | }; |
80 | 85571bc7 | bellard | |
81 | 1d14ffa9 | bellard | static void GCC_FMT_ATTR (2, 3) oss_logerr (int err, const char *fmt, ...) |
82 | 85571bc7 | bellard | { |
83 | 1d14ffa9 | bellard | va_list ap; |
84 | 1d14ffa9 | bellard | |
85 | 571ec3d6 | bellard | va_start (ap, fmt); |
86 | 1d14ffa9 | bellard | AUD_vlog (AUDIO_CAP, fmt, ap); |
87 | 571ec3d6 | bellard | va_end (ap); |
88 | 1d14ffa9 | bellard | |
89 | 1d14ffa9 | bellard | AUD_log (AUDIO_CAP, "Reason: %s\n", strerror (err));
|
90 | 85571bc7 | bellard | } |
91 | 85571bc7 | bellard | |
92 | 1d14ffa9 | bellard | static void GCC_FMT_ATTR (3, 4) oss_logerr2 ( |
93 | 1d14ffa9 | bellard | int err,
|
94 | 1d14ffa9 | bellard | const char *typ, |
95 | 1d14ffa9 | bellard | const char *fmt, |
96 | 1d14ffa9 | bellard | ... |
97 | 1d14ffa9 | bellard | ) |
98 | 1d14ffa9 | bellard | { |
99 | 1d14ffa9 | bellard | va_list ap; |
100 | 1d14ffa9 | bellard | |
101 | c0fe3827 | bellard | AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ);
|
102 | 1d14ffa9 | bellard | |
103 | 1d14ffa9 | bellard | va_start (ap, fmt); |
104 | 1d14ffa9 | bellard | AUD_vlog (AUDIO_CAP, fmt, ap); |
105 | 1d14ffa9 | bellard | va_end (ap); |
106 | 1d14ffa9 | bellard | |
107 | 1d14ffa9 | bellard | AUD_log (AUDIO_CAP, "Reason: %s\n", strerror (err));
|
108 | 1d14ffa9 | bellard | } |
109 | 1d14ffa9 | bellard | |
110 | 1d14ffa9 | bellard | static void oss_anal_close (int *fdp) |
111 | 1d14ffa9 | bellard | { |
112 | 1d14ffa9 | bellard | int err = close (*fdp);
|
113 | 1d14ffa9 | bellard | if (err) {
|
114 | 1d14ffa9 | bellard | oss_logerr (errno, "Failed to close file(fd=%d)\n", *fdp);
|
115 | 1d14ffa9 | bellard | } |
116 | 1d14ffa9 | bellard | *fdp = -1;
|
117 | 1d14ffa9 | bellard | } |
118 | 1d14ffa9 | bellard | |
119 | 1d14ffa9 | bellard | static int oss_write (SWVoiceOut *sw, void *buf, int len) |
120 | 1d14ffa9 | bellard | { |
121 | 1d14ffa9 | bellard | return audio_pcm_sw_write (sw, buf, len);
|
122 | 1d14ffa9 | bellard | } |
123 | 1d14ffa9 | bellard | |
124 | 1d14ffa9 | bellard | static int aud_to_ossfmt (audfmt_e fmt) |
125 | 85571bc7 | bellard | { |
126 | 85571bc7 | bellard | switch (fmt) {
|
127 | 1d14ffa9 | bellard | case AUD_FMT_S8:
|
128 | 1d14ffa9 | bellard | return AFMT_S8;
|
129 | 1d14ffa9 | bellard | |
130 | 1d14ffa9 | bellard | case AUD_FMT_U8:
|
131 | 1d14ffa9 | bellard | return AFMT_U8;
|
132 | 1d14ffa9 | bellard | |
133 | 1d14ffa9 | bellard | case AUD_FMT_S16:
|
134 | 1d14ffa9 | bellard | return AFMT_S16_LE;
|
135 | 1d14ffa9 | bellard | |
136 | 1d14ffa9 | bellard | case AUD_FMT_U16:
|
137 | 1d14ffa9 | bellard | return AFMT_U16_LE;
|
138 | 1d14ffa9 | bellard | |
139 | 85571bc7 | bellard | default:
|
140 | 1d14ffa9 | bellard | dolog ("Internal logic error: Bad audio format %d\n", fmt);
|
141 | 1d14ffa9 | bellard | #ifdef DEBUG_AUDIO
|
142 | 1d14ffa9 | bellard | abort (); |
143 | 1d14ffa9 | bellard | #endif
|
144 | 1d14ffa9 | bellard | return AFMT_U8;
|
145 | 85571bc7 | bellard | } |
146 | 85571bc7 | bellard | } |
147 | 85571bc7 | bellard | |
148 | 1d14ffa9 | bellard | static int oss_to_audfmt (int ossfmt, audfmt_e *fmt, int *endianness) |
149 | 85571bc7 | bellard | { |
150 | 1d14ffa9 | bellard | switch (ossfmt) {
|
151 | 1d14ffa9 | bellard | case AFMT_S8:
|
152 | 1d14ffa9 | bellard | *endianness =0;
|
153 | 1d14ffa9 | bellard | *fmt = AUD_FMT_S8; |
154 | 1d14ffa9 | bellard | break;
|
155 | 1d14ffa9 | bellard | |
156 | 1d14ffa9 | bellard | case AFMT_U8:
|
157 | 1d14ffa9 | bellard | *endianness = 0;
|
158 | 1d14ffa9 | bellard | *fmt = AUD_FMT_U8; |
159 | 1d14ffa9 | bellard | break;
|
160 | 1d14ffa9 | bellard | |
161 | 1d14ffa9 | bellard | case AFMT_S16_LE:
|
162 | 1d14ffa9 | bellard | *endianness = 0;
|
163 | 1d14ffa9 | bellard | *fmt = AUD_FMT_S16; |
164 | 1d14ffa9 | bellard | break;
|
165 | 1d14ffa9 | bellard | |
166 | 1d14ffa9 | bellard | case AFMT_U16_LE:
|
167 | 1d14ffa9 | bellard | *endianness = 0;
|
168 | 1d14ffa9 | bellard | *fmt = AUD_FMT_U16; |
169 | 1d14ffa9 | bellard | break;
|
170 | 1d14ffa9 | bellard | |
171 | 1d14ffa9 | bellard | case AFMT_S16_BE:
|
172 | 1d14ffa9 | bellard | *endianness = 1;
|
173 | 1d14ffa9 | bellard | *fmt = AUD_FMT_S16; |
174 | 1d14ffa9 | bellard | break;
|
175 | 1d14ffa9 | bellard | |
176 | 1d14ffa9 | bellard | case AFMT_U16_BE:
|
177 | 1d14ffa9 | bellard | *endianness = 1;
|
178 | 1d14ffa9 | bellard | *fmt = AUD_FMT_U16; |
179 | 1d14ffa9 | bellard | break;
|
180 | 1d14ffa9 | bellard | |
181 | 85571bc7 | bellard | default:
|
182 | 1d14ffa9 | bellard | dolog ("Unrecognized audio format %d\n", ossfmt);
|
183 | 1d14ffa9 | bellard | return -1; |
184 | 85571bc7 | bellard | } |
185 | 1d14ffa9 | bellard | |
186 | 1d14ffa9 | bellard | return 0; |
187 | 85571bc7 | bellard | } |
188 | 85571bc7 | bellard | |
189 | c0fe3827 | bellard | #if defined DEBUG_MISMATCHES || defined DEBUG
|
190 | 1d14ffa9 | bellard | static void oss_dump_info (struct oss_params *req, struct oss_params *obt) |
191 | 85571bc7 | bellard | { |
192 | 85571bc7 | bellard | dolog ("parameter | requested value | obtained value\n");
|
193 | 85571bc7 | bellard | dolog ("format | %10d | %10d\n", req->fmt, obt->fmt);
|
194 | 1d14ffa9 | bellard | dolog ("channels | %10d | %10d\n",
|
195 | 1d14ffa9 | bellard | req->nchannels, obt->nchannels); |
196 | 85571bc7 | bellard | dolog ("frequency | %10d | %10d\n", req->freq, obt->freq);
|
197 | 85571bc7 | bellard | dolog ("nfrags | %10d | %10d\n", req->nfrags, obt->nfrags);
|
198 | 1d14ffa9 | bellard | dolog ("fragsize | %10d | %10d\n",
|
199 | 1d14ffa9 | bellard | req->fragsize, obt->fragsize); |
200 | 85571bc7 | bellard | } |
201 | 85571bc7 | bellard | #endif
|
202 | 85571bc7 | bellard | |
203 | 1d14ffa9 | bellard | static int oss_open (int in, struct oss_params *req, |
204 | 1d14ffa9 | bellard | struct oss_params *obt, int *pfd) |
205 | 85571bc7 | bellard | { |
206 | 85571bc7 | bellard | int fd;
|
207 | 85571bc7 | bellard | int mmmmssss;
|
208 | 85571bc7 | bellard | audio_buf_info abinfo; |
209 | 85571bc7 | bellard | int fmt, freq, nchannels;
|
210 | 1d14ffa9 | bellard | const char *dspname = in ? conf.devpath_in : conf.devpath_out; |
211 | 1d14ffa9 | bellard | const char *typ = in ? "ADC" : "DAC"; |
212 | 85571bc7 | bellard | |
213 | 1d14ffa9 | bellard | fd = open (dspname, (in ? O_RDONLY : O_WRONLY) | O_NONBLOCK); |
214 | 85571bc7 | bellard | if (-1 == fd) { |
215 | 1d14ffa9 | bellard | oss_logerr2 (errno, typ, "Failed to open `%s'\n", dspname);
|
216 | 85571bc7 | bellard | return -1; |
217 | 85571bc7 | bellard | } |
218 | 85571bc7 | bellard | |
219 | 85571bc7 | bellard | freq = req->freq; |
220 | 85571bc7 | bellard | nchannels = req->nchannels; |
221 | 85571bc7 | bellard | fmt = req->fmt; |
222 | 85571bc7 | bellard | |
223 | 85571bc7 | bellard | if (ioctl (fd, SNDCTL_DSP_SAMPLESIZE, &fmt)) {
|
224 | 1d14ffa9 | bellard | oss_logerr2 (errno, typ, "Failed to set sample size %d\n", req->fmt);
|
225 | 85571bc7 | bellard | goto err;
|
226 | 85571bc7 | bellard | } |
227 | 85571bc7 | bellard | |
228 | 85571bc7 | bellard | if (ioctl (fd, SNDCTL_DSP_CHANNELS, &nchannels)) {
|
229 | 1d14ffa9 | bellard | oss_logerr2 (errno, typ, "Failed to set number of channels %d\n",
|
230 | 1d14ffa9 | bellard | req->nchannels); |
231 | 85571bc7 | bellard | goto err;
|
232 | 85571bc7 | bellard | } |
233 | 85571bc7 | bellard | |
234 | 85571bc7 | bellard | if (ioctl (fd, SNDCTL_DSP_SPEED, &freq)) {
|
235 | 1d14ffa9 | bellard | oss_logerr2 (errno, typ, "Failed to set frequency %d\n", req->freq);
|
236 | 85571bc7 | bellard | goto err;
|
237 | 85571bc7 | bellard | } |
238 | 85571bc7 | bellard | |
239 | 85571bc7 | bellard | if (ioctl (fd, SNDCTL_DSP_NONBLOCK)) {
|
240 | 1d14ffa9 | bellard | oss_logerr2 (errno, typ, "Failed to set non-blocking mode\n");
|
241 | 85571bc7 | bellard | goto err;
|
242 | 85571bc7 | bellard | } |
243 | 85571bc7 | bellard | |
244 | 85571bc7 | bellard | mmmmssss = (req->nfrags << 16) | lsbindex (req->fragsize);
|
245 | 85571bc7 | bellard | if (ioctl (fd, SNDCTL_DSP_SETFRAGMENT, &mmmmssss)) {
|
246 | 1d14ffa9 | bellard | oss_logerr2 (errno, typ, "Failed to set buffer length (%d, %d)\n",
|
247 | 1d14ffa9 | bellard | req->nfrags, req->fragsize); |
248 | 85571bc7 | bellard | goto err;
|
249 | 85571bc7 | bellard | } |
250 | 85571bc7 | bellard | |
251 | 1d14ffa9 | bellard | if (ioctl (fd, in ? SNDCTL_DSP_GETISPACE : SNDCTL_DSP_GETOSPACE, &abinfo)) {
|
252 | 1d14ffa9 | bellard | oss_logerr2 (errno, typ, "Failed to get buffer length\n");
|
253 | 85571bc7 | bellard | goto err;
|
254 | 85571bc7 | bellard | } |
255 | 85571bc7 | bellard | |
256 | 85571bc7 | bellard | obt->fmt = fmt; |
257 | 85571bc7 | bellard | obt->nchannels = nchannels; |
258 | 85571bc7 | bellard | obt->freq = freq; |
259 | 85571bc7 | bellard | obt->nfrags = abinfo.fragstotal; |
260 | 85571bc7 | bellard | obt->fragsize = abinfo.fragsize; |
261 | 85571bc7 | bellard | *pfd = fd; |
262 | 85571bc7 | bellard | |
263 | c0fe3827 | bellard | #ifdef DEBUG_MISMATCHES
|
264 | 85571bc7 | bellard | if ((req->fmt != obt->fmt) ||
|
265 | 85571bc7 | bellard | (req->nchannels != obt->nchannels) || |
266 | 85571bc7 | bellard | (req->freq != obt->freq) || |
267 | 85571bc7 | bellard | (req->fragsize != obt->fragsize) || |
268 | 85571bc7 | bellard | (req->nfrags != obt->nfrags)) { |
269 | 85571bc7 | bellard | dolog ("Audio parameters mismatch\n");
|
270 | 1d14ffa9 | bellard | oss_dump_info (req, obt); |
271 | 85571bc7 | bellard | } |
272 | c0fe3827 | bellard | #endif
|
273 | 85571bc7 | bellard | |
274 | 1d14ffa9 | bellard | #ifdef DEBUG
|
275 | 1d14ffa9 | bellard | oss_dump_info (req, obt); |
276 | 85571bc7 | bellard | #endif
|
277 | 85571bc7 | bellard | return 0; |
278 | 85571bc7 | bellard | |
279 | 1d14ffa9 | bellard | err:
|
280 | 1d14ffa9 | bellard | oss_anal_close (&fd); |
281 | 85571bc7 | bellard | return -1; |
282 | 85571bc7 | bellard | } |
283 | 85571bc7 | bellard | |
284 | 1d14ffa9 | bellard | static int oss_run_out (HWVoiceOut *hw) |
285 | 85571bc7 | bellard | { |
286 | 1d14ffa9 | bellard | OSSVoiceOut *oss = (OSSVoiceOut *) hw; |
287 | 85571bc7 | bellard | int err, rpos, live, decr;
|
288 | 85571bc7 | bellard | int samples;
|
289 | 85571bc7 | bellard | uint8_t *dst; |
290 | 85571bc7 | bellard | st_sample_t *src; |
291 | 85571bc7 | bellard | struct audio_buf_info abinfo;
|
292 | 85571bc7 | bellard | struct count_info cntinfo;
|
293 | c0fe3827 | bellard | int bufsize;
|
294 | 85571bc7 | bellard | |
295 | 1d14ffa9 | bellard | live = audio_pcm_hw_get_live_out (hw); |
296 | 1d14ffa9 | bellard | if (!live) {
|
297 | 1d14ffa9 | bellard | return 0; |
298 | 1d14ffa9 | bellard | } |
299 | 85571bc7 | bellard | |
300 | c0fe3827 | bellard | bufsize = hw->samples << hw->info.shift; |
301 | c0fe3827 | bellard | |
302 | 85571bc7 | bellard | if (oss->mmapped) {
|
303 | 85571bc7 | bellard | int bytes;
|
304 | 85571bc7 | bellard | |
305 | 85571bc7 | bellard | err = ioctl (oss->fd, SNDCTL_DSP_GETOPTR, &cntinfo); |
306 | 85571bc7 | bellard | if (err < 0) { |
307 | 1d14ffa9 | bellard | oss_logerr (errno, "SNDCTL_DSP_GETOPTR failed\n");
|
308 | 1d14ffa9 | bellard | return 0; |
309 | 85571bc7 | bellard | } |
310 | 85571bc7 | bellard | |
311 | 85571bc7 | bellard | if (cntinfo.ptr == oss->old_optr) {
|
312 | 1d14ffa9 | bellard | if (abs (hw->samples - live) < 64) { |
313 | c0fe3827 | bellard | dolog ("warning: Overrun\n");
|
314 | 1d14ffa9 | bellard | } |
315 | 1d14ffa9 | bellard | return 0; |
316 | 85571bc7 | bellard | } |
317 | 85571bc7 | bellard | |
318 | 85571bc7 | bellard | if (cntinfo.ptr > oss->old_optr) {
|
319 | 85571bc7 | bellard | bytes = cntinfo.ptr - oss->old_optr; |
320 | 85571bc7 | bellard | } |
321 | 85571bc7 | bellard | else {
|
322 | c0fe3827 | bellard | bytes = bufsize + cntinfo.ptr - oss->old_optr; |
323 | 85571bc7 | bellard | } |
324 | 85571bc7 | bellard | |
325 | 1d14ffa9 | bellard | decr = audio_MIN (bytes >> hw->info.shift, live); |
326 | 85571bc7 | bellard | } |
327 | 85571bc7 | bellard | else {
|
328 | 85571bc7 | bellard | err = ioctl (oss->fd, SNDCTL_DSP_GETOSPACE, &abinfo); |
329 | 85571bc7 | bellard | if (err < 0) { |
330 | 1d14ffa9 | bellard | oss_logerr (errno, "SNDCTL_DSP_GETOPTR failed\n");
|
331 | 1d14ffa9 | bellard | return 0; |
332 | 1d14ffa9 | bellard | } |
333 | 1d14ffa9 | bellard | |
334 | 8ead62cf | bellard | if (abinfo.bytes > bufsize) {
|
335 | 8ead62cf | bellard | if (conf.debug) {
|
336 | 8ead62cf | bellard | dolog ("warning: Invalid available size, size=%d bufsize=%d\n"
|
337 | 8ead62cf | bellard | "please report your OS/audio hw to malc@pulsesoft.com\n",
|
338 | 8ead62cf | bellard | abinfo.bytes, bufsize); |
339 | 8ead62cf | bellard | } |
340 | 8ead62cf | bellard | abinfo.bytes = bufsize; |
341 | 8ead62cf | bellard | } |
342 | 8ead62cf | bellard | |
343 | 8ead62cf | bellard | if (abinfo.bytes < 0) { |
344 | 8ead62cf | bellard | if (conf.debug) {
|
345 | 8ead62cf | bellard | dolog ("warning: Invalid available size, size=%d bufsize=%d\n",
|
346 | 8ead62cf | bellard | abinfo.bytes, bufsize); |
347 | 8ead62cf | bellard | } |
348 | 1d14ffa9 | bellard | return 0; |
349 | 85571bc7 | bellard | } |
350 | 85571bc7 | bellard | |
351 | 1d14ffa9 | bellard | decr = audio_MIN (abinfo.bytes >> hw->info.shift, live); |
352 | 1d14ffa9 | bellard | if (!decr) {
|
353 | 1d14ffa9 | bellard | return 0; |
354 | 1d14ffa9 | bellard | } |
355 | 85571bc7 | bellard | } |
356 | 85571bc7 | bellard | |
357 | 85571bc7 | bellard | samples = decr; |
358 | 85571bc7 | bellard | rpos = hw->rpos; |
359 | 85571bc7 | bellard | while (samples) {
|
360 | 85571bc7 | bellard | int left_till_end_samples = hw->samples - rpos;
|
361 | 85571bc7 | bellard | int convert_samples = audio_MIN (samples, left_till_end_samples);
|
362 | 85571bc7 | bellard | |
363 | 1d14ffa9 | bellard | src = hw->mix_buf + rpos; |
364 | 1d14ffa9 | bellard | dst = advance (oss->pcm_buf, rpos << hw->info.shift); |
365 | 85571bc7 | bellard | |
366 | 85571bc7 | bellard | hw->clip (dst, src, convert_samples); |
367 | 85571bc7 | bellard | if (!oss->mmapped) {
|
368 | 85571bc7 | bellard | int written;
|
369 | 85571bc7 | bellard | |
370 | 1d14ffa9 | bellard | written = write (oss->fd, dst, convert_samples << hw->info.shift); |
371 | 85571bc7 | bellard | /* XXX: follow errno recommendations ? */
|
372 | 85571bc7 | bellard | if (written == -1) { |
373 | 1d14ffa9 | bellard | oss_logerr ( |
374 | 1d14ffa9 | bellard | errno, |
375 | 1d14ffa9 | bellard | "Failed to write %d bytes of audio data from %p\n",
|
376 | 1d14ffa9 | bellard | convert_samples << hw->info.shift, |
377 | 1d14ffa9 | bellard | dst |
378 | 1d14ffa9 | bellard | ); |
379 | 85571bc7 | bellard | continue;
|
380 | 85571bc7 | bellard | } |
381 | 85571bc7 | bellard | |
382 | 1d14ffa9 | bellard | if (written != convert_samples << hw->info.shift) {
|
383 | 1d14ffa9 | bellard | int wsamples = written >> hw->info.shift;
|
384 | 1d14ffa9 | bellard | int wbytes = wsamples << hw->info.shift;
|
385 | 85571bc7 | bellard | if (wbytes != written) {
|
386 | c0fe3827 | bellard | dolog ("warning: Misaligned write %d (requested %d), "
|
387 | 1d14ffa9 | bellard | "alignment %d\n",
|
388 | 1d14ffa9 | bellard | wbytes, written, hw->info.align + 1);
|
389 | 85571bc7 | bellard | } |
390 | 1d14ffa9 | bellard | decr -= wsamples; |
391 | 85571bc7 | bellard | rpos = (rpos + wsamples) % hw->samples; |
392 | 85571bc7 | bellard | break;
|
393 | 85571bc7 | bellard | } |
394 | 85571bc7 | bellard | } |
395 | 1d14ffa9 | bellard | |
396 | 85571bc7 | bellard | rpos = (rpos + convert_samples) % hw->samples; |
397 | 85571bc7 | bellard | samples -= convert_samples; |
398 | 85571bc7 | bellard | } |
399 | 85571bc7 | bellard | if (oss->mmapped) {
|
400 | 85571bc7 | bellard | oss->old_optr = cntinfo.ptr; |
401 | 85571bc7 | bellard | } |
402 | 85571bc7 | bellard | |
403 | 85571bc7 | bellard | hw->rpos = rpos; |
404 | 1d14ffa9 | bellard | return decr;
|
405 | 85571bc7 | bellard | } |
406 | 85571bc7 | bellard | |
407 | 1d14ffa9 | bellard | static void oss_fini_out (HWVoiceOut *hw) |
408 | 85571bc7 | bellard | { |
409 | 85571bc7 | bellard | int err;
|
410 | 1d14ffa9 | bellard | OSSVoiceOut *oss = (OSSVoiceOut *) hw; |
411 | 85571bc7 | bellard | |
412 | 1d14ffa9 | bellard | ldebug ("oss_fini\n");
|
413 | 1d14ffa9 | bellard | oss_anal_close (&oss->fd); |
414 | 85571bc7 | bellard | |
415 | 85571bc7 | bellard | if (oss->pcm_buf) {
|
416 | 85571bc7 | bellard | if (oss->mmapped) {
|
417 | c0fe3827 | bellard | err = munmap (oss->pcm_buf, hw->samples << hw->info.shift); |
418 | 85571bc7 | bellard | if (err) {
|
419 | 1d14ffa9 | bellard | oss_logerr (errno, "Failed to unmap buffer %p, size %d\n",
|
420 | c0fe3827 | bellard | oss->pcm_buf, hw->samples << hw->info.shift); |
421 | 85571bc7 | bellard | } |
422 | 85571bc7 | bellard | } |
423 | 85571bc7 | bellard | else {
|
424 | 85571bc7 | bellard | qemu_free (oss->pcm_buf); |
425 | 85571bc7 | bellard | } |
426 | 85571bc7 | bellard | oss->pcm_buf = NULL;
|
427 | 85571bc7 | bellard | } |
428 | 85571bc7 | bellard | } |
429 | 85571bc7 | bellard | |
430 | c0fe3827 | bellard | static int oss_init_out (HWVoiceOut *hw, audsettings_t *as) |
431 | 85571bc7 | bellard | { |
432 | 1d14ffa9 | bellard | OSSVoiceOut *oss = (OSSVoiceOut *) hw; |
433 | 85571bc7 | bellard | struct oss_params req, obt;
|
434 | 1d14ffa9 | bellard | int endianness;
|
435 | 1d14ffa9 | bellard | int err;
|
436 | 1d14ffa9 | bellard | int fd;
|
437 | 1d14ffa9 | bellard | audfmt_e effective_fmt; |
438 | c0fe3827 | bellard | audsettings_t obt_as; |
439 | 85571bc7 | bellard | |
440 | 571ec3d6 | bellard | oss->fd = -1;
|
441 | 571ec3d6 | bellard | |
442 | c0fe3827 | bellard | req.fmt = aud_to_ossfmt (as->fmt); |
443 | c0fe3827 | bellard | req.freq = as->freq; |
444 | c0fe3827 | bellard | req.nchannels = as->nchannels; |
445 | 85571bc7 | bellard | req.fragsize = conf.fragsize; |
446 | 85571bc7 | bellard | req.nfrags = conf.nfrags; |
447 | 85571bc7 | bellard | |
448 | 1d14ffa9 | bellard | if (oss_open (0, &req, &obt, &fd)) { |
449 | 85571bc7 | bellard | return -1; |
450 | 1d14ffa9 | bellard | } |
451 | 85571bc7 | bellard | |
452 | 1d14ffa9 | bellard | err = oss_to_audfmt (obt.fmt, &effective_fmt, &endianness); |
453 | 1d14ffa9 | bellard | if (err) {
|
454 | 1d14ffa9 | bellard | oss_anal_close (&fd); |
455 | 1d14ffa9 | bellard | return -1; |
456 | 1d14ffa9 | bellard | } |
457 | 85571bc7 | bellard | |
458 | c0fe3827 | bellard | obt_as.freq = obt.freq; |
459 | c0fe3827 | bellard | obt_as.nchannels = obt.nchannels; |
460 | c0fe3827 | bellard | obt_as.fmt = effective_fmt; |
461 | d929eba5 | bellard | obt_as.endianness = endianness; |
462 | c0fe3827 | bellard | |
463 | d929eba5 | bellard | audio_pcm_init_info (&hw->info, &obt_as); |
464 | 85571bc7 | bellard | oss->nfrags = obt.nfrags; |
465 | 85571bc7 | bellard | oss->fragsize = obt.fragsize; |
466 | c0fe3827 | bellard | |
467 | c0fe3827 | bellard | if (obt.nfrags * obt.fragsize & hw->info.align) {
|
468 | c0fe3827 | bellard | dolog ("warning: Misaligned DAC buffer, size %d, alignment %d\n",
|
469 | c0fe3827 | bellard | obt.nfrags * obt.fragsize, hw->info.align + 1);
|
470 | c0fe3827 | bellard | } |
471 | c0fe3827 | bellard | |
472 | c0fe3827 | bellard | hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift; |
473 | 85571bc7 | bellard | |
474 | 85571bc7 | bellard | oss->mmapped = 0;
|
475 | 85571bc7 | bellard | if (conf.try_mmap) {
|
476 | c0fe3827 | bellard | oss->pcm_buf = mmap ( |
477 | c0fe3827 | bellard | 0,
|
478 | c0fe3827 | bellard | hw->samples << hw->info.shift, |
479 | c0fe3827 | bellard | PROT_READ | PROT_WRITE, |
480 | c0fe3827 | bellard | MAP_SHARED, |
481 | c0fe3827 | bellard | fd, |
482 | c0fe3827 | bellard | 0
|
483 | c0fe3827 | bellard | ); |
484 | 85571bc7 | bellard | if (oss->pcm_buf == MAP_FAILED) {
|
485 | 1d14ffa9 | bellard | oss_logerr (errno, "Failed to map %d bytes of DAC\n",
|
486 | c0fe3827 | bellard | hw->samples << hw->info.shift); |
487 | 44a095a7 | bellard | } else {
|
488 | 85571bc7 | bellard | int err;
|
489 | 85571bc7 | bellard | int trig = 0; |
490 | 1d14ffa9 | bellard | if (ioctl (fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) { |
491 | 1d14ffa9 | bellard | oss_logerr (errno, "SNDCTL_DSP_SETTRIGGER 0 failed\n");
|
492 | 85571bc7 | bellard | } |
493 | 44a095a7 | bellard | else {
|
494 | 44a095a7 | bellard | trig = PCM_ENABLE_OUTPUT; |
495 | 1d14ffa9 | bellard | if (ioctl (fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) { |
496 | 1d14ffa9 | bellard | oss_logerr ( |
497 | 1d14ffa9 | bellard | errno, |
498 | 1d14ffa9 | bellard | "SNDCTL_DSP_SETTRIGGER PCM_ENABLE_OUTPUT failed\n"
|
499 | 1d14ffa9 | bellard | ); |
500 | 44a095a7 | bellard | } |
501 | 44a095a7 | bellard | else {
|
502 | 44a095a7 | bellard | oss->mmapped = 1;
|
503 | 44a095a7 | bellard | } |
504 | 85571bc7 | bellard | } |
505 | 85571bc7 | bellard | |
506 | 44a095a7 | bellard | if (!oss->mmapped) {
|
507 | c0fe3827 | bellard | err = munmap (oss->pcm_buf, hw->samples << hw->info.shift); |
508 | 44a095a7 | bellard | if (err) {
|
509 | 1d14ffa9 | bellard | oss_logerr (errno, "Failed to unmap buffer %p size %d\n",
|
510 | c0fe3827 | bellard | oss->pcm_buf, hw->samples << hw->info.shift); |
511 | 44a095a7 | bellard | } |
512 | 85571bc7 | bellard | } |
513 | 85571bc7 | bellard | } |
514 | 85571bc7 | bellard | } |
515 | 85571bc7 | bellard | |
516 | 85571bc7 | bellard | if (!oss->mmapped) {
|
517 | c0fe3827 | bellard | oss->pcm_buf = audio_calloc ( |
518 | c0fe3827 | bellard | AUDIO_FUNC, |
519 | c0fe3827 | bellard | hw->samples, |
520 | c0fe3827 | bellard | 1 << hw->info.shift
|
521 | c0fe3827 | bellard | ); |
522 | 85571bc7 | bellard | if (!oss->pcm_buf) {
|
523 | b41cffbe | bellard | dolog ( |
524 | b41cffbe | bellard | "Could not allocate DAC buffer (%d samples, each %d bytes)\n",
|
525 | b41cffbe | bellard | hw->samples, |
526 | b41cffbe | bellard | 1 << hw->info.shift
|
527 | b41cffbe | bellard | ); |
528 | 1d14ffa9 | bellard | oss_anal_close (&fd); |
529 | 85571bc7 | bellard | return -1; |
530 | 85571bc7 | bellard | } |
531 | 85571bc7 | bellard | } |
532 | 85571bc7 | bellard | |
533 | 1d14ffa9 | bellard | oss->fd = fd; |
534 | 85571bc7 | bellard | return 0; |
535 | 85571bc7 | bellard | } |
536 | 85571bc7 | bellard | |
537 | 1d14ffa9 | bellard | static int oss_ctl_out (HWVoiceOut *hw, int cmd, ...) |
538 | 85571bc7 | bellard | { |
539 | 85571bc7 | bellard | int trig;
|
540 | 1d14ffa9 | bellard | OSSVoiceOut *oss = (OSSVoiceOut *) hw; |
541 | 85571bc7 | bellard | |
542 | 1d14ffa9 | bellard | if (!oss->mmapped) {
|
543 | 85571bc7 | bellard | return 0; |
544 | 1d14ffa9 | bellard | } |
545 | 85571bc7 | bellard | |
546 | 85571bc7 | bellard | switch (cmd) {
|
547 | 85571bc7 | bellard | case VOICE_ENABLE:
|
548 | 85571bc7 | bellard | ldebug ("enabling voice\n");
|
549 | 1d14ffa9 | bellard | audio_pcm_info_clear_buf (&hw->info, oss->pcm_buf, hw->samples); |
550 | 85571bc7 | bellard | trig = PCM_ENABLE_OUTPUT; |
551 | 85571bc7 | bellard | if (ioctl (oss->fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) { |
552 | 1d14ffa9 | bellard | oss_logerr ( |
553 | 1d14ffa9 | bellard | errno, |
554 | 1d14ffa9 | bellard | "SNDCTL_DSP_SETTRIGGER PCM_ENABLE_OUTPUT failed\n"
|
555 | 1d14ffa9 | bellard | ); |
556 | 85571bc7 | bellard | return -1; |
557 | 85571bc7 | bellard | } |
558 | 85571bc7 | bellard | break;
|
559 | 85571bc7 | bellard | |
560 | 85571bc7 | bellard | case VOICE_DISABLE:
|
561 | 85571bc7 | bellard | ldebug ("disabling voice\n");
|
562 | 85571bc7 | bellard | trig = 0;
|
563 | 85571bc7 | bellard | if (ioctl (oss->fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) { |
564 | 1d14ffa9 | bellard | oss_logerr (errno, "SNDCTL_DSP_SETTRIGGER 0 failed\n");
|
565 | 85571bc7 | bellard | return -1; |
566 | 85571bc7 | bellard | } |
567 | 85571bc7 | bellard | break;
|
568 | 85571bc7 | bellard | } |
569 | 85571bc7 | bellard | return 0; |
570 | 85571bc7 | bellard | } |
571 | 85571bc7 | bellard | |
572 | c0fe3827 | bellard | static int oss_init_in (HWVoiceIn *hw, audsettings_t *as) |
573 | 1d14ffa9 | bellard | { |
574 | 1d14ffa9 | bellard | OSSVoiceIn *oss = (OSSVoiceIn *) hw; |
575 | 1d14ffa9 | bellard | struct oss_params req, obt;
|
576 | 1d14ffa9 | bellard | int endianness;
|
577 | 1d14ffa9 | bellard | int err;
|
578 | 1d14ffa9 | bellard | int fd;
|
579 | 1d14ffa9 | bellard | audfmt_e effective_fmt; |
580 | c0fe3827 | bellard | audsettings_t obt_as; |
581 | 1d14ffa9 | bellard | |
582 | 571ec3d6 | bellard | oss->fd = -1;
|
583 | 571ec3d6 | bellard | |
584 | c0fe3827 | bellard | req.fmt = aud_to_ossfmt (as->fmt); |
585 | c0fe3827 | bellard | req.freq = as->freq; |
586 | c0fe3827 | bellard | req.nchannels = as->nchannels; |
587 | 1d14ffa9 | bellard | req.fragsize = conf.fragsize; |
588 | 1d14ffa9 | bellard | req.nfrags = conf.nfrags; |
589 | 1d14ffa9 | bellard | if (oss_open (1, &req, &obt, &fd)) { |
590 | 1d14ffa9 | bellard | return -1; |
591 | 1d14ffa9 | bellard | } |
592 | 1d14ffa9 | bellard | |
593 | 1d14ffa9 | bellard | err = oss_to_audfmt (obt.fmt, &effective_fmt, &endianness); |
594 | 1d14ffa9 | bellard | if (err) {
|
595 | 1d14ffa9 | bellard | oss_anal_close (&fd); |
596 | 1d14ffa9 | bellard | return -1; |
597 | 1d14ffa9 | bellard | } |
598 | 1d14ffa9 | bellard | |
599 | c0fe3827 | bellard | obt_as.freq = obt.freq; |
600 | c0fe3827 | bellard | obt_as.nchannels = obt.nchannels; |
601 | c0fe3827 | bellard | obt_as.fmt = effective_fmt; |
602 | d929eba5 | bellard | obt_as.endianness = endianness; |
603 | c0fe3827 | bellard | |
604 | d929eba5 | bellard | audio_pcm_init_info (&hw->info, &obt_as); |
605 | 1d14ffa9 | bellard | oss->nfrags = obt.nfrags; |
606 | 1d14ffa9 | bellard | oss->fragsize = obt.fragsize; |
607 | c0fe3827 | bellard | |
608 | c0fe3827 | bellard | if (obt.nfrags * obt.fragsize & hw->info.align) {
|
609 | c0fe3827 | bellard | dolog ("warning: Misaligned ADC buffer, size %d, alignment %d\n",
|
610 | c0fe3827 | bellard | obt.nfrags * obt.fragsize, hw->info.align + 1);
|
611 | c0fe3827 | bellard | } |
612 | c0fe3827 | bellard | |
613 | c0fe3827 | bellard | hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift; |
614 | c0fe3827 | bellard | oss->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
|
615 | 1d14ffa9 | bellard | if (!oss->pcm_buf) {
|
616 | b41cffbe | bellard | dolog ("Could not allocate ADC buffer (%d samples, each %d bytes)\n",
|
617 | b41cffbe | bellard | hw->samples, 1 << hw->info.shift);
|
618 | 1d14ffa9 | bellard | oss_anal_close (&fd); |
619 | 1d14ffa9 | bellard | return -1; |
620 | 1d14ffa9 | bellard | } |
621 | 1d14ffa9 | bellard | |
622 | 1d14ffa9 | bellard | oss->fd = fd; |
623 | 1d14ffa9 | bellard | return 0; |
624 | 1d14ffa9 | bellard | } |
625 | 1d14ffa9 | bellard | |
626 | 1d14ffa9 | bellard | static void oss_fini_in (HWVoiceIn *hw) |
627 | 1d14ffa9 | bellard | { |
628 | 1d14ffa9 | bellard | OSSVoiceIn *oss = (OSSVoiceIn *) hw; |
629 | 1d14ffa9 | bellard | |
630 | 1d14ffa9 | bellard | oss_anal_close (&oss->fd); |
631 | 1d14ffa9 | bellard | |
632 | 1d14ffa9 | bellard | if (oss->pcm_buf) {
|
633 | 1d14ffa9 | bellard | qemu_free (oss->pcm_buf); |
634 | 1d14ffa9 | bellard | oss->pcm_buf = NULL;
|
635 | 1d14ffa9 | bellard | } |
636 | 1d14ffa9 | bellard | } |
637 | 1d14ffa9 | bellard | |
638 | 1d14ffa9 | bellard | static int oss_run_in (HWVoiceIn *hw) |
639 | 1d14ffa9 | bellard | { |
640 | 1d14ffa9 | bellard | OSSVoiceIn *oss = (OSSVoiceIn *) hw; |
641 | 1d14ffa9 | bellard | int hwshift = hw->info.shift;
|
642 | 1d14ffa9 | bellard | int i;
|
643 | 1d14ffa9 | bellard | int live = audio_pcm_hw_get_live_in (hw);
|
644 | 1d14ffa9 | bellard | int dead = hw->samples - live;
|
645 | 1d14ffa9 | bellard | size_t read_samples = 0;
|
646 | 1d14ffa9 | bellard | struct {
|
647 | 1d14ffa9 | bellard | int add;
|
648 | 1d14ffa9 | bellard | int len;
|
649 | 1d14ffa9 | bellard | } bufs[2] = {
|
650 | 1d14ffa9 | bellard | { hw->wpos, 0 },
|
651 | 1d14ffa9 | bellard | { 0, 0 } |
652 | 1d14ffa9 | bellard | }; |
653 | 1d14ffa9 | bellard | |
654 | 1d14ffa9 | bellard | if (!dead) {
|
655 | 1d14ffa9 | bellard | return 0; |
656 | 1d14ffa9 | bellard | } |
657 | 1d14ffa9 | bellard | |
658 | 1d14ffa9 | bellard | if (hw->wpos + dead > hw->samples) {
|
659 | 1d14ffa9 | bellard | bufs[0].len = (hw->samples - hw->wpos) << hwshift;
|
660 | 1d14ffa9 | bellard | bufs[1].len = (dead - (hw->samples - hw->wpos)) << hwshift;
|
661 | 1d14ffa9 | bellard | } |
662 | 1d14ffa9 | bellard | else {
|
663 | 1d14ffa9 | bellard | bufs[0].len = dead << hwshift;
|
664 | 1d14ffa9 | bellard | } |
665 | 1d14ffa9 | bellard | |
666 | 1d14ffa9 | bellard | |
667 | 1d14ffa9 | bellard | for (i = 0; i < 2; ++i) { |
668 | 1d14ffa9 | bellard | ssize_t nread; |
669 | 1d14ffa9 | bellard | |
670 | 1d14ffa9 | bellard | if (bufs[i].len) {
|
671 | 1d14ffa9 | bellard | void *p = advance (oss->pcm_buf, bufs[i].add << hwshift);
|
672 | 1d14ffa9 | bellard | nread = read (oss->fd, p, bufs[i].len); |
673 | 1d14ffa9 | bellard | |
674 | 1d14ffa9 | bellard | if (nread > 0) { |
675 | 1d14ffa9 | bellard | if (nread & hw->info.align) {
|
676 | b41cffbe | bellard | dolog ("warning: Misaligned read %zd (requested %d), "
|
677 | 1d14ffa9 | bellard | "alignment %d\n", nread, bufs[i].add << hwshift,
|
678 | 1d14ffa9 | bellard | hw->info.align + 1);
|
679 | 1d14ffa9 | bellard | } |
680 | 1d14ffa9 | bellard | read_samples += nread >> hwshift; |
681 | 1d14ffa9 | bellard | hw->conv (hw->conv_buf + bufs[i].add, p, nread >> hwshift, |
682 | 1d14ffa9 | bellard | &nominal_volume); |
683 | 1d14ffa9 | bellard | } |
684 | 1d14ffa9 | bellard | |
685 | 1d14ffa9 | bellard | if (bufs[i].len - nread) {
|
686 | 1d14ffa9 | bellard | if (nread == -1) { |
687 | 1d14ffa9 | bellard | switch (errno) {
|
688 | 1d14ffa9 | bellard | case EINTR:
|
689 | 1d14ffa9 | bellard | case EAGAIN:
|
690 | 1d14ffa9 | bellard | break;
|
691 | 1d14ffa9 | bellard | default:
|
692 | 1d14ffa9 | bellard | oss_logerr ( |
693 | 1d14ffa9 | bellard | errno, |
694 | 1d14ffa9 | bellard | "Failed to read %d bytes of audio (to %p)\n",
|
695 | 1d14ffa9 | bellard | bufs[i].len, p |
696 | 1d14ffa9 | bellard | ); |
697 | 1d14ffa9 | bellard | break;
|
698 | 1d14ffa9 | bellard | } |
699 | 1d14ffa9 | bellard | } |
700 | 1d14ffa9 | bellard | break;
|
701 | 1d14ffa9 | bellard | } |
702 | 1d14ffa9 | bellard | } |
703 | 1d14ffa9 | bellard | } |
704 | 1d14ffa9 | bellard | |
705 | 1d14ffa9 | bellard | hw->wpos = (hw->wpos + read_samples) % hw->samples; |
706 | 1d14ffa9 | bellard | return read_samples;
|
707 | 1d14ffa9 | bellard | } |
708 | 1d14ffa9 | bellard | |
709 | 1d14ffa9 | bellard | static int oss_read (SWVoiceIn *sw, void *buf, int size) |
710 | 1d14ffa9 | bellard | { |
711 | 1d14ffa9 | bellard | return audio_pcm_sw_read (sw, buf, size);
|
712 | 1d14ffa9 | bellard | } |
713 | 1d14ffa9 | bellard | |
714 | 1d14ffa9 | bellard | static int oss_ctl_in (HWVoiceIn *hw, int cmd, ...) |
715 | 1d14ffa9 | bellard | { |
716 | 1d14ffa9 | bellard | (void) hw;
|
717 | 1d14ffa9 | bellard | (void) cmd;
|
718 | 1d14ffa9 | bellard | return 0; |
719 | 1d14ffa9 | bellard | } |
720 | 1d14ffa9 | bellard | |
721 | 85571bc7 | bellard | static void *oss_audio_init (void) |
722 | 85571bc7 | bellard | { |
723 | 85571bc7 | bellard | return &conf;
|
724 | 85571bc7 | bellard | } |
725 | 85571bc7 | bellard | |
726 | 85571bc7 | bellard | static void oss_audio_fini (void *opaque) |
727 | 85571bc7 | bellard | { |
728 | 1d14ffa9 | bellard | (void) opaque;
|
729 | 85571bc7 | bellard | } |
730 | 85571bc7 | bellard | |
731 | 1d14ffa9 | bellard | static struct audio_option oss_options[] = { |
732 | 1d14ffa9 | bellard | {"FRAGSIZE", AUD_OPT_INT, &conf.fragsize,
|
733 | 1d14ffa9 | bellard | "Fragment size in bytes", NULL, 0}, |
734 | 1d14ffa9 | bellard | {"NFRAGS", AUD_OPT_INT, &conf.nfrags,
|
735 | 1d14ffa9 | bellard | "Number of fragments", NULL, 0}, |
736 | 1d14ffa9 | bellard | {"MMAP", AUD_OPT_BOOL, &conf.try_mmap,
|
737 | 1d14ffa9 | bellard | "Try using memory mapped access", NULL, 0}, |
738 | 1d14ffa9 | bellard | {"DAC_DEV", AUD_OPT_STR, &conf.devpath_out,
|
739 | 1d14ffa9 | bellard | "Path to DAC device", NULL, 0}, |
740 | 1d14ffa9 | bellard | {"ADC_DEV", AUD_OPT_STR, &conf.devpath_in,
|
741 | 1d14ffa9 | bellard | "Path to ADC device", NULL, 0}, |
742 | 8ead62cf | bellard | {"DEBUG", AUD_OPT_BOOL, &conf.debug,
|
743 | 8ead62cf | bellard | "Turn on some debugging messages", NULL, 0}, |
744 | 1d14ffa9 | bellard | {NULL, 0, NULL, NULL, NULL, 0} |
745 | 1d14ffa9 | bellard | }; |
746 | 1d14ffa9 | bellard | |
747 | 1d14ffa9 | bellard | static struct audio_pcm_ops oss_pcm_ops = { |
748 | 1d14ffa9 | bellard | oss_init_out, |
749 | 1d14ffa9 | bellard | oss_fini_out, |
750 | 1d14ffa9 | bellard | oss_run_out, |
751 | 1d14ffa9 | bellard | oss_write, |
752 | 1d14ffa9 | bellard | oss_ctl_out, |
753 | 1d14ffa9 | bellard | |
754 | 1d14ffa9 | bellard | oss_init_in, |
755 | 1d14ffa9 | bellard | oss_fini_in, |
756 | 1d14ffa9 | bellard | oss_run_in, |
757 | 1d14ffa9 | bellard | oss_read, |
758 | 1d14ffa9 | bellard | oss_ctl_in |
759 | 85571bc7 | bellard | }; |
760 | 85571bc7 | bellard | |
761 | 1d14ffa9 | bellard | struct audio_driver oss_audio_driver = {
|
762 | 1d14ffa9 | bellard | INIT_FIELD (name = ) "oss",
|
763 | 1d14ffa9 | bellard | INIT_FIELD (descr = ) "OSS http://www.opensound.com",
|
764 | 1d14ffa9 | bellard | INIT_FIELD (options = ) oss_options, |
765 | 1d14ffa9 | bellard | INIT_FIELD (init = ) oss_audio_init, |
766 | 1d14ffa9 | bellard | INIT_FIELD (fini = ) oss_audio_fini, |
767 | 1d14ffa9 | bellard | INIT_FIELD (pcm_ops = ) &oss_pcm_ops, |
768 | 1d14ffa9 | bellard | INIT_FIELD (can_be_default = ) 1,
|
769 | 1d14ffa9 | bellard | INIT_FIELD (max_voices_out = ) INT_MAX, |
770 | 1d14ffa9 | bellard | INIT_FIELD (max_voices_in = ) INT_MAX, |
771 | 1d14ffa9 | bellard | INIT_FIELD (voice_size_out = ) sizeof (OSSVoiceOut),
|
772 | 1d14ffa9 | bellard | INIT_FIELD (voice_size_in = ) sizeof (OSSVoiceIn)
|
773 | 85571bc7 | bellard | }; |