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