]>
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 | ||
8ead62cf FB |
52 | struct audio_capture_ops { |
53 | void (*state) (void *opaque, int enabled); | |
54 | void (*capture) (void *opaque, void *buf, int size); | |
55 | }; | |
56 | ||
c0fe3827 | 57 | typedef struct AudioState AudioState; |
1d14ffa9 FB |
58 | typedef struct SWVoiceOut SWVoiceOut; |
59 | typedef struct SWVoiceIn SWVoiceIn; | |
60 | ||
c0fe3827 FB |
61 | typedef struct QEMUSoundCard { |
62 | AudioState *audio; | |
63 | char *name; | |
64 | LIST_ENTRY (QEMUSoundCard) entries; | |
65 | } QEMUSoundCard; | |
66 | ||
1d14ffa9 FB |
67 | typedef struct QEMUAudioTimeStamp { |
68 | uint64_t old_ts; | |
69 | } QEMUAudioTimeStamp; | |
70 | ||
71 | void AUD_vlog (const char *cap, const char *fmt, va_list ap); | |
72 | void AUD_log (const char *cap, const char *fmt, ...) | |
73 | #ifdef __GNUC__ | |
74 | __attribute__ ((__format__ (__printf__, 2, 3))) | |
75 | #endif | |
76 | ; | |
85571bc7 | 77 | |
c0fe3827 | 78 | AudioState *AUD_init (void); |
1d14ffa9 | 79 | void AUD_help (void); |
c0fe3827 FB |
80 | void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card); |
81 | void AUD_remove_card (QEMUSoundCard *card); | |
8ead62cf FB |
82 | int AUD_add_capture ( |
83 | AudioState *s, | |
84 | audsettings_t *as, | |
8ead62cf FB |
85 | struct audio_capture_ops *ops, |
86 | void *opaque | |
87 | ); | |
1d14ffa9 | 88 | |
c0fe3827 FB |
89 | SWVoiceOut *AUD_open_out ( |
90 | QEMUSoundCard *card, | |
1d14ffa9 FB |
91 | SWVoiceOut *sw, |
92 | const char *name, | |
93 | void *callback_opaque, | |
94 | audio_callback_fn_t callback_fn, | |
d929eba5 | 95 | audsettings_t *settings |
1d14ffa9 | 96 | ); |
c0fe3827 FB |
97 | |
98 | void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw); | |
99 | int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size); | |
100 | int AUD_get_buffer_size_out (SWVoiceOut *sw); | |
101 | void AUD_set_active_out (SWVoiceOut *sw, int on); | |
102 | int AUD_is_active_out (SWVoiceOut *sw); | |
103 | ||
104 | void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); | |
105 | uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts); | |
106 | ||
107 | SWVoiceIn *AUD_open_in ( | |
108 | QEMUSoundCard *card, | |
1d14ffa9 FB |
109 | SWVoiceIn *sw, |
110 | const char *name, | |
111 | void *callback_opaque, | |
112 | audio_callback_fn_t callback_fn, | |
d929eba5 | 113 | audsettings_t *settings |
1d14ffa9 | 114 | ); |
c0fe3827 FB |
115 | |
116 | void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw); | |
117 | int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size); | |
118 | void AUD_set_active_in (SWVoiceIn *sw, int on); | |
119 | int AUD_is_active_in (SWVoiceIn *sw); | |
120 | ||
121 | void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); | |
122 | uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts); | |
85571bc7 FB |
123 | |
124 | static inline void *advance (void *p, int incr) | |
125 | { | |
126 | uint8_t *d = p; | |
127 | return (d + incr); | |
128 | } | |
129 | ||
130 | uint32_t popcount (uint32_t u); | |
8ead62cf | 131 | uint32_t lsbindex (uint32_t u); |
85571bc7 | 132 | |
1d14ffa9 FB |
133 | #ifdef __GNUC__ |
134 | #define audio_MIN(a, b) ( __extension__ ({ \ | |
135 | __typeof (a) ta = a; \ | |
136 | __typeof (b) tb = b; \ | |
137 | ((ta)>(tb)?(tb):(ta)); \ | |
138 | })) | |
139 | ||
140 | #define audio_MAX(a, b) ( __extension__ ({ \ | |
141 | __typeof (a) ta = a; \ | |
142 | __typeof (b) tb = b; \ | |
143 | ((ta)<(tb)?(tb):(ta)); \ | |
144 | })) | |
145 | #else | |
85571bc7 FB |
146 | #define audio_MIN(a, b) ((a)>(b)?(b):(a)) |
147 | #define audio_MAX(a, b) ((a)<(b)?(b):(a)) | |
1d14ffa9 | 148 | #endif |
85571bc7 FB |
149 | |
150 | #endif /* audio.h */ |