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
)
458 const char qemu_prefix
[] = "QEMU_";
459 size_t preflen
, optlen
;
461 if (audio_bug(__func__
, !prefix
)) {
462 dolog ("prefix = NULL\n");
466 if (audio_bug(__func__
, !opt
)) {
467 dolog ("opt = NULL\n");
471 preflen
= strlen (prefix
);
473 for (; opt
->name
; opt
++) {
478 dolog ("Option value pointer for `%s' is not set\n",
483 len
= strlen (opt
->name
);
484 /* len of opt->name + len of prefix + size of qemu_prefix
485 * (includes trailing zero) + zero + underscore (on behalf of
487 optlen
= len
+ preflen
+ sizeof (qemu_prefix
) + 1;
488 optname
= g_malloc (optlen
);
490 pstrcpy (optname
, optlen
, qemu_prefix
);
492 /* copy while upper-casing, including trailing zero */
493 for (i
= 0; i
<= preflen
; ++i
) {
494 optname
[i
+ sizeof (qemu_prefix
) - 1] = qemu_toupper(prefix
[i
]);
496 pstrcat (optname
, optlen
, "_");
497 pstrcat (optname
, optlen
, opt
->name
);
504 int *intp
= opt
->valp
;
505 *intp
= audio_get_conf_int (optname
, *intp
, &def
);
511 audfmt_e
*fmtp
= opt
->valp
;
512 *fmtp
= audio_get_conf_fmt (optname
, *fmtp
, &def
);
518 const char **strp
= opt
->valp
;
519 *strp
= audio_get_conf_str (optname
, *strp
, &def
);
524 dolog ("Bad value tag for option `%s' - %d\n",
529 if (!opt
->overriddenp
) {
530 opt
->overriddenp
= &opt
->overridden
;
532 *opt
->overriddenp
= !def
;
537 static void audio_print_settings (struct audsettings
*as
)
539 dolog ("frequency=%d nchannels=%d fmt=", as
->freq
, as
->nchannels
);
543 AUD_log (NULL
, "S8");
546 AUD_log (NULL
, "U8");
549 AUD_log (NULL
, "S16");
552 AUD_log (NULL
, "U16");
555 AUD_log (NULL
, "S32");
558 AUD_log (NULL
, "U32");
561 AUD_log (NULL
, "invalid(%d)", as
->fmt
);
565 AUD_log (NULL
, " endianness=");
566 switch (as
->endianness
) {
568 AUD_log (NULL
, "little");
571 AUD_log (NULL
, "big");
574 AUD_log (NULL
, "invalid");
577 AUD_log (NULL
, "\n");
580 static int audio_validate_settings (struct audsettings
*as
)
584 invalid
= as
->nchannels
!= 1 && as
->nchannels
!= 2;
585 invalid
|= as
->endianness
!= 0 && as
->endianness
!= 1;
600 invalid
|= as
->freq
<= 0;
601 return invalid
? -1 : 0;
604 static int audio_pcm_info_eq (struct audio_pcm_info
*info
, struct audsettings
*as
)
606 int bits
= 8, sign
= 0;
629 return info
->freq
== as
->freq
630 && info
->nchannels
== as
->nchannels
631 && info
->sign
== sign
632 && info
->bits
== bits
633 && info
->swap_endianness
== (as
->endianness
!= AUDIO_HOST_ENDIANNESS
);
636 void audio_pcm_init_info (struct audio_pcm_info
*info
, struct audsettings
*as
)
638 int bits
= 8, sign
= 0, shift
= 0;
661 info
->freq
= as
->freq
;
664 info
->nchannels
= as
->nchannels
;
665 info
->shift
= (as
->nchannels
== 2) + shift
;
666 info
->align
= (1 << info
->shift
) - 1;
667 info
->bytes_per_second
= info
->freq
<< info
->shift
;
668 info
->swap_endianness
= (as
->endianness
!= AUDIO_HOST_ENDIANNESS
);
671 void audio_pcm_info_clear_buf (struct audio_pcm_info
*info
, void *buf
, int len
)
678 memset (buf
, 0x00, len
<< info
->shift
);
681 switch (info
->bits
) {
683 memset (buf
, 0x80, len
<< info
->shift
);
690 int shift
= info
->nchannels
- 1;
693 if (info
->swap_endianness
) {
697 for (i
= 0; i
< len
<< shift
; i
++) {
707 int shift
= info
->nchannels
- 1;
708 int32_t s
= INT32_MAX
;
710 if (info
->swap_endianness
) {
714 for (i
= 0; i
< len
<< shift
; i
++) {
721 AUD_log (NULL
, "audio_pcm_info_clear_buf: invalid bits %d\n",
731 static void noop_conv (struct st_sample
*dst
, const void *src
, int samples
)
738 static CaptureVoiceOut
*audio_pcm_capture_find_specific (
739 struct audsettings
*as
742 CaptureVoiceOut
*cap
;
743 AudioState
*s
= &glob_audio_state
;
745 for (cap
= s
->cap_head
.lh_first
; cap
; cap
= cap
->entries
.le_next
) {
746 if (audio_pcm_info_eq (&cap
->hw
.info
, as
)) {
753 static void audio_notify_capture (CaptureVoiceOut
*cap
, audcnotification_e cmd
)
755 struct capture_callback
*cb
;
758 dolog ("notification %d sent\n", cmd
);
760 for (cb
= cap
->cb_head
.lh_first
; cb
; cb
= cb
->entries
.le_next
) {
761 cb
->ops
.notify (cb
->opaque
, cmd
);
765 static void audio_capture_maybe_changed (CaptureVoiceOut
*cap
, int enabled
)
767 if (cap
->hw
.enabled
!= enabled
) {
768 audcnotification_e cmd
;
769 cap
->hw
.enabled
= enabled
;
770 cmd
= enabled
? AUD_CNOTIFY_ENABLE
: AUD_CNOTIFY_DISABLE
;
771 audio_notify_capture (cap
, cmd
);
775 static void audio_recalc_and_notify_capture (CaptureVoiceOut
*cap
)
777 HWVoiceOut
*hw
= &cap
->hw
;
781 for (sw
= hw
->sw_head
.lh_first
; sw
; sw
= sw
->entries
.le_next
) {
787 audio_capture_maybe_changed (cap
, enabled
);
790 static void audio_detach_capture (HWVoiceOut
*hw
)
792 SWVoiceCap
*sc
= hw
->cap_head
.lh_first
;
795 SWVoiceCap
*sc1
= sc
->entries
.le_next
;
796 SWVoiceOut
*sw
= &sc
->sw
;
797 CaptureVoiceOut
*cap
= sc
->cap
;
798 int was_active
= sw
->active
;
801 st_rate_stop (sw
->rate
);
805 QLIST_REMOVE (sw
, entries
);
806 QLIST_REMOVE (sc
, entries
);
809 /* We have removed soft voice from the capture:
810 this might have changed the overall status of the capture
811 since this might have been the only active voice */
812 audio_recalc_and_notify_capture (cap
);
818 static int audio_attach_capture (HWVoiceOut
*hw
)
820 AudioState
*s
= &glob_audio_state
;
821 CaptureVoiceOut
*cap
;
823 audio_detach_capture (hw
);
824 for (cap
= s
->cap_head
.lh_first
; cap
; cap
= cap
->entries
.le_next
) {
827 HWVoiceOut
*hw_cap
= &cap
->hw
;
829 sc
= audio_calloc(__func__
, 1, sizeof(*sc
));
831 dolog ("Could not allocate soft capture voice (%zu bytes)\n",
841 sw
->active
= hw
->enabled
;
842 sw
->conv
= noop_conv
;
843 sw
->ratio
= ((int64_t) hw_cap
->info
.freq
<< 32) / sw
->info
.freq
;
844 sw
->vol
= nominal_volume
;
845 sw
->rate
= st_rate_start (sw
->info
.freq
, hw_cap
->info
.freq
);
847 dolog ("Could not start rate conversion for `%s'\n", SW_NAME (sw
));
851 QLIST_INSERT_HEAD (&hw_cap
->sw_head
, sw
, entries
);
852 QLIST_INSERT_HEAD (&hw
->cap_head
, sc
, entries
);
854 sw
->name
= g_strdup_printf ("for %p %d,%d,%d",
855 hw
, sw
->info
.freq
, sw
->info
.bits
,
857 dolog ("Added %s active = %d\n", sw
->name
, sw
->active
);
860 audio_capture_maybe_changed (cap
, 1);
867 * Hard voice (capture)
869 static int audio_pcm_hw_find_min_in (HWVoiceIn
*hw
)
872 int m
= hw
->total_samples_captured
;
874 for (sw
= hw
->sw_head
.lh_first
; sw
; sw
= sw
->entries
.le_next
) {
876 m
= audio_MIN (m
, sw
->total_hw_samples_acquired
);
882 int audio_pcm_hw_get_live_in (HWVoiceIn
*hw
)
884 int live
= hw
->total_samples_captured
- audio_pcm_hw_find_min_in (hw
);
885 if (audio_bug(__func__
, live
< 0 || live
> hw
->samples
)) {
886 dolog ("live=%d hw->samples=%d\n", live
, hw
->samples
);
892 int audio_pcm_hw_clip_out (HWVoiceOut
*hw
, void *pcm_buf
,
893 int live
, int pending
)
895 int left
= hw
->samples
- pending
;
896 int len
= audio_MIN (left
, live
);
900 struct st_sample
*src
= hw
->mix_buf
+ hw
->rpos
;
901 uint8_t *dst
= advance (pcm_buf
, hw
->rpos
<< hw
->info
.shift
);
902 int samples_till_end_of_buf
= hw
->samples
- hw
->rpos
;
903 int samples_to_clip
= audio_MIN (len
, samples_till_end_of_buf
);
905 hw
->clip (dst
, src
, samples_to_clip
);
907 hw
->rpos
= (hw
->rpos
+ samples_to_clip
) % hw
->samples
;
908 len
-= samples_to_clip
;
909 clipped
+= samples_to_clip
;
915 * Soft voice (capture)
917 static int audio_pcm_sw_get_rpos_in (SWVoiceIn
*sw
)
919 HWVoiceIn
*hw
= sw
->hw
;
920 int live
= hw
->total_samples_captured
- sw
->total_hw_samples_acquired
;
923 if (audio_bug(__func__
, live
< 0 || live
> hw
->samples
)) {
924 dolog ("live=%d hw->samples=%d\n", live
, hw
->samples
);
928 rpos
= hw
->wpos
- live
;
933 return hw
->samples
+ rpos
;
937 int audio_pcm_sw_read (SWVoiceIn
*sw
, void *buf
, int size
)
939 HWVoiceIn
*hw
= sw
->hw
;
940 int samples
, live
, ret
= 0, swlim
, isamp
, osamp
, rpos
, total
= 0;
941 struct st_sample
*src
, *dst
= sw
->buf
;
943 rpos
= audio_pcm_sw_get_rpos_in (sw
) % hw
->samples
;
945 live
= hw
->total_samples_captured
- sw
->total_hw_samples_acquired
;
946 if (audio_bug(__func__
, live
< 0 || live
> hw
->samples
)) {
947 dolog ("live_in=%d hw->samples=%d\n", live
, hw
->samples
);
951 samples
= size
>> sw
->info
.shift
;
956 swlim
= (live
* sw
->ratio
) >> 32;
957 swlim
= audio_MIN (swlim
, samples
);
960 src
= hw
->conv_buf
+ rpos
;
961 isamp
= hw
->wpos
- rpos
;
964 isamp
= hw
->samples
- rpos
;
972 if (audio_bug(__func__
, osamp
< 0)) {
973 dolog ("osamp=%d\n", osamp
);
977 st_rate_flow (sw
->rate
, src
, dst
, &isamp
, &osamp
);
979 rpos
= (rpos
+ isamp
) % hw
->samples
;
985 if (!(hw
->ctl_caps
& VOICE_VOLUME_CAP
)) {
986 mixeng_volume (sw
->buf
, ret
, &sw
->vol
);
989 sw
->clip (buf
, sw
->buf
, ret
);
990 sw
->total_hw_samples_acquired
+= total
;
991 return ret
<< sw
->info
.shift
;
995 * Hard voice (playback)
997 static int audio_pcm_hw_find_min_out (HWVoiceOut
*hw
, int *nb_livep
)
1003 for (sw
= hw
->sw_head
.lh_first
; sw
; sw
= sw
->entries
.le_next
) {
1004 if (sw
->active
|| !sw
->empty
) {
1005 m
= audio_MIN (m
, sw
->total_hw_samples_mixed
);
1010 *nb_livep
= nb_live
;
1014 static int audio_pcm_hw_get_live_out (HWVoiceOut
*hw
, int *nb_live
)
1019 smin
= audio_pcm_hw_find_min_out (hw
, &nb_live1
);
1021 *nb_live
= nb_live1
;
1027 if (audio_bug(__func__
, live
< 0 || live
> hw
->samples
)) {
1028 dolog ("live=%d hw->samples=%d\n", live
, hw
->samples
);
1037 * Soft voice (playback)
1039 int audio_pcm_sw_write (SWVoiceOut
*sw
, void *buf
, int size
)
1041 int hwsamples
, samples
, isamp
, osamp
, wpos
, live
, dead
, left
, swlim
, blck
;
1042 int ret
= 0, pos
= 0, total
= 0;
1048 hwsamples
= sw
->hw
->samples
;
1050 live
= sw
->total_hw_samples_mixed
;
1051 if (audio_bug(__func__
, live
< 0 || live
> hwsamples
)) {
1052 dolog ("live=%d hw->samples=%d\n", live
, hwsamples
);
1056 if (live
== hwsamples
) {
1058 dolog ("%s is full %d\n", sw
->name
, live
);
1063 wpos
= (sw
->hw
->rpos
+ live
) % hwsamples
;
1064 samples
= size
>> sw
->info
.shift
;
1066 dead
= hwsamples
- live
;
1067 swlim
= ((int64_t) dead
<< 32) / sw
->ratio
;
1068 swlim
= audio_MIN (swlim
, samples
);
1070 sw
->conv (sw
->buf
, buf
, swlim
);
1072 if (!(sw
->hw
->ctl_caps
& VOICE_VOLUME_CAP
)) {
1073 mixeng_volume (sw
->buf
, swlim
, &sw
->vol
);
1078 dead
= hwsamples
- live
;
1079 left
= hwsamples
- wpos
;
1080 blck
= audio_MIN (dead
, left
);
1089 sw
->hw
->mix_buf
+ wpos
,
1097 wpos
= (wpos
+ osamp
) % hwsamples
;
1101 sw
->total_hw_samples_mixed
+= total
;
1102 sw
->empty
= sw
->total_hw_samples_mixed
== 0;
1106 "%s: write size %d ret %d total sw %d\n",
1108 size
>> sw
->info
.shift
,
1110 sw
->total_hw_samples_mixed
1114 return ret
<< sw
->info
.shift
;
1118 static void audio_pcm_print_info (const char *cap
, struct audio_pcm_info
*info
)
1120 dolog ("%s: bits %d, sign %d, freq %d, nchan %d\n",
1121 cap
, info
->bits
, info
->sign
, info
->freq
, info
->nchannels
);
1126 #include "audio_template.h"
1128 #include "audio_template.h"
1134 static bool audio_timer_running
;
1135 static uint64_t audio_timer_last
;
1137 static int audio_is_timer_needed (void)
1139 HWVoiceIn
*hwi
= NULL
;
1140 HWVoiceOut
*hwo
= NULL
;
1142 while ((hwo
= audio_pcm_hw_find_any_enabled_out (hwo
))) {
1143 if (!hwo
->poll_mode
) return 1;
1145 while ((hwi
= audio_pcm_hw_find_any_enabled_in (hwi
))) {
1146 if (!hwi
->poll_mode
) return 1;
1151 static void audio_reset_timer (AudioState
*s
)
1153 if (audio_is_timer_needed ()) {
1154 timer_mod_anticipate_ns(s
->ts
,
1155 qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) + conf
.period
.ticks
);
1156 if (!audio_timer_running
) {
1157 audio_timer_running
= true;
1158 audio_timer_last
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
1159 trace_audio_timer_start(conf
.period
.ticks
/ SCALE_MS
);
1163 if (audio_timer_running
) {
1164 audio_timer_running
= false;
1165 trace_audio_timer_stop();
1170 static void audio_timer (void *opaque
)
1174 now
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
1175 diff
= now
- audio_timer_last
;
1176 if (diff
> conf
.period
.ticks
* 3 / 2) {
1177 trace_audio_timer_delayed(diff
/ SCALE_MS
);
1179 audio_timer_last
= now
;
1181 audio_run ("timer");
1182 audio_reset_timer (opaque
);
1188 int AUD_write (SWVoiceOut
*sw
, void *buf
, int size
)
1191 /* XXX: Consider options */
1195 if (!sw
->hw
->enabled
) {
1196 dolog ("Writing to disabled voice %s\n", SW_NAME (sw
));
1200 return sw
->hw
->pcm_ops
->write(sw
, buf
, size
);
1203 int AUD_read (SWVoiceIn
*sw
, void *buf
, int size
)
1206 /* XXX: Consider options */
1210 if (!sw
->hw
->enabled
) {
1211 dolog ("Reading from disabled voice %s\n", SW_NAME (sw
));
1215 return sw
->hw
->pcm_ops
->read(sw
, buf
, size
);
1218 int AUD_get_buffer_size_out (SWVoiceOut
*sw
)
1220 return sw
->hw
->samples
<< sw
->hw
->info
.shift
;
1223 void AUD_set_active_out (SWVoiceOut
*sw
, int on
)
1232 if (sw
->active
!= on
) {
1233 AudioState
*s
= &glob_audio_state
;
1234 SWVoiceOut
*temp_sw
;
1238 hw
->pending_disable
= 0;
1241 if (s
->vm_running
) {
1242 hw
->pcm_ops
->ctl_out (hw
, VOICE_ENABLE
, conf
.try_poll_out
);
1243 audio_reset_timer (s
);
1251 for (temp_sw
= hw
->sw_head
.lh_first
; temp_sw
;
1252 temp_sw
= temp_sw
->entries
.le_next
) {
1253 nb_active
+= temp_sw
->active
!= 0;
1256 hw
->pending_disable
= nb_active
== 1;
1260 for (sc
= hw
->cap_head
.lh_first
; sc
; sc
= sc
->entries
.le_next
) {
1261 sc
->sw
.active
= hw
->enabled
;
1263 audio_capture_maybe_changed (sc
->cap
, 1);
1270 void AUD_set_active_in (SWVoiceIn
*sw
, int on
)
1279 if (sw
->active
!= on
) {
1280 AudioState
*s
= &glob_audio_state
;
1286 if (s
->vm_running
) {
1287 hw
->pcm_ops
->ctl_in (hw
, VOICE_ENABLE
, conf
.try_poll_in
);
1288 audio_reset_timer (s
);
1291 sw
->total_hw_samples_acquired
= hw
->total_samples_captured
;
1297 for (temp_sw
= hw
->sw_head
.lh_first
; temp_sw
;
1298 temp_sw
= temp_sw
->entries
.le_next
) {
1299 nb_active
+= temp_sw
->active
!= 0;
1302 if (nb_active
== 1) {
1304 hw
->pcm_ops
->ctl_in (hw
, VOICE_DISABLE
);
1312 static int audio_get_avail (SWVoiceIn
*sw
)
1320 live
= sw
->hw
->total_samples_captured
- sw
->total_hw_samples_acquired
;
1321 if (audio_bug(__func__
, live
< 0 || live
> sw
->hw
->samples
)) {
1322 dolog ("live=%d sw->hw->samples=%d\n", live
, sw
->hw
->samples
);
1327 "%s: get_avail live %d ret %" PRId64
"\n",
1329 live
, (((int64_t) live
<< 32) / sw
->ratio
) << sw
->info
.shift
1332 return (((int64_t) live
<< 32) / sw
->ratio
) << sw
->info
.shift
;
1335 static int audio_get_free (SWVoiceOut
*sw
)
1343 live
= sw
->total_hw_samples_mixed
;
1345 if (audio_bug(__func__
, live
< 0 || live
> sw
->hw
->samples
)) {
1346 dolog ("live=%d sw->hw->samples=%d\n", live
, sw
->hw
->samples
);
1350 dead
= sw
->hw
->samples
- live
;
1353 dolog ("%s: get_free live %d dead %d ret %" PRId64
"\n",
1355 live
, dead
, (((int64_t) dead
<< 32) / sw
->ratio
) << sw
->info
.shift
);
1358 return (((int64_t) dead
<< 32) / sw
->ratio
) << sw
->info
.shift
;
1361 static void audio_capture_mix_and_clear (HWVoiceOut
*hw
, int rpos
, int samples
)
1368 for (sc
= hw
->cap_head
.lh_first
; sc
; sc
= sc
->entries
.le_next
) {
1369 SWVoiceOut
*sw
= &sc
->sw
;
1374 int till_end_of_hw
= hw
->samples
- rpos2
;
1375 int to_write
= audio_MIN (till_end_of_hw
, n
);
1376 int bytes
= to_write
<< hw
->info
.shift
;
1379 sw
->buf
= hw
->mix_buf
+ rpos2
;
1380 written
= audio_pcm_sw_write (sw
, NULL
, bytes
);
1381 if (written
- bytes
) {
1382 dolog ("Could not mix %d bytes into a capture "
1383 "buffer, mixed %d\n",
1388 rpos2
= (rpos2
+ to_write
) % hw
->samples
;
1393 n
= audio_MIN (samples
, hw
->samples
- rpos
);
1394 mixeng_clear (hw
->mix_buf
+ rpos
, n
);
1395 mixeng_clear (hw
->mix_buf
, samples
- n
);
1398 static void audio_run_out (AudioState
*s
)
1400 HWVoiceOut
*hw
= NULL
;
1403 while ((hw
= audio_pcm_hw_find_any_enabled_out (hw
))) {
1405 int live
, free
, nb_live
, cleanup_required
, prev_rpos
;
1407 live
= audio_pcm_hw_get_live_out (hw
, &nb_live
);
1412 if (audio_bug(__func__
, live
< 0 || live
> hw
->samples
)) {
1413 dolog ("live=%d hw->samples=%d\n", live
, hw
->samples
);
1417 if (hw
->pending_disable
&& !nb_live
) {
1420 dolog ("Disabling voice\n");
1423 hw
->pending_disable
= 0;
1424 hw
->pcm_ops
->ctl_out (hw
, VOICE_DISABLE
);
1425 for (sc
= hw
->cap_head
.lh_first
; sc
; sc
= sc
->entries
.le_next
) {
1427 audio_recalc_and_notify_capture (sc
->cap
);
1433 for (sw
= hw
->sw_head
.lh_first
; sw
; sw
= sw
->entries
.le_next
) {
1435 free
= audio_get_free (sw
);
1437 sw
->callback
.fn (sw
->callback
.opaque
, free
);
1444 prev_rpos
= hw
->rpos
;
1445 played
= hw
->pcm_ops
->run_out (hw
, live
);
1446 replay_audio_out(&played
);
1447 if (audio_bug(__func__
, hw
->rpos
>= hw
->samples
)) {
1448 dolog ("hw->rpos=%d hw->samples=%d played=%d\n",
1449 hw
->rpos
, hw
->samples
, played
);
1454 dolog ("played=%d\n", played
);
1458 hw
->ts_helper
+= played
;
1459 audio_capture_mix_and_clear (hw
, prev_rpos
, played
);
1462 cleanup_required
= 0;
1463 for (sw
= hw
->sw_head
.lh_first
; sw
; sw
= sw
->entries
.le_next
) {
1464 if (!sw
->active
&& sw
->empty
) {
1468 if (audio_bug(__func__
, played
> sw
->total_hw_samples_mixed
)) {
1469 dolog ("played=%d sw->total_hw_samples_mixed=%d\n",
1470 played
, sw
->total_hw_samples_mixed
);
1471 played
= sw
->total_hw_samples_mixed
;
1474 sw
->total_hw_samples_mixed
-= played
;
1476 if (!sw
->total_hw_samples_mixed
) {
1478 cleanup_required
|= !sw
->active
&& !sw
->callback
.fn
;
1482 free
= audio_get_free (sw
);
1484 sw
->callback
.fn (sw
->callback
.opaque
, free
);
1489 if (cleanup_required
) {
1492 sw
= hw
->sw_head
.lh_first
;
1494 sw1
= sw
->entries
.le_next
;
1495 if (!sw
->active
&& !sw
->callback
.fn
) {
1496 audio_close_out (sw
);
1504 static void audio_run_in (AudioState
*s
)
1506 HWVoiceIn
*hw
= NULL
;
1508 while ((hw
= audio_pcm_hw_find_any_enabled_in (hw
))) {
1510 int captured
= 0, min
;
1512 if (replay_mode
!= REPLAY_MODE_PLAY
) {
1513 captured
= hw
->pcm_ops
->run_in(hw
);
1515 replay_audio_in(&captured
, hw
->conv_buf
, &hw
->wpos
, hw
->samples
);
1517 min
= audio_pcm_hw_find_min_in (hw
);
1518 hw
->total_samples_captured
+= captured
- min
;
1519 hw
->ts_helper
+= captured
;
1521 for (sw
= hw
->sw_head
.lh_first
; sw
; sw
= sw
->entries
.le_next
) {
1522 sw
->total_hw_samples_acquired
-= min
;
1527 avail
= audio_get_avail (sw
);
1529 sw
->callback
.fn (sw
->callback
.opaque
, avail
);
1536 static void audio_run_capture (AudioState
*s
)
1538 CaptureVoiceOut
*cap
;
1540 for (cap
= s
->cap_head
.lh_first
; cap
; cap
= cap
->entries
.le_next
) {
1541 int live
, rpos
, captured
;
1542 HWVoiceOut
*hw
= &cap
->hw
;
1545 captured
= live
= audio_pcm_hw_get_live_out (hw
, NULL
);
1548 int left
= hw
->samples
- rpos
;
1549 int to_capture
= audio_MIN (live
, left
);
1550 struct st_sample
*src
;
1551 struct capture_callback
*cb
;
1553 src
= hw
->mix_buf
+ rpos
;
1554 hw
->clip (cap
->buf
, src
, to_capture
);
1555 mixeng_clear (src
, to_capture
);
1557 for (cb
= cap
->cb_head
.lh_first
; cb
; cb
= cb
->entries
.le_next
) {
1558 cb
->ops
.capture (cb
->opaque
, cap
->buf
,
1559 to_capture
<< hw
->info
.shift
);
1561 rpos
= (rpos
+ to_capture
) % hw
->samples
;
1566 for (sw
= hw
->sw_head
.lh_first
; sw
; sw
= sw
->entries
.le_next
) {
1567 if (!sw
->active
&& sw
->empty
) {
1571 if (audio_bug(__func__
, captured
> sw
->total_hw_samples_mixed
)) {
1572 dolog ("captured=%d sw->total_hw_samples_mixed=%d\n",
1573 captured
, sw
->total_hw_samples_mixed
);
1574 captured
= sw
->total_hw_samples_mixed
;
1577 sw
->total_hw_samples_mixed
-= captured
;
1578 sw
->empty
= sw
->total_hw_samples_mixed
== 0;
1583 void audio_run (const char *msg
)
1585 AudioState
*s
= &glob_audio_state
;
1589 audio_run_capture (s
);
1592 static double prevtime
;
1596 if (gettimeofday (&tv
, NULL
)) {
1597 perror ("audio_run: gettimeofday");
1601 currtime
= tv
.tv_sec
+ tv
.tv_usec
* 1e-6;
1602 dolog ("Elapsed since last %s: %f\n", msg
, currtime
- prevtime
);
1603 prevtime
= currtime
;
1608 static struct audio_option audio_options
[] = {
1611 .name
= "DAC_FIXED_SETTINGS",
1612 .tag
= AUD_OPT_BOOL
,
1613 .valp
= &conf
.fixed_out
.enabled
,
1614 .descr
= "Use fixed settings for host DAC"
1617 .name
= "DAC_FIXED_FREQ",
1619 .valp
= &conf
.fixed_out
.settings
.freq
,
1620 .descr
= "Frequency for fixed host DAC"
1623 .name
= "DAC_FIXED_FMT",
1625 .valp
= &conf
.fixed_out
.settings
.fmt
,
1626 .descr
= "Format for fixed host DAC"
1629 .name
= "DAC_FIXED_CHANNELS",
1631 .valp
= &conf
.fixed_out
.settings
.nchannels
,
1632 .descr
= "Number of channels for fixed DAC (1 - mono, 2 - stereo)"
1635 .name
= "DAC_VOICES",
1637 .valp
= &conf
.fixed_out
.nb_voices
,
1638 .descr
= "Number of voices for DAC"
1641 .name
= "DAC_TRY_POLL",
1642 .tag
= AUD_OPT_BOOL
,
1643 .valp
= &conf
.try_poll_out
,
1644 .descr
= "Attempt using poll mode for DAC"
1648 .name
= "ADC_FIXED_SETTINGS",
1649 .tag
= AUD_OPT_BOOL
,
1650 .valp
= &conf
.fixed_in
.enabled
,
1651 .descr
= "Use fixed settings for host ADC"
1654 .name
= "ADC_FIXED_FREQ",
1656 .valp
= &conf
.fixed_in
.settings
.freq
,
1657 .descr
= "Frequency for fixed host ADC"
1660 .name
= "ADC_FIXED_FMT",
1662 .valp
= &conf
.fixed_in
.settings
.fmt
,
1663 .descr
= "Format for fixed host ADC"
1666 .name
= "ADC_FIXED_CHANNELS",
1668 .valp
= &conf
.fixed_in
.settings
.nchannels
,
1669 .descr
= "Number of channels for fixed ADC (1 - mono, 2 - stereo)"
1672 .name
= "ADC_VOICES",
1674 .valp
= &conf
.fixed_in
.nb_voices
,
1675 .descr
= "Number of voices for ADC"
1678 .name
= "ADC_TRY_POLL",
1679 .tag
= AUD_OPT_BOOL
,
1680 .valp
= &conf
.try_poll_in
,
1681 .descr
= "Attempt using poll mode for ADC"
1685 .name
= "TIMER_PERIOD",
1687 .valp
= &conf
.period
.hertz
,
1688 .descr
= "Timer period in HZ (0 - use lowest possible)"
1690 { /* End of list */ }
1693 static void audio_pp_nb_voices (const char *typ
, int nb
)
1697 printf ("Does not support %s\n", typ
);
1700 printf ("One %s voice\n", typ
);
1703 printf ("Theoretically supports many %s voices\n", typ
);
1706 printf ("Theoretically supports up to %d %s voices\n", nb
, typ
);
1712 void AUD_help (void)
1714 struct audio_driver
*d
;
1716 /* make sure we print the help text for modular drivers too */
1717 audio_module_load_all();
1719 audio_process_options ("AUDIO", audio_options
);
1720 QLIST_FOREACH(d
, &audio_drivers
, next
) {
1722 audio_process_options (d
->name
, d
->options
);
1726 printf ("Audio options:\n");
1727 audio_print_options ("AUDIO", audio_options
);
1730 printf ("Available drivers:\n");
1732 QLIST_FOREACH(d
, &audio_drivers
, next
) {
1734 printf ("Name: %s\n", d
->name
);
1735 printf ("Description: %s\n", d
->descr
);
1737 audio_pp_nb_voices ("playback", d
->max_voices_out
);
1738 audio_pp_nb_voices ("capture", d
->max_voices_in
);
1741 printf ("Options:\n");
1742 audio_print_options (d
->name
, d
->options
);
1745 printf ("No options\n");
1751 "Options are settable through environment variables.\n"
1754 " set QEMU_AUDIO_DRV=wav\n"
1755 " set QEMU_WAV_PATH=c:\\tune.wav\n"
1757 " export QEMU_AUDIO_DRV=wav\n"
1758 " export QEMU_WAV_PATH=$HOME/tune.wav\n"
1759 "(for csh replace export with setenv in the above)\n"
1765 static int audio_driver_init (AudioState
*s
, struct audio_driver
*drv
)
1768 audio_process_options (drv
->name
, drv
->options
);
1770 s
->drv_opaque
= drv
->init ();
1772 if (s
->drv_opaque
) {
1773 audio_init_nb_voices_out (drv
);
1774 audio_init_nb_voices_in (drv
);
1779 dolog ("Could not init `%s' audio driver\n", drv
->name
);
1784 static void audio_vm_change_state_handler (void *opaque
, int running
,
1787 AudioState
*s
= opaque
;
1788 HWVoiceOut
*hwo
= NULL
;
1789 HWVoiceIn
*hwi
= NULL
;
1790 int op
= running
? VOICE_ENABLE
: VOICE_DISABLE
;
1792 s
->vm_running
= running
;
1793 while ((hwo
= audio_pcm_hw_find_any_enabled_out (hwo
))) {
1794 hwo
->pcm_ops
->ctl_out (hwo
, op
, conf
.try_poll_out
);
1797 while ((hwi
= audio_pcm_hw_find_any_enabled_in (hwi
))) {
1798 hwi
->pcm_ops
->ctl_in (hwi
, op
, conf
.try_poll_in
);
1800 audio_reset_timer (s
);
1803 static bool is_cleaning_up
;
1805 bool audio_is_cleaning_up(void)
1807 return is_cleaning_up
;
1810 void audio_cleanup(void)
1812 AudioState
*s
= &glob_audio_state
;
1813 HWVoiceOut
*hwo
, *hwon
;
1814 HWVoiceIn
*hwi
, *hwin
;
1816 is_cleaning_up
= true;
1817 QLIST_FOREACH_SAFE(hwo
, &glob_audio_state
.hw_head_out
, entries
, hwon
) {
1821 hwo
->pcm_ops
->ctl_out (hwo
, VOICE_DISABLE
);
1823 hwo
->pcm_ops
->fini_out (hwo
);
1825 for (sc
= hwo
->cap_head
.lh_first
; sc
; sc
= sc
->entries
.le_next
) {
1826 CaptureVoiceOut
*cap
= sc
->cap
;
1827 struct capture_callback
*cb
;
1829 for (cb
= cap
->cb_head
.lh_first
; cb
; cb
= cb
->entries
.le_next
) {
1830 cb
->ops
.destroy (cb
->opaque
);
1833 QLIST_REMOVE(hwo
, entries
);
1836 QLIST_FOREACH_SAFE(hwi
, &glob_audio_state
.hw_head_in
, entries
, hwin
) {
1838 hwi
->pcm_ops
->ctl_in (hwi
, VOICE_DISABLE
);
1840 hwi
->pcm_ops
->fini_in (hwi
);
1841 QLIST_REMOVE(hwi
, entries
);
1845 s
->drv
->fini (s
->drv_opaque
);
1850 static const VMStateDescription vmstate_audio
= {
1853 .minimum_version_id
= 1,
1854 .fields
= (VMStateField
[]) {
1855 VMSTATE_END_OF_LIST()
1859 static void audio_init (void)
1863 const char *drvname
;
1864 VMChangeStateEntry
*e
;
1865 AudioState
*s
= &glob_audio_state
;
1866 struct audio_driver
*driver
;
1872 QLIST_INIT (&s
->hw_head_out
);
1873 QLIST_INIT (&s
->hw_head_in
);
1874 QLIST_INIT (&s
->cap_head
);
1875 atexit(audio_cleanup
);
1877 s
->ts
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, audio_timer
, s
);
1879 audio_process_options ("AUDIO", audio_options
);
1881 s
->nb_hw_voices_out
= conf
.fixed_out
.nb_voices
;
1882 s
->nb_hw_voices_in
= conf
.fixed_in
.nb_voices
;
1884 if (s
->nb_hw_voices_out
<= 0) {
1885 dolog ("Bogus number of playback voices %d, setting to 1\n",
1886 s
->nb_hw_voices_out
);
1887 s
->nb_hw_voices_out
= 1;
1890 if (s
->nb_hw_voices_in
<= 0) {
1891 dolog ("Bogus number of capture voices %d, setting to 0\n",
1892 s
->nb_hw_voices_in
);
1893 s
->nb_hw_voices_in
= 0;
1898 drvname
= audio_get_conf_str ("QEMU_AUDIO_DRV", NULL
, &def
);
1902 driver
= audio_driver_lookup(drvname
);
1904 done
= !audio_driver_init(s
, driver
);
1906 dolog ("Unknown audio driver `%s'\n", drvname
);
1907 dolog ("Run with -audio-help to list available drivers\n");
1912 for (i
= 0; !done
&& i
< ARRAY_SIZE(audio_prio_list
); i
++) {
1913 driver
= audio_driver_lookup(audio_prio_list
[i
]);
1914 if (driver
&& driver
->can_be_default
) {
1915 done
= !audio_driver_init(s
, driver
);
1921 driver
= audio_driver_lookup("none");
1922 done
= !audio_driver_init(s
, driver
);
1924 dolog("warning: Using timer based audio emulation\n");
1927 if (conf
.period
.hertz
<= 0) {
1928 if (conf
.period
.hertz
< 0) {
1929 dolog ("warning: Timer period is negative - %d "
1930 "treating as zero\n",
1933 conf
.period
.ticks
= 1;
1935 conf
.period
.ticks
= NANOSECONDS_PER_SECOND
/ conf
.period
.hertz
;
1938 e
= qemu_add_vm_change_state_handler (audio_vm_change_state_handler
, s
);
1940 dolog ("warning: Could not register change state handler\n"
1941 "(Audio can continue looping even after stopping the VM)\n");
1944 QLIST_INIT (&s
->card_head
);
1945 vmstate_register (NULL
, 0, &vmstate_audio
, s
);
1948 void AUD_register_card (const char *name
, QEMUSoundCard
*card
)
1951 card
->name
= g_strdup (name
);
1952 memset (&card
->entries
, 0, sizeof (card
->entries
));
1953 QLIST_INSERT_HEAD (&glob_audio_state
.card_head
, card
, entries
);
1956 void AUD_remove_card (QEMUSoundCard
*card
)
1958 QLIST_REMOVE (card
, entries
);
1959 g_free (card
->name
);
1963 CaptureVoiceOut
*AUD_add_capture (
1964 struct audsettings
*as
,
1965 struct audio_capture_ops
*ops
,
1969 AudioState
*s
= &glob_audio_state
;
1970 CaptureVoiceOut
*cap
;
1971 struct capture_callback
*cb
;
1973 if (audio_validate_settings (as
)) {
1974 dolog ("Invalid settings were passed when trying to add capture\n");
1975 audio_print_settings (as
);
1979 cb
= audio_calloc(__func__
, 1, sizeof(*cb
));
1981 dolog ("Could not allocate capture callback information, size %zu\n",
1986 cb
->opaque
= cb_opaque
;
1988 cap
= audio_pcm_capture_find_specific (as
);
1990 QLIST_INSERT_HEAD (&cap
->cb_head
, cb
, entries
);
1995 CaptureVoiceOut
*cap
;
1997 cap
= audio_calloc(__func__
, 1, sizeof(*cap
));
1999 dolog ("Could not allocate capture voice, size %zu\n",
2005 QLIST_INIT (&hw
->sw_head
);
2006 QLIST_INIT (&cap
->cb_head
);
2008 /* XXX find a more elegant way */
2009 hw
->samples
= 4096 * 4;
2010 hw
->mix_buf
= audio_calloc(__func__
, hw
->samples
,
2011 sizeof(struct st_sample
));
2013 dolog ("Could not allocate capture mix buffer (%d samples)\n",
2018 audio_pcm_init_info (&hw
->info
, as
);
2020 cap
->buf
= audio_calloc(__func__
, hw
->samples
, 1 << hw
->info
.shift
);
2022 dolog ("Could not allocate capture buffer "
2023 "(%d samples, each %d bytes)\n",
2024 hw
->samples
, 1 << hw
->info
.shift
);
2028 hw
->clip
= mixeng_clip
2029 [hw
->info
.nchannels
== 2]
2031 [hw
->info
.swap_endianness
]
2032 [audio_bits_to_index (hw
->info
.bits
)];
2034 QLIST_INSERT_HEAD (&s
->cap_head
, cap
, entries
);
2035 QLIST_INSERT_HEAD (&cap
->cb_head
, cb
, entries
);
2037 QLIST_FOREACH(hw
, &glob_audio_state
.hw_head_out
, entries
) {
2038 audio_attach_capture (hw
);
2043 g_free (cap
->hw
.mix_buf
);
2053 void AUD_del_capture (CaptureVoiceOut
*cap
, void *cb_opaque
)
2055 struct capture_callback
*cb
;
2057 for (cb
= cap
->cb_head
.lh_first
; cb
; cb
= cb
->entries
.le_next
) {
2058 if (cb
->opaque
== cb_opaque
) {
2059 cb
->ops
.destroy (cb_opaque
);
2060 QLIST_REMOVE (cb
, entries
);
2063 if (!cap
->cb_head
.lh_first
) {
2064 SWVoiceOut
*sw
= cap
->hw
.sw_head
.lh_first
, *sw1
;
2067 SWVoiceCap
*sc
= (SWVoiceCap
*) sw
;
2068 #ifdef DEBUG_CAPTURE
2069 dolog ("freeing %s\n", sw
->name
);
2072 sw1
= sw
->entries
.le_next
;
2074 st_rate_stop (sw
->rate
);
2077 QLIST_REMOVE (sw
, entries
);
2078 QLIST_REMOVE (sc
, entries
);
2082 QLIST_REMOVE (cap
, entries
);
2083 g_free (cap
->hw
.mix_buf
);
2092 void AUD_set_volume_out (SWVoiceOut
*sw
, int mute
, uint8_t lvol
, uint8_t rvol
)
2095 HWVoiceOut
*hw
= sw
->hw
;
2097 sw
->vol
.mute
= mute
;
2098 sw
->vol
.l
= nominal_volume
.l
* lvol
/ 255;
2099 sw
->vol
.r
= nominal_volume
.r
* rvol
/ 255;
2101 if (hw
->pcm_ops
->ctl_out
) {
2102 hw
->pcm_ops
->ctl_out (hw
, VOICE_VOLUME
, sw
);
2107 void AUD_set_volume_in (SWVoiceIn
*sw
, int mute
, uint8_t lvol
, uint8_t rvol
)
2110 HWVoiceIn
*hw
= sw
->hw
;
2112 sw
->vol
.mute
= mute
;
2113 sw
->vol
.l
= nominal_volume
.l
* lvol
/ 255;
2114 sw
->vol
.r
= nominal_volume
.r
* rvol
/ 255;
2116 if (hw
->pcm_ops
->ctl_in
) {
2117 hw
->pcm_ops
->ctl_in (hw
, VOICE_VOLUME
, sw
);