]>
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" |
ce35e229 | 31 | #include "hw/qdev-properties-system.h" |
c0fe3827 | 32 | |
cb4f03e8 | 33 | typedef void (*audio_callback_fn) (void *opaque, int avail); |
85571bc7 | 34 | |
e03b5686 | 35 | #if HOST_BIG_ENDIAN |
d929eba5 FB |
36 | #define AUDIO_HOST_ENDIANNESS 1 |
37 | #else | |
38 | #define AUDIO_HOST_ENDIANNESS 0 | |
39 | #endif | |
40 | ||
71830221 | 41 | typedef struct audsettings { |
c0fe3827 FB |
42 | int freq; |
43 | int nchannels; | |
85bc5852 | 44 | AudioFormat fmt; |
d929eba5 | 45 | int endianness; |
71830221 KZ |
46 | } audsettings; |
47 | ||
48 | audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo); | |
49 | int audioformat_bytes_per_sample(AudioFormat fmt); | |
50 | int audio_buffer_frames(AudiodevPerDirectionOptions *pdo, | |
51 | audsettings *as, int def_usecs); | |
52 | int audio_buffer_samples(AudiodevPerDirectionOptions *pdo, | |
53 | audsettings *as, int def_usecs); | |
54 | int audio_buffer_bytes(AudiodevPerDirectionOptions *pdo, | |
55 | audsettings *as, int def_usecs); | |
c0fe3827 | 56 | |
ec36b695 FB |
57 | typedef enum { |
58 | AUD_CNOTIFY_ENABLE, | |
59 | AUD_CNOTIFY_DISABLE | |
60 | } audcnotification_e; | |
61 | ||
8ead62cf | 62 | struct audio_capture_ops { |
ec36b695 | 63 | void (*notify) (void *opaque, audcnotification_e cmd); |
57a878ed | 64 | void (*capture) (void *opaque, const void *buf, int size); |
ec36b695 | 65 | void (*destroy) (void *opaque); |
8ead62cf FB |
66 | }; |
67 | ||
ec36b695 FB |
68 | struct capture_ops { |
69 | void (*info) (void *opaque); | |
70 | void (*destroy) (void *opaque); | |
71 | }; | |
72 | ||
73 | typedef struct CaptureState { | |
74 | void *opaque; | |
75 | struct capture_ops ops; | |
72cf2d4f | 76 | QLIST_ENTRY (CaptureState) entries; |
ec36b695 FB |
77 | } CaptureState; |
78 | ||
1d14ffa9 | 79 | typedef struct SWVoiceOut SWVoiceOut; |
ec36b695 | 80 | typedef struct CaptureVoiceOut CaptureVoiceOut; |
1d14ffa9 FB |
81 | typedef struct SWVoiceIn SWVoiceIn; |
82 | ||
ecd97e95 | 83 | typedef struct AudioState AudioState; |
c0fe3827 | 84 | typedef struct QEMUSoundCard { |
c0fe3827 | 85 | char *name; |
ecd97e95 | 86 | AudioState *state; |
72cf2d4f | 87 | QLIST_ENTRY (QEMUSoundCard) entries; |
c0fe3827 FB |
88 | } QEMUSoundCard; |
89 | ||
1d14ffa9 FB |
90 | typedef struct QEMUAudioTimeStamp { |
91 | uint64_t old_ts; | |
92 | } QEMUAudioTimeStamp; | |
93 | ||
9edc6313 MAL |
94 | void AUD_vlog (const char *cap, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0); |
95 | void AUD_log (const char *cap, const char *fmt, ...) G_GNUC_PRINTF(2, 3); | |
85571bc7 | 96 | |
1a7dafce | 97 | void AUD_register_card (const char *name, QEMUSoundCard *card); |
c0fe3827 | 98 | void AUD_remove_card (QEMUSoundCard *card); |
ecd97e95 KZ |
99 | CaptureVoiceOut *AUD_add_capture( |
100 | AudioState *s, | |
1ea879e5 | 101 | struct audsettings *as, |
8ead62cf FB |
102 | struct audio_capture_ops *ops, |
103 | void *opaque | |
104 | ); | |
ec36b695 | 105 | void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque); |
1d14ffa9 | 106 | |
c0fe3827 FB |
107 | SWVoiceOut *AUD_open_out ( |
108 | QEMUSoundCard *card, | |
1d14ffa9 FB |
109 | SWVoiceOut *sw, |
110 | const char *name, | |
111 | void *callback_opaque, | |
cb4f03e8 | 112 | audio_callback_fn callback_fn, |
1ea879e5 | 113 | struct audsettings *settings |
1d14ffa9 | 114 | ); |
c0fe3827 FB |
115 | |
116 | void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw); | |
7520462b | 117 | size_t AUD_write (SWVoiceOut *sw, void *pcm_buf, size_t size); |
c0fe3827 FB |
118 | int AUD_get_buffer_size_out (SWVoiceOut *sw); |
119 | void AUD_set_active_out (SWVoiceOut *sw, int on); | |
120 | int AUD_is_active_out (SWVoiceOut *sw); | |
121 | ||
122 | void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); | |
123 | uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); | |
124 | ||
683efdcb AZ |
125 | void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol); |
126 | void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol); | |
127 | ||
cecc1e79 KZ |
128 | #define AUDIO_MAX_CHANNELS 16 |
129 | typedef struct Volume { | |
130 | bool mute; | |
131 | int channels; | |
132 | uint8_t vol[AUDIO_MAX_CHANNELS]; | |
133 | } Volume; | |
134 | ||
135 | void audio_set_volume_out(SWVoiceOut *sw, Volume *vol); | |
136 | void audio_set_volume_in(SWVoiceIn *sw, Volume *vol); | |
137 | ||
c0fe3827 FB |
138 | SWVoiceIn *AUD_open_in ( |
139 | QEMUSoundCard *card, | |
1d14ffa9 FB |
140 | SWVoiceIn *sw, |
141 | const char *name, | |
142 | void *callback_opaque, | |
cb4f03e8 | 143 | audio_callback_fn callback_fn, |
1ea879e5 | 144 | struct audsettings *settings |
1d14ffa9 | 145 | ); |
c0fe3827 FB |
146 | |
147 | void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw); | |
7520462b | 148 | size_t AUD_read (SWVoiceIn *sw, void *pcm_buf, size_t size); |
c0fe3827 FB |
149 | void AUD_set_active_in (SWVoiceIn *sw, int on); |
150 | int AUD_is_active_in (SWVoiceIn *sw); | |
151 | ||
152 | void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); | |
153 | uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); | |
85571bc7 FB |
154 | |
155 | static inline void *advance (void *p, int incr) | |
156 | { | |
157 | uint8_t *d = p; | |
158 | return (d + incr); | |
159 | } | |
160 | ||
ecd97e95 KZ |
161 | int wav_start_capture(AudioState *state, CaptureState *s, const char *path, |
162 | int freq, int bits, int nchannels); | |
295e390f | 163 | |
a384c205 MAL |
164 | void audio_cleanup(void); |
165 | ||
e709d2ac | 166 | void audio_sample_to_uint64(const void *samples, int pos, |
3d4d16f4 PD |
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 | ||
039a6837 | 171 | void audio_define(Audiodev *audio); |
71830221 | 172 | void audio_parse_option(const char *opt); |
0f957c53 | 173 | bool audio_init_audiodevs(void); |
5e03b6da | 174 | void audio_help(void); |
71830221 KZ |
175 | void audio_legacy_help(void); |
176 | ||
ecd97e95 KZ |
177 | AudioState *audio_state_by_name(const char *name); |
178 | const char *audio_get_id(QEMUSoundCard *card); | |
179 | ||
88e47b9a KZ |
180 | #define DEFINE_AUDIO_PROPERTIES(_s, _f) \ |
181 | DEFINE_PROP_AUDIODEV("audiodev", _s, _f) | |
182 | ||
175de524 | 183 | #endif /* QEMU_AUDIO_H */ |