VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/winaudio.c@ 5523

Last change on this file since 5523 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.3 KB
Line 
1/** @file
2 *
3 * VBox audio device:
4 * Windows audio driver
5 */
6
7/*
8 * Copyright (C) 2006-2007 innotek GmbH
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#include <Windows.h>
20#include <mmsystem.h>
21
22#include <VBox/pdm.h>
23#include <VBox/err.h>
24
25#define LOG_GROUP LOG_GROUP_DEV_AC97
26#include <VBox/log.h>
27#include <iprt/assert.h>
28#include <iprt/uuid.h>
29#include <iprt/string.h>
30#include <iprt/alloc.h>
31
32#include "Builtins.h"
33#include "../../vl_vbox.h"
34
35#include "audio.h"
36#include "audio_int.h"
37
38#define WINMM_BUFFER_SIZE 4096
39#define WINMM_NUMBER_BUFFERS 32
40
41typedef struct OSSVoiceOut {
42 HWVoiceOut hw;
43 void *pcm_buf;
44 int fd;
45 int nfrags;
46 int fragsize;
47 int old_optr;
48 int default_bufsize;
49
50 int fStart;
51 LPWAVEHDR lpwh;
52 int cBuffers;
53 int idxBuffer;
54 HWAVEOUT hStream;
55} OSSVoiceOut;
56
57typedef struct OSSVoiceIn {
58 HWVoiceIn hw;
59 void *pcm_buf;
60 int fd;
61 int nfrags;
62 int fragsize;
63 int old_optr;
64
65 WAVEHDR wh;
66 HWAVEIN hStream;
67} OSSVoiceIn;
68
69
70static int winmm_write (SWVoiceOut *sw, void *buf, int len)
71{
72 Log(("winmm_write: %08x %x\n", buf, len));
73 return pcm_sw_write (sw, buf, len);
74}
75
76
77static void winmm_run_out (HWVoiceOut *hw)
78{
79 OSSVoiceOut *oss = (OSSVoiceOut *) hw;
80 int err, rpos, live, decr;
81 int samples;
82 uint8_t *dst;
83 st_sample_t *src;
84 MMTIME mmtime;
85
86 live = pcm_hw_get_live (hw, NULL);
87 Log(("winmm_run_out live=%x\n", live));
88 if (live <= 0)
89 return;
90
91 mmtime.wType = TIME_SAMPLES;
92 err = waveOutGetPosition(oss->hStream, &mmtime, sizeof(mmtime));
93 if (err != MMSYSERR_NOERROR) {
94 Log( ("WINMMAUD: waveOutGetPosition failed with %d\n", err));
95 return;
96 }
97 if (mmtime.u.sample > 0 && mmtime.u.sample == oss->old_optr) {
98 if (abs (hw->samples - live) < 64)
99 Log( ("winmmaudio: overrun\n"));
100 return;
101 }
102
103 samples = oss->default_bufsize >> hw->info.shift;
104
105 decr = audio_MIN (samples, live);
106
107 Log(("winmm_run_out: current pos %08X room left=%08X, decr=%08x\n", mmtime.u.sample, samples, decr));
108
109 samples = decr;
110 rpos = hw->rpos;
111 while (samples)
112 {
113 int rc;
114 int left_till_end_samples = hw->samples - rpos;
115 int convert_samples = audio_MIN (samples, left_till_end_samples);
116
117 Assert(oss->lpwh[oss->idxBuffer].dwFlags & WHDR_PREPARED);
118 Assert( (oss->lpwh[oss->idxBuffer].dwFlags & WHDR_DONE) ||
119 !(oss->lpwh[oss->idxBuffer].dwFlags & WHDR_INQUEUE));
120
121 if (!(oss->lpwh[oss->idxBuffer].dwFlags & WHDR_DONE) && (oss->lpwh[oss->idxBuffer].dwFlags & WHDR_INQUEUE))
122 {
123 Log(("winmm: buffer overrun -> current buffer=%d!!\n", oss->idxBuffer));
124 break;
125 }
126
127 src = advance (hw->mix_buf, rpos * sizeof (st_sample_t));
128 dst = oss->lpwh[oss->idxBuffer].lpData;
129
130 Log(("winmm_run_out: buffer=%d dst=%08x src=%08x convert_samples %08X\n", oss->idxBuffer, dst, src, convert_samples));
131
132 hw->clip (dst, src, convert_samples);
133 sniffer_run_out (hw, dst, convert_samples);
134
135 /* Update the size of the buffer */
136 oss->lpwh[oss->idxBuffer].dwBufferLength = convert_samples << hw->info.shift;
137 rc = waveOutWrite(oss->hStream, &oss->lpwh[oss->idxBuffer], sizeof(oss->lpwh[oss->idxBuffer]));
138 if (rc != MMSYSERR_NOERROR)
139 {
140 Log( ("WINMMAUD: waveOutWrite failed with %d\n", rc));
141 break;
142 }
143
144 memset (src, 0, convert_samples * sizeof (st_sample_t));
145
146 rpos = (rpos + convert_samples) % hw->samples;
147 samples -= convert_samples;
148
149 oss->idxBuffer++;
150 if (oss->idxBuffer >= oss->cBuffers)
151 oss->idxBuffer = 0;
152 }
153
154 pcm_hw_dec_live (hw, decr);
155 hw->rpos = rpos;
156 oss->old_optr = mmtime.u.sample;
157}
158
159static void winmm_fini_out (HWVoiceOut *hw)
160{
161 MMRESULT err;
162 OSSVoiceOut *oss = (OSSVoiceOut *) hw;
163
164 Log( ("WINMMAUD: winmm_fini_out\n"));
165 waveOutReset(oss->hStream);
166 err = waveOutClose(oss->hStream);
167 if (err != MMSYSERR_NOERROR) {
168 Log( ("WINMMAUD: Failed to close OSS descriptor %d\n", err));
169 }
170 oss->fd = -1;
171
172 if (oss->pcm_buf) {
173 RTMemFree(oss->pcm_buf);
174 oss->pcm_buf = NULL;
175 }
176}
177
178#ifdef DEBUG
179void CALLBACK winmmBufferDone(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance, DWORD dwParam1, DWORD dwParam2)
180{
181 if (uMsg == WOM_DONE)
182 {
183 LPWAVEHDR lpwh = (LPWAVEHDR)dwParam1;
184 OSSVoiceOut *oss = (OSSVoiceOut *)dwInstance;
185 int bufidx;
186
187 bufidx = (dwParam1 - (DWORD)oss->lpwh) / sizeof(WAVEHDR);
188 Log(("winmm: WOM_DONE %08X %08X index=%d\n", lpwh->lpData, lpwh->dwBufferLength, bufidx));
189 }
190 return;
191}
192
193#endif
194
195static int winmm_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt)
196{
197 OSSVoiceOut *oss = (OSSVoiceOut *) hw;
198 MMRESULT rc;
199 WAVEFORMATEX waveInfo;
200 int i;
201
202 Log(("winmm_init_out %x freq=%d nchannels=%d\n", hw, freq, nchannels));
203
204 waveInfo.cbSize = sizeof(WAVEFORMATEX);
205 waveInfo.nChannels = nchannels;
206 waveInfo.nSamplesPerSec = freq;
207 waveInfo.wFormatTag = WAVE_FORMAT_PCM;
208
209 switch (fmt)
210 {
211 case AUD_FMT_U8:
212 case AUD_FMT_S8:
213 waveInfo.wBitsPerSample = 8;
214 break;
215 case AUD_FMT_U16:
216 case AUD_FMT_S16:
217 waveInfo.wBitsPerSample = 16;
218 break;
219 default:
220 AssertFailed();
221 return -1;
222 }
223 waveInfo.nBlockAlign = waveInfo.wBitsPerSample*waveInfo.nSamplesPerSec/8;
224 waveInfo.nAvgBytesPerSec = waveInfo.wBitsPerSample*waveInfo.nSamplesPerSec;
225
226#ifdef DEBUG
227 rc = waveOutOpen(&oss->hStream, WAVE_MAPPER, &waveInfo, &winmmBufferDone, oss, CALLBACK_FUNCTION);
228#else
229 rc = waveOutOpen(&oss->hStream, WAVE_MAPPER, &waveInfo, 0, 0, CALLBACK_NULL);
230#endif
231 if (rc != MMSYSERR_NOERROR)
232 {
233 AssertMsgFailed(("waveOutOpen failed with %d\n", rc));
234 return -1;
235 }
236
237 pcm_init_info (&hw->info, freq, nchannels, fmt);
238 hw->bufsize = WINMM_NUMBER_BUFFERS * WINMM_BUFFER_SIZE;
239
240 oss->pcm_buf = RTMemAllocZ (hw->bufsize);
241 if (!oss->pcm_buf)
242 {
243 AssertFailed();
244 rc = waveOutClose (oss->hStream);
245 oss->hStream = (HWAVEOUT)-1;
246 return -1;
247 }
248
249 Log(("PCM buffer %08X size %d\n", oss->pcm_buf, hw->bufsize));
250 oss->cBuffers = hw->bufsize / WINMM_BUFFER_SIZE;
251 oss->lpwh = RTMemAllocZ (oss->cBuffers * sizeof(*oss->lpwh));
252 if (!oss->lpwh)
253 {
254 RTMemFree(oss->pcm_buf);
255 AssertFailed();
256 rc = waveOutClose (oss->hStream);
257 oss->hStream = (HWAVEOUT)-1;
258 return -1;
259 }
260
261 for (i=0;i<oss->cBuffers;i++)
262 {
263 oss->lpwh[i].lpData = (char *)oss->pcm_buf + i*WINMM_BUFFER_SIZE;
264 oss->lpwh[i].dwBufferLength = WINMM_BUFFER_SIZE;
265
266 rc = waveOutPrepareHeader(oss->hStream, &oss->lpwh[i], sizeof(oss->lpwh[i]));
267 if (rc != MMSYSERR_NOERROR)
268 {
269 AssertMsgFailed(("waveOutPrepareHeader failed with %d\n", rc));
270 return -1;
271 }
272 }
273
274 oss->default_bufsize = WINMM_BUFFER_SIZE;
275
276 waveOutSetVolume(oss->hStream, 0xffffffff);
277 return 0;
278}
279
280static int winmm_ctl_out (HWVoiceOut *hw, int cmd, ...)
281{
282 OSSVoiceOut *oss = (OSSVoiceOut *) hw;
283 MMRESULT rc;
284
285 switch (cmd) {
286 case VOICE_SETBUFSIZE:
287 {
288 int buflen, i;
289
290 va_list ap;
291 va_start (ap, cmd);
292 buflen = va_arg (ap, int);
293 va_end (ap);
294
295 Assert(buflen);
296
297 Log(("winmm_ctl_out: setbufsize to %x\n", buflen));
298
299 if (buflen > oss->default_bufsize)
300 {
301 oss->default_bufsize = buflen;
302 oss->cBuffers = hw->bufsize / buflen;
303
304 for (i=0;i<oss->cBuffers;i++)
305 {
306 rc = waveOutUnprepareHeader(oss->hStream, &oss->lpwh[i], sizeof(oss->lpwh[i]));
307 if (rc != MMSYSERR_NOERROR)
308 {
309 AssertMsgFailed(("waveOutPrepareHeader failed with %d\n", rc));
310 return -1;
311 }
312 }
313
314 for (i=0;i<oss->cBuffers;i++)
315 {
316 oss->lpwh[i].lpData = (char *)oss->pcm_buf + i*oss->default_bufsize;
317 oss->lpwh[i].dwBufferLength = oss->default_bufsize;
318
319 rc = waveOutPrepareHeader(oss->hStream, &oss->lpwh[i], sizeof(oss->lpwh[i]));
320 if (rc != MMSYSERR_NOERROR)
321 {
322 AssertMsgFailed(("waveOutPrepareHeader failed with %d\n", rc));
323 return -1;
324 }
325 }
326 }
327 break;
328 }
329
330 case VOICE_ENABLE:
331 {
332 Log( ("WINMMAUD: enabling voice\n"));
333 oss->old_optr = 0;
334 oss->idxBuffer = 0;
335 oss->fStart = 1;
336 pcm_info_clear (&hw->info, oss->pcm_buf, hw->samples);
337 break;
338 }
339
340 case VOICE_DISABLE:
341 Log( ("WINMMAUD: disabling voice\n"));
342 rc = waveOutReset(oss->hStream);
343 if (rc != MMSYSERR_NOERROR) {
344 Log( ("WINMMAUD: waveOutPause failed with %d\n", rc));
345 return -1;
346 }
347 break;
348 }
349 return 0;
350}
351
352static int winmm_init_in (HWVoiceIn *hw,
353 int freq, int nchannels, audfmt_e fmt)
354{
355 OSSVoiceIn *oss = (OSSVoiceIn *) hw;
356 MMRESULT rc;
357 WAVEFORMATEX waveInfo;
358
359 return -1;
360
361 waveInfo.cbSize = sizeof(WAVEFORMATEX);
362 waveInfo.nChannels = nchannels;
363 waveInfo.nSamplesPerSec = freq;
364 waveInfo.wFormatTag = WAVE_FORMAT_PCM;
365
366 switch (fmt)
367 {
368 case AUD_FMT_U8:
369 case AUD_FMT_S8:
370 waveInfo.wBitsPerSample = 8;
371 break;
372 case AUD_FMT_U16:
373 case AUD_FMT_S16:
374 waveInfo.wBitsPerSample = 16;
375 break;
376 default:
377 AssertFailed();
378 return -1;
379 }
380 waveInfo.nBlockAlign = waveInfo.wBitsPerSample*waveInfo.nSamplesPerSec/8;
381 waveInfo.nAvgBytesPerSec = waveInfo.wBitsPerSample*waveInfo.nSamplesPerSec;
382
383 rc = waveInOpen(&oss->hStream, WAVE_MAPPER, &waveInfo, 0, 0, CALLBACK_NULL);
384 if (rc != MMSYSERR_NOERROR)
385 {
386 Log(("waveInOpen failed with %d\n", rc));
387 return -1;
388 }
389
390 pcm_init_info (&hw->info, freq, nchannels, fmt);
391 hw->bufsize = waveInfo.nAvgBytesPerSec/2;
392
393 oss->pcm_buf = RTMemAllocZ (hw->bufsize);
394 if (!oss->pcm_buf) {
395 rc = waveInClose(oss->hStream);
396 oss->hStream = (HWAVEIN)-1;
397 return -1;
398 }
399
400 return 0;
401}
402
403static void winmm_fini_in (HWVoiceIn *hw)
404{
405 MMRESULT err;
406 OSSVoiceIn *oss = (OSSVoiceIn *) hw;
407 err = waveInClose(oss->hStream);
408 if (err) {
409 Log( ("WINMMAUD: waveInClose failed with %d\n", err));
410 }
411 oss->fd = -1;
412 if (oss->pcm_buf) {
413 RTMemFree(oss->pcm_buf);
414 oss->pcm_buf = NULL;
415 }
416}
417
418static void winmm_run_in (HWVoiceIn *hw)
419{
420#if 0
421 OSSVoiceIn *oss = (OSSVoiceIn *) hw;
422 int hwshift = hw->info.shift;
423 int i;
424 int live = hw->total_samples_acquired - pcm_hw_find_min_samples_in (hw);
425 int dead = hw->samples - live;
426 size_t read_samples = 0;
427 struct {
428 int add;
429 int len;
430 } bufs[2] = {
431 { hw->wpos },
432 { 0, 0 }
433 };
434
435 if (!dead) {
436 Log( ("WINMMAUD: empty tot=%d min=%d\n",
437 hw->total_samples_acquired, pcm_hw_find_min_samples_in (hw)));
438 return;
439 }
440
441 if (hw->wpos + dead > hw->samples) {
442 bufs[0].len = (hw->samples - hw->wpos) << hwshift;
443 bufs[1].len = (dead - (hw->samples - hw->wpos)) << hwshift;
444 }
445 else {
446 bufs[0].len = dead << hwshift;
447 }
448
449
450 for (i = 0; i < 2; ++i) {
451 ssize_t nread;
452
453 if (bufs[i].len) {
454 void *p = advance (oss->pcm_buf, bufs[i].add << hwshift);
455 nread = read (oss->fd, p, bufs[i].len);
456
457 if (nread > 0) {
458 if (nread & hw->info.align) {
459 Log( ("WINMMAUD: Unaligned read %d\n", nread));
460 }
461 read_samples += nread >> hwshift;
462 hw->conv (hw->conv_buf + bufs[i].add, p, nread >> hwshift,
463 &nominal_volume);
464 }
465
466 if (bufs[i].len - nread) {
467 if (nread == -1) {
468 switch (errno) {
469 case EINTR:
470 case EAGAIN:
471 break;
472 default:
473 Log( ("WINMMAUD: Failed to read %d bytes (to %p): %s\n",
474 bufs[i].len, p, errstr ()));
475 }
476 }
477 break;
478 }
479 }
480 }
481 hw->total_samples_acquired += read_samples;
482 hw->wpos = (hw->wpos + read_samples) % hw->samples;
483#endif
484}
485
486static int winmm_read (SWVoiceIn *sw, void *buf, int size)
487{
488 return pcm_sw_read (sw, buf, size);
489}
490
491static int winmm_ctl_in (HWVoiceIn *hw, int cmd, ...)
492{
493 (void) hw;
494 (void) cmd;
495 return 0;
496}
497
498#if 0
499static int winmm_read_recsrc (int fd)
500{
501 int recsrc;
502 int err = ioctl (fd, SOUND_MIXER_READ_RECSRC, &recsrc);
503 if (err) {
504 Log( ("WINMMAUD: Failed to read record source mask\nReason: %s\n",
505 errstr ()));
506 return -1;
507 }
508 return recsrc;
509}
510
511static int winmm_write_recsrc (int fd, int *recsrc)
512{
513 int err = ioctl (fd, SOUND_MIXER_READ_RECSRC, &recsrc);
514 if (err) {
515 Log( ("WINMMAUD: Failed to write record source mask\nReason: %s\n",
516 errstr ()));
517 return -1;
518 }
519 return 0;
520}
521
522static const char *winmm_mixer_names[] = SOUND_DEVICE_NAMES;
523
524static int winmm_read_volume (int fd, int ctl)
525{
526 int vol;
527 MMRESULT err;
528 DWORD dwVolume;
529
530 err = waveOutGetVolume(oss->hStream, &dwVolume);
531 if (err) {
532 Log( ("WINMMAUD: Failed to read %s volume\nReason: %s\n",
533 winmm_mixer_names[ctl], errstr ()));
534 return -1;
535 }
536 return (int) (((dwVolume & 0xFFFF) * 100) / 0xFFFF);
537}
538
539static int winmm_write_volume (int fd, int ctl, int *vol)
540{
541 DWORD dwVolume;
542
543 dwVolume = (vol * 0xFFFF / 100);
544 dwVolume = dwVolume | (dwVolume << 16);
545
546 err = waveOutSetVolume(oss->hStream, dwVolume);
547 if (err) {
548 Log( ("WINMMAUD: Failed to write %s volume\nReason: %s\n",
549 winmm_mixer_names[ctl], errstr ()));
550 return -1;
551 }
552 return 0;
553}
554#endif
555
556static void *winmm_audio_init (void)
557{
558#if 0
559 int fd, err, i;
560
561 fd = open (conf.mixer_name, O_RDWR);
562 if (fd < 0) {
563 Log( ("WINMMAUD: Failed to open mixer `%s'\nReason: %s\n",
564 conf.mixer_name, errstr ()));
565 goto ret;
566 }
567
568 conf.recsrc = winmm_read_recsrc (fd);
569
570 if (audio_state.allow_mixer_access) {
571 for (i = 0; i < sizeof (conf.vol) / sizeof (conf.vol[0]); ++i) {
572 conf.vol[0].vol = winmm_read_volume (fd, conf.vol[i].ctl);
573 }
574 }
575
576 err = close (fd);
577 if (err) {
578 Log( ("WINMMAUD: Failed to close mixer device\nReason: %s\n", errstr ()));
579 }
580 ret:
581 return &conf;
582#endif
583 return (void *)1;
584}
585
586static void winmm_audio_fini (void *opaque)
587{
588#if 0
589 int fd, err, temp, i;
590
591 fd = open (conf.mixer_name, O_RDWR);
592 if (fd < 0) {
593 Log( ("WINMMAUD: Failed to open mixer `%s'\nReason: %s\n",
594 conf.mixer_name, errstr ()));
595 return;
596 }
597
598 if (conf.recsrc != -1) {
599 temp = conf.recsrc;
600 winmm_write_recsrc (fd, &temp);
601 }
602
603 for (i = 0; i < sizeof (conf.vol) / sizeof (conf.vol[0]); ++i) {
604 temp = conf.vol[i].vol;
605 if (temp != -1)
606 winmm_write_volume (fd, conf.vol[i].ctl, &temp);
607 }
608
609 err = close (fd);
610 if (err) {
611 Log( ("WINMMAUD: Failed to close mixer device\nReason: %s\n", errstr ()));
612 }
613#endif
614}
615
616#if 0
617static int aud_to_winmm_record_source (audrecsource_t s)
618{
619 switch (s) {
620 case AUD_REC_MIC: return SOUND_MASK_MIC;
621 case AUD_REC_CD: return SOUND_MASK_CD;
622 case AUD_REC_VIDEO: return SOUND_MASK_VIDEO;
623 case AUD_REC_AUX: return SOUND_MASK_LINE1; /* ??? */
624 case AUD_REC_LINE_IN: return SOUND_MASK_LINE;
625 case AUD_REC_PHONE: return SOUND_MASK_PHONEIN;
626 default:
627 Log( ("WINMMAUD: Unknown recording source %d using MIC\n", s));
628 return SOUND_MIXER_MIC;
629 }
630}
631
632static int winmm_to_aud_record_source (int s)
633{
634 switch (s) {
635 case SOUND_MASK_MIC: return AUD_REC_MIC;
636 case SOUND_MASK_CD: return AUD_REC_CD;
637 case SOUND_MASK_VIDEO: return AUD_REC_VIDEO;
638 case SOUND_MASK_LINE1: return AUD_REC_AUX;
639 case SOUND_MASK_LINE: return AUD_REC_LINE_IN;
640 case SOUND_MASK_PHONEIN: return AUD_REC_PHONE;
641 default:
642 Log( ("WINMMAUD: Unknown OSS recording source %d using MIC\n", s));
643 return AUD_REC_MIC;
644 }
645}
646#endif
647
648#if 0
649static int winmm_set_record_source (audrecsource_t *lrs, audrecsource_t *rrs)
650{
651#if 0
652 int source, fd, err;
653 int ret = -1;
654
655 source = aud_to_winmm_record_source (*lrs);
656 if (source == -1) {
657 Log( ("WINMMAUD: Unsupported recording source %s\n",
658 AUD_record_source_name (*lrs)));
659 return -1;
660 }
661
662 fd = open (conf.mixer_name, O_RDWR);
663
664 if (fd == -1) {
665 Log( ("WINMMAUD: Failed to open mixer device\nReason: %s\n", errstr ()));
666 return -1;
667 }
668
669 err = ioctl (fd, SOUND_MIXER_WRITE_RECSRC, &source);
670 if (err) {
671 Log( ("WINMMAUD: Failed to set recording source to %s\nReason: %s\n",
672 AUD_record_source_name (*lrs), errstr ()));
673 goto err;
674 }
675
676 *rrs = *lrs = winmm_to_aud_record_source (source);
677 ret = 0;
678
679 err:
680 if (close (fd)) {
681 Log( ("WINMMAUD: Failed to close mixer device\nReason: %s\n",
682 errstr ())));
683 }
684 return ret;
685#else
686 return 0;
687#endif
688}
689
690static int winmm_set_volume (audmixerctl_t m, int *mute,
691 uint8_t *lvol, uint8_t *rvol)
692{
693 int vol;
694 int winmm_mixerctl, err;
695 int fd = open (conf.mixer_name, O_RDWR);
696 int ret = -1;
697
698 if (fd == -1) {
699 Log( ("WINMMAUD: Failed to open mixer device\nReason: %s\n", errstr ()));
700 return -1;
701 }
702
703 vol = *mute ? 0 : ((*lvol * 100) / 256) | (((*rvol * 100) / 256) << 8);
704
705 switch (m) {
706 case AUD_MIXER_VOLUME:
707 winmm_mixerctl = SOUND_MIXER_VOLUME;
708 break;
709 case AUD_MIXER_PCM:
710 winmm_mixerctl = SOUND_MIXER_PCM;
711 break;
712 case AUD_MIXER_LINE_IN:
713 winmm_mixerctl = SOUND_MIXER_LINE;
714 break;
715 default:
716 Log( ("WINMMAUD: Unknown mixer control %d\n", m));
717 return -1;
718 }
719
720 err = ioctl (fd, MIXER_WRITE (winmm_mixerctl), &vol);
721 if (err) {
722 Log( ("WINMMAUD: Failed to update mixer\nReason: %s\n", errstr ()));
723 goto err;
724 }
725
726 if (!*mute) {
727 *lvol = ((vol & 0xff) * 100) / 256;
728 *rvol = ((vol >> 8) * 100) / 256;
729 }
730 ret = 0;
731
732 err:
733 if (close (fd)) {
734 Log( ("WINMMAUD: Failed to close mixer device\nReason: %s\n",
735 errstr ()));
736 }
737 return ret;
738}
739#endif
740
741static int winmm_audio_ctl (void *opaque, int cmd, ...)
742{
743 int ret = 0;
744#if 0
745 switch (cmd) {
746 case SET_RECORD_SOURCE:
747 {
748 va_list ap;
749 va_start (ap, cmd);
750 audrecsource_t *lrs = va_arg (ap, audrecsource_t *);
751 audrecsource_t *rrs = va_arg (ap, audrecsource_t *);
752 va_end (ap);
753 ret = winmm_set_record_source (lrs, rrs);
754 }
755 break;
756 case SET_VOLUME:
757 {
758 va_list ap;
759 va_start (ap, cmd);
760 audmixerctl_t m = va_arg (ap, audmixerctl_t);
761 int *mute = va_arg (ap, int *);
762 uint8_t *lvol = va_arg (ap, uint8_t *);
763 uint8_t *rvol = va_arg (ap, uint8_t *);
764 va_end (ap);
765 ret = winmm_set_volume (m, mute, lvol, rvol);
766 }
767 break;
768 default:
769 ret = -1;
770 break;
771 }
772#endif
773 return ret;
774}
775
776static struct pcm_ops winmm_pcm_ops = {
777 winmm_init_out,
778 winmm_fini_out,
779 winmm_run_out,
780 winmm_write,
781 winmm_ctl_out,
782
783 winmm_init_in,
784 winmm_fini_in,
785 winmm_run_in,
786 winmm_read,
787 winmm_ctl_in,
788};
789
790struct audio_driver winmm_audio_driver = {
791 "WINMM",
792 winmm_audio_init,
793 winmm_audio_fini,
794 winmm_audio_ctl,
795 &winmm_pcm_ops,
796 1,
797 INT_MAX,
798 INT_MAX,
799 sizeof (OSSVoiceOut),
800 sizeof (OSSVoiceIn)
801};
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette