]>
Commit | Line | Data |
---|---|---|
85571bc7 FB |
1 | /* |
2 | * QEMU Audio subsystem header | |
1d14ffa9 FB |
3 | * |
4 | * Copyright (c) 2003-2005 Vassili Karpov (malc) | |
5 | * | |
85571bc7 FB |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | * THE SOFTWARE. | |
23 | */ | |
175de524 | 24 | |
85571bc7 FB |
25 | #ifndef QEMU_AUDIO_H |
26 | #define QEMU_AUDIO_H | |
27 | ||
1de7afc9 | 28 | #include "qemu/queue.h" |
85bc5852 | 29 | #include "qapi/qapi-types-audio.h" |
88e47b9a | 30 | #include "hw/qdev-properties.h" |
c0fe3827 | 31 | |
cb4f03e8 | 32 | typedef void (*audio_callback_fn) (void *opaque, int avail); |
85571bc7 | 33 | |
e2542fe2 | 34 | #ifdef HOST_WORDS_BIGENDIAN |
d929eba5 FB |
35 | #define AUDIO_HOST_ENDIANNESS 1 |
36 | #else | |
37 | #define AUDIO_HOST_ENDIANNESS 0 | |
38 | #endif | |
39 | ||
71830221 | 40 | typedef struct audsettings { |
c0fe3827 FB |
41 | int freq; |
42 | int nchannels; | |
85bc5852 | 43 | AudioFormat fmt; |
d929eba5 | 44 | int endianness; |
71830221 KZ |
45 | } audsettings; |
46 | ||
47 | audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo); | |
48 | int audioformat_bytes_per_sample(AudioFormat fmt); | |
49 | int audio_buffer_frames(AudiodevPerDirectionOptions *pdo, | |
50 | audsettings *as, int def_usecs); | |
51 | int audio_buffer_samples(AudiodevPerDirectionOptions *pdo, | |
52 | audsettings *as, int def_usecs); | |
53 | int audio_buffer_bytes(AudiodevPerDirectionOptions *pdo, | |
54 | audsettings *as, int def_usecs); | |
c0fe3827 | 55 | |
ec36b695 FB |
56 | typedef enum { |
57 | AUD_CNOTIFY_ENABLE, | |
58 | AUD_CNOTIFY_DISABLE | |
59 | } audcnotification_e; | |
60 | ||
8ead62cf | 61 | struct audio_capture_ops { |
ec36b695 | 62 | void (*notify) (void *opaque, audcnotification_e cmd); |
8ead62cf | 63 | void (*capture) (void *opaque, void *buf, int size); |
ec36b695 | 64 | void (*destroy) (void *opaque); |
8ead62cf FB |
65 | }; |
66 | ||
ec36b695 FB |
67 | struct capture_ops { |
68 | void (*info) (void *opaque); | |
69 | void (*destroy) (void *opaque); | |
70 | }; | |
71 | ||
72 | typedef struct CaptureState { | |
73 | void *opaque; | |
74 | struct capture_ops ops; | |
72cf2d4f | 75 | QLIST_ENTRY (CaptureState) entries; |
ec36b695 FB |
76 | } CaptureState; |
77 | ||
1d14ffa9 | 78 | typedef struct SWVoiceOut SWVoiceOut; |
ec36b695 | 79 | typedef struct CaptureVoiceOut CaptureVoiceOut; |
1d14ffa9 FB |
80 | typedef struct SWVoiceIn SWVoiceIn; |
81 | ||
ecd97e95 | 82 | typedef struct AudioState AudioState; |
c0fe3827 | 83 | typedef struct QEMUSoundCard { |
c0fe3827 | 84 | char *name; |
ecd97e95 | 85 | AudioState *state; |
72cf2d4f | 86 | QLIST_ENTRY (QEMUSoundCard) entries; |
c0fe3827 FB |
87 | } QEMUSoundCard; |
88 | ||
1d14ffa9 FB |
89 | typedef struct QEMUAudioTimeStamp { |
90 | uint64_t old_ts; | |
91 | } QEMUAudioTimeStamp; | |
92 | ||
8b7968f7 | 93 | void AUD_vlog (const char *cap, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0); |
e5924d89 | 94 | void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3); |
85571bc7 | 95 | |
1a7dafce | 96 | void AUD_register_card (const char *name, QEMUSoundCard *card); |
c0fe3827 | 97 | void AUD_remove_card (QEMUSoundCard *card); |
ecd97e95 KZ |
98 | CaptureVoiceOut *AUD_add_capture( |
99 | AudioState *s, | |
1ea879e5 | 100 | struct audsettings *as, |
8ead62cf FB |
101 | struct audio_capture_ops *ops, |
102 | void *opaque | |
103 | ); | |
ec36b695 | 104 | void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque); |
1d14ffa9 | 105 | |
c0fe3827 FB |
106 | SWVoiceOut *AUD_open_out ( |
107 | QEMUSoundCard *card, | |
1d14ffa9 FB |
108 | SWVoiceOut *sw, |
109 | const char *name, | |
110 | void *callback_opaque, | |
cb4f03e8 | 111 | audio_callback_fn callback_fn, |
1ea879e5 | 112 | struct audsettings *settings |
1d14ffa9 | 113 | ); |
c0fe3827 FB |
114 | |
115 | void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw); | |
7520462b | 116 | size_t AUD_write (SWVoiceOut *sw, void *pcm_buf, size_t size); |
c0fe3827 FB |
117 | int AUD_get_buffer_size_out (SWVoiceOut *sw); |
118 | void AUD_set_active_out (SWVoiceOut *sw, int on); | |
119 | int AUD_is_active_out (SWVoiceOut *sw); | |
120 | ||
121 | void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); | |
122 | uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); | |
123 | ||
683efdcb AZ |
124 | void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol); |
125 | void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol); | |
126 | ||
cecc1e79 KZ |
127 | #define AUDIO_MAX_CHANNELS 16 |
128 | typedef struct Volume { | |
129 | bool mute; | |
130 | int channels; | |
131 | uint8_t vol[AUDIO_MAX_CHANNELS]; | |
132 | } Volume; | |
133 | ||
134 | void audio_set_volume_out(SWVoiceOut *sw, Volume *vol); | |
135 | void audio_set_volume_in(SWVoiceIn *sw, Volume *vol); | |
136 | ||
c0fe3827 FB |
137 | SWVoiceIn *AUD_open_in ( |
138 | QEMUSoundCard *card, | |
1d14ffa9 FB |
139 | SWVoiceIn *sw, |
140 | const char *name, | |
141 | void *callback_opaque, | |
cb4f03e8 | 142 | audio_callback_fn callback_fn, |
1ea879e5 | 143 | struct audsettings *settings |
1d14ffa9 | 144 | ); |
c0fe3827 FB |
145 | |
146 | void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw); | |
7520462b | 147 | size_t AUD_read (SWVoiceIn *sw, void *pcm_buf, size_t size); |
c0fe3827 FB |
148 | void AUD_set_active_in (SWVoiceIn *sw, int on); |
149 | int AUD_is_active_in (SWVoiceIn *sw); | |
150 | ||
151 | void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); | |
152 | uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); | |
85571bc7 FB |
153 | |
154 | static inline void *advance (void *p, int incr) | |
155 | { | |
156 | uint8_t *d = p; | |
157 | return (d + incr); | |
158 | } | |
159 | ||
ecd97e95 KZ |
160 | int wav_start_capture(AudioState *state, CaptureState *s, const char *path, |
161 | int freq, int bits, int nchannels); | |
295e390f | 162 | |
a384c205 MAL |
163 | bool audio_is_cleaning_up(void); |
164 | void audio_cleanup(void); | |
165 | ||
3d4d16f4 PD |
166 | void audio_sample_to_uint64(void *samples, int pos, |
167 | uint64_t *left, uint64_t *right); | |
168 | void audio_sample_from_uint64(void *samples, int pos, | |
169 | uint64_t left, uint64_t right); | |
170 | ||
71830221 KZ |
171 | void audio_parse_option(const char *opt); |
172 | void audio_init_audiodevs(void); | |
173 | void audio_legacy_help(void); | |
174 | ||
ecd97e95 KZ |
175 | AudioState *audio_state_by_name(const char *name); |
176 | const char *audio_get_id(QEMUSoundCard *card); | |
177 | ||
88e47b9a KZ |
178 | #define DEFINE_AUDIO_PROPERTIES(_s, _f) \ |
179 | DEFINE_PROP_AUDIODEV("audiodev", _s, _f) | |
180 | ||
175de524 | 181 | #endif /* QEMU_AUDIO_H */ |