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
24 #ifndef QEMU_AUDIO_INT_H
25 #define QEMU_AUDIO_INT_H
27 #include "sys-queue.h"
29 #ifdef CONFIG_COREAUDIO
31 /* #define RECIPROCAL */
35 int audio_bug (const char *funcname
, int cond
);
48 audio_option_tag_e tag
;
55 struct audio_callback
{
57 audio_callback_fn_t fn
;
60 struct audio_pcm_info
{
71 typedef struct HWVoiceOut
{
76 struct audio_pcm_info info
;
87 LIST_HEAD (sw_out_listhead
, SWVoiceOut
) sw_head
;
88 struct audio_pcm_ops
*pcm_ops
;
89 LIST_ENTRY (HWVoiceOut
) entries
;
92 typedef struct HWVoiceIn
{
95 struct audio_pcm_info info
;
101 int total_samples_captured
;
104 st_sample_t
*conv_buf
;
107 LIST_HEAD (sw_in_listhead
, SWVoiceIn
) sw_head
;
108 struct audio_pcm_ops
*pcm_ops
;
109 LIST_ENTRY (HWVoiceIn
) entries
;
112 extern struct audio_driver no_audio_driver
;
113 extern struct audio_driver oss_audio_driver
;
114 extern struct audio_driver sdl_audio_driver
;
115 extern struct audio_driver wav_audio_driver
;
116 extern struct audio_driver fmod_audio_driver
;
117 extern struct audio_driver alsa_audio_driver
;
118 extern struct audio_driver coreaudio_audio_driver
;
119 extern struct audio_driver dsound_audio_driver
;
120 extern volume_t nominal_volume
;
122 struct audio_driver
{
125 struct audio_option
*options
;
126 void *(*init
) (void);
127 void (*fini
) (void *);
128 struct audio_pcm_ops
*pcm_ops
;
136 typedef struct AudioState
{
137 int fixed_settings_out
;
139 int fixed_channels_out
;
141 int nb_hw_voices_out
;
144 int fixed_settings_in
;
146 int fixed_channels_in
;
152 struct audio_driver
*drv
;
162 extern AudioState audio_state
;
165 struct audio_pcm_info info
;
170 int total_hw_samples_mixed
;
176 struct audio_callback callback
;
177 LIST_ENTRY (SWVoiceOut
) entries
;
182 struct audio_pcm_info info
;
185 int total_hw_samples_acquired
;
186 st_sample_t
*conv_buf
;
191 struct audio_callback callback
;
192 LIST_ENTRY (SWVoiceIn
) entries
;
195 struct audio_pcm_ops
{
196 int (*init_out
)(HWVoiceOut
*hw
, int freq
, int nchannels
, audfmt_e fmt
);
197 void (*fini_out
)(HWVoiceOut
*hw
);
198 int (*run_out
) (HWVoiceOut
*hw
);
199 int (*write
) (SWVoiceOut
*sw
, void *buf
, int size
);
200 int (*ctl_out
) (HWVoiceOut
*hw
, int cmd
, ...);
202 int (*init_in
) (HWVoiceIn
*hw
, int freq
, int nchannels
, audfmt_e fmt
);
203 void (*fini_in
) (HWVoiceIn
*hw
);
204 int (*run_in
) (HWVoiceIn
*hw
);
205 int (*read
) (SWVoiceIn
*sw
, void *buf
, int size
);
206 int (*ctl_in
) (HWVoiceIn
*hw
, int cmd
, ...);
209 void audio_pcm_init_info (struct audio_pcm_info
*info
, int freq
,
210 int nchannels
, audfmt_e fmt
, int swap_endian
);
211 void audio_pcm_info_clear_buf (struct audio_pcm_info
*info
, void *buf
, int len
);
213 int audio_pcm_sw_write (SWVoiceOut
*sw
, void *buf
, int len
);
214 int audio_pcm_hw_get_live_in (HWVoiceIn
*hw
);
216 int audio_pcm_sw_read (SWVoiceIn
*sw
, void *buf
, int len
);
217 int audio_pcm_hw_get_live_out (HWVoiceOut
*hw
);
218 int audio_pcm_hw_get_live_out2 (HWVoiceOut
*hw
, int *nb_live
);
220 #define VOICE_ENABLE 1
221 #define VOICE_DISABLE 2
223 static inline int audio_ring_dist (int dst
, int src
, int len
)
225 return (dst
>= src
) ? (dst
- src
) : (len
- src
+ dst
);
228 static inline int audio_need_to_swap_endian (int endianness
)
230 #ifdef WORDS_BIGENDIAN
231 return endianness
!= 1;
233 return endianness
!= 0;
238 #define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2)))
239 #define INIT_FIELD(f) . f
240 #define GCC_FMT_ATTR(n, m) __attribute__ ((__format__ (printf, n, m)))
242 #define GCC_ATTR /**/
243 #define INIT_FIELD(f) /**/
244 #define GCC_FMT_ATTR(n, m)
247 static void GCC_ATTR
dolog (const char *fmt
, ...)
252 AUD_vlog (AUDIO_CAP
, fmt
, ap
);
257 static void GCC_ATTR
ldebug (const char *fmt
, ...)
262 AUD_vlog (AUDIO_CAP
, fmt
, ap
);
266 #if defined NDEBUG && defined __GNUC__
268 #elif defined NDEBUG && defined _MSC_VER
269 #define ldebug __noop
271 static void GCC_ATTR
ldebug (const char *fmt
, ...)
280 #define AUDIO_STRINGIFY_(n) #n
281 #define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
283 #if defined _MSC_VER || defined __GNUC__
284 #define AUDIO_FUNC __FUNCTION__
286 #define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__)
289 #endif /* audio_int.h */