audio_int.h 7.15 KB
Newer Older
1 2
/*
 * QEMU Audio subsystem header
3 4 5
 *
 * Copyright (c) 2003-2005 Vassili Karpov (malc)
 *
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 * 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

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#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;
ths's avatar
ths committed
47 48
    int *overriddenp;
    int overridden;
49 50 51 52
};

struct audio_callback {
    void *opaque;
malc's avatar
malc committed
53
    audio_callback_fn fn;
54
};
55

56 57 58 59 60 61 62 63
struct audio_pcm_info {
    int bits;
    int sign;
    int freq;
    int nchannels;
    int align;
    int shift;
    int bytes_per_second;
64
    int swap_endianness;
65
};
66

bellard's avatar
bellard committed
67 68
typedef struct SWVoiceCap SWVoiceCap;

69
typedef struct HWVoiceOut {
70
    int enabled;
malc's avatar
malc committed
71
    int poll_mode;
72
    int pending_disable;
73
    struct audio_pcm_info info;
74 75 76 77

    f_sample *clip;

    int rpos;
78
    uint64_t ts_helper;
79

malc's avatar
malc committed
80
    struct st_sample *mix_buf;
81 82

    int samples;
83 84
    QLIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
    QLIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head;
85
    int ctl_caps;
86
    struct audio_pcm_ops *pcm_ops;
87
    QLIST_ENTRY (HWVoiceOut) entries;
88
} HWVoiceOut;
89

90 91
typedef struct HWVoiceIn {
    int enabled;
malc's avatar
malc committed
92
    int poll_mode;
93 94 95
    struct audio_pcm_info info;

    t_sample *conv;
bellard's avatar
bellard committed
96

97 98 99
    int wpos;
    int total_samples_captured;
    uint64_t ts_helper;
100

malc's avatar
malc committed
101
    struct st_sample *conv_buf;
102

103
    int samples;
104
    QLIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
105
    int ctl_caps;
106
    struct audio_pcm_ops *pcm_ops;
107
    QLIST_ENTRY (HWVoiceIn) entries;
108
} HWVoiceIn;
109

110
struct SWVoiceOut {
111
    QEMUSoundCard *card;
112
    struct audio_pcm_info info;
113 114
    t_sample *conv;
    int64_t ratio;
malc's avatar
malc committed
115
    struct st_sample *buf;
116
    void *rate;
117 118 119 120 121
    int total_hw_samples_mixed;
    int active;
    int empty;
    HWVoiceOut *hw;
    char *name;
malc's avatar
malc committed
122
    struct mixeng_volume vol;
123
    struct audio_callback callback;
124
    QLIST_ENTRY (SWVoiceOut) entries;
125
};
126

127
struct SWVoiceIn {
128
    QEMUSoundCard *card;
129
    int active;
130 131 132 133
    struct audio_pcm_info info;
    int64_t ratio;
    void *rate;
    int total_hw_samples_acquired;
malc's avatar
malc committed
134
    struct st_sample *buf;
135 136
    f_sample *clip;
    HWVoiceIn *hw;
137
    char *name;
malc's avatar
malc committed
138
    struct mixeng_volume vol;
139
    struct audio_callback callback;
140
    QLIST_ENTRY (SWVoiceIn) entries;
141 142
};

bellard's avatar
bellard committed
143 144 145 146 147 148
struct audio_driver {
    const char *name;
    const char *descr;
    struct audio_option *options;
    void *(*init) (void);
    void (*fini) (void *);
149
    struct audio_pcm_ops *pcm_ops;
bellard's avatar
bellard committed
150 151 152 153 154
    int can_be_default;
    int max_voices_out;
    int max_voices_in;
    int voice_size_out;
    int voice_size_in;
155
    int ctl_caps;
bellard's avatar
bellard committed
156 157
};

158
struct audio_pcm_ops {
malc's avatar
malc committed
159
    int  (*init_out)(HWVoiceOut *hw, struct audsettings *as);
160
    void (*fini_out)(HWVoiceOut *hw);
malc's avatar
malc committed
161
    int  (*run_out) (HWVoiceOut *hw, int live);
162 163 164
    int  (*write)   (SWVoiceOut *sw, void *buf, int size);
    int  (*ctl_out) (HWVoiceOut *hw, int cmd, ...);

malc's avatar
malc committed
165
    int  (*init_in) (HWVoiceIn *hw, struct audsettings *as);
166 167 168 169
    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, ...);
170 171
};

172 173 174
struct capture_callback {
    struct audio_capture_ops ops;
    void *opaque;
175
    QLIST_ENTRY (capture_callback) entries;
176 177
};

bellard's avatar
bellard committed
178
struct CaptureVoiceOut {
179 180
    HWVoiceOut hw;
    void *buf;
181 182
    QLIST_HEAD (cb_listhead, capture_callback) cb_head;
    QLIST_ENTRY (CaptureVoiceOut) entries;
bellard's avatar
bellard committed
183 184 185 186 187
};

struct SWVoiceCap {
    SWVoiceOut sw;
    CaptureVoiceOut *cap;
188
    QLIST_ENTRY (SWVoiceCap) entries;
bellard's avatar
bellard committed
189
};
190

bellard's avatar
bellard committed
191 192 193 194 195
struct AudioState {
    struct audio_driver *drv;
    void *drv_opaque;

    QEMUTimer *ts;
196 197 198 199
    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;
bellard's avatar
bellard committed
200 201
    int nb_hw_voices_out;
    int nb_hw_voices_in;
202
    int vm_running;
bellard's avatar
bellard committed
203 204 205 206 207 208 209 210 211 212
};

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;
213
extern struct audio_driver esd_audio_driver;
malc's avatar
malc committed
214
extern struct audio_driver pa_audio_driver;
Gerd Hoffmann's avatar
Gerd Hoffmann committed
215
extern struct audio_driver spice_audio_driver;
216
extern struct audio_driver winwave_audio_driver;
217
extern const struct mixeng_volume nominal_volume;
bellard's avatar
bellard committed
218

malc's avatar
malc committed
219
void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as);
220 221 222 223 224 225
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);
226

227 228 229
int audio_pcm_hw_clip_out (HWVoiceOut *hw, void *pcm_buf,
                           int live, int pending);

bellard's avatar
bellard committed
230 231 232
int audio_bug (const char *funcname, int cond);
void *audio_calloc (const char *funcname, int nmemb, size_t size);

malc's avatar
malc committed
233 234
void audio_run (const char *msg);

235 236
#define VOICE_ENABLE 1
#define VOICE_DISABLE 2
237
#define VOICE_VOLUME 3
238

239 240
#define VOICE_VOLUME_CAP (1 << VOICE_VOLUME)

241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
static inline int audio_ring_dist (int dst, int src, int len)
{
    return (dst >= src) ? (dst - src) : (len - src + dst);
}

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

288
#endif /* audio_int.h */