00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef QEMU_AUDIO_INT_H
00025 #define QEMU_AUDIO_INT_H
00026
00027 #ifdef CONFIG_COREAUDIO
00028 #define FLOAT_MIXENG
00029
00030 #endif
00031 #include "mixeng.h"
00032
00033 struct audio_pcm_ops;
00034
00035 typedef enum {
00036 AUD_OPT_INT,
00037 AUD_OPT_FMT,
00038 AUD_OPT_STR,
00039 AUD_OPT_BOOL
00040 } audio_option_tag_e;
00041
00042 struct audio_option {
00043 const char *name;
00044 audio_option_tag_e tag;
00045 void *valp;
00046 const char *descr;
00047 int *overriddenp;
00048 int overridden;
00049 };
00050
00051 struct audio_callback {
00052 void *opaque;
00053 audio_callback_fn_t fn;
00054 };
00055
00056 struct audio_pcm_info {
00057 int bits;
00058 int sign;
00059 int freq;
00060 int nchannels;
00061 int align;
00062 int shift;
00063 int bytes_per_second;
00064 int swap_endianness;
00065 };
00066
00067 typedef struct SWVoiceCap SWVoiceCap;
00068
00069 typedef struct HWVoiceOut {
00070 int enabled;
00071 int pending_disable;
00072 struct audio_pcm_info info;
00073
00074 f_sample *clip;
00075
00076 int rpos;
00077 uint64_t ts_helper;
00078
00079 struct st_sample *mix_buf;
00080
00081 int samples;
00082 LIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
00083 LIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head;
00084 struct audio_pcm_ops *pcm_ops;
00085 LIST_ENTRY (HWVoiceOut) entries;
00086 } HWVoiceOut;
00087
00088 typedef struct HWVoiceIn {
00089 int enabled;
00090 struct audio_pcm_info info;
00091
00092 t_sample *conv;
00093
00094 int wpos;
00095 int total_samples_captured;
00096 uint64_t ts_helper;
00097
00098 struct st_sample *conv_buf;
00099
00100 int samples;
00101 LIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
00102 struct audio_pcm_ops *pcm_ops;
00103 LIST_ENTRY (HWVoiceIn) entries;
00104 } HWVoiceIn;
00105
00106 struct SWVoiceOut {
00107 struct audio_pcm_info info;
00108 t_sample *conv;
00109 int64_t ratio;
00110 struct st_sample *buf;
00111 void *rate;
00112 int total_hw_samples_mixed;
00113 int active;
00114 int empty;
00115 HWVoiceOut *hw;
00116 char *name;
00117 struct mixeng_volume vol;
00118 struct audio_callback callback;
00119 LIST_ENTRY (SWVoiceOut) entries;
00120 };
00121
00122 struct SWVoiceIn {
00123 int active;
00124 struct audio_pcm_info info;
00125 int64_t ratio;
00126 void *rate;
00127 int total_hw_samples_acquired;
00128 struct st_sample *buf;
00129 f_sample *clip;
00130 HWVoiceIn *hw;
00131 char *name;
00132 struct mixeng_volume vol;
00133 struct audio_callback callback;
00134 LIST_ENTRY (SWVoiceIn) entries;
00135 };
00136
00137 struct audio_driver {
00138 const char *name;
00139 const char *descr;
00140 struct audio_option *options;
00141 void *(*init) (void);
00142 void (*fini) (void *);
00143 struct audio_pcm_ops *pcm_ops;
00144 int can_be_default;
00145 int max_voices_out;
00146 int max_voices_in;
00147 int voice_size_out;
00148 int voice_size_in;
00149 };
00150
00151 struct audio_pcm_ops {
00152 int (*init_out)(HWVoiceOut *hw, struct audsettings *as);
00153 void (*fini_out)(HWVoiceOut *hw);
00154 int (*run_out) (HWVoiceOut *hw);
00155 int (*write) (SWVoiceOut *sw, void *buf, int size);
00156 int (*ctl_out) (HWVoiceOut *hw, int cmd, ...);
00157
00158 int (*init_in) (HWVoiceIn *hw, struct audsettings *as);
00159 void (*fini_in) (HWVoiceIn *hw);
00160 int (*run_in) (HWVoiceIn *hw);
00161 int (*read) (SWVoiceIn *sw, void *buf, int size);
00162 int (*ctl_in) (HWVoiceIn *hw, int cmd, ...);
00163 };
00164
00165 struct capture_callback {
00166 struct audio_capture_ops ops;
00167 void *opaque;
00168 LIST_ENTRY (capture_callback) entries;
00169 };
00170
00171 struct CaptureVoiceOut {
00172 HWVoiceOut hw;
00173 void *buf;
00174 LIST_HEAD (cb_listhead, capture_callback) cb_head;
00175 LIST_ENTRY (CaptureVoiceOut) entries;
00176 };
00177
00178 struct SWVoiceCap {
00179 SWVoiceOut sw;
00180 CaptureVoiceOut *cap;
00181 LIST_ENTRY (SWVoiceCap) entries;
00182 };
00183
00184 struct AudioState {
00185 struct audio_driver *drv;
00186 void *drv_opaque;
00187
00188 QEMUTimer *ts;
00189 LIST_HEAD (card_listhead, QEMUSoundCard) card_head;
00190 LIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in;
00191 LIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out;
00192 LIST_HEAD (cap_listhead, CaptureVoiceOut) cap_head;
00193 int nb_hw_voices_out;
00194 int nb_hw_voices_in;
00195 int vm_running;
00196 };
00197
00198 extern struct audio_driver no_audio_driver;
00199 extern struct audio_driver oss_audio_driver;
00200 extern struct audio_driver sdl_audio_driver;
00201 extern struct audio_driver wav_audio_driver;
00202 extern struct audio_driver fmod_audio_driver;
00203 extern struct audio_driver alsa_audio_driver;
00204 extern struct audio_driver coreaudio_audio_driver;
00205 extern struct audio_driver dsound_audio_driver;
00206 extern struct audio_driver esd_audio_driver;
00207 extern struct audio_driver pa_audio_driver;
00208 extern struct mixeng_volume nominal_volume;
00209
00210 void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as);
00211 void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
00212
00213 int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
00214 int audio_pcm_hw_get_live_in (HWVoiceIn *hw);
00215
00216 int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
00217 int audio_pcm_hw_get_live_out (HWVoiceOut *hw);
00218 int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live);
00219
00220 int audio_bug (const char *funcname, int cond);
00221 void *audio_calloc (const char *funcname, int nmemb, size_t size);
00222
00223 #define VOICE_ENABLE 1
00224 #define VOICE_DISABLE 2
00225
00226 static inline int audio_ring_dist (int dst, int src, int len)
00227 {
00228 return (dst >= src) ? (dst - src) : (len - src + dst);
00229 }
00230
00231 #if defined __GNUC__
00232 #define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2)))
00233 #define INIT_FIELD(f) . f
00234 #define GCC_FMT_ATTR(n, m) __attribute__ ((__format__ (__printf__, n, m)))
00235 #else
00236 #define GCC_ATTR
00237 #define INIT_FIELD(f)
00238 #define GCC_FMT_ATTR(n, m)
00239 #endif
00240
00241 static void GCC_ATTR dolog (const char *fmt, ...)
00242 {
00243 va_list ap;
00244
00245 va_start (ap, fmt);
00246 AUD_vlog (AUDIO_CAP, fmt, ap);
00247 va_end (ap);
00248 }
00249
00250 #ifdef DEBUG
00251 static void GCC_ATTR ldebug (const char *fmt, ...)
00252 {
00253 va_list ap;
00254
00255 va_start (ap, fmt);
00256 AUD_vlog (AUDIO_CAP, fmt, ap);
00257 va_end (ap);
00258 }
00259 #else
00260 #if defined NDEBUG && defined __GNUC__
00261 #define ldebug(...)
00262 #elif defined NDEBUG && defined _MSC_VER
00263 #define ldebug __noop
00264 #else
00265 static void GCC_ATTR ldebug (const char *fmt, ...)
00266 {
00267 (void) fmt;
00268 }
00269 #endif
00270 #endif
00271
00272 #undef GCC_ATTR
00273
00274 #define AUDIO_STRINGIFY_(n) #n
00275 #define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
00276
00277 #if defined _MSC_VER || defined __GNUC__
00278 #define AUDIO_FUNC __FUNCTION__
00279 #else
00280 #define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__)
00281 #endif
00282
00283 #endif