1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#ifndef QEMU_AUDIO_H
26#define QEMU_AUDIO_H
27
28#include "qemu/queue.h"
29
30typedef void (*audio_callback_fn) (void *opaque, int avail);
31
32typedef enum {
33 AUD_FMT_U8,
34 AUD_FMT_S8,
35 AUD_FMT_U16,
36 AUD_FMT_S16,
37 AUD_FMT_U32,
38 AUD_FMT_S32
39} audfmt_e;
40
41#ifdef HOST_WORDS_BIGENDIAN
42#define AUDIO_HOST_ENDIANNESS 1
43#else
44#define AUDIO_HOST_ENDIANNESS 0
45#endif
46
47struct audsettings {
48 int freq;
49 int nchannels;
50 audfmt_e fmt;
51 int endianness;
52};
53
54typedef enum {
55 AUD_CNOTIFY_ENABLE,
56 AUD_CNOTIFY_DISABLE
57} audcnotification_e;
58
59struct audio_capture_ops {
60 void (*notify) (void *opaque, audcnotification_e cmd);
61 void (*capture) (void *opaque, void *buf, int size);
62 void (*destroy) (void *opaque);
63};
64
65struct capture_ops {
66 void (*info) (void *opaque);
67 void (*destroy) (void *opaque);
68};
69
70typedef struct CaptureState {
71 void *opaque;
72 struct capture_ops ops;
73 QLIST_ENTRY (CaptureState) entries;
74} CaptureState;
75
76typedef struct SWVoiceOut SWVoiceOut;
77typedef struct CaptureVoiceOut CaptureVoiceOut;
78typedef struct SWVoiceIn SWVoiceIn;
79
80typedef struct QEMUSoundCard {
81 char *name;
82 QLIST_ENTRY (QEMUSoundCard) entries;
83} QEMUSoundCard;
84
85typedef struct QEMUAudioTimeStamp {
86 uint64_t old_ts;
87} QEMUAudioTimeStamp;
88
89void AUD_vlog (const char *cap, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
90void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
91
92void AUD_help (void);
93void AUD_register_card (const char *name, QEMUSoundCard *card);
94void AUD_remove_card (QEMUSoundCard *card);
95CaptureVoiceOut *AUD_add_capture (
96 struct audsettings *as,
97 struct audio_capture_ops *ops,
98 void *opaque
99 );
100void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
101
102SWVoiceOut *AUD_open_out (
103 QEMUSoundCard *card,
104 SWVoiceOut *sw,
105 const char *name,
106 void *callback_opaque,
107 audio_callback_fn callback_fn,
108 struct audsettings *settings
109 );
110
111void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
112int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
113int AUD_get_buffer_size_out (SWVoiceOut *sw);
114void AUD_set_active_out (SWVoiceOut *sw, int on);
115int AUD_is_active_out (SWVoiceOut *sw);
116
117void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
118uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
119
120void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol);
121void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol);
122
123SWVoiceIn *AUD_open_in (
124 QEMUSoundCard *card,
125 SWVoiceIn *sw,
126 const char *name,
127 void *callback_opaque,
128 audio_callback_fn callback_fn,
129 struct audsettings *settings
130 );
131
132void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
133int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
134void AUD_set_active_in (SWVoiceIn *sw, int on);
135int AUD_is_active_in (SWVoiceIn *sw);
136
137void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
138uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
139
140static inline void *advance (void *p, int incr)
141{
142 uint8_t *d = p;
143 return (d + incr);
144}
145
146#ifdef __GNUC__
147#define audio_MIN(a, b) ( __extension__ ({ \
148 __typeof (a) ta = a; \
149 __typeof (b) tb = b; \
150 ((ta)>(tb)?(tb):(ta)); \
151}))
152
153#define audio_MAX(a, b) ( __extension__ ({ \
154 __typeof (a) ta = a; \
155 __typeof (b) tb = b; \
156 ((ta)<(tb)?(tb):(ta)); \
157}))
158#else
159#define audio_MIN(a, b) ((a)>(b)?(b):(a))
160#define audio_MAX(a, b) ((a)<(b)?(b):(a))
161#endif
162
163int wav_start_capture (CaptureState *s, const char *path, int freq,
164 int bits, int nchannels);
165
166bool audio_is_cleaning_up(void);
167void audio_cleanup(void);
168
169void audio_sample_to_uint64(void *samples, int pos,
170 uint64_t *left, uint64_t *right);
171void audio_sample_from_uint64(void *samples, int pos,
172 uint64_t left, uint64_t right);
173
174#endif
175