bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU Audio subsystem header |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (c) 2003-2005 Vassili Karpov (malc) |
| 5 | * |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 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: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 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 |
| 22 | * THE SOFTWARE. |
| 23 | */ |
| 24 | #ifndef QEMU_AUDIO_INT_H |
| 25 | #define QEMU_AUDIO_INT_H |
| 26 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 27 | #ifdef CONFIG_COREAUDIO |
| 28 | #define FLOAT_MIXENG |
| 29 | /* #define RECIPROCAL */ |
| 30 | #endif |
| 31 | #include "mixeng.h" |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 32 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 33 | struct audio_pcm_ops; |
| 34 | |
| 35 | typedef enum { |
| 36 | AUD_OPT_INT, |
| 37 | AUD_OPT_FMT, |
| 38 | AUD_OPT_STR, |
| 39 | AUD_OPT_BOOL |
| 40 | } audio_option_tag_e; |
| 41 | |
| 42 | struct audio_option { |
| 43 | const char *name; |
| 44 | audio_option_tag_e tag; |
| 45 | void *valp; |
| 46 | const char *descr; |
ths | fe8f096 | 2007-07-12 10:59:21 +0000 | [diff] [blame] | 47 | int *overriddenp; |
| 48 | int overridden; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | struct audio_callback { |
| 52 | void *opaque; |
malc | cb4f03e | 2009-10-15 02:40:17 +0400 | [diff] [blame] | 53 | audio_callback_fn fn; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | struct audio_pcm_info { |
| 57 | int bits; |
| 58 | int sign; |
| 59 | int freq; |
| 60 | int nchannels; |
| 61 | int align; |
| 62 | int shift; |
| 63 | int bytes_per_second; |
bellard | d929eba | 2006-07-04 21:47:22 +0000 | [diff] [blame] | 64 | int swap_endianness; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 67 | typedef struct SWVoiceCap SWVoiceCap; |
| 68 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 69 | typedef struct HWVoiceOut { |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 70 | int enabled; |
malc | 713a98f | 2009-09-12 02:28:45 +0400 | [diff] [blame] | 71 | int poll_mode; |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 72 | int pending_disable; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 73 | struct audio_pcm_info info; |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 74 | |
| 75 | f_sample *clip; |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 76 | |
| 77 | int rpos; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 78 | uint64_t ts_helper; |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 79 | |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 80 | struct st_sample *mix_buf; |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 81 | |
| 82 | int samples; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 83 | QLIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head; |
| 84 | QLIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head; |
blueswir1 | 35f4b58 | 2008-10-06 18:08:30 +0000 | [diff] [blame] | 85 | struct audio_pcm_ops *pcm_ops; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 86 | QLIST_ENTRY (HWVoiceOut) entries; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 87 | } HWVoiceOut; |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 88 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 89 | typedef struct HWVoiceIn { |
| 90 | int enabled; |
malc | 713a98f | 2009-09-12 02:28:45 +0400 | [diff] [blame] | 91 | int poll_mode; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 92 | struct audio_pcm_info info; |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 93 | |
| 94 | t_sample *conv; |
| 95 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 96 | int wpos; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 97 | int total_samples_captured; |
| 98 | uint64_t ts_helper; |
| 99 | |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 100 | struct st_sample *conv_buf; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 101 | |
| 102 | int samples; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 103 | QLIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head; |
blueswir1 | 35f4b58 | 2008-10-06 18:08:30 +0000 | [diff] [blame] | 104 | struct audio_pcm_ops *pcm_ops; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 105 | QLIST_ENTRY (HWVoiceIn) entries; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 106 | } HWVoiceIn; |
| 107 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 108 | struct SWVoiceOut { |
malc | 1a7dafc | 2009-05-14 03:11:35 +0400 | [diff] [blame] | 109 | QEMUSoundCard *card; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 110 | struct audio_pcm_info info; |
| 111 | t_sample *conv; |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 112 | int64_t ratio; |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 113 | struct st_sample *buf; |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 114 | void *rate; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 115 | int total_hw_samples_mixed; |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 116 | int active; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 117 | int empty; |
| 118 | HWVoiceOut *hw; |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 119 | char *name; |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 120 | struct mixeng_volume vol; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 121 | struct audio_callback callback; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 122 | QLIST_ENTRY (SWVoiceOut) entries; |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 123 | }; |
| 124 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 125 | struct SWVoiceIn { |
malc | 1a7dafc | 2009-05-14 03:11:35 +0400 | [diff] [blame] | 126 | QEMUSoundCard *card; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 127 | int active; |
| 128 | struct audio_pcm_info info; |
| 129 | int64_t ratio; |
| 130 | void *rate; |
| 131 | int total_hw_samples_acquired; |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 132 | struct st_sample *buf; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 133 | f_sample *clip; |
| 134 | HWVoiceIn *hw; |
| 135 | char *name; |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 136 | struct mixeng_volume vol; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 137 | struct audio_callback callback; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 138 | QLIST_ENTRY (SWVoiceIn) entries; |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 141 | struct audio_driver { |
| 142 | const char *name; |
| 143 | const char *descr; |
| 144 | struct audio_option *options; |
| 145 | void *(*init) (void); |
| 146 | void (*fini) (void *); |
blueswir1 | 35f4b58 | 2008-10-06 18:08:30 +0000 | [diff] [blame] | 147 | struct audio_pcm_ops *pcm_ops; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 148 | int can_be_default; |
| 149 | int max_voices_out; |
| 150 | int max_voices_in; |
| 151 | int voice_size_out; |
| 152 | int voice_size_in; |
| 153 | }; |
| 154 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 155 | struct audio_pcm_ops { |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 156 | int (*init_out)(HWVoiceOut *hw, struct audsettings *as); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 157 | void (*fini_out)(HWVoiceOut *hw); |
malc | bdff253 | 2009-09-18 11:37:39 +0400 | [diff] [blame] | 158 | int (*run_out) (HWVoiceOut *hw, int live); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 159 | int (*write) (SWVoiceOut *sw, void *buf, int size); |
| 160 | int (*ctl_out) (HWVoiceOut *hw, int cmd, ...); |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 161 | |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 162 | int (*init_in) (HWVoiceIn *hw, struct audsettings *as); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 163 | void (*fini_in) (HWVoiceIn *hw); |
| 164 | int (*run_in) (HWVoiceIn *hw); |
| 165 | int (*read) (SWVoiceIn *sw, void *buf, int size); |
| 166 | int (*ctl_in) (HWVoiceIn *hw, int cmd, ...); |
| 167 | }; |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 168 | |
bellard | 8ead62c | 2006-07-04 16:51:32 +0000 | [diff] [blame] | 169 | struct capture_callback { |
| 170 | struct audio_capture_ops ops; |
| 171 | void *opaque; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 172 | QLIST_ENTRY (capture_callback) entries; |
bellard | 8ead62c | 2006-07-04 16:51:32 +0000 | [diff] [blame] | 173 | }; |
| 174 | |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 175 | struct CaptureVoiceOut { |
bellard | 8ead62c | 2006-07-04 16:51:32 +0000 | [diff] [blame] | 176 | HWVoiceOut hw; |
| 177 | void *buf; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 178 | QLIST_HEAD (cb_listhead, capture_callback) cb_head; |
| 179 | QLIST_ENTRY (CaptureVoiceOut) entries; |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | struct SWVoiceCap { |
| 183 | SWVoiceOut sw; |
| 184 | CaptureVoiceOut *cap; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 185 | QLIST_ENTRY (SWVoiceCap) entries; |
bellard | ec36b69 | 2006-07-16 18:57:03 +0000 | [diff] [blame] | 186 | }; |
bellard | 8ead62c | 2006-07-04 16:51:32 +0000 | [diff] [blame] | 187 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 188 | struct AudioState { |
| 189 | struct audio_driver *drv; |
| 190 | void *drv_opaque; |
| 191 | |
| 192 | QEMUTimer *ts; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 193 | QLIST_HEAD (card_listhead, QEMUSoundCard) card_head; |
| 194 | QLIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in; |
| 195 | QLIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out; |
| 196 | QLIST_HEAD (cap_listhead, CaptureVoiceOut) cap_head; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 197 | int nb_hw_voices_out; |
| 198 | int nb_hw_voices_in; |
malc | 978dd63 | 2009-02-18 20:44:04 +0000 | [diff] [blame] | 199 | int vm_running; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 200 | }; |
| 201 | |
| 202 | extern struct audio_driver no_audio_driver; |
| 203 | extern struct audio_driver oss_audio_driver; |
| 204 | extern struct audio_driver sdl_audio_driver; |
| 205 | extern struct audio_driver wav_audio_driver; |
| 206 | extern struct audio_driver fmod_audio_driver; |
| 207 | extern struct audio_driver alsa_audio_driver; |
| 208 | extern struct audio_driver coreaudio_audio_driver; |
| 209 | extern struct audio_driver dsound_audio_driver; |
balrog | ca9cc28 | 2008-01-14 04:24:29 +0000 | [diff] [blame] | 210 | extern struct audio_driver esd_audio_driver; |
malc | b8e59f1 | 2008-07-02 21:03:08 +0000 | [diff] [blame] | 211 | extern struct audio_driver pa_audio_driver; |
Gerd Hoffmann | 3e31375 | 2010-11-09 17:29:46 +0100 | [diff] [blame] | 212 | extern struct audio_driver spice_audio_driver; |
malc | d563163 | 2009-10-10 01:13:41 +0400 | [diff] [blame] | 213 | extern struct audio_driver winwave_audio_driver; |
Michael Walle | 00e0767 | 2011-01-05 01:05:47 +0100 | [diff] [blame] | 214 | extern const struct mixeng_volume nominal_volume; |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 215 | |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 216 | void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 217 | void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len); |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 218 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 219 | int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len); |
| 220 | int audio_pcm_hw_get_live_in (HWVoiceIn *hw); |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 221 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 222 | int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len); |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 223 | |
malc | ddabec7 | 2009-09-18 10:59:38 +0400 | [diff] [blame] | 224 | int audio_pcm_hw_clip_out (HWVoiceOut *hw, void *pcm_buf, |
| 225 | int live, int pending); |
| 226 | |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 227 | int audio_bug (const char *funcname, int cond); |
| 228 | void *audio_calloc (const char *funcname, int nmemb, size_t size); |
| 229 | |
malc | 713a98f | 2009-09-12 02:28:45 +0400 | [diff] [blame] | 230 | void audio_run (const char *msg); |
| 231 | |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 232 | #define VOICE_ENABLE 1 |
| 233 | #define VOICE_DISABLE 2 |
| 234 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 235 | static inline int audio_ring_dist (int dst, int src, int len) |
| 236 | { |
| 237 | return (dst >= src) ? (dst - src) : (len - src + dst); |
| 238 | } |
| 239 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 240 | static void GCC_ATTR dolog (const char *fmt, ...) |
| 241 | { |
| 242 | va_list ap; |
| 243 | |
| 244 | va_start (ap, fmt); |
| 245 | AUD_vlog (AUDIO_CAP, fmt, ap); |
| 246 | va_end (ap); |
| 247 | } |
| 248 | |
| 249 | #ifdef DEBUG |
| 250 | static void GCC_ATTR ldebug (const char *fmt, ...) |
| 251 | { |
| 252 | va_list ap; |
| 253 | |
| 254 | va_start (ap, fmt); |
| 255 | AUD_vlog (AUDIO_CAP, fmt, ap); |
| 256 | va_end (ap); |
| 257 | } |
| 258 | #else |
| 259 | #if defined NDEBUG && defined __GNUC__ |
| 260 | #define ldebug(...) |
| 261 | #elif defined NDEBUG && defined _MSC_VER |
| 262 | #define ldebug __noop |
| 263 | #else |
| 264 | static void GCC_ATTR ldebug (const char *fmt, ...) |
| 265 | { |
| 266 | (void) fmt; |
| 267 | } |
| 268 | #endif |
| 269 | #endif |
| 270 | |
| 271 | #undef GCC_ATTR |
| 272 | |
| 273 | #define AUDIO_STRINGIFY_(n) #n |
| 274 | #define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n) |
| 275 | |
| 276 | #if defined _MSC_VER || defined __GNUC__ |
| 277 | #define AUDIO_FUNC __FUNCTION__ |
| 278 | #else |
| 279 | #define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__) |
| 280 | #endif |
| 281 | |
bellard | fb06518 | 2004-11-09 23:09:44 +0000 | [diff] [blame] | 282 | #endif /* audio_int.h */ |