blob: ca240ccc7bd85fb39ea0dc26ba7421e3d4f4c092 [file] [log] [blame]
bellardfb065182004-11-09 23:09:44 +00001/*
2 * QEMU Audio subsystem header
bellard1d14ffa2005-10-30 18:58:22 +00003 *
4 * Copyright (c) 2003-2005 Vassili Karpov (malc)
5 *
bellardfb065182004-11-09 23:09:44 +00006 * 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
bellard1d14ffa2005-10-30 18:58:22 +000027#ifdef CONFIG_COREAUDIO
28#define FLOAT_MIXENG
29/* #define RECIPROCAL */
30#endif
31#include "mixeng.h"
bellardfb065182004-11-09 23:09:44 +000032
bellard1d14ffa2005-10-30 18:58:22 +000033struct audio_pcm_ops;
34
35typedef enum {
36 AUD_OPT_INT,
37 AUD_OPT_FMT,
38 AUD_OPT_STR,
39 AUD_OPT_BOOL
40} audio_option_tag_e;
41
42struct audio_option {
43 const char *name;
44 audio_option_tag_e tag;
45 void *valp;
46 const char *descr;
47 int *overridenp;
48 int overriden;
49};
50
51struct audio_callback {
52 void *opaque;
53 audio_callback_fn_t fn;
54};
55
56struct 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;
64 int swap_endian;
65};
66
67typedef struct HWVoiceOut {
bellardfb065182004-11-09 23:09:44 +000068 int enabled;
69 int pending_disable;
70 int valid;
bellard1d14ffa2005-10-30 18:58:22 +000071 struct audio_pcm_info info;
bellardfb065182004-11-09 23:09:44 +000072
73 f_sample *clip;
bellardfb065182004-11-09 23:09:44 +000074
75 int rpos;
bellard1d14ffa2005-10-30 18:58:22 +000076 uint64_t ts_helper;
bellardfb065182004-11-09 23:09:44 +000077
bellardfb065182004-11-09 23:09:44 +000078 st_sample_t *mix_buf;
79
80 int samples;
bellard1d14ffa2005-10-30 18:58:22 +000081 LIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
82 struct audio_pcm_ops *pcm_ops;
83 LIST_ENTRY (HWVoiceOut) entries;
84} HWVoiceOut;
bellardfb065182004-11-09 23:09:44 +000085
bellard1d14ffa2005-10-30 18:58:22 +000086typedef struct HWVoiceIn {
87 int enabled;
bellard1d14ffa2005-10-30 18:58:22 +000088 struct audio_pcm_info info;
bellardfb065182004-11-09 23:09:44 +000089
90 t_sample *conv;
91
bellard1d14ffa2005-10-30 18:58:22 +000092 int wpos;
bellard1d14ffa2005-10-30 18:58:22 +000093 int total_samples_captured;
94 uint64_t ts_helper;
95
96 st_sample_t *conv_buf;
97
98 int samples;
99 LIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
100 struct audio_pcm_ops *pcm_ops;
101 LIST_ENTRY (HWVoiceIn) entries;
102} HWVoiceIn;
103
bellard1d14ffa2005-10-30 18:58:22 +0000104struct SWVoiceOut {
105 struct audio_pcm_info info;
106 t_sample *conv;
bellardfb065182004-11-09 23:09:44 +0000107 int64_t ratio;
108 st_sample_t *buf;
109 void *rate;
bellard1d14ffa2005-10-30 18:58:22 +0000110 int total_hw_samples_mixed;
bellardfb065182004-11-09 23:09:44 +0000111 int active;
bellard1d14ffa2005-10-30 18:58:22 +0000112 int empty;
113 HWVoiceOut *hw;
bellardfb065182004-11-09 23:09:44 +0000114 char *name;
bellard1d14ffa2005-10-30 18:58:22 +0000115 volume_t vol;
116 struct audio_callback callback;
117 LIST_ENTRY (SWVoiceOut) entries;
bellardfb065182004-11-09 23:09:44 +0000118};
119
bellard1d14ffa2005-10-30 18:58:22 +0000120struct SWVoiceIn {
121 int active;
122 struct audio_pcm_info info;
123 int64_t ratio;
124 void *rate;
125 int total_hw_samples_acquired;
bellard571ec3d2005-11-20 16:24:34 +0000126 st_sample_t *buf;
bellard1d14ffa2005-10-30 18:58:22 +0000127 f_sample *clip;
128 HWVoiceIn *hw;
129 char *name;
130 volume_t vol;
131 struct audio_callback callback;
132 LIST_ENTRY (SWVoiceIn) entries;
bellardfb065182004-11-09 23:09:44 +0000133};
134
bellardc0fe3822005-11-05 18:55:28 +0000135struct audio_driver {
136 const char *name;
137 const char *descr;
138 struct audio_option *options;
139 void *(*init) (void);
140 void (*fini) (void *);
141 struct audio_pcm_ops *pcm_ops;
142 int can_be_default;
143 int max_voices_out;
144 int max_voices_in;
145 int voice_size_out;
146 int voice_size_in;
147};
148
bellard1d14ffa2005-10-30 18:58:22 +0000149struct audio_pcm_ops {
bellardc0fe3822005-11-05 18:55:28 +0000150 int (*init_out)(HWVoiceOut *hw, audsettings_t *as);
bellard1d14ffa2005-10-30 18:58:22 +0000151 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, ...);
bellardfb065182004-11-09 23:09:44 +0000155
bellardc0fe3822005-11-05 18:55:28 +0000156 int (*init_in) (HWVoiceIn *hw, audsettings_t *as);
bellard1d14ffa2005-10-30 18:58:22 +0000157 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, ...);
161};
bellardfb065182004-11-09 23:09:44 +0000162
bellardc0fe3822005-11-05 18:55:28 +0000163struct AudioState {
164 struct audio_driver *drv;
165 void *drv_opaque;
166
167 QEMUTimer *ts;
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;
172 int nb_hw_voices_in;
173};
174
175extern struct audio_driver no_audio_driver;
176extern struct audio_driver oss_audio_driver;
177extern struct audio_driver sdl_audio_driver;
178extern struct audio_driver wav_audio_driver;
179extern struct audio_driver fmod_audio_driver;
180extern struct audio_driver alsa_audio_driver;
181extern struct audio_driver coreaudio_audio_driver;
182extern struct audio_driver dsound_audio_driver;
183extern volume_t nominal_volume;
184
185void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as,
186 int swap_endian);
bellard1d14ffa2005-10-30 18:58:22 +0000187void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
bellardfb065182004-11-09 23:09:44 +0000188
bellard1d14ffa2005-10-30 18:58:22 +0000189int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
190int audio_pcm_hw_get_live_in (HWVoiceIn *hw);
bellardfb065182004-11-09 23:09:44 +0000191
bellard1d14ffa2005-10-30 18:58:22 +0000192int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
193int audio_pcm_hw_get_live_out (HWVoiceOut *hw);
194int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live);
bellardfb065182004-11-09 23:09:44 +0000195
bellardc0fe3822005-11-05 18:55:28 +0000196int audio_bug (const char *funcname, int cond);
197void *audio_calloc (const char *funcname, int nmemb, size_t size);
198
bellardfb065182004-11-09 23:09:44 +0000199#define VOICE_ENABLE 1
200#define VOICE_DISABLE 2
201
bellard1d14ffa2005-10-30 18:58:22 +0000202static inline int audio_ring_dist (int dst, int src, int len)
203{
204 return (dst >= src) ? (dst - src) : (len - src + dst);
205}
206
207static inline int audio_need_to_swap_endian (int endianness)
208{
209#ifdef WORDS_BIGENDIAN
210 return endianness != 1;
211#else
212 return endianness != 0;
213#endif
214}
215
216#if defined __GNUC__
217#define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2)))
218#define INIT_FIELD(f) . f
bellard4787c712005-11-11 00:06:10 +0000219#define GCC_FMT_ATTR(n, m) __attribute__ ((__format__ (__printf__, n, m)))
bellard1d14ffa2005-10-30 18:58:22 +0000220#else
221#define GCC_ATTR /**/
222#define INIT_FIELD(f) /**/
223#define GCC_FMT_ATTR(n, m)
224#endif
225
226static void GCC_ATTR dolog (const char *fmt, ...)
227{
228 va_list ap;
229
230 va_start (ap, fmt);
231 AUD_vlog (AUDIO_CAP, fmt, ap);
232 va_end (ap);
233}
234
235#ifdef DEBUG
236static void GCC_ATTR ldebug (const char *fmt, ...)
237{
238 va_list ap;
239
240 va_start (ap, fmt);
241 AUD_vlog (AUDIO_CAP, fmt, ap);
242 va_end (ap);
243}
244#else
245#if defined NDEBUG && defined __GNUC__
246#define ldebug(...)
247#elif defined NDEBUG && defined _MSC_VER
248#define ldebug __noop
249#else
250static void GCC_ATTR ldebug (const char *fmt, ...)
251{
252 (void) fmt;
253}
254#endif
255#endif
256
257#undef GCC_ATTR
258
259#define AUDIO_STRINGIFY_(n) #n
260#define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
261
262#if defined _MSC_VER || defined __GNUC__
263#define AUDIO_FUNC __FUNCTION__
264#else
265#define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__)
266#endif
267
bellardfb065182004-11-09 23:09:44 +0000268#endif /* audio_int.h */