root / audio / audio.h @ e6bb7d7e
History | View | Annotate | Download (4.9 kB)
1 | 85571bc7 | bellard | /*
|
---|---|---|---|
2 | 85571bc7 | bellard | * QEMU Audio subsystem header
|
3 | 1d14ffa9 | bellard | *
|
4 | 1d14ffa9 | bellard | * Copyright (c) 2003-2005 Vassili Karpov (malc)
|
5 | 1d14ffa9 | bellard | *
|
6 | 85571bc7 | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 85571bc7 | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | 85571bc7 | bellard | * in the Software without restriction, including without limitation the rights
|
9 | 85571bc7 | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 85571bc7 | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | 85571bc7 | bellard | * furnished to do so, subject to the following conditions:
|
12 | 85571bc7 | bellard | *
|
13 | 85571bc7 | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | 85571bc7 | bellard | * all copies or substantial portions of the Software.
|
15 | 85571bc7 | bellard | *
|
16 | 85571bc7 | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 85571bc7 | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 85571bc7 | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 85571bc7 | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 85571bc7 | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 85571bc7 | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 85571bc7 | bellard | * THE SOFTWARE.
|
23 | 85571bc7 | bellard | */
|
24 | 85571bc7 | bellard | #ifndef QEMU_AUDIO_H
|
25 | 85571bc7 | bellard | #define QEMU_AUDIO_H
|
26 | 85571bc7 | bellard | |
27 | 5fa0ab8f | bellard | #include "config-host.h" |
28 | c0fe3827 | bellard | #include "sys-queue.h" |
29 | c0fe3827 | bellard | |
30 | 1d14ffa9 | bellard | typedef void (*audio_callback_fn_t) (void *opaque, int avail); |
31 | 85571bc7 | bellard | |
32 | 85571bc7 | bellard | typedef enum { |
33 | c0fe3827 | bellard | AUD_FMT_U8, |
34 | c0fe3827 | bellard | AUD_FMT_S8, |
35 | c0fe3827 | bellard | AUD_FMT_U16, |
36 | f941aa25 | ths | AUD_FMT_S16, |
37 | f941aa25 | ths | AUD_FMT_U32, |
38 | f941aa25 | ths | AUD_FMT_S32 |
39 | 85571bc7 | bellard | } audfmt_e; |
40 | 85571bc7 | bellard | |
41 | d929eba5 | bellard | #ifdef WORDS_BIGENDIAN
|
42 | d929eba5 | bellard | #define AUDIO_HOST_ENDIANNESS 1 |
43 | d929eba5 | bellard | #else
|
44 | d929eba5 | bellard | #define AUDIO_HOST_ENDIANNESS 0 |
45 | d929eba5 | bellard | #endif
|
46 | d929eba5 | bellard | |
47 | c0fe3827 | bellard | typedef struct { |
48 | c0fe3827 | bellard | int freq;
|
49 | c0fe3827 | bellard | int nchannels;
|
50 | c0fe3827 | bellard | audfmt_e fmt; |
51 | d929eba5 | bellard | int endianness;
|
52 | c0fe3827 | bellard | } audsettings_t; |
53 | c0fe3827 | bellard | |
54 | ec36b695 | bellard | typedef enum { |
55 | ec36b695 | bellard | AUD_CNOTIFY_ENABLE, |
56 | ec36b695 | bellard | AUD_CNOTIFY_DISABLE |
57 | ec36b695 | bellard | } audcnotification_e; |
58 | ec36b695 | bellard | |
59 | 8ead62cf | bellard | struct audio_capture_ops {
|
60 | ec36b695 | bellard | void (*notify) (void *opaque, audcnotification_e cmd); |
61 | 8ead62cf | bellard | void (*capture) (void *opaque, void *buf, int size); |
62 | ec36b695 | bellard | void (*destroy) (void *opaque); |
63 | 8ead62cf | bellard | }; |
64 | 8ead62cf | bellard | |
65 | ec36b695 | bellard | struct capture_ops {
|
66 | ec36b695 | bellard | void (*info) (void *opaque); |
67 | ec36b695 | bellard | void (*destroy) (void *opaque); |
68 | ec36b695 | bellard | }; |
69 | ec36b695 | bellard | |
70 | ec36b695 | bellard | typedef struct CaptureState { |
71 | ec36b695 | bellard | void *opaque;
|
72 | ec36b695 | bellard | struct capture_ops ops;
|
73 | ec36b695 | bellard | LIST_ENTRY (CaptureState) entries; |
74 | ec36b695 | bellard | } CaptureState; |
75 | ec36b695 | bellard | |
76 | 1d14ffa9 | bellard | typedef struct SWVoiceOut SWVoiceOut; |
77 | ec36b695 | bellard | typedef struct CaptureVoiceOut CaptureVoiceOut; |
78 | 1d14ffa9 | bellard | typedef struct SWVoiceIn SWVoiceIn; |
79 | 1d14ffa9 | bellard | |
80 | c0fe3827 | bellard | typedef struct QEMUSoundCard { |
81 | c0fe3827 | bellard | AudioState *audio; |
82 | c0fe3827 | bellard | char *name;
|
83 | c0fe3827 | bellard | LIST_ENTRY (QEMUSoundCard) entries; |
84 | c0fe3827 | bellard | } QEMUSoundCard; |
85 | c0fe3827 | bellard | |
86 | 1d14ffa9 | bellard | typedef struct QEMUAudioTimeStamp { |
87 | 1d14ffa9 | bellard | uint64_t old_ts; |
88 | 1d14ffa9 | bellard | } QEMUAudioTimeStamp; |
89 | 1d14ffa9 | bellard | |
90 | 1d14ffa9 | bellard | void AUD_vlog (const char *cap, const char *fmt, va_list ap); |
91 | 1d14ffa9 | bellard | void AUD_log (const char *cap, const char *fmt, ...) |
92 | 1d14ffa9 | bellard | #ifdef __GNUC__
|
93 | 1d14ffa9 | bellard | __attribute__ ((__format__ (__printf__, 2, 3))) |
94 | 1d14ffa9 | bellard | #endif
|
95 | 1d14ffa9 | bellard | ; |
96 | 85571bc7 | bellard | |
97 | c0fe3827 | bellard | AudioState *AUD_init (void);
|
98 | 1d14ffa9 | bellard | void AUD_help (void); |
99 | c0fe3827 | bellard | void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card); |
100 | c0fe3827 | bellard | void AUD_remove_card (QEMUSoundCard *card);
|
101 | ec36b695 | bellard | CaptureVoiceOut *AUD_add_capture ( |
102 | 8ead62cf | bellard | AudioState *s, |
103 | 8ead62cf | bellard | audsettings_t *as, |
104 | 8ead62cf | bellard | struct audio_capture_ops *ops,
|
105 | 8ead62cf | bellard | void *opaque
|
106 | 8ead62cf | bellard | ); |
107 | ec36b695 | bellard | void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque); |
108 | 1d14ffa9 | bellard | |
109 | c0fe3827 | bellard | SWVoiceOut *AUD_open_out ( |
110 | c0fe3827 | bellard | QEMUSoundCard *card, |
111 | 1d14ffa9 | bellard | SWVoiceOut *sw, |
112 | 1d14ffa9 | bellard | const char *name, |
113 | 1d14ffa9 | bellard | void *callback_opaque,
|
114 | 1d14ffa9 | bellard | audio_callback_fn_t callback_fn, |
115 | d929eba5 | bellard | audsettings_t *settings |
116 | 1d14ffa9 | bellard | ); |
117 | c0fe3827 | bellard | |
118 | c0fe3827 | bellard | void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
|
119 | c0fe3827 | bellard | int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size); |
120 | c0fe3827 | bellard | int AUD_get_buffer_size_out (SWVoiceOut *sw);
|
121 | c0fe3827 | bellard | void AUD_set_active_out (SWVoiceOut *sw, int on); |
122 | c0fe3827 | bellard | int AUD_is_active_out (SWVoiceOut *sw);
|
123 | c0fe3827 | bellard | |
124 | c0fe3827 | bellard | void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
|
125 | c0fe3827 | bellard | uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); |
126 | c0fe3827 | bellard | |
127 | 683efdcb | balrog | void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol); |
128 | 683efdcb | balrog | void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol); |
129 | 683efdcb | balrog | |
130 | c0fe3827 | bellard | SWVoiceIn *AUD_open_in ( |
131 | c0fe3827 | bellard | QEMUSoundCard *card, |
132 | 1d14ffa9 | bellard | SWVoiceIn *sw, |
133 | 1d14ffa9 | bellard | const char *name, |
134 | 1d14ffa9 | bellard | void *callback_opaque,
|
135 | 1d14ffa9 | bellard | audio_callback_fn_t callback_fn, |
136 | d929eba5 | bellard | audsettings_t *settings |
137 | 1d14ffa9 | bellard | ); |
138 | c0fe3827 | bellard | |
139 | c0fe3827 | bellard | void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
|
140 | c0fe3827 | bellard | int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size); |
141 | c0fe3827 | bellard | void AUD_set_active_in (SWVoiceIn *sw, int on); |
142 | c0fe3827 | bellard | int AUD_is_active_in (SWVoiceIn *sw);
|
143 | c0fe3827 | bellard | |
144 | c0fe3827 | bellard | void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
|
145 | c0fe3827 | bellard | uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); |
146 | 85571bc7 | bellard | |
147 | 85571bc7 | bellard | static inline void *advance (void *p, int incr) |
148 | 85571bc7 | bellard | { |
149 | 85571bc7 | bellard | uint8_t *d = p; |
150 | 85571bc7 | bellard | return (d + incr);
|
151 | 85571bc7 | bellard | } |
152 | 85571bc7 | bellard | |
153 | 85571bc7 | bellard | uint32_t popcount (uint32_t u); |
154 | 8ead62cf | bellard | uint32_t lsbindex (uint32_t u); |
155 | 85571bc7 | bellard | |
156 | 1d14ffa9 | bellard | #ifdef __GNUC__
|
157 | 1d14ffa9 | bellard | #define audio_MIN(a, b) ( __extension__ ({ \
|
158 | 1d14ffa9 | bellard | __typeof (a) ta = a; \ |
159 | 1d14ffa9 | bellard | __typeof (b) tb = b; \ |
160 | 1d14ffa9 | bellard | ((ta)>(tb)?(tb):(ta)); \ |
161 | 1d14ffa9 | bellard | })) |
162 | 1d14ffa9 | bellard | |
163 | 1d14ffa9 | bellard | #define audio_MAX(a, b) ( __extension__ ({ \
|
164 | 1d14ffa9 | bellard | __typeof (a) ta = a; \ |
165 | 1d14ffa9 | bellard | __typeof (b) tb = b; \ |
166 | 1d14ffa9 | bellard | ((ta)<(tb)?(tb):(ta)); \ |
167 | 1d14ffa9 | bellard | })) |
168 | 1d14ffa9 | bellard | #else
|
169 | 85571bc7 | bellard | #define audio_MIN(a, b) ((a)>(b)?(b):(a))
|
170 | 85571bc7 | bellard | #define audio_MAX(a, b) ((a)<(b)?(b):(a))
|
171 | 1d14ffa9 | bellard | #endif
|
172 | 85571bc7 | bellard | |
173 | 85571bc7 | bellard | #endif /* audio.h */ |