2004-11-09 23:09:44 +00:00
|
|
|
/*
|
|
|
|
* QEMU Audio subsystem header
|
2005-10-30 18:58:22 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2005 Vassili Karpov (malc)
|
|
|
|
*
|
2004-11-09 23:09:44 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#ifndef QEMU_AUDIO_INT_H
|
|
|
|
#define QEMU_AUDIO_INT_H
|
|
|
|
|
2005-10-30 18:58:22 +00:00
|
|
|
#ifdef CONFIG_COREAUDIO
|
|
|
|
#define FLOAT_MIXENG
|
|
|
|
/* #define RECIPROCAL */
|
|
|
|
#endif
|
|
|
|
#include "mixeng.h"
|
|
|
|
|
|
|
|
struct audio_pcm_ops;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
AUD_OPT_INT,
|
|
|
|
AUD_OPT_FMT,
|
|
|
|
AUD_OPT_STR,
|
|
|
|
AUD_OPT_BOOL
|
|
|
|
} audio_option_tag_e;
|
|
|
|
|
|
|
|
struct audio_option {
|
|
|
|
const char *name;
|
|
|
|
audio_option_tag_e tag;
|
|
|
|
void *valp;
|
|
|
|
const char *descr;
|
2007-07-12 10:59:21 +00:00
|
|
|
int *overriddenp;
|
|
|
|
int overridden;
|
2005-10-30 18:58:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct audio_callback {
|
|
|
|
void *opaque;
|
2009-10-14 22:40:17 +00:00
|
|
|
audio_callback_fn fn;
|
2005-10-30 18:58:22 +00:00
|
|
|
};
|
2004-11-09 23:09:44 +00:00
|
|
|
|
2005-10-30 18:58:22 +00:00
|
|
|
struct audio_pcm_info {
|
|
|
|
int bits;
|
|
|
|
int sign;
|
|
|
|
int freq;
|
|
|
|
int nchannels;
|
|
|
|
int align;
|
|
|
|
int shift;
|
|
|
|
int bytes_per_second;
|
2006-07-04 21:47:22 +00:00
|
|
|
int swap_endianness;
|
2005-10-30 18:58:22 +00:00
|
|
|
};
|
2004-11-09 23:09:44 +00:00
|
|
|
|
2006-07-16 18:57:03 +00:00
|
|
|
typedef struct SWVoiceCap SWVoiceCap;
|
|
|
|
|
2005-10-30 18:58:22 +00:00
|
|
|
typedef struct HWVoiceOut {
|
2004-11-09 23:09:44 +00:00
|
|
|
int enabled;
|
2009-09-11 22:28:45 +00:00
|
|
|
int poll_mode;
|
2004-11-09 23:09:44 +00:00
|
|
|
int pending_disable;
|
2005-10-30 18:58:22 +00:00
|
|
|
struct audio_pcm_info info;
|
2004-11-09 23:09:44 +00:00
|
|
|
|
|
|
|
f_sample *clip;
|
|
|
|
|
|
|
|
int rpos;
|
2005-10-30 18:58:22 +00:00
|
|
|
uint64_t ts_helper;
|
2004-11-09 23:09:44 +00:00
|
|
|
|
2008-12-03 22:48:44 +00:00
|
|
|
struct st_sample *mix_buf;
|
2004-11-09 23:09:44 +00:00
|
|
|
|
|
|
|
int samples;
|
2009-09-12 07:36:22 +00:00
|
|
|
QLIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
|
|
|
|
QLIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head;
|
2008-10-06 18:08:30 +00:00
|
|
|
struct audio_pcm_ops *pcm_ops;
|
2009-09-12 07:36:22 +00:00
|
|
|
QLIST_ENTRY (HWVoiceOut) entries;
|
2005-10-30 18:58:22 +00:00
|
|
|
} HWVoiceOut;
|
2004-11-09 23:09:44 +00:00
|
|
|
|
2005-10-30 18:58:22 +00:00
|
|
|
typedef struct HWVoiceIn {
|
|
|
|
int enabled;
|
2009-09-11 22:28:45 +00:00
|
|
|
int poll_mode;
|
2005-10-30 18:58:22 +00:00
|
|
|
struct audio_pcm_info info;
|
|
|
|
|
|
|
|
t_sample *conv;
|
2004-11-11 16:55:09 +00:00
|
|
|
|
2005-10-30 18:58:22 +00:00
|
|
|
int wpos;
|
|
|
|
int total_samples_captured;
|
|
|
|
uint64_t ts_helper;
|
2004-11-09 23:09:44 +00:00
|
|
|
|
2008-12-03 22:48:44 +00:00
|
|
|
struct st_sample *conv_buf;
|
2004-11-09 23:09:44 +00:00
|
|
|
|
2005-10-30 18:58:22 +00:00
|
|
|
int samples;
|
2009-09-12 07:36:22 +00:00
|
|
|
QLIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
|
2008-10-06 18:08:30 +00:00
|
|
|
struct audio_pcm_ops *pcm_ops;
|
2009-09-12 07:36:22 +00:00
|
|
|
QLIST_ENTRY (HWVoiceIn) entries;
|
2005-10-30 18:58:22 +00:00
|
|
|
} HWVoiceIn;
|
2004-11-09 23:09:44 +00:00
|
|
|
|
2005-10-30 18:58:22 +00:00
|
|
|
struct SWVoiceOut {
|
2009-05-13 23:11:35 +00:00
|
|
|
QEMUSoundCard *card;
|
2005-10-30 18:58:22 +00:00
|
|
|
struct audio_pcm_info info;
|
2004-11-09 23:09:44 +00:00
|
|
|
t_sample *conv;
|
|
|
|
int64_t ratio;
|
2008-12-03 22:48:44 +00:00
|
|
|
struct st_sample *buf;
|
2004-11-09 23:09:44 +00:00
|
|
|
void *rate;
|
2005-10-30 18:58:22 +00:00
|
|
|
int total_hw_samples_mixed;
|
|
|
|
int active;
|
|
|
|
int empty;
|
|
|
|
HWVoiceOut *hw;
|
|
|
|
char *name;
|
2008-12-03 22:48:44 +00:00
|
|
|
struct mixeng_volume vol;
|
2005-10-30 18:58:22 +00:00
|
|
|
struct audio_callback callback;
|
2009-09-12 07:36:22 +00:00
|
|
|
QLIST_ENTRY (SWVoiceOut) entries;
|
2005-10-30 18:58:22 +00:00
|
|
|
};
|
2004-11-09 23:09:44 +00:00
|
|
|
|
2005-10-30 18:58:22 +00:00
|
|
|
struct SWVoiceIn {
|
2009-05-13 23:11:35 +00:00
|
|
|
QEMUSoundCard *card;
|
2004-11-09 23:09:44 +00:00
|
|
|
int active;
|
2005-10-30 18:58:22 +00:00
|
|
|
struct audio_pcm_info info;
|
|
|
|
int64_t ratio;
|
|
|
|
void *rate;
|
|
|
|
int total_hw_samples_acquired;
|
2008-12-03 22:48:44 +00:00
|
|
|
struct st_sample *buf;
|
2005-10-30 18:58:22 +00:00
|
|
|
f_sample *clip;
|
|
|
|
HWVoiceIn *hw;
|
2004-11-09 23:09:44 +00:00
|
|
|
char *name;
|
2008-12-03 22:48:44 +00:00
|
|
|
struct mixeng_volume vol;
|
2005-10-30 18:58:22 +00:00
|
|
|
struct audio_callback callback;
|
2009-09-12 07:36:22 +00:00
|
|
|
QLIST_ENTRY (SWVoiceIn) entries;
|
2004-11-09 23:09:44 +00:00
|
|
|
};
|
|
|
|
|
2005-11-05 18:55:28 +00:00
|
|
|
struct audio_driver {
|
|
|
|
const char *name;
|
|
|
|
const char *descr;
|
|
|
|
struct audio_option *options;
|
|
|
|
void *(*init) (void);
|
|
|
|
void (*fini) (void *);
|
2008-10-06 18:08:30 +00:00
|
|
|
struct audio_pcm_ops *pcm_ops;
|
2005-11-05 18:55:28 +00:00
|
|
|
int can_be_default;
|
|
|
|
int max_voices_out;
|
|
|
|
int max_voices_in;
|
|
|
|
int voice_size_out;
|
|
|
|
int voice_size_in;
|
|
|
|
};
|
|
|
|
|
2005-10-30 18:58:22 +00:00
|
|
|
struct audio_pcm_ops {
|
2008-12-03 22:48:44 +00:00
|
|
|
int (*init_out)(HWVoiceOut *hw, struct audsettings *as);
|
2005-10-30 18:58:22 +00:00
|
|
|
void (*fini_out)(HWVoiceOut *hw);
|
2009-09-18 07:37:39 +00:00
|
|
|
int (*run_out) (HWVoiceOut *hw, int live);
|
2005-10-30 18:58:22 +00:00
|
|
|
int (*write) (SWVoiceOut *sw, void *buf, int size);
|
|
|
|
int (*ctl_out) (HWVoiceOut *hw, int cmd, ...);
|
|
|
|
|
2008-12-03 22:48:44 +00:00
|
|
|
int (*init_in) (HWVoiceIn *hw, struct audsettings *as);
|
2005-10-30 18:58:22 +00:00
|
|
|
void (*fini_in) (HWVoiceIn *hw);
|
|
|
|
int (*run_in) (HWVoiceIn *hw);
|
|
|
|
int (*read) (SWVoiceIn *sw, void *buf, int size);
|
|
|
|
int (*ctl_in) (HWVoiceIn *hw, int cmd, ...);
|
2004-11-09 23:09:44 +00:00
|
|
|
};
|
|
|
|
|
2006-07-04 16:51:32 +00:00
|
|
|
struct capture_callback {
|
|
|
|
struct audio_capture_ops ops;
|
|
|
|
void *opaque;
|
2009-09-12 07:36:22 +00:00
|
|
|
QLIST_ENTRY (capture_callback) entries;
|
2006-07-04 16:51:32 +00:00
|
|
|
};
|
|
|
|
|
2006-07-16 18:57:03 +00:00
|
|
|
struct CaptureVoiceOut {
|
2006-07-04 16:51:32 +00:00
|
|
|
HWVoiceOut hw;
|
|
|
|
void *buf;
|
2009-09-12 07:36:22 +00:00
|
|
|
QLIST_HEAD (cb_listhead, capture_callback) cb_head;
|
|
|
|
QLIST_ENTRY (CaptureVoiceOut) entries;
|
2006-07-16 18:57:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SWVoiceCap {
|
|
|
|
SWVoiceOut sw;
|
|
|
|
CaptureVoiceOut *cap;
|
2009-09-12 07:36:22 +00:00
|
|
|
QLIST_ENTRY (SWVoiceCap) entries;
|
2006-07-16 18:57:03 +00:00
|
|
|
};
|
2006-07-04 16:51:32 +00:00
|
|
|
|
2005-11-05 18:55:28 +00:00
|
|
|
struct AudioState {
|
|
|
|
struct audio_driver *drv;
|
|
|
|
void *drv_opaque;
|
|
|
|
|
|
|
|
QEMUTimer *ts;
|
2009-09-12 07:36:22 +00:00
|
|
|
QLIST_HEAD (card_listhead, QEMUSoundCard) card_head;
|
|
|
|
QLIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in;
|
|
|
|
QLIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out;
|
|
|
|
QLIST_HEAD (cap_listhead, CaptureVoiceOut) cap_head;
|
2005-11-05 18:55:28 +00:00
|
|
|
int nb_hw_voices_out;
|
|
|
|
int nb_hw_voices_in;
|
2009-02-18 20:44:04 +00:00
|
|
|
int vm_running;
|
2005-11-05 18:55:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct audio_driver no_audio_driver;
|
|
|
|
extern struct audio_driver oss_audio_driver;
|
|
|
|
extern struct audio_driver sdl_audio_driver;
|
|
|
|
extern struct audio_driver wav_audio_driver;
|
|
|
|
extern struct audio_driver fmod_audio_driver;
|
|
|
|
extern struct audio_driver alsa_audio_driver;
|
|
|
|
extern struct audio_driver coreaudio_audio_driver;
|
|
|
|
extern struct audio_driver dsound_audio_driver;
|
2008-01-14 04:24:29 +00:00
|
|
|
extern struct audio_driver esd_audio_driver;
|
2008-07-02 21:03:08 +00:00
|
|
|
extern struct audio_driver pa_audio_driver;
|
2009-10-09 21:13:41 +00:00
|
|
|
extern struct audio_driver winwave_audio_driver;
|
2008-12-03 22:48:44 +00:00
|
|
|
extern struct mixeng_volume nominal_volume;
|
2005-11-05 18:55:28 +00:00
|
|
|
|
2008-12-03 22:48:44 +00:00
|
|
|
void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as);
|
2005-10-30 18:58:22 +00:00
|
|
|
void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
|
|
|
|
|
|
|
|
int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
|
|
|
|
int audio_pcm_hw_get_live_in (HWVoiceIn *hw);
|
|
|
|
|
|
|
|
int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
|
2004-11-09 23:09:44 +00:00
|
|
|
|
2009-09-18 06:59:38 +00:00
|
|
|
int audio_pcm_hw_clip_out (HWVoiceOut *hw, void *pcm_buf,
|
|
|
|
int live, int pending);
|
|
|
|
|
2005-11-05 18:55:28 +00:00
|
|
|
int audio_bug (const char *funcname, int cond);
|
|
|
|
void *audio_calloc (const char *funcname, int nmemb, size_t size);
|
|
|
|
|
2009-09-11 22:28:45 +00:00
|
|
|
void audio_run (const char *msg);
|
|
|
|
|
2004-11-09 23:09:44 +00:00
|
|
|
#define VOICE_ENABLE 1
|
|
|
|
#define VOICE_DISABLE 2
|
|
|
|
|
2005-10-30 18:58:22 +00:00
|
|
|
static inline int audio_ring_dist (int dst, int src, int len)
|
|
|
|
{
|
|
|
|
return (dst >= src) ? (dst - src) : (len - src + dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined __GNUC__
|
|
|
|
#define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2)))
|
2005-11-11 00:06:10 +00:00
|
|
|
#define GCC_FMT_ATTR(n, m) __attribute__ ((__format__ (__printf__, n, m)))
|
2005-10-30 18:58:22 +00:00
|
|
|
#else
|
|
|
|
#define GCC_ATTR /**/
|
|
|
|
#define GCC_FMT_ATTR(n, m)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void GCC_ATTR dolog (const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
|
|
|
AUD_vlog (AUDIO_CAP, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
static void GCC_ATTR ldebug (const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
|
|
|
AUD_vlog (AUDIO_CAP, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#if defined NDEBUG && defined __GNUC__
|
|
|
|
#define ldebug(...)
|
|
|
|
#elif defined NDEBUG && defined _MSC_VER
|
|
|
|
#define ldebug __noop
|
|
|
|
#else
|
|
|
|
static void GCC_ATTR ldebug (const char *fmt, ...)
|
|
|
|
{
|
|
|
|
(void) fmt;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#undef GCC_ATTR
|
|
|
|
|
|
|
|
#define AUDIO_STRINGIFY_(n) #n
|
|
|
|
#define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
|
|
|
|
|
|
|
|
#if defined _MSC_VER || defined __GNUC__
|
|
|
|
#define AUDIO_FUNC __FUNCTION__
|
|
|
|
#else
|
|
|
|
#define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__)
|
|
|
|
#endif
|
|
|
|
|
2004-11-09 23:09:44 +00:00
|
|
|
#endif /* audio_int.h */
|