]>
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 | */ | |
24 | #ifndef QEMU_AUDIO_H | |
25 | #define QEMU_AUDIO_H | |
26 | ||
d929eba5 | 27 | #include "config.h" |
c0fe3827 FB |
28 | #include "sys-queue.h" |
29 | ||
1d14ffa9 | 30 | typedef void (*audio_callback_fn_t) (void *opaque, int avail); |
85571bc7 | 31 | |
85571bc7 | 32 | typedef enum { |
c0fe3827 FB |
33 | AUD_FMT_U8, |
34 | AUD_FMT_S8, | |
35 | AUD_FMT_U16, | |
36 | AUD_FMT_S16 | |
85571bc7 FB |
37 | } audfmt_e; |
38 | ||
d929eba5 FB |
39 | #ifdef WORDS_BIGENDIAN |
40 | #define AUDIO_HOST_ENDIANNESS 1 | |
41 | #else | |
42 | #define AUDIO_HOST_ENDIANNESS 0 | |
43 | #endif | |
44 | ||
c0fe3827 FB |
45 | typedef struct { |
46 | int freq; | |
47 | int nchannels; | |
48 | audfmt_e fmt; | |
d929eba5 | 49 | int endianness; |
c0fe3827 FB |
50 | } audsettings_t; |
51 | ||
ec36b695 FB |
52 | typedef enum { |
53 | AUD_CNOTIFY_ENABLE, | |
54 | AUD_CNOTIFY_DISABLE | |
55 | } audcnotification_e; | |
56 | ||
8ead62cf | 57 | struct audio_capture_ops { |
ec36b695 | 58 | void (*notify) (void *opaque, audcnotification_e cmd); |
8ead62cf | 59 | void (*capture) (void *opaque, void *buf, int size); |
ec36b695 | 60 | void (*destroy) (void *opaque); |
8ead62cf FB |
61 | }; |
62 | ||
ec36b695 FB |
63 | struct capture_ops { |
64 | void (*info) (void *opaque); | |
65 | void (*destroy) (void *opaque); | |
66 | }; | |
67 | ||
68 | typedef struct CaptureState { | |
69 | void *opaque; | |
70 | struct capture_ops ops; | |
71 | LIST_ENTRY (CaptureState) entries; | |
72 | } CaptureState; | |
73 | ||
c0fe3827 | 74 | typedef struct AudioState AudioState; |
1d14ffa9 | 75 | typedef struct SWVoiceOut SWVoiceOut; |
ec36b695 | 76 | typedef struct CaptureVoiceOut CaptureVoiceOut; |
1d14ffa9 FB |
77 | typedef struct SWVoiceIn SWVoiceIn; |
78 | ||
c0fe3827 FB |
79 | typedef struct QEMUSoundCard { |
80 | AudioState *audio; | |
81 | char *name; | |
82 | LIST_ENTRY (QEMUSoundCard) entries; | |
83 | } QEMUSoundCard; | |
84 | ||
1d14ffa9 FB |
85 | typedef struct QEMUAudioTimeStamp { |
86 | uint64_t old_ts; | |
87 | } QEMUAudioTimeStamp; | |
88 | ||
89 | void AUD_vlog (const char *cap, const char *fmt, va_list ap); | |
90 | void AUD_log (const char *cap, const char *fmt, ...) | |
91 | #ifdef __GNUC__ | |
92 | __attribute__ ((__format__ (__printf__, 2, 3))) | |
93 | #endif | |
94 | ; | |
85571bc7 | 95 | |
c0fe3827 | 96 | AudioState *AUD_init (void); |
1d14ffa9 | 97 | void AUD_help (void); |
c0fe3827 FB |
98 | void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card); |
99 | void AUD_remove_card (QEMUSoundCard *card); | |
ec36b695 | 100 | CaptureVoiceOut *AUD_add_capture ( |
8ead62cf FB |
101 | AudioState *s, |
102 | audsettings_t *as, | |
8ead62cf FB |
103 | struct audio_capture_ops *ops, |
104 | void *opaque | |
105 | ); | |
ec36b695 | 106 | void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque); |
1d14ffa9 | 107 | |
c0fe3827 FB |
108 | SWVoiceOut *AUD_open_out ( |
109 | QEMUSoundCard *card, | |
1d14ffa9 FB |
110 | SWVoiceOut *sw, |
111 | const char *name, | |
112 | void *callback_opaque, | |
113 | audio_callback_fn_t callback_fn, | |
d929eba5 | 114 | audsettings_t *settings |
1d14ffa9 | 115 | ); |
c0fe3827 FB |
116 | |
117 | void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw); | |
118 | int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size); | |
119 | int AUD_get_buffer_size_out (SWVoiceOut *sw); | |
120 | void AUD_set_active_out (SWVoiceOut *sw, int on); | |
121 | int AUD_is_active_out (SWVoiceOut *sw); | |
122 | ||
123 | void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); | |
124 | uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); | |
125 | ||
126 | SWVoiceIn *AUD_open_in ( | |
127 | QEMUSoundCard *card, | |
1d14ffa9 FB |
128 | SWVoiceIn *sw, |
129 | const char *name, | |
130 | void *callback_opaque, | |
131 | audio_callback_fn_t callback_fn, | |
d929eba5 | 132 | audsettings_t *settings |
1d14ffa9 | 133 | ); |
c0fe3827 FB |
134 | |
135 | void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw); | |
136 | int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size); | |
137 | void AUD_set_active_in (SWVoiceIn *sw, int on); | |
138 | int AUD_is_active_in (SWVoiceIn *sw); | |
139 | ||
140 | void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); | |
141 | uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); | |
85571bc7 FB |
142 | |
143 | static inline void *advance (void *p, int incr) | |
144 | { | |
145 | uint8_t *d = p; | |
146 | return (d + incr); | |
147 | } | |
148 | ||
149 | uint32_t popcount (uint32_t u); | |
8ead62cf | 150 | uint32_t lsbindex (uint32_t u); |
85571bc7 | 151 | |
1d14ffa9 FB |
152 | #ifdef __GNUC__ |
153 | #define audio_MIN(a, b) ( __extension__ ({ \ | |
154 | __typeof (a) ta = a; \ | |
155 | __typeof (b) tb = b; \ | |
156 | ((ta)>(tb)?(tb):(ta)); \ | |
157 | })) | |
158 | ||
159 | #define audio_MAX(a, b) ( __extension__ ({ \ | |
160 | __typeof (a) ta = a; \ | |
161 | __typeof (b) tb = b; \ | |
162 | ((ta)<(tb)?(tb):(ta)); \ | |
163 | })) | |
164 | #else | |
85571bc7 FB |
165 | #define audio_MIN(a, b) ((a)>(b)?(b):(a)) |
166 | #define audio_MAX(a, b) ((a)<(b)?(b):(a)) | |
1d14ffa9 | 167 | #endif |
85571bc7 FB |
168 | |
169 | #endif /* audio.h */ |