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