4 * Copyright (c) 2003-2005 Vassili Karpov (malc)
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 #include "qemu/osdep.h"
27 #include "monitor/monitor.h"
28 #include "qemu/timer.h"
29 #include "sysemu/sysemu.h"
30 #include "qemu/cutils.h"
31 #include "sysemu/replay.h"
34 #define AUDIO_CAP "audio"
35 #include "audio_int.h"
37 /* #define DEBUG_LIVE */
38 /* #define DEBUG_OUT */
39 /* #define DEBUG_CAPTURE */
40 /* #define DEBUG_POLL */
42 #define SW_NAME(sw) (sw)->name ? (sw)->name : "unknown"
45 /* Order of CONFIG_AUDIO_DRIVERS is import.
46 The 1st one is the one used by default, that is the reason
47 that we generate the list.
49 static const char *audio_prio_list
[] = {
56 static QLIST_HEAD(, audio_driver
) audio_drivers
;
58 void audio_driver_register(audio_driver
*drv
)
60 QLIST_INSERT_HEAD(&audio_drivers
, drv
, next
);
63 audio_driver
*audio_driver_lookup(const char *name
)
65 struct audio_driver
*d
;
67 QLIST_FOREACH(d
, &audio_drivers
, next
) {
68 if (strcmp(name
, d
->name
) == 0) {
73 audio_module_load_one(name
);
74 QLIST_FOREACH(d
, &audio_drivers
, next
) {
75 if (strcmp(name
, d
->name
) == 0) {
83 static void audio_module_load_all(void)
87 for (i
= 0; i
< ARRAY_SIZE(audio_prio_list
); i
++) {
88 audio_driver_lookup(audio_prio_list
[i
]);
92 struct fixed_settings
{
96 struct audsettings settings
;
100 struct fixed_settings fixed_out
;
101 struct fixed_settings fixed_in
;
109 .fixed_out
= { /* DAC fixed settings */
117 .endianness
= AUDIO_HOST_ENDIANNESS
,
121 .fixed_in
= { /* ADC fixed settings */
129 .endianness
= AUDIO_HOST_ENDIANNESS
,
133 .period
= { .hertz
= 100 },
138 static AudioState glob_audio_state
;
140 const struct mixeng_volume nominal_volume
= {
151 #ifdef AUDIO_IS_FLAWLESS_AND_NO_CHECKS_ARE_REQURIED
154 static void audio_print_options (const char *prefix
,
155 struct audio_option
*opt
);
157 int audio_bug (const char *funcname
, int cond
)
162 AUD_log (NULL
, "A bug was just triggered in %s\n", funcname
);
164 struct audio_driver
*d
;
167 AUD_log (NULL
, "Save all your work and restart without audio\n");
168 AUD_log (NULL
, "Please send bug report to av1474@comtv.ru\n");
169 AUD_log (NULL
, "I am sorry\n");
170 d
= glob_audio_state
.drv
;
172 audio_print_options (d
->name
, d
->options
);
175 AUD_log (NULL
, "Context:\n");
177 #if defined AUDIO_BREAKPOINT_ON_BUG
178 # if defined HOST_I386
179 # if defined __GNUC__
181 # elif defined _MSC_VER
196 static inline int audio_bits_to_index (int bits
)
209 audio_bug ("bits_to_index", 1);
210 AUD_log (NULL
, "invalid bits %d\n", bits
);
215 void *audio_calloc (const char *funcname
, int nmemb
, size_t size
)
221 cond
= !nmemb
|| !size
;
225 if (audio_bug ("audio_calloc", cond
)) {
226 AUD_log (NULL
, "%s passed invalid arguments to audio_calloc\n",
228 AUD_log (NULL
, "nmemb=%d size=%zu (len=%zu)\n", nmemb
, size
, len
);
232 return g_malloc0 (len
);
235 static char *audio_alloc_prefix (const char *s
)
237 const char qemu_prefix
[] = "QEMU_";
246 r
= g_malloc (len
+ sizeof (qemu_prefix
));
248 u
= r
+ sizeof (qemu_prefix
) - 1;
250 pstrcpy (r
, len
+ sizeof (qemu_prefix
), qemu_prefix
);
251 pstrcat (r
, len
+ sizeof (qemu_prefix
), s
);
253 for (i
= 0; i
< len
; ++i
) {
254 u
[i
] = qemu_toupper(u
[i
]);
260 static const char *audio_audfmt_to_string (audfmt_e fmt
)
282 dolog ("Bogus audfmt %d returning S16\n", fmt
);
286 static audfmt_e
audio_string_to_audfmt (const char *s
, audfmt_e defval
,
289 if (!strcasecmp (s
, "u8")) {
293 else if (!strcasecmp (s
, "u16")) {
297 else if (!strcasecmp (s
, "u32")) {
301 else if (!strcasecmp (s
, "s8")) {
305 else if (!strcasecmp (s
, "s16")) {
309 else if (!strcasecmp (s
, "s32")) {
314 dolog ("Bogus audio format `%s' using %s\n",
315 s
, audio_audfmt_to_string (defval
));
321 static audfmt_e
audio_get_conf_fmt (const char *envname
,
325 const char *var
= getenv (envname
);
330 return audio_string_to_audfmt (var
, defval
, defaultp
);
333 static int audio_get_conf_int (const char *key
, int defval
, int *defaultp
)
338 strval
= getenv (key
);
339 if (strval
&& !qemu_strtoi(strval
, NULL
, 10, &val
)) {
349 static const char *audio_get_conf_str (const char *key
,
353 const char *val
= getenv (key
);
364 void AUD_vlog (const char *cap
, const char *fmt
, va_list ap
)
367 fprintf(stderr
, "%s: ", cap
);
370 vfprintf(stderr
, fmt
, ap
);
373 void AUD_log (const char *cap
, const char *fmt
, ...)
378 AUD_vlog (cap
, fmt
, ap
);
382 static void audio_print_options (const char *prefix
,
383 struct audio_option
*opt
)
388 dolog ("No prefix specified\n");
393 dolog ("No options\n");
397 uprefix
= audio_alloc_prefix (prefix
);
399 for (; opt
->name
; opt
++) {
400 const char *state
= "default";
401 printf (" %s_%s: ", uprefix
, opt
->name
);
403 if (opt
->overriddenp
&& *opt
->overriddenp
) {
410 int *intp
= opt
->valp
;
411 printf ("boolean, %s = %d\n", state
, *intp
? 1 : 0);
417 int *intp
= opt
->valp
;
418 printf ("integer, %s = %d\n", state
, *intp
);
424 audfmt_e
*fmtp
= opt
->valp
;
426 "format, %s = %s, (one of: U8 S8 U16 S16 U32 S32)\n",
428 audio_audfmt_to_string (*fmtp
)
435 const char **strp
= opt
->valp
;
436 printf ("string, %s = %s\n",
438 *strp
? *strp
: "(not set)");
444 dolog ("Bad value tag for option %s_%s %d\n",
445 uprefix
, opt
->name
, opt
->tag
);
448 printf (" %s\n", opt
->descr
);
454 static void audio_process_options (const char *prefix
,
455 struct audio_option
*opt
)
459 if (audio_bug(__func__
, !prefix
)) {
460 dolog ("prefix = NULL\n");
464 if (audio_bug(__func__
, !opt
)) {
465 dolog ("opt = NULL\n");
469 prefix_upper
= g_utf8_strup(prefix
, -1);
471 for (; opt
->name
; opt
++) {
476 dolog ("Option value pointer for `%s' is not set\n",
481 optname
= g_strdup_printf("QEMU_%s_%s", prefix_upper
, opt
->name
);
488 int *intp
= opt
->valp
;
489 *intp
= audio_get_conf_int (optname
, *intp
, &def
);
495 audfmt_e
*fmtp
= opt
->valp
;
496 *fmtp
= audio_get_conf_fmt (optname
, *fmtp
, &def
);
502 const char **strp
= opt
->valp
;
503 *strp
= audio_get_conf_str (optname
, *strp
, &def
);
508 dolog ("Bad value tag for option `%s' - %d\n",
513 if (!opt
->overriddenp
) {
514 opt
->overriddenp
= &opt
->overridden
;
516 *opt
->overriddenp
= !def
;
519 g_free(prefix_upper
);
522 static void audio_print_settings (struct audsettings
*as
)
524 dolog ("frequency=%d nchannels=%d fmt=", as
->freq
, as
->nchannels
);
528 AUD_log (NULL
, "S8");
531 AUD_log (NULL
, "U8");
534 AUD_log (NULL
, "S16");
537 AUD_log (NULL
, "U16");
540 AUD_log (NULL
, "S32");
543 AUD_log (NULL
, "U32");
546 AUD_log (NULL
, "invalid(%d)", as
->fmt
);
550 AUD_log (NULL
, " endianness=");
551 switch (as
->endianness
) {
553 AUD_log (NULL
, "little");
556 AUD_log (NULL
, "big");
559 AUD_log (NULL
, "invalid");
562 AUD_log (NULL
, "\n");
565 static int audio_validate_settings (struct audsettings
*as
)
569 invalid
= as
->nchannels
!= 1 && as
->nchannels
!= 2;
570 invalid
|= as
->endianness
!= 0 && as
->endianness
!= 1;
585 invalid
|= as
->freq
<= 0;
586 return invalid
? -1 : 0;
589 static int audio_pcm_info_eq (struct audio_pcm_info
*info
, struct audsettings
*as
)
591 int bits
= 8, sign
= 0;
614 return info
->freq
== as
->freq
615 && info
->nchannels
== as
->nchannels
616 && info
->sign
== sign
617 && info
->bits
== bits
618 && info
->swap_endianness
== (as
->endianness
!= AUDIO_HOST_ENDIANNESS
);
621 void audio_pcm_init_info (struct audio_pcm_info
*info
, struct audsettings
*as
)
623 int bits
= 8, sign
= 0, shift
= 0;
646 info
->freq
= as
->freq
;
649 info
->nchannels
= as
->nchannels
;
650 info
->shift
= (as
->nchannels
== 2) + shift
;
651 info
->align
= (1 << info
->shift
) - 1;
652 info
->bytes_per_second
= info
->freq
<< info
->shift
;
653 info
->swap_endianness
= (as
->endianness
!= AUDIO_HOST_ENDIANNESS
);
656 void audio_pcm_info_clear_buf (struct audio_pcm_info
*info
, void *buf
, int len
)
663 memset (buf
, 0x00, len
<< info
->shift
);
666 switch (info
->bits
) {
668 memset (buf
, 0x80, len
<< info
->shift
);
675 int shift
= info
->nchannels
- 1;
678 if (info
->swap_endianness
) {
682 for (i
= 0; i
< len
<< shift
; i
++) {
692 int shift
= info
->nchannels
- 1;
693 int32_t s
= INT32_MAX
;
695 if (info
->swap_endianness
) {
699 for (i
= 0; i
< len
<< shift
; i
++) {
706 AUD_log (NULL
, "audio_pcm_info_clear_buf: invalid bits %d\n",
716 static void noop_conv (struct st_sample
*dst
, const void *src
, int samples
)
723 static CaptureVoiceOut
*audio_pcm_capture_find_specific (
724 struct audsettings
*as
727 CaptureVoiceOut
*cap
;
728 AudioState
*s
= &glob_audio_state
;
730 for (cap
= s
->cap_head
.lh_first
; cap
; cap
= cap
->entries
.le_next
) {
731 if (audio_pcm_info_eq (&cap
->hw
.info
, as
)) {
738 static void audio_notify_capture (CaptureVoiceOut
*cap
, audcnotification_e cmd
)
740 struct capture_callback
*cb
;
743 dolog ("notification %d sent\n", cmd
);
745 for (cb
= cap
->cb_head
.lh_first
; cb
; cb
= cb
->entries
.le_next
) {
746 cb
->ops
.notify (cb
->opaque
, cmd
);
750 static void audio_capture_maybe_changed (CaptureVoiceOut
*cap
, int enabled
)
752 if (cap
->hw
.enabled
!= enabled
) {
753 audcnotification_e cmd
;
754 cap
->hw
.enabled
= enabled
;
755 cmd
= enabled
? AUD_CNOTIFY_ENABLE
: AUD_CNOTIFY_DISABLE
;
756 audio_notify_capture (cap
, cmd
);
760 static void audio_recalc_and_notify_capture (CaptureVoiceOut
*cap
)
762 HWVoiceOut
*hw
= &cap
->hw
;
766 for (sw
= hw
->sw_head
.lh_first
; sw
; sw
= sw
->entries
.le_next
) {
772 audio_capture_maybe_changed (cap
, enabled
);
775 static void audio_detach_capture (HWVoiceOut
*hw
)
777 SWVoiceCap
*sc
= hw
->cap_head
.lh_first
;
780 SWVoiceCap
*sc1
= sc
->entries
.le_next
;
781 SWVoiceOut
*sw
= &sc
->sw
;
782 CaptureVoiceOut
*cap
= sc
->cap
;
783 int was_active
= sw
->active
;
786 st_rate_stop (sw
->rate
);
790 QLIST_REMOVE (sw
, entries
);
791 QLIST_REMOVE (sc
, entries
);
794 /* We have removed soft voice from the capture:
795 this might have changed the overall status of the capture
796 since this might have been the only active voice */
797 audio_recalc_and_notify_capture (cap
);
803 static int audio_attach_capture (HWVoiceOut
*hw
)
805 AudioState
*s
= &glob_audio_state
;
806 CaptureVoiceOut
*cap
;
808 audio_detach_capture (hw
);
809 for (cap
= s
->cap_head
.lh_first
; cap
; cap
= cap
->entries
.le_next
) {
812 HWVoiceOut
*hw_cap
= &cap
->hw
;
814 sc
= audio_calloc(__func__
, 1, sizeof(*sc
));
816 dolog ("Could not allocate soft capture voice (%zu bytes)\n",
826 sw
->active
= hw
->enabled
;
827 sw
->conv
= noop_conv
;
828 sw
->ratio
= ((int64_t) hw_cap
->info
.freq
<< 32) / sw
->info
.freq
;
829 sw
->vol
= nominal_volume
;
830 sw
->rate
= st_rate_start (sw
->info
.freq
, hw_cap
->info
.freq
);
832 dolog ("Could not start rate conversion for `%s'\n", SW_NAME (sw
));
836 QLIST_INSERT_HEAD (&hw_cap
->sw_head
, sw
, entries
);
837 QLIST_INSERT_HEAD (&hw
->cap_head
, sc
, entries
);
839 sw
->name
= g_strdup_printf ("for %p %d,%d,%d",
840 hw
, sw
->info
.freq
, sw
->info
.bits
,
842 dolog ("Added %s active = %d\n", sw
->name
, sw
->active
);
845 audio_capture_maybe_changed (cap
, 1);
852 * Hard voice (capture)
854 static int audio_pcm_hw_find_min_in (HWVoiceIn
*hw
)
857 int m
= hw
->total_samples_captured
;
859 for (sw
= hw
->sw_head
.lh_first
; sw
; sw
= sw
->entries
.le_next
) {
861 m
= audio_MIN (m
, sw
->total_hw_samples_acquired
);
867 int audio_pcm_hw_get_live_in (HWVoiceIn
*hw
)
869 int live
= hw
->total_samples_captured
- audio_pcm_hw_find_min_in (hw
);
870 if (audio_bug(__func__
, live
< 0 || live
> hw
->samples
)) {
871 dolog ("live=%d hw->samples=%d\n", live
, hw
->samples
);
877 int audio_pcm_hw_clip_out (HWVoiceOut
*hw
, void *pcm_buf
,
878 int live
, int pending
)
880 int left
= hw
->samples
- pending
;
881 int len
= audio_MIN (left
, live
);
885 struct st_sample
*src
= hw
->mix_buf
+ hw
->rpos
;
886 uint8_t *dst
= advance (pcm_buf
, hw
->rpos
<< hw
->info
.shift
);
887 int samples_till_end_of_buf
= hw
->samples
- hw
->rpos
;
888 int samples_to_clip
= audio_MIN (len
, samples_till_end_of_buf
);
890 hw
->clip (dst
, src
, samples_to_clip
);
892 hw
->rpos
= (hw
->rpos
+ samples_to_clip
) % hw
->samples
;
893 len
-= samples_to_clip
;
894 clipped
+= samples_to_clip
;
900 * Soft voice (capture)
902 static int audio_pcm_sw_get_rpos_in (SWVoiceIn
*sw
)
904 HWVoiceIn
*hw
= sw
->hw
;
905 int live
= hw
->total_samples_captured
- sw
->total_hw_samples_acquired
;
908 if (audio_bug(__func__
, live
< 0 || live
> hw
->samples
)) {
909 dolog ("live=%d hw->samples=%d\n", live
, hw
->samples
);
913 rpos
= hw
->wpos
- live
;
918 return hw
->samples
+ rpos
;
922 int audio_pcm_sw_read (SWVoiceIn
*sw
, void *buf
, int size
)
924 HWVoiceIn
*hw
= sw
->hw
;
925 int samples
, live
, ret
= 0, swlim
, isamp
, osamp
, rpos
, total
= 0;
926 struct st_sample
*src
, *dst
= sw
->buf
;
928 rpos
= audio_pcm_sw_get_rpos_in (sw
) % hw
->samples
;
930 live
= hw
->total_samples_captured
- sw
->total_hw_samples_acquired
;
931 if (audio_bug(__func__
, live
< 0 || live
> hw
->samples
)) {
932 dolog ("live_in=%d hw->samples=%d\n", live
, hw
->samples
);
936 samples
= size
>> sw
->info
.shift
;
941 swlim
= (live
* sw
->ratio
) >> 32;
942 swlim
= audio_MIN (swlim
, samples
);
945 src
= hw
->conv_buf
+ rpos
;
946 isamp
= hw
->wpos
- rpos
;
949 isamp
= hw
->samples
- rpos
;
957 if (audio_bug(__func__
, osamp
< 0)) {
958 dolog ("osamp=%d\n", osamp
);
962 st_rate_flow (sw
->rate
, src
, dst
, &isamp
, &osamp
);
964 rpos
= (rpos
+ isamp
) % hw
->samples
;
970 if (!(hw
->ctl_caps
& VOICE_VOLUME_CAP
)) {
971 mixeng_volume (sw
->buf
, ret
, &sw
->vol
);
974 sw
->clip (buf
, sw
->buf
, ret
);
975 sw
->total_hw_samples_acquired
+= total
;
976 return ret
<< sw
->info
.shift
;
980 * Hard voice (playback)
982 static int audio_pcm_hw_find_min_out (HWVoiceOut
*hw
, int *nb_livep
)
988 for (sw
= hw
->sw_head
.lh_first
; sw
; sw
= sw
->entries
.le_next
) {
989 if (sw
->active
|| !sw
->empty
) {
990 m
= audio_MIN (m
, sw
->total_hw_samples_mixed
);
999 static int audio_pcm_hw_get_live_out (HWVoiceOut
*hw
, int *nb_live
)
1004 smin
= audio_pcm_hw_find_min_out (hw
, &nb_live1
);
1006 *nb_live
= nb_live1
;
1012 if (audio_bug(__func__
, live
< 0 || live
> hw
->samples
)) {
1013 dolog ("live=%d hw->samples=%d\n", live
, hw
->samples
);
1022 * Soft voice (playback)
1024 int audio_pcm_sw_write (SWVoiceOut
*sw
, void *buf
, int size
)
1026 int hwsamples
, samples
, isamp
, osamp
, wpos
, live
, dead
, left
, swlim
, blck
;
1027 int ret
= 0, pos
= 0, total
= 0;
1033 hwsamples
= sw
->hw
->samples
;
1035 live
= sw
->total_hw_samples_mixed
;
1036 if (audio_bug(__func__
, live
< 0 || live
> hwsamples
)) {
1037 dolog ("live=%d hw->samples=%d\n", live
, hwsamples
);
1041 if (live
== hwsamples
) {
1043 dolog ("%s is full %d\n", sw
->name
, live
);
1048 wpos
= (sw
->hw
->rpos
+ live
) % hwsamples
;
1049 samples
= size
>> sw
->info
.shift
;
1051 dead
= hwsamples
- live
;
1052 swlim
= ((int64_t) dead
<< 32) / sw
->ratio
;
1053 swlim
= audio_MIN (swlim
, samples
);
1055 sw
->conv (sw
->buf
, buf
, swlim
);
1057 if (!(sw
->hw
->ctl_caps
& VOICE_VOLUME_CAP
)) {
1058 mixeng_volume (sw
->buf
, swlim
, &sw
->vol
);
1063 dead
= hwsamples
- live
;
1064 left
= hwsamples
- wpos
;
1065 blck
= audio_MIN (dead
, left
);
1074 sw
->hw
->mix_buf
+ wpos
,
1082 wpos
= (wpos
+ osamp
) % hwsamples
;
1086 sw
->total_hw_samples_mixed
+= total
;
1087 sw
->empty
= sw
->total_hw_samples_mixed
== 0;
1091 "%s: write size %d ret %d total sw %d\n",
1093 size
>> sw
->info
.shift
,
1095 sw
->total_hw_samples_mixed
1099 return ret
<< sw
->info
.shift
;
1103 static void audio_pcm_print_info (const char *cap
, struct audio_pcm_info
*info
)
1105 dolog ("%s: bits %d, sign %d, freq %d, nchan %d\n",
1106 cap
, info
->bits
, info
->sign
, info
->freq
, info
->nchannels
);
1111 #include "audio_template.h"
1113 #include "audio_template.h"
1119 static bool audio_timer_running
;
1120 static uint64_t audio_timer_last
;
1122 static int audio_is_timer_needed (void)
1124 HWVoiceIn
*hwi
= NULL
;
1125 HWVoiceOut
*hwo
= NULL
;
1127 while ((hwo
= audio_pcm_hw_find_any_enabled_out (hwo
))) {
1128 if (!hwo
->poll_mode
) return 1;
1130 while ((hwi
= audio_pcm_hw_find_any_enabled_in (hwi
))) {
1131 if (!hwi
->poll_mode
) return 1;
1136 static void audio_reset_timer (AudioState
*s
)
1138 if (audio_is_timer_needed ()) {
1139 timer_mod_anticipate_ns(s
->ts
,
1140 qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) + conf
.period
.ticks
);
1141 if (!audio_timer_running
) {
1142 audio_timer_running
= true;
1143 audio_timer_last
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
1144 trace_audio_timer_start(conf
.period
.ticks
/ SCALE_MS
);
1148 if (audio_timer_running
) {
1149 audio_timer_running
= false;
1150 trace_audio_timer_stop();
1155 static void audio_timer (void *opaque
)
1159 now
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
1160 diff
= now
- audio_timer_last
;
1161 if (diff
> conf
.period
.ticks
* 3 / 2) {
1162 trace_audio_timer_delayed(diff
/ SCALE_MS
);
1164 audio_timer_last
= now
;
1166 audio_run ("timer");
1167 audio_reset_timer (opaque
);
1173 int AUD_write (SWVoiceOut
*sw
, void *buf
, int size
)
1176 /* XXX: Consider options */
1180 if (!sw
->hw
->enabled
) {
1181 dolog ("Writing to disabled voice %s\n", SW_NAME (sw
));
1185 return sw
->hw
->pcm_ops
->write(sw
, buf
, size
);
1188 int AUD_read (SWVoiceIn
*sw
, void *buf
, int size
)
1191 /* XXX: Consider options */
1195 if (!sw
->hw
->enabled
) {
1196 dolog ("Reading from disabled voice %s\n", SW_NAME (sw
));
1200 return sw
->hw
->pcm_ops
->read(sw
, buf
, size
);
1203 int AUD_get_buffer_size_out (SWVoiceOut
*sw
)
1205 return sw
->hw
->samples
<< sw
->hw
->info
.shift
;
1208 void AUD_set_active_out (SWVoiceOut
*sw
, int on
)
1217 if (sw
->active
!= on
) {
1218 AudioState
*s
= &glob_audio_state
;
1219 SWVoiceOut
*temp_sw
;
1223 hw
->pending_disable
= 0;
1226 if (s
->vm_running
) {
1227 hw
->pcm_ops
->ctl_out (hw
, VOICE_ENABLE
, conf
.try_poll_out
);
1228 audio_reset_timer (s
);
1236 for (temp_sw
= hw
->sw_head
.lh_first
; temp_sw
;
1237 temp_sw
= temp_sw
->entries
.le_next
) {
1238 nb_active
+= temp_sw
->active
!= 0;
1241 hw
->pending_disable
= nb_active
== 1;
1245 for (sc
= hw
->cap_head
.lh_first
; sc
; sc
= sc
->entries
.le_next
) {
1246 sc
->sw
.active
= hw
->enabled
;
1248 audio_capture_maybe_changed (sc
->cap
, 1);
1255 void AUD_set_active_in (SWVoiceIn
*sw
, int on
)
1264 if (sw
->active
!= on
) {
1265 AudioState
*s
= &glob_audio_state
;
1271 if (s
->vm_running
) {
1272 hw
->pcm_ops
->ctl_in (hw
, VOICE_ENABLE
, conf
.try_poll_in
);
1273 audio_reset_timer (s
);
1276 sw
->total_hw_samples_acquired
= hw
->total_samples_captured
;
1282 for (temp_sw
= hw
->sw_head
.lh_first
; temp_sw
;
1283 temp_sw
= temp_sw
->entries
.le_next
) {
1284 nb_active
+= temp_sw
->active
!= 0;
1287 if (nb_active
== 1) {
1289 hw
->pcm_ops
->ctl_in (hw
, VOICE_DISABLE
);
1297 static int audio_get_avail (SWVoiceIn
*sw
)
1305 live
= sw
->hw
->total_samples_captured
- sw
->total_hw_samples_acquired
;
1306 if (audio_bug(__func__
, live
< 0 || live
> sw
->hw
->samples
)) {
1307 dolog ("live=%d sw->hw->samples=%d\n", live
, sw
->hw
->samples
);
1312 "%s: get_avail live %d ret %" PRId64
"\n",
1314 live
, (((int64_t) live
<< 32) / sw
->ratio
) << sw
->info
.shift
1317 return (((int64_t) live
<< 32) / sw
->ratio
) << sw
->info
.shift
;
1320 static int audio_get_free (SWVoiceOut
*sw
)
1328 live
= sw
->total_hw_samples_mixed
;
1330 if (audio_bug(__func__
, live
< 0 || live
> sw
->hw
->samples
)) {
1331 dolog ("live=%d sw->hw->samples=%d\n", live
, sw
->hw
->samples
);
1335 dead
= sw
->hw
->samples
- live
;
1338 dolog ("%s: get_free live %d dead %d ret %" PRId64
"\n",
1340 live
, dead
, (((int64_t) dead
<< 32) / sw
->ratio
) << sw
->info
.shift
);
1343 return (((int64_t) dead
<< 32) / sw
->ratio
) << sw
->info
.shift
;
1346 static void audio_capture_mix_and_clear (HWVoiceOut
*hw
, int rpos
, int samples
)
1353 for (sc
= hw
->cap_head
.lh_first
; sc
; sc
= sc
->entries
.le_next
) {
1354 SWVoiceOut
*sw
= &sc
->sw
;
1359 int till_end_of_hw
= hw
->samples
- rpos2
;
1360 int to_write
= audio_MIN (till_end_of_hw
, n
);
1361 int bytes
= to_write
<< hw
->info
.shift
;
1364 sw
->buf
= hw
->mix_buf
+ rpos2
;
1365 written
= audio_pcm_sw_write (sw
, NULL
, bytes
);
1366 if (written
- bytes
) {
1367 dolog ("Could not mix %d bytes into a capture "
1368 "buffer, mixed %d\n",
1373 rpos2
= (rpos2
+ to_write
) % hw
->samples
;
1378 n
= audio_MIN (samples
, hw
->samples
- rpos
);
1379 mixeng_clear (hw
->mix_buf
+ rpos
, n
);
1380 mixeng_clear (hw
->mix_buf
, samples
- n
);
1383 static void audio_run_out (AudioState
*s
)
1385 HWVoiceOut
*hw
= NULL
;
1388 while ((hw
= audio_pcm_hw_find_any_enabled_out (hw
))) {
1390 int live
, free
, nb_live
, cleanup_required
, prev_rpos
;
1392 live
= audio_pcm_hw_get_live_out (hw
, &nb_live
);
1397 if (audio_bug(__func__
, live
< 0 || live
> hw
->samples
)) {
1398 dolog ("live=%d hw->samples=%d\n", live
, hw
->samples
);
1402 if (hw
->pending_disable
&& !nb_live
) {
1405 dolog ("Disabling voice\n");
1408 hw
->pending_disable
= 0;
1409 hw
->pcm_ops
->ctl_out (hw
, VOICE_DISABLE
);
1410 for (sc
= hw
->cap_head
.lh_first
; sc
; sc
= sc
->entries
.le_next
) {
1412 audio_recalc_and_notify_capture (sc
->cap
);
1418 for (sw
= hw
->sw_head
.lh_first
; sw
; sw
= sw
->entries
.le_next
) {
1420 free
= audio_get_free (sw
);
1422 sw
->callback
.fn (sw
->callback
.opaque
, free
);
1429 prev_rpos
= hw
->rpos
;
1430 played
= hw
->pcm_ops
->run_out (hw
, live
);
1431 replay_audio_out(&played
);
1432 if (audio_bug(__func__
, hw
->rpos
>= hw
->samples
)) {
1433 dolog ("hw->rpos=%d hw->samples=%d played=%d\n",
1434 hw
->rpos
, hw
->samples
, played
);
1439 dolog ("played=%d\n", played
);
1443 hw
->ts_helper
+= played
;
1444 audio_capture_mix_and_clear (hw
, prev_rpos
, played
);
1447 cleanup_required
= 0;
1448 for (sw
= hw
->sw_head
.lh_first
; sw
; sw
= sw
->entries
.le_next
) {
1449 if (!sw
->active
&& sw
->empty
) {
1453 if (audio_bug(__func__
, played
> sw
->total_hw_samples_mixed
)) {
1454 dolog ("played=%d sw->total_hw_samples_mixed=%d\n",
1455 played
, sw
->total_hw_samples_mixed
);
1456 played
= sw
->total_hw_samples_mixed
;
1459 sw
->total_hw_samples_mixed
-= played
;
1461 if (!sw
->total_hw_samples_mixed
) {
1463 cleanup_required
|= !sw
->active
&& !sw
->callback
.fn
;
1467 free
= audio_get_free (sw
);
1469 sw
->callback
.fn (sw
->callback
.opaque
, free
);
1474 if (cleanup_required
) {
1477 sw
= hw
->sw_head
.lh_first
;
1479 sw1
= sw
->entries
.le_next
;
1480 if (!sw
->active
&& !sw
->callback
.fn
) {
1481 audio_close_out (sw
);
1489 static void audio_run_in (AudioState
*s
)
1491 HWVoiceIn
*hw
= NULL
;
1493 while ((hw
= audio_pcm_hw_find_any_enabled_in (hw
))) {
1495 int captured
= 0, min
;
1497 if (replay_mode
!= REPLAY_MODE_PLAY
) {
1498 captured
= hw
->pcm_ops
->run_in(hw
);
1500 replay_audio_in(&captured
, hw
->conv_buf
, &hw
->wpos
, hw
->samples
);
1502 min
= audio_pcm_hw_find_min_in (hw
);
1503 hw
->total_samples_captured
+= captured
- min
;
1504 hw
->ts_helper
+= captured
;
1506 for (sw
= hw
->sw_head
.lh_first
; sw
; sw
= sw
->entries
.le_next
) {
1507 sw
->total_hw_samples_acquired
-= min
;
1512 avail
= audio_get_avail (sw
);
1514 sw
->callback
.fn (sw
->callback
.opaque
, avail
);
1521 static void audio_run_capture (AudioState
*s
)
1523 CaptureVoiceOut
*cap
;
1525 for (cap
= s
->cap_head
.lh_first
; cap
; cap
= cap
->entries
.le_next
) {
1526 int live
, rpos
, captured
;
1527 HWVoiceOut
*hw
= &cap
->hw
;
1530 captured
= live
= audio_pcm_hw_get_live_out (hw
, NULL
);
1533 int left
= hw
->samples
- rpos
;
1534 int to_capture
= audio_MIN (live
, left
);
1535 struct st_sample
*src
;
1536 struct capture_callback
*cb
;
1538 src
= hw
->mix_buf
+ rpos
;
1539 hw
->clip (cap
->buf
, src
, to_capture
);
1540 mixeng_clear (src
, to_capture
);
1542 for (cb
= cap
->cb_head
.lh_first
; cb
; cb
= cb
->entries
.le_next
) {
1543 cb
->ops
.capture (cb
->opaque
, cap
->buf
,
1544 to_capture
<< hw
->info
.shift
);
1546 rpos
= (rpos
+ to_capture
) % hw
->samples
;
1551 for (sw
= hw
->sw_head
.lh_first
; sw
; sw
= sw
->entries
.le_next
) {
1552 if (!sw
->active
&& sw
->empty
) {
1556 if (audio_bug(__func__
, captured
> sw
->total_hw_samples_mixed
)) {
1557 dolog ("captured=%d sw->total_hw_samples_mixed=%d\n",
1558 captured
, sw
->total_hw_samples_mixed
);
1559 captured
= sw
->total_hw_samples_mixed
;
1562 sw
->total_hw_samples_mixed
-= captured
;
1563 sw
->empty
= sw
->total_hw_samples_mixed
== 0;
1568 void audio_run (const char *msg
)
1570 AudioState
*s
= &glob_audio_state
;
1574 audio_run_capture (s
);
1577 static double prevtime
;
1581 if (gettimeofday (&tv
, NULL
)) {
1582 perror ("audio_run: gettimeofday");
1586 currtime
= tv
.tv_sec
+ tv
.tv_usec
* 1e-6;
1587 dolog ("Elapsed since last %s: %f\n", msg
, currtime
- prevtime
);
1588 prevtime
= currtime
;
1593 static struct audio_option audio_options
[] = {
1596 .name
= "DAC_FIXED_SETTINGS",
1597 .tag
= AUD_OPT_BOOL
,
1598 .valp
= &conf
.fixed_out
.enabled
,
1599 .descr
= "Use fixed settings for host DAC"
1602 .name
= "DAC_FIXED_FREQ",
1604 .valp
= &conf
.fixed_out
.settings
.freq
,
1605 .descr
= "Frequency for fixed host DAC"
1608 .name
= "DAC_FIXED_FMT",
1610 .valp
= &conf
.fixed_out
.settings
.fmt
,
1611 .descr
= "Format for fixed host DAC"
1614 .name
= "DAC_FIXED_CHANNELS",
1616 .valp
= &conf
.fixed_out
.settings
.nchannels
,
1617 .descr
= "Number of channels for fixed DAC (1 - mono, 2 - stereo)"
1620 .name
= "DAC_VOICES",
1622 .valp
= &conf
.fixed_out
.nb_voices
,
1623 .descr
= "Number of voices for DAC"
1626 .name
= "DAC_TRY_POLL",
1627 .tag
= AUD_OPT_BOOL
,
1628 .valp
= &conf
.try_poll_out
,
1629 .descr
= "Attempt using poll mode for DAC"
1633 .name
= "ADC_FIXED_SETTINGS",
1634 .tag
= AUD_OPT_BOOL
,
1635 .valp
= &conf
.fixed_in
.enabled
,
1636 .descr
= "Use fixed settings for host ADC"
1639 .name
= "ADC_FIXED_FREQ",
1641 .valp
= &conf
.fixed_in
.settings
.freq
,
1642 .descr
= "Frequency for fixed host ADC"
1645 .name
= "ADC_FIXED_FMT",
1647 .valp
= &conf
.fixed_in
.settings
.fmt
,
1648 .descr
= "Format for fixed host ADC"
1651 .name
= "ADC_FIXED_CHANNELS",
1653 .valp
= &conf
.fixed_in
.settings
.nchannels
,
1654 .descr
= "Number of channels for fixed ADC (1 - mono, 2 - stereo)"
1657 .name
= "ADC_VOICES",
1659 .valp
= &conf
.fixed_in
.nb_voices
,
1660 .descr
= "Number of voices for ADC"
1663 .name
= "ADC_TRY_POLL",
1664 .tag
= AUD_OPT_BOOL
,
1665 .valp
= &conf
.try_poll_in
,
1666 .descr
= "Attempt using poll mode for ADC"
1670 .name
= "TIMER_PERIOD",
1672 .valp
= &conf
.period
.hertz
,
1673 .descr
= "Timer period in HZ (0 - use lowest possible)"
1675 { /* End of list */ }
1678 static void audio_pp_nb_voices (const char *typ
, int nb
)
1682 printf ("Does not support %s\n", typ
);
1685 printf ("One %s voice\n", typ
);
1688 printf ("Theoretically supports many %s voices\n", typ
);
1691 printf ("Theoretically supports up to %d %s voices\n", nb
, typ
);
1697 void AUD_help (void)
1699 struct audio_driver
*d
;
1701 /* make sure we print the help text for modular drivers too */
1702 audio_module_load_all();
1704 audio_process_options ("AUDIO", audio_options
);
1705 QLIST_FOREACH(d
, &audio_drivers
, next
) {
1707 audio_process_options (d
->name
, d
->options
);
1711 printf ("Audio options:\n");
1712 audio_print_options ("AUDIO", audio_options
);
1715 printf ("Available drivers:\n");
1717 QLIST_FOREACH(d
, &audio_drivers
, next
) {
1719 printf ("Name: %s\n", d
->name
);
1720 printf ("Description: %s\n", d
->descr
);
1722 audio_pp_nb_voices ("playback", d
->max_voices_out
);
1723 audio_pp_nb_voices ("capture", d
->max_voices_in
);
1726 printf ("Options:\n");
1727 audio_print_options (d
->name
, d
->options
);
1730 printf ("No options\n");
1736 "Options are settable through environment variables.\n"
1739 " set QEMU_AUDIO_DRV=wav\n"
1740 " set QEMU_WAV_PATH=c:\\tune.wav\n"
1742 " export QEMU_AUDIO_DRV=wav\n"
1743 " export QEMU_WAV_PATH=$HOME/tune.wav\n"
1744 "(for csh replace export with setenv in the above)\n"
1750 static int audio_driver_init(AudioState
*s
, struct audio_driver
*drv
, bool msg
)
1753 audio_process_options (drv
->name
, drv
->options
);
1755 s
->drv_opaque
= drv
->init ();
1757 if (s
->drv_opaque
) {
1758 audio_init_nb_voices_out (drv
);
1759 audio_init_nb_voices_in (drv
);
1765 dolog("Could not init `%s' audio driver\n", drv
->name
);
1771 static void audio_vm_change_state_handler (void *opaque
, int running
,
1774 AudioState
*s
= opaque
;
1775 HWVoiceOut
*hwo
= NULL
;
1776 HWVoiceIn
*hwi
= NULL
;
1777 int op
= running
? VOICE_ENABLE
: VOICE_DISABLE
;
1779 s
->vm_running
= running
;
1780 while ((hwo
= audio_pcm_hw_find_any_enabled_out (hwo
))) {
1781 hwo
->pcm_ops
->ctl_out (hwo
, op
, conf
.try_poll_out
);
1784 while ((hwi
= audio_pcm_hw_find_any_enabled_in (hwi
))) {
1785 hwi
->pcm_ops
->ctl_in (hwi
, op
, conf
.try_poll_in
);
1787 audio_reset_timer (s
);
1790 static bool is_cleaning_up
;
1792 bool audio_is_cleaning_up(void)
1794 return is_cleaning_up
;
1797 void audio_cleanup(void)
1799 AudioState
*s
= &glob_audio_state
;
1800 HWVoiceOut
*hwo
, *hwon
;
1801 HWVoiceIn
*hwi
, *hwin
;
1803 is_cleaning_up
= true;
1804 QLIST_FOREACH_SAFE(hwo
, &glob_audio_state
.hw_head_out
, entries
, hwon
) {
1808 hwo
->pcm_ops
->ctl_out (hwo
, VOICE_DISABLE
);
1810 hwo
->pcm_ops
->fini_out (hwo
);
1812 for (sc
= hwo
->cap_head
.lh_first
; sc
; sc
= sc
->entries
.le_next
) {
1813 CaptureVoiceOut
*cap
= sc
->cap
;
1814 struct capture_callback
*cb
;
1816 for (cb
= cap
->cb_head
.lh_first
; cb
; cb
= cb
->entries
.le_next
) {
1817 cb
->ops
.destroy (cb
->opaque
);
1820 QLIST_REMOVE(hwo
, entries
);
1823 QLIST_FOREACH_SAFE(hwi
, &glob_audio_state
.hw_head_in
, entries
, hwin
) {
1825 hwi
->pcm_ops
->ctl_in (hwi
, VOICE_DISABLE
);
1827 hwi
->pcm_ops
->fini_in (hwi
);
1828 QLIST_REMOVE(hwi
, entries
);
1832 s
->drv
->fini (s
->drv_opaque
);
1837 static const VMStateDescription vmstate_audio
= {
1840 .minimum_version_id
= 1,
1841 .fields
= (VMStateField
[]) {
1842 VMSTATE_END_OF_LIST()
1846 static void audio_init (void)
1850 const char *drvname
;
1851 VMChangeStateEntry
*e
;
1852 AudioState
*s
= &glob_audio_state
;
1853 struct audio_driver
*driver
;
1859 QLIST_INIT (&s
->hw_head_out
);
1860 QLIST_INIT (&s
->hw_head_in
);
1861 QLIST_INIT (&s
->cap_head
);
1862 atexit(audio_cleanup
);
1864 s
->ts
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, audio_timer
, s
);
1866 audio_process_options ("AUDIO", audio_options
);
1868 s
->nb_hw_voices_out
= conf
.fixed_out
.nb_voices
;
1869 s
->nb_hw_voices_in
= conf
.fixed_in
.nb_voices
;
1871 if (s
->nb_hw_voices_out
<= 0) {
1872 dolog ("Bogus number of playback voices %d, setting to 1\n",
1873 s
->nb_hw_voices_out
);
1874 s
->nb_hw_voices_out
= 1;
1877 if (s
->nb_hw_voices_in
<= 0) {
1878 dolog ("Bogus number of capture voices %d, setting to 0\n",
1879 s
->nb_hw_voices_in
);
1880 s
->nb_hw_voices_in
= 0;
1885 drvname
= audio_get_conf_str ("QEMU_AUDIO_DRV", NULL
, &def
);
1889 driver
= audio_driver_lookup(drvname
);
1891 done
= !audio_driver_init(s
, driver
, true);
1893 dolog ("Unknown audio driver `%s'\n", drvname
);
1894 dolog ("Run with -audio-help to list available drivers\n");
1899 for (i
= 0; !done
&& i
< ARRAY_SIZE(audio_prio_list
); i
++) {
1900 driver
= audio_driver_lookup(audio_prio_list
[i
]);
1901 if (driver
&& driver
->can_be_default
) {
1902 done
= !audio_driver_init(s
, driver
, false);
1908 driver
= audio_driver_lookup("none");
1909 done
= !audio_driver_init(s
, driver
, false);
1911 dolog("warning: Using timer based audio emulation\n");
1914 if (conf
.period
.hertz
<= 0) {
1915 if (conf
.period
.hertz
< 0) {
1916 dolog ("warning: Timer period is negative - %d "
1917 "treating as zero\n",
1920 conf
.period
.ticks
= 1;
1922 conf
.period
.ticks
= NANOSECONDS_PER_SECOND
/ conf
.period
.hertz
;
1925 e
= qemu_add_vm_change_state_handler (audio_vm_change_state_handler
, s
);
1927 dolog ("warning: Could not register change state handler\n"
1928 "(Audio can continue looping even after stopping the VM)\n");
1931 QLIST_INIT (&s
->card_head
);
1932 vmstate_register (NULL
, 0, &vmstate_audio
, s
);
1935 void AUD_register_card (const char *name
, QEMUSoundCard
*card
)
1938 card
->name
= g_strdup (name
);
1939 memset (&card
->entries
, 0, sizeof (card
->entries
));
1940 QLIST_INSERT_HEAD (&glob_audio_state
.card_head
, card
, entries
);
1943 void AUD_remove_card (QEMUSoundCard
*card
)
1945 QLIST_REMOVE (card
, entries
);
1946 g_free (card
->name
);
1950 CaptureVoiceOut
*AUD_add_capture (
1951 struct audsettings
*as
,
1952 struct audio_capture_ops
*ops
,
1956 AudioState
*s
= &glob_audio_state
;
1957 CaptureVoiceOut
*cap
;
1958 struct capture_callback
*cb
;
1960 if (audio_validate_settings (as
)) {
1961 dolog ("Invalid settings were passed when trying to add capture\n");
1962 audio_print_settings (as
);
1966 cb
= audio_calloc(__func__
, 1, sizeof(*cb
));
1968 dolog ("Could not allocate capture callback information, size %zu\n",
1973 cb
->opaque
= cb_opaque
;
1975 cap
= audio_pcm_capture_find_specific (as
);
1977 QLIST_INSERT_HEAD (&cap
->cb_head
, cb
, entries
);
1982 CaptureVoiceOut
*cap
;
1984 cap
= audio_calloc(__func__
, 1, sizeof(*cap
));
1986 dolog ("Could not allocate capture voice, size %zu\n",
1992 QLIST_INIT (&hw
->sw_head
);
1993 QLIST_INIT (&cap
->cb_head
);
1995 /* XXX find a more elegant way */
1996 hw
->samples
= 4096 * 4;
1997 hw
->mix_buf
= audio_calloc(__func__
, hw
->samples
,
1998 sizeof(struct st_sample
));
2000 dolog ("Could not allocate capture mix buffer (%d samples)\n",
2005 audio_pcm_init_info (&hw
->info
, as
);
2007 cap
->buf
= audio_calloc(__func__
, hw
->samples
, 1 << hw
->info
.shift
);
2009 dolog ("Could not allocate capture buffer "
2010 "(%d samples, each %d bytes)\n",
2011 hw
->samples
, 1 << hw
->info
.shift
);
2015 hw
->clip
= mixeng_clip
2016 [hw
->info
.nchannels
== 2]
2018 [hw
->info
.swap_endianness
]
2019 [audio_bits_to_index (hw
->info
.bits
)];
2021 QLIST_INSERT_HEAD (&s
->cap_head
, cap
, entries
);
2022 QLIST_INSERT_HEAD (&cap
->cb_head
, cb
, entries
);
2024 QLIST_FOREACH(hw
, &glob_audio_state
.hw_head_out
, entries
) {
2025 audio_attach_capture (hw
);
2030 g_free (cap
->hw
.mix_buf
);
2040 void AUD_del_capture (CaptureVoiceOut
*cap
, void *cb_opaque
)
2042 struct capture_callback
*cb
;
2044 for (cb
= cap
->cb_head
.lh_first
; cb
; cb
= cb
->entries
.le_next
) {
2045 if (cb
->opaque
== cb_opaque
) {
2046 cb
->ops
.destroy (cb_opaque
);
2047 QLIST_REMOVE (cb
, entries
);
2050 if (!cap
->cb_head
.lh_first
) {
2051 SWVoiceOut
*sw
= cap
->hw
.sw_head
.lh_first
, *sw1
;
2054 SWVoiceCap
*sc
= (SWVoiceCap
*) sw
;
2055 #ifdef DEBUG_CAPTURE
2056 dolog ("freeing %s\n", sw
->name
);
2059 sw1
= sw
->entries
.le_next
;
2061 st_rate_stop (sw
->rate
);
2064 QLIST_REMOVE (sw
, entries
);
2065 QLIST_REMOVE (sc
, entries
);
2069 QLIST_REMOVE (cap
, entries
);
2070 g_free (cap
->hw
.mix_buf
);
2079 void AUD_set_volume_out (SWVoiceOut
*sw
, int mute
, uint8_t lvol
, uint8_t rvol
)
2082 HWVoiceOut
*hw
= sw
->hw
;
2084 sw
->vol
.mute
= mute
;
2085 sw
->vol
.l
= nominal_volume
.l
* lvol
/ 255;
2086 sw
->vol
.r
= nominal_volume
.r
* rvol
/ 255;
2088 if (hw
->pcm_ops
->ctl_out
) {
2089 hw
->pcm_ops
->ctl_out (hw
, VOICE_VOLUME
, sw
);
2094 void AUD_set_volume_in (SWVoiceIn
*sw
, int mute
, uint8_t lvol
, uint8_t rvol
)
2097 HWVoiceIn
*hw
= sw
->hw
;
2099 sw
->vol
.mute
= mute
;
2100 sw
->vol
.l
= nominal_volume
.l
* lvol
/ 255;
2101 sw
->vol
.r
= nominal_volume
.r
* rvol
/ 255;
2103 if (hw
->pcm_ops
->ctl_in
) {
2104 hw
->pcm_ops
->ctl_in (hw
, VOICE_VOLUME
, sw
);