2 * QEMU Audio subsystem header
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
28 #include "qemu/queue.h"
29 #include "qapi/qapi-types-audio.h"
30 #include "hw/qdev-properties.h"
31 #include "hw/qdev-properties-system.h"
33 typedef void (*audio_callback_fn
) (void *opaque
, int avail
);
36 #define AUDIO_HOST_ENDIANNESS 1
38 #define AUDIO_HOST_ENDIANNESS 0
41 typedef struct audsettings
{
48 audsettings
audiodev_to_audsettings(AudiodevPerDirectionOptions
*pdo
);
49 int audioformat_bytes_per_sample(AudioFormat fmt
);
50 int audio_buffer_frames(AudiodevPerDirectionOptions
*pdo
,
51 audsettings
*as
, int def_usecs
);
52 int audio_buffer_samples(AudiodevPerDirectionOptions
*pdo
,
53 audsettings
*as
, int def_usecs
);
54 int audio_buffer_bytes(AudiodevPerDirectionOptions
*pdo
,
55 audsettings
*as
, int def_usecs
);
62 struct audio_capture_ops
{
63 void (*notify
) (void *opaque
, audcnotification_e cmd
);
64 void (*capture
) (void *opaque
, const void *buf
, int size
);
65 void (*destroy
) (void *opaque
);
69 void (*info
) (void *opaque
);
70 void (*destroy
) (void *opaque
);
73 typedef struct CaptureState
{
75 struct capture_ops ops
;
76 QLIST_ENTRY (CaptureState
) entries
;
79 typedef struct SWVoiceOut SWVoiceOut
;
80 typedef struct CaptureVoiceOut CaptureVoiceOut
;
81 typedef struct SWVoiceIn SWVoiceIn
;
83 typedef struct AudioState AudioState
;
84 typedef struct QEMUSoundCard
{
87 QLIST_ENTRY (QEMUSoundCard
) entries
;
90 typedef struct QEMUAudioTimeStamp
{
94 void AUD_vlog (const char *cap
, const char *fmt
, va_list ap
) G_GNUC_PRINTF(2, 0);
95 void AUD_log (const char *cap
, const char *fmt
, ...) G_GNUC_PRINTF(2, 3);
97 void AUD_register_card (const char *name
, QEMUSoundCard
*card
);
98 void AUD_remove_card (QEMUSoundCard
*card
);
99 CaptureVoiceOut
*AUD_add_capture(
101 struct audsettings
*as
,
102 struct audio_capture_ops
*ops
,
105 void AUD_del_capture (CaptureVoiceOut
*cap
, void *cb_opaque
);
107 SWVoiceOut
*AUD_open_out (
111 void *callback_opaque
,
112 audio_callback_fn callback_fn
,
113 struct audsettings
*settings
116 void AUD_close_out (QEMUSoundCard
*card
, SWVoiceOut
*sw
);
117 size_t AUD_write (SWVoiceOut
*sw
, void *pcm_buf
, size_t size
);
118 int AUD_get_buffer_size_out (SWVoiceOut
*sw
);
119 void AUD_set_active_out (SWVoiceOut
*sw
, int on
);
120 int AUD_is_active_out (SWVoiceOut
*sw
);
122 void AUD_init_time_stamp_out (SWVoiceOut
*sw
, QEMUAudioTimeStamp
*ts
);
123 uint64_t AUD_get_elapsed_usec_out (SWVoiceOut
*sw
, QEMUAudioTimeStamp
*ts
);
125 void AUD_set_volume_out (SWVoiceOut
*sw
, int mute
, uint8_t lvol
, uint8_t rvol
);
126 void AUD_set_volume_in (SWVoiceIn
*sw
, int mute
, uint8_t lvol
, uint8_t rvol
);
128 #define AUDIO_MAX_CHANNELS 16
129 typedef struct Volume
{
132 uint8_t vol
[AUDIO_MAX_CHANNELS
];
135 void audio_set_volume_out(SWVoiceOut
*sw
, Volume
*vol
);
136 void audio_set_volume_in(SWVoiceIn
*sw
, Volume
*vol
);
138 SWVoiceIn
*AUD_open_in (
142 void *callback_opaque
,
143 audio_callback_fn callback_fn
,
144 struct audsettings
*settings
147 void AUD_close_in (QEMUSoundCard
*card
, SWVoiceIn
*sw
);
148 size_t AUD_read (SWVoiceIn
*sw
, void *pcm_buf
, size_t size
);
149 void AUD_set_active_in (SWVoiceIn
*sw
, int on
);
150 int AUD_is_active_in (SWVoiceIn
*sw
);
152 void AUD_init_time_stamp_in (SWVoiceIn
*sw
, QEMUAudioTimeStamp
*ts
);
153 uint64_t AUD_get_elapsed_usec_in (SWVoiceIn
*sw
, QEMUAudioTimeStamp
*ts
);
155 static inline void *advance (void *p
, int incr
)
161 int wav_start_capture(AudioState
*state
, CaptureState
*s
, const char *path
,
162 int freq
, int bits
, int nchannels
);
164 void audio_cleanup(void);
166 void audio_sample_to_uint64(const void *samples
, int pos
,
167 uint64_t *left
, uint64_t *right
);
168 void audio_sample_from_uint64(void *samples
, int pos
,
169 uint64_t left
, uint64_t right
);
171 void audio_define(Audiodev
*audio
);
172 void audio_parse_option(const char *opt
);
173 void audio_init_audiodevs(void);
174 void audio_legacy_help(void);
176 AudioState
*audio_state_by_name(const char *name
);
177 const char *audio_get_id(QEMUSoundCard
*card
);
179 #define DEFINE_AUDIO_PROPERTIES(_s, _f) \
180 DEFINE_PROP_AUDIODEV("audiodev", _s, _f)
182 #endif /* QEMU_AUDIO_H */