• 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-host.h"
28 #include "qemu-queue.h"
29 #include "qemu-common.h"  /* For QEMUTimer */
30 
31 typedef void (*audio_callback_fn) (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 HOST_WORDS_BIGENDIAN
43 #define AUDIO_HOST_ENDIANNESS 1
44 #else
45 #define AUDIO_HOST_ENDIANNESS 0
46 #endif
47 
48 struct audsettings {
49     int freq;
50     int nchannels;
51     audfmt_e fmt;
52     int endianness;
53 };
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     QLIST_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     char *name;
83     QLIST_ENTRY (QEMUSoundCard) entries;
84 } QEMUSoundCard;
85 
86 typedef struct QEMUAudioTimeStamp {
87     uint64_t old_ts;
88 } QEMUAudioTimeStamp;
89 
90 void AUD_vlog (const char *cap, const char *fmt, va_list ap);
91 void AUD_log (const char *cap, const char *fmt, ...)
92 #ifdef __GNUC__
93     __attribute__ ((__format__ (__printf__, 2, 3)))
94 #endif
95     ;
96 
97 void AUD_help (void);
98 void AUD_register_card (const char *name, QEMUSoundCard *card);
99 void AUD_remove_card (QEMUSoundCard *card);
100 CaptureVoiceOut *AUD_add_capture (
101     struct audsettings *as,
102     struct audio_capture_ops *ops,
103     void *opaque
104     );
105 void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
106 
107 SWVoiceOut *AUD_open_out (
108     QEMUSoundCard *card,
109     SWVoiceOut *sw,
110     const char *name,
111     void *callback_opaque,
112     audio_callback_fn callback_fn,
113     struct audsettings *settings
114     );
115 
116 void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
117 int  AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
118 int  AUD_get_buffer_size_out (SWVoiceOut *sw);
119 void AUD_set_active_out (SWVoiceOut *sw, int on);
120 int  AUD_is_active_out (SWVoiceOut *sw);
121 
122 void     AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
123 uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
124 
125 void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol);
126 void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol);
127 
128 SWVoiceIn *AUD_open_in (
129     QEMUSoundCard *card,
130     SWVoiceIn *sw,
131     const char *name,
132     void *callback_opaque,
133     audio_callback_fn callback_fn,
134     struct audsettings *settings
135     );
136 
137 void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
138 int  AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
139 void AUD_set_active_in (SWVoiceIn *sw, int on);
140 int  AUD_is_active_in (SWVoiceIn *sw);
141 
142 void     AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
143 uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
144 
advance(void * p,int incr)145 static inline void *advance (void *p, int incr)
146 {
147     uint8_t *d = p;
148     return (d + incr);
149 }
150 
151 #ifdef __GNUC__
152 #define audio_MIN(a, b) ( __extension__ ({      \
153     __typeof (a) ta = a;                        \
154     __typeof (b) tb = b;                        \
155     ((ta)>(tb)?(tb):(ta));                      \
156 }))
157 
158 #define audio_MAX(a, b) ( __extension__ ({      \
159     __typeof (a) ta = a;                        \
160     __typeof (b) tb = b;                        \
161     ((ta)<(tb)?(tb):(ta));                      \
162 }))
163 #else
164 #define audio_MIN(a, b) ((a)>(b)?(b):(a))
165 #define audio_MAX(a, b) ((a)<(b)?(b):(a))
166 #endif
167 
168 int wav_start_capture (CaptureState *s, const char *path, int freq,
169                        int bits, int nchannels);
170 
171 extern int
172 audio_get_backend_count( int  is_input );
173 
174 extern const char*
175 audio_get_backend_name( int   is_input, int  index, const char*  *pinfo );
176 
177 extern int
178 audio_check_backend_name( int  is_input, const char*  name );
179 
180 #endif  /* audio.h */
181