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