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