Revision 1d14ffa9 audio/audio_int.h

b/audio/audio_int.h
1 1
/*
2 2
 * QEMU Audio subsystem header
3
 * 
4
 * Copyright (c) 2003-2004 Vassili Karpov (malc)
5
 * 
3
 *
4
 * Copyright (c) 2003-2005 Vassili Karpov (malc)
5
 *
6 6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 7
 * of this software and associated documentation files (the "Software"), to deal
8 8
 * in the Software without restriction, including without limitation the rights
......
24 24
#ifndef QEMU_AUDIO_INT_H
25 25
#define QEMU_AUDIO_INT_H
26 26

  
27
#include "vl.h"
27
#include "sys-queue.h"
28

  
29
#ifdef CONFIG_COREAUDIO
30
#define FLOAT_MIXENG
31
/* #define RECIPROCAL */
32
#endif
33
#include "mixeng.h"
34

  
35
int audio_bug (const char *funcname, int cond);
36

  
37
struct audio_pcm_ops;
38

  
39
typedef enum {
40
    AUD_OPT_INT,
41
    AUD_OPT_FMT,
42
    AUD_OPT_STR,
43
    AUD_OPT_BOOL
44
} audio_option_tag_e;
45

  
46
struct audio_option {
47
    const char *name;
48
    audio_option_tag_e tag;
49
    void *valp;
50
    const char *descr;
51
    int *overridenp;
52
    int overriden;
53
};
54

  
55
struct audio_callback {
56
    void *opaque;
57
    audio_callback_fn_t fn;
58
};
28 59

  
29
struct pcm_ops;
60
struct audio_pcm_info {
61
    int bits;
62
    int sign;
63
    int freq;
64
    int nchannels;
65
    int align;
66
    int shift;
67
    int bytes_per_second;
68
    int swap_endian;
69
};
30 70

  
31
typedef struct HWVoice {
71
typedef struct HWVoiceOut {
32 72
    int active;
33 73
    int enabled;
34 74
    int pending_disable;
35 75
    int valid;
36
    int freq;
76
    struct audio_pcm_info info;
37 77

  
38 78
    f_sample *clip;
39
    audfmt_e fmt;
40
    int nchannels;
41

  
42
    int align;
43
    int shift;
44 79

  
45 80
    int rpos;
46 81
    int bufsize;
82
    uint64_t ts_helper;
47 83

  
48
    int bytes_per_second;
49 84
    st_sample_t *mix_buf;
50 85

  
51 86
    int samples;
52
    int64_t old_ticks;
53
    int nb_voices;
54
    struct SWVoice **pvoice;
55
    struct pcm_ops *pcm_ops;
56
} HWVoice;
87
    LIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
88
    struct audio_pcm_ops *pcm_ops;
89
    LIST_ENTRY (HWVoiceOut) entries;
90
} HWVoiceOut;
57 91

  
58
extern struct pcm_ops no_pcm_ops;
59
extern struct audio_output_driver no_output_driver;
92
typedef struct HWVoiceIn {
93
    int enabled;
94
    int active;
95
    struct audio_pcm_info info;
96

  
97
    t_sample *conv;
60 98

  
61
extern struct pcm_ops oss_pcm_ops;
62
extern struct audio_output_driver oss_output_driver;
99
    int wpos;
100
    int bufsize;
101
    int total_samples_captured;
102
    uint64_t ts_helper;
63 103

  
64
extern struct pcm_ops sdl_pcm_ops;
65
extern struct audio_output_driver sdl_output_driver;
104
    st_sample_t *conv_buf;
66 105

  
67
extern struct pcm_ops wav_pcm_ops;
68
extern struct audio_output_driver wav_output_driver;
106
    int samples;
107
    LIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
108
    struct audio_pcm_ops *pcm_ops;
109
    LIST_ENTRY (HWVoiceIn) entries;
110
} HWVoiceIn;
69 111

  
70
extern struct pcm_ops fmod_pcm_ops;
71
extern struct audio_output_driver fmod_output_driver;
112
extern struct audio_driver no_audio_driver;
113
extern struct audio_driver oss_audio_driver;
114
extern struct audio_driver sdl_audio_driver;
115
extern struct audio_driver wav_audio_driver;
116
extern struct audio_driver fmod_audio_driver;
117
extern struct audio_driver alsa_audio_driver;
118
extern struct audio_driver coreaudio_audio_driver;
119
extern struct audio_driver dsound_audio_driver;
120
extern volume_t nominal_volume;
72 121

  
73
struct audio_output_driver {
122
struct audio_driver {
74 123
    const char *name;
124
    const char *descr;
125
    struct audio_option *options;
75 126
    void *(*init) (void);
76 127
    void (*fini) (void *);
77
    struct pcm_ops *pcm_ops;
128
    struct audio_pcm_ops *pcm_ops;
78 129
    int can_be_default;
79
    int max_voices;
80
    int voice_size;
130
    int max_voices_out;
131
    int max_voices_in;
132
    int voice_size_out;
133
    int voice_size_in;
81 134
};
82 135

  
83 136
typedef struct AudioState {
84
    int fixed_format;
85
    int fixed_freq;
86
    int fixed_channels;
87
    int fixed_fmt;
88
    int nb_hw_voices;
89
    int64_t ticks_threshold;
90
    int freq_threshold;
137
    int fixed_settings_out;
138
    int fixed_freq_out;
139
    int fixed_channels_out;
140
    int fixed_fmt_out;
141
    int nb_hw_voices_out;
142
    int greedy_out;
143

  
144
    int fixed_settings_in;
145
    int fixed_freq_in;
146
    int fixed_channels_in;
147
    int fixed_fmt_in;
148
    int nb_hw_voices_in;
149
    int greedy_in;
150

  
91 151
    void *opaque;
92
    struct audio_output_driver *drv;
93
} AudioState;
94
extern AudioState audio_state;
152
    struct audio_driver *drv;
95 153

  
96
struct SWVoice {
97
    int freq;
98
    audfmt_e fmt;
99
    int nchannels;
154
    QEMUTimer *ts;
155
    union {
156
        int usec;
157
        int64_t ticks;
158
    } period;
100 159

  
101
    int shift;
102
    int align;
160
    int plive;
161
} AudioState;
162
extern AudioState audio_state;
103 163

  
164
struct SWVoiceOut {
165
    struct audio_pcm_info info;
104 166
    t_sample *conv;
105

  
106
    int left;
107
    int pos;
108
    int bytes_per_second;
109 167
    int64_t ratio;
110 168
    st_sample_t *buf;
111 169
    void *rate;
170
    int total_hw_samples_mixed;
171
    int active;
172
    int empty;
173
    HWVoiceOut *hw;
174
    char *name;
175
    volume_t vol;
176
    struct audio_callback callback;
177
    LIST_ENTRY (SWVoiceOut) entries;
178
};
112 179

  
113
    int wpos;
114
    int live;
180
struct SWVoiceIn {
115 181
    int active;
116
    int64_t old_ticks;
117
    HWVoice *hw;
182
    struct audio_pcm_info info;
183
    int64_t ratio;
184
    void *rate;
185
    int total_hw_samples_acquired;
186
    st_sample_t *conv_buf;
187
    f_sample *clip;
188
    HWVoiceIn *hw;
118 189
    char *name;
190
    volume_t vol;
191
    struct audio_callback callback;
192
    LIST_ENTRY (SWVoiceIn) entries;
119 193
};
120 194

  
121
struct pcm_ops {
122
    int  (*init)  (HWVoice *hw, int freq, int nchannels, audfmt_e fmt);
123
    void (*fini)  (HWVoice *hw);
124
    void (*run)   (HWVoice *hw);
125
    int  (*write) (SWVoice *sw, void *buf, int size);
126
    int  (*ctl)   (HWVoice *hw, int cmd, ...);
195
struct audio_pcm_ops {
196
    int  (*init_out)(HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt);
197
    void (*fini_out)(HWVoiceOut *hw);
198
    int  (*run_out) (HWVoiceOut *hw);
199
    int  (*write)   (SWVoiceOut *sw, void *buf, int size);
200
    int  (*ctl_out) (HWVoiceOut *hw, int cmd, ...);
201

  
202
    int  (*init_in) (HWVoiceIn *hw, int freq, int nchannels, audfmt_e fmt);
203
    void (*fini_in) (HWVoiceIn *hw);
204
    int  (*run_in)  (HWVoiceIn *hw);
205
    int  (*read)    (SWVoiceIn *sw, void *buf, int size);
206
    int  (*ctl_in)  (HWVoiceIn *hw, int cmd, ...);
127 207
};
128 208

  
129
void      pcm_sw_free_resources (SWVoice *sw);
130
int       pcm_sw_alloc_resources (SWVoice *sw);
131
void      pcm_sw_fini (SWVoice *sw);
132
int       pcm_sw_init (SWVoice *sw, HWVoice *hw, int freq,
133
                       int nchannels, audfmt_e fmt);
134

  
135
void      pcm_hw_clear (HWVoice *hw, void *buf, int len);
136
HWVoice * pcm_hw_find_any (HWVoice *hw);
137
HWVoice * pcm_hw_find_any_active (HWVoice *hw);
138
HWVoice * pcm_hw_find_any_passive (HWVoice *hw);
139
HWVoice * pcm_hw_find_specific (HWVoice *hw, int freq,
140
                                int nchannels, audfmt_e fmt);
141
HWVoice * pcm_hw_add (int freq, int nchannels, audfmt_e fmt);
142
int       pcm_hw_add_sw (HWVoice *hw, SWVoice *sw);
143
int       pcm_hw_del_sw (HWVoice *hw, SWVoice *sw);
144
SWVoice * pcm_create_voice_pair (int freq, int nchannels, audfmt_e fmt);
145

  
146
void      pcm_hw_free_resources (HWVoice *hw);
147
int       pcm_hw_alloc_resources (HWVoice *hw);
148
void      pcm_hw_fini (HWVoice *hw);
149
void      pcm_hw_gc (HWVoice *hw);
150
int       pcm_hw_get_live (HWVoice *hw);
151
int       pcm_hw_get_live2 (HWVoice *hw, int *nb_active);
152
void      pcm_hw_dec_live (HWVoice *hw, int decr);
153
int       pcm_hw_write (SWVoice *sw, void *buf, int len);
154

  
155
int         audio_get_conf_int (const char *key, int defval);
156
const char *audio_get_conf_str (const char *key, const char *defval);
157

  
158
struct audio_output_driver;
209
void audio_pcm_init_info (struct audio_pcm_info *info, int freq,
210
                          int nchannels, audfmt_e fmt, int swap_endian);
211
void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
212

  
213
int  audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
214
int  audio_pcm_hw_get_live_in (HWVoiceIn *hw);
215

  
216
int  audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
217
int  audio_pcm_hw_get_live_out (HWVoiceOut *hw);
218
int  audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live);
159 219

  
160 220
#define VOICE_ENABLE 1
161 221
#define VOICE_DISABLE 2
162 222

  
223
static inline int audio_ring_dist (int dst, int src, int len)
224
{
225
    return (dst >= src) ? (dst - src) : (len - src + dst);
226
}
227

  
228
static inline int audio_need_to_swap_endian (int endianness)
229
{
230
#ifdef WORDS_BIGENDIAN
231
    return endianness != 1;
232
#else
233
    return endianness != 0;
234
#endif
235
}
236

  
237
#if defined __GNUC__
238
#define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2)))
239
#define INIT_FIELD(f) . f
240
#define GCC_FMT_ATTR(n, m) __attribute__ ((__format__ (printf, n, m)))
241
#else
242
#define GCC_ATTR /**/
243
#define INIT_FIELD(f) /**/
244
#define GCC_FMT_ATTR(n, m)
245
#endif
246

  
247
static void GCC_ATTR dolog (const char *fmt, ...)
248
{
249
    va_list ap;
250

  
251
    va_start (ap, fmt);
252
    AUD_vlog (AUDIO_CAP, fmt, ap);
253
    va_end (ap);
254
}
255

  
256
#ifdef DEBUG
257
static void GCC_ATTR ldebug (const char *fmt, ...)
258
{
259
    va_list ap;
260

  
261
    va_start (ap, fmt);
262
    AUD_vlog (AUDIO_CAP, fmt, ap);
263
    va_end (ap);
264
}
265
#else
266
#if defined NDEBUG && defined __GNUC__
267
#define ldebug(...)
268
#elif defined NDEBUG && defined _MSC_VER
269
#define ldebug __noop
270
#else
271
static void GCC_ATTR ldebug (const char *fmt, ...)
272
{
273
    (void) fmt;
274
}
275
#endif
276
#endif
277

  
278
#undef GCC_ATTR
279

  
280
#define AUDIO_STRINGIFY_(n) #n
281
#define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
282

  
283
#if defined _MSC_VER || defined __GNUC__
284
#define AUDIO_FUNC __FUNCTION__
285
#else
286
#define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__)
287
#endif
288

  
163 289
#endif /* audio_int.h */

Also available in: Unified diff