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 #ifdef CONFIG_COREAUDIO
29 /* #define RECIPROCAL */
44 audio_option_tag_e tag;
51 struct audio_callback {
53 audio_callback_fn_t fn;
56 struct audio_pcm_info {
67 typedef struct HWVoiceOut {
71 struct audio_pcm_info info;
81 LIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
82 struct audio_pcm_ops *pcm_ops;
83 LIST_ENTRY (HWVoiceOut) entries;
86 typedef struct HWVoiceIn {
88 struct audio_pcm_info info;
93 int total_samples_captured;
96 st_sample_t *conv_buf;
99 LIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
100 struct audio_pcm_ops *pcm_ops;
101 LIST_ENTRY (HWVoiceIn) entries;
105 struct audio_pcm_info info;
110 int total_hw_samples_mixed;
116 struct audio_callback callback;
117 LIST_ENTRY (SWVoiceOut) entries;
122 struct audio_pcm_info info;
125 int total_hw_samples_acquired;
131 struct audio_callback callback;
132 LIST_ENTRY (SWVoiceIn) entries;
135 struct audio_driver {
138 struct audio_option *options;
139 void *(*init) (void);
140 void (*fini) (void *);
141 struct audio_pcm_ops *pcm_ops;
149 struct audio_pcm_ops {
150 int (*init_out)(HWVoiceOut *hw, audsettings_t *as);
151 void (*fini_out)(HWVoiceOut *hw);
152 int (*run_out) (HWVoiceOut *hw);
153 int (*write) (SWVoiceOut *sw, void *buf, int size);
154 int (*ctl_out) (HWVoiceOut *hw, int cmd, ...);
156 int (*init_in) (HWVoiceIn *hw, audsettings_t *as);
157 void (*fini_in) (HWVoiceIn *hw);
158 int (*run_in) (HWVoiceIn *hw);
159 int (*read) (SWVoiceIn *sw, void *buf, int size);
160 int (*ctl_in) (HWVoiceIn *hw, int cmd, ...);
164 struct audio_driver *drv;
168 LIST_HEAD (card_head, QEMUSoundCard) card_head;
169 LIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in;
170 LIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out;
171 int nb_hw_voices_out;
175 extern struct audio_driver no_audio_driver;
176 extern struct audio_driver oss_audio_driver;
177 extern struct audio_driver sdl_audio_driver;
178 extern struct audio_driver wav_audio_driver;
179 extern struct audio_driver fmod_audio_driver;
180 extern struct audio_driver alsa_audio_driver;
181 extern struct audio_driver coreaudio_audio_driver;
182 extern struct audio_driver dsound_audio_driver;
183 extern volume_t nominal_volume;
185 void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as,
187 void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
189 int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
190 int audio_pcm_hw_get_live_in (HWVoiceIn *hw);
192 int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
193 int audio_pcm_hw_get_live_out (HWVoiceOut *hw);
194 int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live);
196 int audio_bug (const char *funcname, int cond);
197 void *audio_calloc (const char *funcname, int nmemb, size_t size);
199 #define VOICE_ENABLE 1
200 #define VOICE_DISABLE 2
202 static inline int audio_ring_dist (int dst, int src, int len)
204 return (dst >= src) ? (dst - src) : (len - src + dst);
207 static inline int audio_need_to_swap_endian (int endianness)
209 #ifdef WORDS_BIGENDIAN
210 return endianness != 1;
212 return endianness != 0;
217 #define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2)))
218 #define INIT_FIELD(f) . f
219 #define GCC_FMT_ATTR(n, m) __attribute__ ((__format__ (__printf__, n, m)))
221 #define GCC_ATTR /**/
222 #define INIT_FIELD(f) /**/
223 #define GCC_FMT_ATTR(n, m)
226 static void GCC_ATTR dolog (const char *fmt, ...)
231 AUD_vlog (AUDIO_CAP, fmt, ap);
236 static void GCC_ATTR ldebug (const char *fmt, ...)
241 AUD_vlog (AUDIO_CAP, fmt, ap);
245 #if defined NDEBUG && defined __GNUC__
247 #elif defined NDEBUG && defined _MSC_VER
248 #define ldebug __noop
250 static void GCC_ATTR ldebug (const char *fmt, ...)
259 #define AUDIO_STRINGIFY_(n) #n
260 #define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
262 #if defined _MSC_VER || defined __GNUC__
263 #define AUDIO_FUNC __FUNCTION__
265 #define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__)
268 #endif /* audio_int.h */